{
  "version": 3,
  "sources": ["../../../../src/packages/lockfile.verification/localTarballDepsAreUpToDate.ts"],
  "sourcesContent": ["import { getTarballIntegrity } from '../crypto.hash/index.ts';\nimport { refToRelative } from '../dependency-path/index.ts';\nimport type {\n  ProjectSnapshot,\n  PackageSnapshots,\n} from '../lockfile.types/index.ts';\nimport { refIsLocalTarball } from '../lockfile.utils/index.ts';\nimport { DEPENDENCIES_FIELDS } from '../types/index.ts';\nimport path from 'node:path';\nimport pEvery from 'p-every';\nimport type { TarballResolution } from '../resolver-base/index.ts';\n\nexport type LocalTarballDepsUpToDateContext = {\n  /**\n   * Local cache of local absolute file paths to their integrity. Expected to be\n   * initialized to an empty map by the caller.\n   */\n  readonly fileIntegrityCache: Map<string, Promise<string>>;\n  readonly lockfilePackages?: PackageSnapshots | undefined;\n  readonly lockfileDir: string;\n};\n\n/**\n * Returns false if a local tarball file has been changed on disk since the last\n * installation recorded by the project snapshot.\n *\n * This function only inspects the project's lockfile snapshot. It does not\n * inspect the current project manifest. The caller of this function is expected\n * to handle changes to the project manifest that would cause the corresponding\n * project snapshot to become out of date.\n */\nexport async function localTarballDepsAreUpToDate(\n  {\n    fileIntegrityCache,\n    lockfilePackages,\n    lockfileDir,\n  }: LocalTarballDepsUpToDateContext,\n  project: {\n    snapshot: ProjectSnapshot;\n  }\n): Promise<boolean> {\n  return pEvery.default(\n    DEPENDENCIES_FIELDS,\n    (depField: 'optionalDependencies' | 'dependencies' | 'devDependencies') => {\n      const lockfileDeps = project.snapshot[depField];\n\n      // If the lockfile is missing a snapshot for this project's dependencies, we\n      // can return true. The \"satisfiesPackageManifest\" logic in\n      // \"allProjectsAreUpToDate\" will catch mismatches between a project's\n      // manifest and snapshot dependencies size.\n      if (lockfileDeps == null) {\n        return true;\n      }\n\n      return pEvery.default(\n        Object.entries(lockfileDeps),\n        async ([depName, ref]: [string, string]): Promise<boolean> => {\n          if (!refIsLocalTarball(ref)) {\n            return true;\n          }\n\n          const depPath = refToRelative(ref, depName);\n\n          const packageSnapshot =\n            depPath != null ? lockfilePackages?.[depPath] : null;\n\n          // If there's no snapshot for this local tarball yet, the project is out\n          // of date and needs to be resolved. This should only happen with a\n          // broken lockfile.\n          if (packageSnapshot == null) {\n            return false;\n          }\n\n          const filePath = path.join(lockfileDir, ref.slice('file:'.length));\n\n          const fileIntegrityPromise =\n            fileIntegrityCache.get(filePath) ?? getTarballIntegrity(filePath);\n          if (!fileIntegrityCache.has(filePath)) {\n            fileIntegrityCache.set(filePath, fileIntegrityPromise);\n          }\n\n          let fileIntegrity: string;\n          try {\n            fileIntegrity = await fileIntegrityPromise;\n            // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars\n          } catch (_err: any) {\n            // If there was an error reading the tarball, assume the lockfile is\n            // out of date. The full resolution process will emit a clearer error\n            // later during install.\n            return false;\n          }\n\n          return (\n            (packageSnapshot.resolution as TarballResolution).integrity ===\n            fileIntegrity\n          );\n        }\n      );\n    }\n  );\n}\n"],
  "mappings": "AAAA,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAK9B,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,OAAO,UAAU;AACjB,OAAO,YAAY;AAsBnB,eAAsB,4BACpB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF,GACA,SAGkB;AAClB,SAAO,OAAO;AAAA,IACZ;AAAA,IACA,CAAC,aAA0E;AACzE,YAAM,eAAe,QAAQ,SAAS,QAAQ;AAM9C,UAAI,gBAAgB,MAAM;AACxB,eAAO;AAAA,MACT;AAEA,aAAO,OAAO;AAAA,QACZ,OAAO,QAAQ,YAAY;AAAA,QAC3B,OAAO,CAAC,SAAS,GAAG,MAA0C;AAC5D,cAAI,CAAC,kBAAkB,GAAG,GAAG;AAC3B,mBAAO;AAAA,UACT;AAEA,gBAAM,UAAU,cAAc,KAAK,OAAO;AAE1C,gBAAM,kBACJ,WAAW,OAAO,mBAAmB,OAAO,IAAI;AAKlD,cAAI,mBAAmB,MAAM;AAC3B,mBAAO;AAAA,UACT;AAEA,gBAAM,WAAW,KAAK,KAAK,aAAa,IAAI,MAAM,QAAQ,MAAM,CAAC;AAEjE,gBAAM,uBACJ,mBAAmB,IAAI,QAAQ,KAAK,oBAAoB,QAAQ;AAClE,cAAI,CAAC,mBAAmB,IAAI,QAAQ,GAAG;AACrC,+BAAmB,IAAI,UAAU,oBAAoB;AAAA,UACvD;AAEA,cAAI;AACJ,cAAI;AACF,4BAAgB,MAAM;AAAA,UAExB,SAAS,MAAW;AAIlB,mBAAO;AAAA,UACT;AAEA,iBACG,gBAAgB,WAAiC,cAClD;AAAA,QAEJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
  "names": []
}
