{
  "version": 3,
  "sources": ["../../../../src/packages/plugin-commands-store-inspecting/catFile.ts"],
  "sourcesContent": ["import path from 'node:path';\nimport util from 'node:util';\n\nimport type { Config } from '../config/index.ts';\nimport { PnpmError } from '../error/index.ts';\nimport gfs from '../graceful-fs/index.ts';\nimport { getStorePath } from '../store-path/index.ts';\n\nimport renderHelp from 'render-help';\n\n// eslint-disable-next-line optimize-regex/optimize-regex\nconst INTEGRITY_REGEX: RegExp = /^([^-]+)-([A-Za-z0-9+/=]+)$/;\n\nexport const skipPackageManagerCheck = true;\n\nexport const commandNames = ['cat-file'];\n\nexport const rcOptionsTypes = cliOptionsTypes;\n\nexport function cliOptionsTypes(): Record<string, unknown> {\n  return {};\n}\n\nexport function help(): string {\n  return renderHelp({\n    description:\n      'Prints the contents of a file based on the hash value stored in the index file.',\n    descriptionLists: [],\n    usages: ['pnpm cat-file <hash>'],\n  });\n}\n\nexport type CatFileCommandOptions = Pick<Config, 'storeDir' | 'pnpmHomeDir'>;\n\nexport async function handler(\n  opts: CatFileCommandOptions,\n  params: string[]\n): Promise<string> {\n  if (params.length === 0) {\n    throw new PnpmError('MISSING_HASH', 'Missing file hash', {\n      hint: help(),\n    });\n  }\n\n  if (typeof params[0] !== 'string') {\n    throw new PnpmError('INVALID_HASH', 'Invalid file hash', {\n      hint: help(),\n    });\n  }\n\n  const match = params[0].match(INTEGRITY_REGEX);\n\n  if (match === null) {\n    throw new PnpmError('INVALID_HASH', 'Invalid file hash', {\n      hint: help(),\n    });\n  }\n\n  const [, , integrityHash] = match;\n\n  if (typeof integrityHash !== 'string') {\n    throw new PnpmError('INVALID_HASH', 'Invalid file hash', {\n      hint: help(),\n    });\n  }\n\n  const toHex = Buffer.from(integrityHash, 'base64').toString('hex');\n\n  const storeDir = await getStorePath({\n    pkgRoot: process.cwd(),\n    storePath: opts.storeDir,\n    pnpmHomeDir: opts.pnpmHomeDir,\n  });\n\n  const cafsDir = path.join(storeDir, 'files');\n\n  const filePath = path.resolve(cafsDir, toHex.slice(0, 2), toHex.slice(2));\n\n  try {\n    return gfs.readFileSync(filePath, 'utf8');\n  } catch (err: unknown) {\n    if (\n      util.types.isNativeError(err) &&\n      'code' in err &&\n      err.code === 'ENOENT'\n    ) {\n      throw new PnpmError('INVALID_HASH', 'Corresponding hash file not found');\n    }\n\n    throw err;\n  }\n}\n"],
  "mappings": "AAAA,OAAO,UAAU;AACjB,OAAO,UAAU;AAGjB,SAAS,iBAAiB;AAC1B,OAAO,SAAS;AAChB,SAAS,oBAAoB;AAE7B,OAAO,gBAAgB;AAGvB,MAAM,kBAA0B;AAEzB,MAAM,0BAA0B;AAEhC,MAAM,eAAe,CAAC,UAAU;AAEhC,MAAM,iBAAiB;AAEvB,SAAS,kBAA2C;AACzD,SAAO,CAAC;AACV;AAEO,SAAS,OAAe;AAC7B,SAAO,WAAW;AAAA,IAChB,aACE;AAAA,IACF,kBAAkB,CAAC;AAAA,IACnB,QAAQ,CAAC,sBAAsB;AAAA,EACjC,CAAC;AACH;AAIA,eAAsB,QACpB,MACA,QACiB;AACjB,MAAI,OAAO,WAAW,GAAG;AACvB,UAAM,IAAI,UAAU,gBAAgB,qBAAqB;AAAA,MACvD,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AAEA,MAAI,OAAO,OAAO,CAAC,MAAM,UAAU;AACjC,UAAM,IAAI,UAAU,gBAAgB,qBAAqB;AAAA,MACvD,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AAEA,QAAM,QAAQ,OAAO,CAAC,EAAE,MAAM,eAAe;AAE7C,MAAI,UAAU,MAAM;AAClB,UAAM,IAAI,UAAU,gBAAgB,qBAAqB;AAAA,MACvD,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AAEA,QAAM,CAAC,EAAE,EAAE,aAAa,IAAI;AAE5B,MAAI,OAAO,kBAAkB,UAAU;AACrC,UAAM,IAAI,UAAU,gBAAgB,qBAAqB;AAAA,MACvD,MAAM,KAAK;AAAA,IACb,CAAC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