@rushstack/rush-resolver-cache-plugin 5.173.0 → 5.174.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/lib-commonjs/afterInstallAsync.js +19 -6
  2. package/lib-commonjs/afterInstallAsync.js.map +1 -1
  3. package/lib-commonjs/computeResolverCacheFromLockfileAsync.js +17 -11
  4. package/lib-commonjs/computeResolverCacheFromLockfileAsync.js.map +1 -1
  5. package/lib-commonjs/helpers.js +32 -70
  6. package/lib-commonjs/helpers.js.map +1 -1
  7. package/lib-commonjs/pnpm/depPath/common.js +38 -0
  8. package/lib-commonjs/pnpm/depPath/common.js.map +1 -0
  9. package/lib-commonjs/pnpm/depPath/hash.js +43 -0
  10. package/lib-commonjs/pnpm/depPath/hash.js.map +1 -0
  11. package/lib-commonjs/pnpm/depPath/v10.js +15 -0
  12. package/lib-commonjs/pnpm/depPath/v10.js.map +1 -0
  13. package/lib-commonjs/pnpm/depPath/v8.js +26 -0
  14. package/lib-commonjs/pnpm/depPath/v8.js.map +1 -0
  15. package/lib-commonjs/pnpm/depPath/v9.js +15 -0
  16. package/lib-commonjs/pnpm/depPath/v9.js.map +1 -0
  17. package/lib-commonjs/pnpm/keys/v6.js +10 -0
  18. package/lib-commonjs/pnpm/keys/v6.js.map +1 -0
  19. package/lib-commonjs/pnpm/keys/v9.js +10 -0
  20. package/lib-commonjs/pnpm/keys/v9.js.map +1 -0
  21. package/lib-commonjs/pnpm/pnpmVersionHelpers.js +55 -0
  22. package/lib-commonjs/pnpm/pnpmVersionHelpers.js.map +1 -0
  23. package/lib-commonjs/pnpm/store/v10.js +38 -0
  24. package/lib-commonjs/pnpm/store/v10.js.map +1 -0
  25. package/lib-commonjs/pnpm/store/v3.js +10 -0
  26. package/lib-commonjs/pnpm/store/v3.js.map +1 -0
  27. package/lib-commonjs/pnpm/v10.js +14 -0
  28. package/lib-commonjs/pnpm/v10.js.map +1 -0
  29. package/lib-commonjs/pnpm/v8.js +14 -0
  30. package/lib-commonjs/pnpm/v8.js.map +1 -0
  31. package/lib-commonjs/pnpm/v9.js +16 -0
  32. package/lib-commonjs/pnpm/v9.js.map +1 -0
  33. package/lib-commonjs/types.js.map +1 -1
  34. package/lib-dts/afterInstallAsync.d.ts.map +1 -1
  35. package/lib-dts/computeResolverCacheFromLockfileAsync.d.ts +7 -0
  36. package/lib-dts/computeResolverCacheFromLockfileAsync.d.ts.map +1 -1
  37. package/lib-dts/helpers.d.ts +17 -9
  38. package/lib-dts/helpers.d.ts.map +1 -1
  39. package/lib-dts/pnpm/depPath/common.d.ts +8 -0
  40. package/lib-dts/pnpm/depPath/common.d.ts.map +1 -0
  41. package/lib-dts/pnpm/depPath/hash.d.ts +3 -0
  42. package/lib-dts/pnpm/depPath/hash.d.ts.map +1 -0
  43. package/lib-dts/pnpm/depPath/v10.d.ts +2 -0
  44. package/lib-dts/pnpm/depPath/v10.d.ts.map +1 -0
  45. package/lib-dts/pnpm/depPath/v8.d.ts +2 -0
  46. package/lib-dts/pnpm/depPath/v8.d.ts.map +1 -0
  47. package/lib-dts/pnpm/depPath/v9.d.ts +2 -0
  48. package/lib-dts/pnpm/depPath/v9.d.ts.map +1 -0
  49. package/lib-dts/pnpm/keys/v6.d.ts +2 -0
  50. package/lib-dts/pnpm/keys/v6.d.ts.map +1 -0
  51. package/lib-dts/pnpm/keys/v9.d.ts +2 -0
  52. package/lib-dts/pnpm/keys/v9.d.ts.map +1 -0
  53. package/lib-dts/pnpm/pnpmVersionHelpers.d.ts +38 -0
  54. package/lib-dts/pnpm/pnpmVersionHelpers.d.ts.map +1 -0
  55. package/lib-dts/pnpm/store/v10.d.ts +3 -0
  56. package/lib-dts/pnpm/store/v10.d.ts.map +1 -0
  57. package/lib-dts/pnpm/store/v3.d.ts +3 -0
  58. package/lib-dts/pnpm/store/v3.d.ts.map +1 -0
  59. package/lib-dts/pnpm/v10.d.ts +3 -0
  60. package/lib-dts/pnpm/v10.d.ts.map +1 -0
  61. package/lib-dts/pnpm/v8.d.ts +3 -0
  62. package/lib-dts/pnpm/v8.d.ts.map +1 -0
  63. package/lib-dts/pnpm/v9.d.ts +3 -0
  64. package/lib-dts/pnpm/v9.d.ts.map +1 -0
  65. package/lib-dts/types.d.ts +1 -0
  66. package/lib-dts/types.d.ts.map +1 -1
  67. package/lib-esm/afterInstallAsync.js +19 -6
  68. package/lib-esm/afterInstallAsync.js.map +1 -1
  69. package/lib-esm/computeResolverCacheFromLockfileAsync.js +18 -12
  70. package/lib-esm/computeResolverCacheFromLockfileAsync.js.map +1 -1
  71. package/lib-esm/helpers.js +31 -67
  72. package/lib-esm/helpers.js.map +1 -1
  73. package/lib-esm/pnpm/depPath/common.js +34 -0
  74. package/lib-esm/pnpm/depPath/common.js.map +1 -0
  75. package/lib-esm/pnpm/depPath/hash.js +39 -0
  76. package/lib-esm/pnpm/depPath/hash.js.map +1 -0
  77. package/lib-esm/pnpm/depPath/v10.js +12 -0
  78. package/lib-esm/pnpm/depPath/v10.js.map +1 -0
  79. package/lib-esm/pnpm/depPath/v8.js +23 -0
  80. package/lib-esm/pnpm/depPath/v8.js.map +1 -0
  81. package/lib-esm/pnpm/depPath/v9.js +12 -0
  82. package/lib-esm/pnpm/depPath/v9.js.map +1 -0
  83. package/lib-esm/pnpm/keys/v6.js +7 -0
  84. package/lib-esm/pnpm/keys/v6.js.map +1 -0
  85. package/lib-esm/pnpm/keys/v9.js +7 -0
  86. package/lib-esm/pnpm/keys/v9.js.map +1 -0
  87. package/lib-esm/pnpm/pnpmVersionHelpers.js +19 -0
  88. package/lib-esm/pnpm/pnpmVersionHelpers.js.map +1 -0
  89. package/lib-esm/pnpm/store/v10.js +35 -0
  90. package/lib-esm/pnpm/store/v10.js.map +1 -0
  91. package/lib-esm/pnpm/store/v3.js +7 -0
  92. package/lib-esm/pnpm/store/v3.js.map +1 -0
  93. package/lib-esm/pnpm/v10.js +11 -0
  94. package/lib-esm/pnpm/v10.js.map +1 -0
  95. package/lib-esm/pnpm/v8.js +11 -0
  96. package/lib-esm/pnpm/v8.js.map +1 -0
  97. package/lib-esm/pnpm/v9.js +13 -0
  98. package/lib-esm/pnpm/v9.js.map +1 -0
  99. package/lib-esm/types.js.map +1 -1
  100. package/package.json +5 -5
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.afterInstallAsync = afterInstallAsync;
6
6
  const externals_1 = require("./externals");
7
7
  const computeResolverCacheFromLockfileAsync_1 = require("./computeResolverCacheFromLockfileAsync");
8
+ const pnpmVersionHelpers_1 = require("./pnpm/pnpmVersionHelpers");
8
9
  /**
9
10
  * Gets information used to determine compatibility of optional dependencies.
10
11
  * @returns Information about the platform Rush is running on
@@ -37,9 +38,23 @@ async function afterInstallAsync(rushSession, rushConfiguration, subspace, varia
37
38
  const { terminal } = logger;
38
39
  const rushRoot = `${rushConfiguration.rushJsonFolder}/`;
39
40
  const lockFilePath = subspace.getCommittedShrinkwrapFilePath(variant);
40
- const pnpmStoreDir = `${rushConfiguration.pnpmOptions.pnpmStorePath}/v3/files/`;
41
+ const pnpmStorePath = rushConfiguration.pnpmOptions.pnpmStorePath;
42
+ const pnpmMajorVersion = (() => {
43
+ const major = parseInt(rushConfiguration.packageManagerToolVersion, 10);
44
+ switch (major) {
45
+ case 10:
46
+ return 10;
47
+ case 9:
48
+ return 9;
49
+ case 8:
50
+ return 8;
51
+ default:
52
+ throw new Error(`Unsupported pnpm major version: ${major}`);
53
+ }
54
+ })();
55
+ const pnpmHelpers = await (0, pnpmVersionHelpers_1.getPnpmVersionHelpersAsync)(pnpmMajorVersion);
41
56
  terminal.writeLine(`Using pnpm-lock from: ${lockFilePath}`);
42
- terminal.writeLine(`Using pnpm store folder: ${pnpmStoreDir}`);
57
+ terminal.writeLine(`Using pnpm ${pnpmMajorVersion} store at: ${pnpmStorePath}`);
43
58
  const workspaceRoot = subspace.getSubspaceTempFolderPath();
44
59
  const cacheFilePath = `${workspaceRoot}/resolver-cache.json`;
45
60
  const lockFile = externals_1.PnpmShrinkwrapFile.loadFromFile(lockFilePath, {
@@ -102,10 +117,7 @@ async function afterInstallAsync(rushSession, rushConfiguration, subspace, varia
102
117
  // 0baba219027e1ade11c875d762dfaff5ff92375bfcdf1ebc511c20c4d43df1cbc7f24c62bb2c1618fe1778d675a5a3b367adda6377137220844093455258e52f
103
118
  const prefixIndex = descriptionFileHash.indexOf('-');
104
119
  const hash = Buffer.from(descriptionFileHash.slice(prefixIndex + 1), 'base64').toString('hex');
105
- // The pnpm store directory has index files of package contents at paths:
106
- // <store>/v3/files/<hash (0-2)>/<hash (2-)>-index.json
107
- // See https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/store/cafs/src/getFilePathInCafs.ts#L33
108
- const indexPath = `${pnpmStoreDir}${hash.slice(0, 2)}/${hash.slice(2)}-index.json`;
120
+ const indexPath = pnpmHelpers.getStoreIndexPath(pnpmStorePath, context, hash);
109
121
  try {
110
122
  const indexContent = await externals_1.FileSystem.readFileAsync(indexPath);
111
123
  let endIndex = indexContent.lastIndexOf(END_TOKEN);
@@ -177,6 +189,7 @@ async function afterInstallAsync(rushSession, rushConfiguration, subspace, varia
177
189
  platformInfo: getPlatformInfo(),
178
190
  projectByImporterPath,
179
191
  lockfile: lockFile,
192
+ pnpmVersion: pnpmMajorVersion,
180
193
  afterExternalPackagesAsync
181
194
  });
182
195
  const extendedCacheFile = {
@@ -1 +1 @@
1
- {"version":3,"file":"afterInstallAsync.js","sourceRoot":"","sources":["../src/afterInstallAsync.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAoE3D,8CAyNC;AAjRD,2CAAoE;AACpE,mGAGiD;AAGjD;;;GAGG;AACH,SAAS,eAAe;;IACtB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,EACJ,QAAQ,EAAE,EAAE,EACZ,IAAI,EAAE,GAAG,EACT,mBAAmB;IACnB,8DAA8D;MAC/D,GAAG,MAAA,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AW,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAE7E,MAAM,UAAU,GAAW,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAE7D,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,sBAAU,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE;YACnD,kBAAkB,EAAE,IAAI;SACzB,CAAC;QACF,sBAAU,CAAC,cAAc,CAAC,uBAAuB,EAAE,yBAAyB,EAAE;YAC5E,kBAAkB,EAAE,IAAI;SACzB,CAAC;KACH,CAAC,CAAC;IAEH,oGAAoG;IACpG,8BAAkB,CAAC,UAAU,EAAE,CAAC;IAEhC,QAAQ,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type {\n RushSession,\n RushConfiguration,\n RushConfigurationProject,\n ILogger,\n LookupByPath,\n Subspace\n} from '@rushstack/rush-sdk';\nimport type { IResolverCacheFile } from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport { Async, FileSystem, PnpmShrinkwrapFile } from './externals';\nimport {\n computeResolverCacheFromLockfileAsync,\n type IPlatformInfo\n} from './computeResolverCacheFromLockfileAsync';\nimport type { IResolverContext } from './types';\n\n/**\n * Gets information used to determine compatibility of optional dependencies.\n * @returns Information about the platform Rush is running on\n */\nfunction getPlatformInfo(): IPlatformInfo {\n // Acquiring the libc version is a bit more obnoxious than platform and arch,\n // but all of them are ultimately on the same object.\n const {\n platform: os,\n arch: cpu,\n glibcVersionRuntime\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } = (process.report?.getReport() as any)?.header ?? process;\n const libc: 'glibc' | 'musl' = glibcVersionRuntime ? 'glibc' : 'musl';\n\n return {\n os,\n cpu,\n libc\n };\n}\n\nconst END_TOKEN: string = '/package.json\":';\nconst RESOLVER_CACHE_FILE_VERSION: 2 = 2;\n\ninterface IExtendedResolverCacheFile extends IResolverCacheFile {\n /**\n * The hash of the shrinkwrap file this cache file was generated from.\n */\n shrinkwrapHash: string;\n /**\n * The version of the resolver cache file.\n */\n version: number;\n}\n\ninterface INestedPackageJsonCache {\n subPackagesByIntegrity: [string, string[] | boolean][];\n version: number;\n}\n\n/**\n * Plugin entry point for after install.\n * @param rushSession - The Rush Session\n * @param rushConfiguration - The Rush Configuration\n * @param subspace - The subspace that was just installed\n * @param variant - The variant that was just installed\n * @param logger - The initialized logger\n */\nexport async function afterInstallAsync(\n rushSession: RushSession,\n rushConfiguration: RushConfiguration,\n subspace: Subspace,\n variant: string | undefined,\n logger: ILogger\n): Promise<void> {\n const { terminal } = logger;\n const rushRoot: string = `${rushConfiguration.rushJsonFolder}/`;\n\n const lockFilePath: string = subspace.getCommittedShrinkwrapFilePath(variant);\n\n const pnpmStoreDir: string = `${rushConfiguration.pnpmOptions.pnpmStorePath}/v3/files/`;\n\n terminal.writeLine(`Using pnpm-lock from: ${lockFilePath}`);\n terminal.writeLine(`Using pnpm store folder: ${pnpmStoreDir}`);\n\n const workspaceRoot: string = subspace.getSubspaceTempFolderPath();\n const cacheFilePath: string = `${workspaceRoot}/resolver-cache.json`;\n\n const lockFile: PnpmShrinkwrapFile | undefined = PnpmShrinkwrapFile.loadFromFile(lockFilePath, {\n withCaching: true,\n subspaceHasNoProjects: subspace.getProjects().length === 0\n });\n if (!lockFile) {\n throw new Error(`Failed to load shrinkwrap file: ${lockFilePath}`);\n }\n\n if (!lockFile.hash) {\n throw new Error(\n `Shrinkwrap file does not have a hash. This indicates linking to an old version of Rush.`\n );\n }\n\n try {\n const oldCacheFileContent: string = await FileSystem.readFileAsync(cacheFilePath);\n const oldCache: IExtendedResolverCacheFile = JSON.parse(oldCacheFileContent);\n if (oldCache.version === RESOLVER_CACHE_FILE_VERSION && oldCache.shrinkwrapHash === lockFile.hash) {\n // Cache is valid, use it\n return;\n }\n } catch (err) {\n // Ignore\n }\n\n const projectByImporterPath: LookupByPath<RushConfigurationProject> =\n rushConfiguration.getProjectLookupForRoot(workspaceRoot);\n\n const subPackageCacheFilePath: string = `${workspaceRoot}/subpackage-entry-cache.json`;\n\n terminal.writeLine(`Resolver cache will be written at ${cacheFilePath}`);\n\n let oldSubPackagesByIntegrity: Map<string, string[] | boolean> | undefined;\n const subPackagesByIntegrity: Map<string, string[] | boolean> = new Map();\n try {\n const cacheContent: string = await FileSystem.readFileAsync(subPackageCacheFilePath);\n const cacheJson: INestedPackageJsonCache = JSON.parse(cacheContent);\n if (cacheJson.version !== RESOLVER_CACHE_FILE_VERSION) {\n terminal.writeLine(\n `Expected subpackage cache version ${RESOLVER_CACHE_FILE_VERSION}, got ${cacheJson.version}`\n );\n } else {\n oldSubPackagesByIntegrity = new Map(cacheJson.subPackagesByIntegrity);\n terminal.writeLine(`Loaded subpackage cache from ${subPackageCacheFilePath}`);\n }\n } catch (err) {\n // Ignore\n }\n\n async function afterExternalPackagesAsync(\n contexts: Map<string, IResolverContext>,\n missingOptionalDependencies: Set<string>\n ): Promise<void> {\n /**\n * Loads the index file from the pnpm store to discover nested package.json files in an external package\n * For internal packages, assumes there are no nested package.json files.\n * @param context - The context to find nested package.json files for\n * @returns A promise that resolves to the nested package.json paths, false if the package fails to load, or true if the package has no nested package.json files.\n */\n async function tryFindNestedPackageJsonsForContextAsync(\n context: IResolverContext\n ): Promise<string[] | boolean> {\n const { descriptionFileRoot, descriptionFileHash } = context;\n\n if (descriptionFileHash === undefined) {\n // Assume this package has no nested package json files for now.\n terminal.writeDebugLine(\n `Package at ${descriptionFileRoot} does not have a file list. Assuming no nested \"package.json\" files.`\n );\n return true;\n }\n\n // Convert an integrity hash like\n // sha512-C6uiGQJ+Gt4RyHXXYt+v9f+SN1v83x68URwgxNQ98cvH8kxiuywWGP4XeNZ1paOzZ63aY3cTciCEQJNFUljlLw==\n // To its hex representation, e.g.\n // 0baba219027e1ade11c875d762dfaff5ff92375bfcdf1ebc511c20c4d43df1cbc7f24c62bb2c1618fe1778d675a5a3b367adda6377137220844093455258e52f\n const prefixIndex: number = descriptionFileHash.indexOf('-');\n const hash: string = Buffer.from(descriptionFileHash.slice(prefixIndex + 1), 'base64').toString('hex');\n\n // The pnpm store directory has index files of package contents at paths:\n // <store>/v3/files/<hash (0-2)>/<hash (2-)>-index.json\n // See https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/store/cafs/src/getFilePathInCafs.ts#L33\n const indexPath: string = `${pnpmStoreDir}${hash.slice(0, 2)}/${hash.slice(2)}-index.json`;\n\n try {\n const indexContent: string = await FileSystem.readFileAsync(indexPath);\n let endIndex: number = indexContent.lastIndexOf(END_TOKEN);\n if (endIndex > 0) {\n const nestedPackageDirs: string[] = [];\n do {\n const startIndex: number = indexContent.lastIndexOf('\"', endIndex);\n if (startIndex < 0) {\n throw new Error(\n `Malformed index file at ${indexPath}: missing starting quote for nested package.json path`\n );\n }\n const nestedPath: string = indexContent.slice(startIndex + 1, endIndex);\n nestedPackageDirs.push(nestedPath);\n endIndex = indexContent.lastIndexOf(END_TOKEN, startIndex - 1);\n } while (endIndex > 0);\n return nestedPackageDirs;\n }\n return true;\n } catch (error) {\n if (!context.optional) {\n throw new Error(\n `Error reading index file for: \"${\n context.descriptionFileRoot\n }\" (${descriptionFileHash}): ${error.toString()}`\n );\n }\n return false;\n }\n }\n /**\n * Loads the index file from the pnpm store to discover nested package.json files in an external package\n * For internal packages, assumes there are no nested package.json files.\n * @param context - The context to find nested package.json files for\n * @returns A promise that resolves when the nested package.json files are found, if applicable\n */\n async function findNestedPackageJsonsForContextAsync(context: IResolverContext): Promise<void> {\n const { descriptionFileRoot, descriptionFileHash } = context;\n\n if (descriptionFileHash === undefined) {\n // Assume this package has no nested package json files for now.\n terminal.writeDebugLine(\n `Package at ${descriptionFileRoot} does not have a file list. Assuming no nested \"package.json\" files.`\n );\n return;\n }\n\n let result: string[] | boolean | undefined =\n oldSubPackagesByIntegrity?.get(descriptionFileHash) ??\n subPackagesByIntegrity.get(descriptionFileHash);\n if (result === undefined) {\n result = await tryFindNestedPackageJsonsForContextAsync(context);\n }\n subPackagesByIntegrity.set(descriptionFileHash, result);\n if (result === true) {\n // Default case. Do nothing.\n } else if (result === false) {\n terminal.writeLine(`Trimming missing optional dependency at: ${descriptionFileRoot}`);\n contexts.delete(descriptionFileRoot);\n missingOptionalDependencies.add(descriptionFileRoot);\n } else {\n terminal.writeDebugLine(\n `Nested \"package.json\" files found for package at ${descriptionFileRoot}: ${result.join(', ')}`\n );\n // eslint-disable-next-line require-atomic-updates\n context.nestedPackageDirs = result;\n }\n }\n\n // For external packages, update the contexts with data from the pnpm store\n // This gives us the list of nested package.json files, as well as the actual package name\n // We could also cache package.json contents, but that proves to be inefficient.\n await Async.forEachAsync(contexts.values(), findNestedPackageJsonsForContextAsync, {\n concurrency: 20\n });\n }\n\n const rawCacheFile: IResolverCacheFile = await computeResolverCacheFromLockfileAsync({\n workspaceRoot,\n commonPrefixToTrim: rushRoot,\n platformInfo: getPlatformInfo(),\n projectByImporterPath,\n lockfile: lockFile,\n afterExternalPackagesAsync\n });\n\n const extendedCacheFile: IExtendedResolverCacheFile = {\n version: RESOLVER_CACHE_FILE_VERSION,\n shrinkwrapHash: lockFile.hash,\n ...rawCacheFile\n };\n\n const newSubPackageCache: INestedPackageJsonCache = {\n version: RESOLVER_CACHE_FILE_VERSION,\n subPackagesByIntegrity: Array.from(subPackagesByIntegrity)\n };\n const serializedSubpackageCache: string = JSON.stringify(newSubPackageCache);\n\n const serialized: string = JSON.stringify(extendedCacheFile);\n\n await Promise.all([\n FileSystem.writeFileAsync(cacheFilePath, serialized, {\n ensureFolderExists: true\n }),\n FileSystem.writeFileAsync(subPackageCacheFilePath, serializedSubpackageCache, {\n ensureFolderExists: true\n })\n ]);\n\n // Free the memory used by the lockfiles, since nothing should read the lockfile from this point on.\n PnpmShrinkwrapFile.clearCache();\n\n terminal.writeLine(`Resolver cache written.`);\n}\n"]}
1
+ {"version":3,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c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type {\n RushSession,\n RushConfiguration,\n RushConfigurationProject,\n ILogger,\n LookupByPath,\n Subspace\n} from '@rushstack/rush-sdk';\nimport type { IResolverCacheFile } from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport { Async, FileSystem, PnpmShrinkwrapFile } from './externals';\nimport {\n computeResolverCacheFromLockfileAsync,\n type IPlatformInfo\n} from './computeResolverCacheFromLockfileAsync';\nimport {\n type PnpmMajorVersion,\n type IPnpmVersionHelpers,\n getPnpmVersionHelpersAsync\n} from './pnpm/pnpmVersionHelpers';\nimport type { IResolverContext } from './types';\n\n/**\n * Gets information used to determine compatibility of optional dependencies.\n * @returns Information about the platform Rush is running on\n */\nfunction getPlatformInfo(): IPlatformInfo {\n // Acquiring the libc version is a bit more obnoxious than platform and arch,\n // but all of them are ultimately on the same object.\n const {\n platform: os,\n arch: cpu,\n glibcVersionRuntime\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } = (process.report?.getReport() as any)?.header ?? process;\n const libc: 'glibc' | 'musl' = glibcVersionRuntime ? 'glibc' : 'musl';\n\n return {\n os,\n cpu,\n libc\n };\n}\n\nconst END_TOKEN: string = '/package.json\":';\nconst RESOLVER_CACHE_FILE_VERSION: 2 = 2;\n\ninterface IExtendedResolverCacheFile extends IResolverCacheFile {\n /**\n * The hash of the shrinkwrap file this cache file was generated from.\n */\n shrinkwrapHash: string;\n /**\n * The version of the resolver cache file.\n */\n version: number;\n}\n\ninterface INestedPackageJsonCache {\n subPackagesByIntegrity: [string, string[] | boolean][];\n version: number;\n}\n\n/**\n * Plugin entry point for after install.\n * @param rushSession - The Rush Session\n * @param rushConfiguration - The Rush Configuration\n * @param subspace - The subspace that was just installed\n * @param variant - The variant that was just installed\n * @param logger - The initialized logger\n */\nexport async function afterInstallAsync(\n rushSession: RushSession,\n rushConfiguration: RushConfiguration,\n subspace: Subspace,\n variant: string | undefined,\n logger: ILogger\n): Promise<void> {\n const { terminal } = logger;\n const rushRoot: string = `${rushConfiguration.rushJsonFolder}/`;\n\n const lockFilePath: string = subspace.getCommittedShrinkwrapFilePath(variant);\n\n const pnpmStorePath: string = rushConfiguration.pnpmOptions.pnpmStorePath;\n\n const pnpmMajorVersion: PnpmMajorVersion = (() => {\n const major: number = parseInt(rushConfiguration.packageManagerToolVersion, 10);\n switch (major) {\n case 10:\n return 10;\n case 9:\n return 9;\n case 8:\n return 8;\n default:\n throw new Error(`Unsupported pnpm major version: ${major}`);\n }\n })();\n\n const pnpmHelpers: IPnpmVersionHelpers = await getPnpmVersionHelpersAsync(pnpmMajorVersion);\n\n terminal.writeLine(`Using pnpm-lock from: ${lockFilePath}`);\n terminal.writeLine(`Using pnpm ${pnpmMajorVersion} store at: ${pnpmStorePath}`);\n\n const workspaceRoot: string = subspace.getSubspaceTempFolderPath();\n const cacheFilePath: string = `${workspaceRoot}/resolver-cache.json`;\n\n const lockFile: PnpmShrinkwrapFile | undefined = PnpmShrinkwrapFile.loadFromFile(lockFilePath, {\n withCaching: true,\n subspaceHasNoProjects: subspace.getProjects().length === 0\n });\n if (!lockFile) {\n throw new Error(`Failed to load shrinkwrap file: ${lockFilePath}`);\n }\n\n if (!lockFile.hash) {\n throw new Error(\n `Shrinkwrap file does not have a hash. This indicates linking to an old version of Rush.`\n );\n }\n\n try {\n const oldCacheFileContent: string = await FileSystem.readFileAsync(cacheFilePath);\n const oldCache: IExtendedResolverCacheFile = JSON.parse(oldCacheFileContent);\n if (oldCache.version === RESOLVER_CACHE_FILE_VERSION && oldCache.shrinkwrapHash === lockFile.hash) {\n // Cache is valid, use it\n return;\n }\n } catch (err) {\n // Ignore\n }\n\n const projectByImporterPath: LookupByPath<RushConfigurationProject> =\n rushConfiguration.getProjectLookupForRoot(workspaceRoot);\n\n const subPackageCacheFilePath: string = `${workspaceRoot}/subpackage-entry-cache.json`;\n\n terminal.writeLine(`Resolver cache will be written at ${cacheFilePath}`);\n\n let oldSubPackagesByIntegrity: Map<string, string[] | boolean> | undefined;\n const subPackagesByIntegrity: Map<string, string[] | boolean> = new Map();\n try {\n const cacheContent: string = await FileSystem.readFileAsync(subPackageCacheFilePath);\n const cacheJson: INestedPackageJsonCache = JSON.parse(cacheContent);\n if (cacheJson.version !== RESOLVER_CACHE_FILE_VERSION) {\n terminal.writeLine(\n `Expected subpackage cache version ${RESOLVER_CACHE_FILE_VERSION}, got ${cacheJson.version}`\n );\n } else {\n oldSubPackagesByIntegrity = new Map(cacheJson.subPackagesByIntegrity);\n terminal.writeLine(`Loaded subpackage cache from ${subPackageCacheFilePath}`);\n }\n } catch (err) {\n // Ignore\n }\n\n async function afterExternalPackagesAsync(\n contexts: Map<string, IResolverContext>,\n missingOptionalDependencies: Set<string>\n ): Promise<void> {\n /**\n * Loads the index file from the pnpm store to discover nested package.json files in an external package\n * For internal packages, assumes there are no nested package.json files.\n * @param context - The context to find nested package.json files for\n * @returns A promise that resolves to the nested package.json paths, false if the package fails to load, or true if the package has no nested package.json files.\n */\n async function tryFindNestedPackageJsonsForContextAsync(\n context: IResolverContext\n ): Promise<string[] | boolean> {\n const { descriptionFileRoot, descriptionFileHash } = context;\n\n if (descriptionFileHash === undefined) {\n // Assume this package has no nested package json files for now.\n terminal.writeDebugLine(\n `Package at ${descriptionFileRoot} does not have a file list. Assuming no nested \"package.json\" files.`\n );\n return true;\n }\n\n // Convert an integrity hash like\n // sha512-C6uiGQJ+Gt4RyHXXYt+v9f+SN1v83x68URwgxNQ98cvH8kxiuywWGP4XeNZ1paOzZ63aY3cTciCEQJNFUljlLw==\n // To its hex representation, e.g.\n // 0baba219027e1ade11c875d762dfaff5ff92375bfcdf1ebc511c20c4d43df1cbc7f24c62bb2c1618fe1778d675a5a3b367adda6377137220844093455258e52f\n const prefixIndex: number = descriptionFileHash.indexOf('-');\n const hash: string = Buffer.from(descriptionFileHash.slice(prefixIndex + 1), 'base64').toString('hex');\n\n const indexPath: string = pnpmHelpers.getStoreIndexPath(pnpmStorePath, context, hash);\n\n try {\n const indexContent: string = await FileSystem.readFileAsync(indexPath);\n let endIndex: number = indexContent.lastIndexOf(END_TOKEN);\n if (endIndex > 0) {\n const nestedPackageDirs: string[] = [];\n do {\n const startIndex: number = indexContent.lastIndexOf('\"', endIndex);\n if (startIndex < 0) {\n throw new Error(\n `Malformed index file at ${indexPath}: missing starting quote for nested package.json path`\n );\n }\n const nestedPath: string = indexContent.slice(startIndex + 1, endIndex);\n nestedPackageDirs.push(nestedPath);\n endIndex = indexContent.lastIndexOf(END_TOKEN, startIndex - 1);\n } while (endIndex > 0);\n return nestedPackageDirs;\n }\n return true;\n } catch (error) {\n if (!context.optional) {\n throw new Error(\n `Error reading index file for: \"${\n context.descriptionFileRoot\n }\" (${descriptionFileHash}): ${error.toString()}`\n );\n }\n return false;\n }\n }\n /**\n * Loads the index file from the pnpm store to discover nested package.json files in an external package\n * For internal packages, assumes there are no nested package.json files.\n * @param context - The context to find nested package.json files for\n * @returns A promise that resolves when the nested package.json files are found, if applicable\n */\n async function findNestedPackageJsonsForContextAsync(context: IResolverContext): Promise<void> {\n const { descriptionFileRoot, descriptionFileHash } = context;\n\n if (descriptionFileHash === undefined) {\n // Assume this package has no nested package json files for now.\n terminal.writeDebugLine(\n `Package at ${descriptionFileRoot} does not have a file list. Assuming no nested \"package.json\" files.`\n );\n return;\n }\n\n let result: string[] | boolean | undefined =\n oldSubPackagesByIntegrity?.get(descriptionFileHash) ??\n subPackagesByIntegrity.get(descriptionFileHash);\n if (result === undefined) {\n result = await tryFindNestedPackageJsonsForContextAsync(context);\n }\n subPackagesByIntegrity.set(descriptionFileHash, result);\n if (result === true) {\n // Default case. Do nothing.\n } else if (result === false) {\n terminal.writeLine(`Trimming missing optional dependency at: ${descriptionFileRoot}`);\n contexts.delete(descriptionFileRoot);\n missingOptionalDependencies.add(descriptionFileRoot);\n } else {\n terminal.writeDebugLine(\n `Nested \"package.json\" files found for package at ${descriptionFileRoot}: ${result.join(', ')}`\n );\n // eslint-disable-next-line require-atomic-updates\n context.nestedPackageDirs = result;\n }\n }\n\n // For external packages, update the contexts with data from the pnpm store\n // This gives us the list of nested package.json files, as well as the actual package name\n // We could also cache package.json contents, but that proves to be inefficient.\n await Async.forEachAsync(contexts.values(), findNestedPackageJsonsForContextAsync, {\n concurrency: 20\n });\n }\n\n const rawCacheFile: IResolverCacheFile = await computeResolverCacheFromLockfileAsync({\n workspaceRoot,\n commonPrefixToTrim: rushRoot,\n platformInfo: getPlatformInfo(),\n projectByImporterPath,\n lockfile: lockFile,\n pnpmVersion: pnpmMajorVersion,\n afterExternalPackagesAsync\n });\n\n const extendedCacheFile: IExtendedResolverCacheFile = {\n version: RESOLVER_CACHE_FILE_VERSION,\n shrinkwrapHash: lockFile.hash,\n ...rawCacheFile\n };\n\n const newSubPackageCache: INestedPackageJsonCache = {\n version: RESOLVER_CACHE_FILE_VERSION,\n subPackagesByIntegrity: Array.from(subPackagesByIntegrity)\n };\n const serializedSubpackageCache: string = JSON.stringify(newSubPackageCache);\n\n const serialized: string = JSON.stringify(extendedCacheFile);\n\n await Promise.all([\n FileSystem.writeFileAsync(cacheFilePath, serialized, {\n ensureFolderExists: true\n }),\n FileSystem.writeFileAsync(subPackageCacheFilePath, serializedSubpackageCache, {\n ensureFolderExists: true\n })\n ]);\n\n // Free the memory used by the lockfiles, since nothing should read the lockfile from this point on.\n PnpmShrinkwrapFile.clearCache();\n\n terminal.writeLine(`Resolver cache written.`);\n}\n"]}
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.computeResolverCacheFromLockfileAsync = computeResolverCacheFromLockfileAsync;
6
6
  const helpers_1 = require("./helpers");
7
+ const pnpmVersionHelpers_1 = require("./pnpm/pnpmVersionHelpers");
7
8
  function isPackageCompatible(pack, platformInfo) {
8
9
  var _a, _b, _c;
9
10
  if ((_a = pack.os) === null || _a === void 0 ? void 0 : _a.every((value) => value.toLowerCase() !== platformInfo.os)) {
@@ -67,13 +68,14 @@ function extractBundledDependencies(contexts, context) {
67
68
  }
68
69
  }
69
70
  }
71
+ const BACKSLASH_REGEX = /\\/g;
70
72
  /**
71
73
  * Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency
72
74
  * @param path - Path using backslashes as path separators
73
75
  * @returns The same string using forward slashes as path separators
74
76
  */
75
77
  function convertToSlashes(path) {
76
- return path.replace(/\\/g, '/');
78
+ return path.replace(BACKSLASH_REGEX, '/');
77
79
  }
78
80
  /**
79
81
  * Given a lockfile and information about the workspace and platform, computes the resolver cache file.
@@ -89,19 +91,22 @@ async function computeResolverCacheFromLockfileAsync(params) {
89
91
  const commonPrefixToTrim = convertToSlashes(params.commonPrefixToTrim);
90
92
  const contexts = new Map();
91
93
  const missingOptionalDependencies = new Set();
94
+ const helpers = await (0, pnpmVersionHelpers_1.getPnpmVersionHelpersAsync)(params.pnpmVersion);
95
+ const { packages } = lockfile;
92
96
  // Enumerate external dependencies first, to simplify looping over them for store data
93
- for (const [key, pack] of lockfile.packages) {
97
+ for (const [key, pack] of packages) {
94
98
  let name = pack.name;
95
- const descriptionFileRoot = (0, helpers_1.getDescriptionFileRootFromKey)(workspaceRoot, key, name);
99
+ const descriptionFileRoot = (0, helpers_1.getDescriptionFileRootFromKey)(workspaceRoot, key, helpers.depPathToFilename, name);
96
100
  // Skip optional dependencies that are incompatible with the current environment
97
101
  if (pack.optional && !isPackageCompatible(pack, platformInfo)) {
98
102
  missingOptionalDependencies.add(descriptionFileRoot);
99
103
  continue;
100
104
  }
101
105
  const integrity = (_a = pack.resolution) === null || _a === void 0 ? void 0 : _a.integrity;
102
- if (!name && key.startsWith('/')) {
103
- const versionIndex = key.indexOf('@', 2);
104
- name = key.slice(1, versionIndex);
106
+ // Extract name and version from the key if not already provided
107
+ const parsed = (0, helpers_1.extractNameAndVersionFromKey)(key);
108
+ if (parsed) {
109
+ name || (name = parsed.name);
105
110
  }
106
111
  if (!name) {
107
112
  throw new Error(`Missing name for ${key}`);
@@ -111,16 +116,17 @@ async function computeResolverCacheFromLockfileAsync(params) {
111
116
  descriptionFileHash: integrity,
112
117
  isProject: false,
113
118
  name,
119
+ version: parsed === null || parsed === void 0 ? void 0 : parsed.version,
114
120
  deps: new Map(),
115
121
  ordinal: -1,
116
122
  optional: pack.optional
117
123
  };
118
124
  contexts.set(descriptionFileRoot, context);
119
125
  if (pack.dependencies) {
120
- (0, helpers_1.resolveDependencies)(workspaceRoot, pack.dependencies, context);
126
+ (0, helpers_1.resolveDependencies)(workspaceRoot, pack.dependencies, context, helpers, packages);
121
127
  }
122
128
  if (pack.optionalDependencies) {
123
- (0, helpers_1.resolveDependencies)(workspaceRoot, pack.optionalDependencies, context);
129
+ (0, helpers_1.resolveDependencies)(workspaceRoot, pack.optionalDependencies, context, helpers, packages);
124
130
  }
125
131
  }
126
132
  if (afterExternalPackagesAsync) {
@@ -153,13 +159,13 @@ async function computeResolverCacheFromLockfileAsync(params) {
153
159
  };
154
160
  contexts.set(descriptionFileRoot, context);
155
161
  if (importer.dependencies) {
156
- (0, helpers_1.resolveDependencies)(workspaceRoot, importer.dependencies, context);
162
+ (0, helpers_1.resolveDependencies)(workspaceRoot, importer.dependencies, context, helpers, packages);
157
163
  }
158
164
  if (importer.devDependencies) {
159
- (0, helpers_1.resolveDependencies)(workspaceRoot, importer.devDependencies, context);
165
+ (0, helpers_1.resolveDependencies)(workspaceRoot, importer.devDependencies, context, helpers, packages);
160
166
  }
161
167
  if (importer.optionalDependencies) {
162
- (0, helpers_1.resolveDependencies)(workspaceRoot, importer.optionalDependencies, context);
168
+ (0, helpers_1.resolveDependencies)(workspaceRoot, importer.optionalDependencies, context, helpers, packages);
163
169
  }
164
170
  }
165
171
  let ordinal = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"computeResolverCacheFromLockfileAsync.js","sourceRoot":"","sources":["../src/computeResolverCacheFromLockfileAsync.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AA8J3D,sFAsHC;AA1QD,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EAAC,aAAa,EAAE,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED,IAAI,OAAO,GAAW,CAAC,CAAC;IACxB,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,kEAAkE;IAClE,MAAM,kBAAkB,GAAgC,KAAK,CAAC,IAAI,CAChE,QAAQ,EACR,IAAA,iCAAuB,EAAC,2BAA2B,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CACnF,CAAC;IAEF,MAAM,SAAS,GAAuB;QACpC,QAAQ,EAAE,kBAAkB;QAC5B,QAAQ,EAAE,kBAAkB;KAC7B,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { LookupByPath } from '@rushstack/rush-sdk';\nimport type { IPnpmShrinkwrapDependencyYaml } from '@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile';\nimport type {\n ISerializedResolveContext,\n IResolverCacheFile\n} from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport type { PnpmShrinkwrapFile } from './externals';\nimport { getDescriptionFileRootFromKey, resolveDependencies, createContextSerializer } from './helpers';\nimport type { IResolverContext } from './types';\n\n/**\n * The only parts of a RushConfigurationProject needed by this tool.\n * Reduced for unit test typings.\n */\nexport interface IPartialRushProject {\n projectFolder: string;\n packageJson: {\n name: string;\n };\n}\n\nexport interface IPlatformInfo {\n os: typeof process.platform;\n cpu: typeof process.arch;\n libc: 'glibc' | 'musl';\n}\n\nfunction isPackageCompatible(\n pack: Pick<IPnpmShrinkwrapDependencyYaml, 'os' | 'cpu' | 'libc'>,\n platformInfo: IPlatformInfo\n): boolean {\n if (pack.os?.every((value) => value.toLowerCase() !== platformInfo.os)) {\n return false;\n }\n if (pack.cpu?.every((value) => value.toLowerCase() !== platformInfo.cpu)) {\n return false;\n }\n if (pack.libc?.every((value) => value.toLowerCase() !== platformInfo.libc)) {\n return false;\n }\n return true;\n}\n\nfunction extractBundledDependencies(\n contexts: Map<string, IResolverContext>,\n context: IResolverContext\n): void {\n let { nestedPackageDirs } = context;\n if (!nestedPackageDirs) {\n return;\n }\n\n let foundBundledDependencies: boolean = false;\n for (let i: number = nestedPackageDirs.length - 1; i >= 0; i--) {\n const nestedDir: string = nestedPackageDirs[i];\n if (!nestedDir.startsWith('node_modules/')) {\n continue;\n }\n\n const isScoped: boolean = nestedDir.charAt(/* 'node_modules/'.length */ 13) === '@';\n let index: number = nestedDir.indexOf('/', 13);\n if (isScoped) {\n index = nestedDir.indexOf('/', index + 1);\n }\n\n const name: string = index === -1 ? nestedDir.slice(13) : nestedDir.slice(13, index);\n if (name.startsWith('.')) {\n continue;\n }\n\n if (!foundBundledDependencies) {\n foundBundledDependencies = true;\n // Make a copy of the nestedPackageDirs array so that we don't mutate the version being\n // saved into the subpackage index cache.\n context.nestedPackageDirs = nestedPackageDirs = nestedPackageDirs.slice(0);\n }\n // Remove this nested package from the list\n nestedPackageDirs.splice(i, 1);\n\n const remainder: string = index === -1 ? '' : nestedDir.slice(index + 1);\n const nestedRoot: string = `${context.descriptionFileRoot}/node_modules/${name}`;\n let nestedContext: IResolverContext | undefined = contexts.get(nestedRoot);\n if (!nestedContext) {\n nestedContext = {\n descriptionFileRoot: nestedRoot,\n descriptionFileHash: undefined,\n isProject: false,\n name,\n deps: new Map(),\n ordinal: -1\n };\n contexts.set(nestedRoot, nestedContext);\n }\n\n context.deps.set(name, nestedRoot);\n\n if (remainder) {\n nestedContext.nestedPackageDirs ??= [];\n nestedContext.nestedPackageDirs.push(remainder);\n }\n }\n}\n\n/**\n * Options for computing the resolver cache from a lockfile.\n */\nexport interface IComputeResolverCacheFromLockfileOptions {\n /**\n * The root folder of the workspace being installed\n */\n workspaceRoot: string;\n /**\n * The common root path to trim from the description file roots for brevity\n */\n commonPrefixToTrim: string;\n /**\n * Information about the platform Rush is running on\n */\n platformInfo: IPlatformInfo;\n /**\n * A lookup of projects by their importer path\n */\n projectByImporterPath: Pick<LookupByPath<IPartialRushProject>, 'findChildPath'>;\n /**\n * The lockfile to compute the cache from\n */\n lockfile: PnpmShrinkwrapFile;\n /**\n * A callback to process external packages after they have been enumerated.\n * Broken out as a separate function to facilitate testing without hitting the disk.\n * @remarks This is useful for fetching additional data from the pnpm store\n * @param contexts - The current context information per description file root\n * @param missingOptionalDependencies - The set of optional dependencies that were not installed\n * @returns A promise that resolves when the external packages have been processed\n */\n afterExternalPackagesAsync?: (\n contexts: Map<string, IResolverContext>,\n missingOptionalDependencies: Set<string>\n ) => Promise<void>;\n}\n\n/**\n * Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency\n * @param path - Path using backslashes as path separators\n * @returns The same string using forward slashes as path separators\n */\nfunction convertToSlashes(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\n/**\n * Given a lockfile and information about the workspace and platform, computes the resolver cache file.\n * @param params - The options for computing the resolver cache\n * @returns A promise that resolves with the resolver cache file\n */\nexport async function computeResolverCacheFromLockfileAsync(\n params: IComputeResolverCacheFromLockfileOptions\n): Promise<IResolverCacheFile> {\n const { platformInfo, projectByImporterPath, lockfile, afterExternalPackagesAsync } = params;\n // Needs to be normalized to `/` for path.posix.join to work correctly\n const workspaceRoot: string = convertToSlashes(params.workspaceRoot);\n // Needs to be normalized to `/` for path.posix.join to work correctly\n const commonPrefixToTrim: string = convertToSlashes(params.commonPrefixToTrim);\n\n const contexts: Map<string, IResolverContext> = new Map();\n const missingOptionalDependencies: Set<string> = new Set();\n\n // Enumerate external dependencies first, to simplify looping over them for store data\n for (const [key, pack] of lockfile.packages) {\n let name: string | undefined = pack.name;\n const descriptionFileRoot: string = getDescriptionFileRootFromKey(workspaceRoot, key, name);\n\n // Skip optional dependencies that are incompatible with the current environment\n if (pack.optional && !isPackageCompatible(pack, platformInfo)) {\n missingOptionalDependencies.add(descriptionFileRoot);\n continue;\n }\n\n const integrity: string | undefined = pack.resolution?.integrity;\n\n if (!name && key.startsWith('/')) {\n const versionIndex: number = key.indexOf('@', 2);\n name = key.slice(1, versionIndex);\n }\n\n if (!name) {\n throw new Error(`Missing name for ${key}`);\n }\n\n const context: IResolverContext = {\n descriptionFileRoot,\n descriptionFileHash: integrity,\n isProject: false,\n name,\n deps: new Map(),\n ordinal: -1,\n optional: pack.optional\n };\n\n contexts.set(descriptionFileRoot, context);\n\n if (pack.dependencies) {\n resolveDependencies(workspaceRoot, pack.dependencies, context);\n }\n if (pack.optionalDependencies) {\n resolveDependencies(workspaceRoot, pack.optionalDependencies, context);\n }\n }\n\n if (afterExternalPackagesAsync) {\n await afterExternalPackagesAsync(contexts, missingOptionalDependencies);\n }\n\n for (const context of contexts.values()) {\n if (context.nestedPackageDirs) {\n extractBundledDependencies(contexts, context);\n }\n }\n\n // Add the data for workspace projects\n for (const [importerPath, importer] of lockfile.importers) {\n // Ignore the root project. This plugin assumes you don't have one.\n // A non-empty root project results in global dependency hoisting, and that's bad for strictness.\n if (importerPath === '.') {\n continue;\n }\n\n const project: IPartialRushProject | undefined = projectByImporterPath.findChildPath(importerPath);\n if (!project) {\n throw new Error(`Missing project for importer ${importerPath}`);\n }\n\n const descriptionFileRoot: string = convertToSlashes(project.projectFolder);\n\n const context: IResolverContext = {\n descriptionFileRoot,\n descriptionFileHash: undefined, // Not needed anymore\n name: project.packageJson.name,\n isProject: true,\n deps: new Map(),\n ordinal: -1\n };\n\n contexts.set(descriptionFileRoot, context);\n\n if (importer.dependencies) {\n resolveDependencies(workspaceRoot, importer.dependencies, context);\n }\n if (importer.devDependencies) {\n resolveDependencies(workspaceRoot, importer.devDependencies, context);\n }\n if (importer.optionalDependencies) {\n resolveDependencies(workspaceRoot, importer.optionalDependencies, context);\n }\n }\n\n let ordinal: number = 0;\n for (const context of contexts.values()) {\n context.ordinal = ordinal++;\n }\n\n // Convert the intermediate representation to the final cache file\n const serializedContexts: ISerializedResolveContext[] = Array.from(\n contexts,\n createContextSerializer(missingOptionalDependencies, contexts, commonPrefixToTrim)\n );\n\n const cacheFile: IResolverCacheFile = {\n basePath: commonPrefixToTrim,\n contexts: serializedContexts\n };\n\n return cacheFile;\n}\n"]}
1
+ {"version":3,"file":"computeResolverCacheFromLockfileAsync.js","sourceRoot":"","sources":["../src/computeResolverCacheFromLockfileAsync.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAkL3D,sFAiIC;AAzSD,uCAKmB;AACnB,kEAImC;AAoBnC,SAAS,mBAAmB,CAC1B,IAAgE,EAChE,YAA2B;;IAE3B,IAAI,MAAA,IAAI,CAAC,EAAE,0CAAE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAA,IAAI,CAAC,GAAG,0CAAE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,0BAA0B,CACjC,QAAuC,EACvC,OAAyB;;IAEzB,IAAI,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,IAAI,wBAAwB,GAAY,KAAK,CAAC;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copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { LookupByPath } from '@rushstack/rush-sdk';\nimport type { IPnpmShrinkwrapDependencyYaml } from '@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile';\nimport type {\n ISerializedResolveContext,\n IResolverCacheFile\n} from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport type { PnpmShrinkwrapFile } from './externals';\nimport {\n getDescriptionFileRootFromKey,\n resolveDependencies,\n createContextSerializer,\n extractNameAndVersionFromKey\n} from './helpers';\nimport {\n type PnpmMajorVersion,\n type IPnpmVersionHelpers,\n getPnpmVersionHelpersAsync\n} from './pnpm/pnpmVersionHelpers';\nimport type { IResolverContext } from './types';\n\n/**\n * The only parts of a RushConfigurationProject needed by this tool.\n * Reduced for unit test typings.\n */\nexport interface IPartialRushProject {\n projectFolder: string;\n packageJson: {\n name: string;\n };\n}\n\nexport interface IPlatformInfo {\n os: typeof process.platform;\n cpu: typeof process.arch;\n libc: 'glibc' | 'musl';\n}\n\nfunction isPackageCompatible(\n pack: Pick<IPnpmShrinkwrapDependencyYaml, 'os' | 'cpu' | 'libc'>,\n platformInfo: IPlatformInfo\n): boolean {\n if (pack.os?.every((value) => value.toLowerCase() !== platformInfo.os)) {\n return false;\n }\n if (pack.cpu?.every((value) => value.toLowerCase() !== platformInfo.cpu)) {\n return false;\n }\n if (pack.libc?.every((value) => value.toLowerCase() !== platformInfo.libc)) {\n return false;\n }\n return true;\n}\n\nfunction extractBundledDependencies(\n contexts: Map<string, IResolverContext>,\n context: IResolverContext\n): void {\n let { nestedPackageDirs } = context;\n if (!nestedPackageDirs) {\n return;\n }\n\n let foundBundledDependencies: boolean = false;\n for (let i: number = nestedPackageDirs.length - 1; i >= 0; i--) {\n const nestedDir: string = nestedPackageDirs[i];\n if (!nestedDir.startsWith('node_modules/')) {\n continue;\n }\n\n const isScoped: boolean = nestedDir.charAt(/* 'node_modules/'.length */ 13) === '@';\n let index: number = nestedDir.indexOf('/', 13);\n if (isScoped) {\n index = nestedDir.indexOf('/', index + 1);\n }\n\n const name: string = index === -1 ? nestedDir.slice(13) : nestedDir.slice(13, index);\n if (name.startsWith('.')) {\n continue;\n }\n\n if (!foundBundledDependencies) {\n foundBundledDependencies = true;\n // Make a copy of the nestedPackageDirs array so that we don't mutate the version being\n // saved into the subpackage index cache.\n context.nestedPackageDirs = nestedPackageDirs = nestedPackageDirs.slice(0);\n }\n // Remove this nested package from the list\n nestedPackageDirs.splice(i, 1);\n\n const remainder: string = index === -1 ? '' : nestedDir.slice(index + 1);\n const nestedRoot: string = `${context.descriptionFileRoot}/node_modules/${name}`;\n let nestedContext: IResolverContext | undefined = contexts.get(nestedRoot);\n if (!nestedContext) {\n nestedContext = {\n descriptionFileRoot: nestedRoot,\n descriptionFileHash: undefined,\n isProject: false,\n name,\n deps: new Map(),\n ordinal: -1\n };\n contexts.set(nestedRoot, nestedContext);\n }\n\n context.deps.set(name, nestedRoot);\n\n if (remainder) {\n nestedContext.nestedPackageDirs ??= [];\n nestedContext.nestedPackageDirs.push(remainder);\n }\n }\n}\n\n// Re-export for downstream consumers\nexport type { PnpmMajorVersion, IPnpmVersionHelpers } from './pnpm/pnpmVersionHelpers';\n\n/**\n * Options for computing the resolver cache from a lockfile.\n */\nexport interface IComputeResolverCacheFromLockfileOptions {\n /**\n * The root folder of the workspace being installed\n */\n workspaceRoot: string;\n /**\n * The common root path to trim from the description file roots for brevity\n */\n commonPrefixToTrim: string;\n /**\n * Information about the platform Rush is running on\n */\n platformInfo: IPlatformInfo;\n /**\n * A lookup of projects by their importer path\n */\n projectByImporterPath: Pick<LookupByPath<IPartialRushProject>, 'findChildPath'>;\n /**\n * The lockfile to compute the cache from\n */\n lockfile: PnpmShrinkwrapFile;\n /**\n * The major version of pnpm configured in rush.json (e.g. `\"10.27.0\"` → 10).\n * Used to select the correct dep-path hashing algorithm and store layout.\n */\n pnpmVersion: PnpmMajorVersion;\n /**\n * A callback to process external packages after they have been enumerated.\n * Broken out as a separate function to facilitate testing without hitting the disk.\n * @remarks This is useful for fetching additional data from the pnpm store\n * @param contexts - The current context information per description file root\n * @param missingOptionalDependencies - The set of optional dependencies that were not installed\n * @returns A promise that resolves when the external packages have been processed\n */\n afterExternalPackagesAsync?: (\n contexts: Map<string, IResolverContext>,\n missingOptionalDependencies: Set<string>\n ) => Promise<void>;\n}\n\nconst BACKSLASH_REGEX: RegExp = /\\\\/g;\n\n/**\n * Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency\n * @param path - Path using backslashes as path separators\n * @returns The same string using forward slashes as path separators\n */\nfunction convertToSlashes(path: string): string {\n return path.replace(BACKSLASH_REGEX, '/');\n}\n\n/**\n * Given a lockfile and information about the workspace and platform, computes the resolver cache file.\n * @param params - The options for computing the resolver cache\n * @returns A promise that resolves with the resolver cache file\n */\nexport async function computeResolverCacheFromLockfileAsync(\n params: IComputeResolverCacheFromLockfileOptions\n): Promise<IResolverCacheFile> {\n const { platformInfo, projectByImporterPath, lockfile, afterExternalPackagesAsync } = params;\n // Needs to be normalized to `/` for path.posix.join to work correctly\n const workspaceRoot: string = convertToSlashes(params.workspaceRoot);\n // Needs to be normalized to `/` for path.posix.join to work correctly\n const commonPrefixToTrim: string = convertToSlashes(params.commonPrefixToTrim);\n\n const contexts: Map<string, IResolverContext> = new Map();\n const missingOptionalDependencies: Set<string> = new Set();\n\n const helpers: IPnpmVersionHelpers = await getPnpmVersionHelpersAsync(params.pnpmVersion);\n\n const { packages } = lockfile;\n\n // Enumerate external dependencies first, to simplify looping over them for store data\n for (const [key, pack] of packages) {\n let name: string | undefined = pack.name;\n const descriptionFileRoot: string = getDescriptionFileRootFromKey(\n workspaceRoot,\n key,\n helpers.depPathToFilename,\n name\n );\n\n // Skip optional dependencies that are incompatible with the current environment\n if (pack.optional && !isPackageCompatible(pack, platformInfo)) {\n missingOptionalDependencies.add(descriptionFileRoot);\n continue;\n }\n\n const integrity: string | undefined = pack.resolution?.integrity;\n\n // Extract name and version from the key if not already provided\n const parsed: { name: string; version: string } | undefined = extractNameAndVersionFromKey(key);\n if (parsed) {\n name ||= parsed.name;\n }\n\n if (!name) {\n throw new Error(`Missing name for ${key}`);\n }\n\n const context: IResolverContext = {\n descriptionFileRoot,\n descriptionFileHash: integrity,\n isProject: false,\n name,\n version: parsed?.version,\n deps: new Map(),\n ordinal: -1,\n optional: pack.optional\n };\n\n contexts.set(descriptionFileRoot, context);\n\n if (pack.dependencies) {\n resolveDependencies(workspaceRoot, pack.dependencies, context, helpers, packages);\n }\n if (pack.optionalDependencies) {\n resolveDependencies(workspaceRoot, pack.optionalDependencies, context, helpers, packages);\n }\n }\n\n if (afterExternalPackagesAsync) {\n await afterExternalPackagesAsync(contexts, missingOptionalDependencies);\n }\n\n for (const context of contexts.values()) {\n if (context.nestedPackageDirs) {\n extractBundledDependencies(contexts, context);\n }\n }\n\n // Add the data for workspace projects\n for (const [importerPath, importer] of lockfile.importers) {\n // Ignore the root project. This plugin assumes you don't have one.\n // A non-empty root project results in global dependency hoisting, and that's bad for strictness.\n if (importerPath === '.') {\n continue;\n }\n\n const project: IPartialRushProject | undefined = projectByImporterPath.findChildPath(importerPath);\n if (!project) {\n throw new Error(`Missing project for importer ${importerPath}`);\n }\n\n const descriptionFileRoot: string = convertToSlashes(project.projectFolder);\n\n const context: IResolverContext = {\n descriptionFileRoot,\n descriptionFileHash: undefined, // Not needed anymore\n name: project.packageJson.name,\n isProject: true,\n deps: new Map(),\n ordinal: -1\n };\n\n contexts.set(descriptionFileRoot, context);\n\n if (importer.dependencies) {\n resolveDependencies(workspaceRoot, importer.dependencies, context, helpers, packages);\n }\n if (importer.devDependencies) {\n resolveDependencies(workspaceRoot, importer.devDependencies, context, helpers, packages);\n }\n if (importer.optionalDependencies) {\n resolveDependencies(workspaceRoot, importer.optionalDependencies, context, helpers, packages);\n }\n }\n\n let ordinal: number = 0;\n for (const context of contexts.values()) {\n context.ordinal = ordinal++;\n }\n\n // Convert the intermediate representation to the final cache file\n const serializedContexts: ISerializedResolveContext[] = Array.from(\n contexts,\n createContextSerializer(missingOptionalDependencies, contexts, commonPrefixToTrim)\n );\n\n const cacheFile: IResolverCacheFile = {\n basePath: commonPrefixToTrim,\n contexts: serializedContexts\n };\n\n return cacheFile;\n}\n"]}
@@ -35,90 +35,47 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  };
36
36
  })();
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.createBase32Hash = createBase32Hash;
39
- exports.depPathToFilename = depPathToFilename;
40
38
  exports.resolveDependencyKey = resolveDependencyKey;
41
39
  exports.getDescriptionFileRootFromKey = getDescriptionFileRootFromKey;
42
40
  exports.resolveDependencies = resolveDependencies;
43
- exports.depPathToFilenameUnescaped = depPathToFilenameUnescaped;
41
+ exports.extractNameAndVersionFromKey = extractNameAndVersionFromKey;
44
42
  exports.createContextSerializer = createContextSerializer;
45
- const node_crypto_1 = require("node:crypto");
46
43
  const path = __importStar(require("node:path"));
47
- const MAX_LENGTH_WITHOUT_HASH = 120 - 26 - 1;
48
- const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567'.split('');
49
- // https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118
50
- function createBase32Hash(input) {
51
- const data = (0, node_crypto_1.createHash)('md5').update(input).digest();
52
- const mask = 0x1f;
53
- let out = '';
54
- let bits = 0; // Number of bits currently in the buffer
55
- let buffer = 0; // Bits waiting to be written out, MSB first
56
- for (let i = 0; i < data.length; ++i) {
57
- // eslint-disable-next-line no-bitwise
58
- buffer = (buffer << 8) | (0xff & data[i]);
59
- bits += 8;
60
- // Write out as much as we can:
61
- while (bits > 5) {
62
- bits -= 5;
63
- // eslint-disable-next-line no-bitwise
64
- out += BASE32[mask & (buffer >> bits)];
65
- }
66
- }
67
- // Partial character:
68
- if (bits) {
69
- // eslint-disable-next-line no-bitwise
70
- out += BASE32[mask & (buffer << (5 - bits))];
71
- }
72
- return out;
73
- }
74
- // https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/packages/dependency-path/src/index.ts#L167-L189
75
- function depPathToFilename(depPath) {
76
- let filename = depPathToFilenameUnescaped(depPath).replace(/[\\/:*?"<>|]/g, '+');
77
- if (filename.includes('(')) {
78
- filename = filename.replace(/(\)\()|\(/g, '_').replace(/\)$/, '');
79
- }
80
- if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {
81
- return `${filename.substring(0, MAX_LENGTH_WITHOUT_HASH)}_${createBase32Hash(filename)}`;
82
- }
83
- return filename;
84
- }
85
44
  /**
86
45
  * Computes the root folder for a dependency from a reference to it in another package
87
46
  * @param lockfileFolder - The folder that contains the lockfile
88
47
  * @param key - The key of the dependency
89
48
  * @param specifier - The specifier in the lockfile for the dependency
90
49
  * @param context - The owning package
50
+ * @param helpers - Version-specific pnpm helpers
91
51
  * @returns The identifier for the dependency
92
52
  */
93
- function resolveDependencyKey(lockfileFolder, key, specifier, context) {
94
- if (specifier.startsWith('/')) {
95
- return getDescriptionFileRootFromKey(lockfileFolder, specifier);
96
- }
97
- else if (specifier.startsWith('link:')) {
98
- if (context.isProject) {
99
- return path.posix.join(context.descriptionFileRoot, specifier.slice(5));
100
- }
101
- else {
102
- return path.posix.join(lockfileFolder, specifier.slice(5));
103
- }
53
+ function resolveDependencyKey(lockfileFolder, key, specifier, context, helpers, packageKeys) {
54
+ if (specifier.startsWith('link:')) {
55
+ return path.posix.join(context.isProject ? context.descriptionFileRoot : lockfileFolder, specifier.slice(5));
104
56
  }
105
57
  else if (specifier.startsWith('file:')) {
106
- return getDescriptionFileRootFromKey(lockfileFolder, specifier, key);
58
+ return getDescriptionFileRootFromKey(lockfileFolder, specifier, helpers.depPathToFilename, key);
107
59
  }
108
60
  else {
109
- return getDescriptionFileRootFromKey(lockfileFolder, `/${key}@${specifier}`);
61
+ const resolvedKey = (packageKeys === null || packageKeys === void 0 ? void 0 : packageKeys.has(specifier))
62
+ ? specifier
63
+ : helpers.buildDependencyKey(key, specifier);
64
+ return getDescriptionFileRootFromKey(lockfileFolder, resolvedKey, helpers.depPathToFilename);
110
65
  }
111
66
  }
112
67
  /**
113
68
  * Computes the physical path to a dependency based on its entry
114
69
  * @param lockfileFolder - The folder that contains the lockfile during installation
115
70
  * @param key - The key of the dependency
71
+ * @param depPathToFilename - Version-specific function to convert dep paths to filenames
116
72
  * @param name - The name of the dependency, if provided
117
73
  * @returns The physical path to the dependency
118
74
  */
119
- function getDescriptionFileRootFromKey(lockfileFolder, key, name) {
120
- if (!key.startsWith('file:')) {
121
- name = key.slice(1, key.indexOf('@', 2));
75
+ function getDescriptionFileRootFromKey(lockfileFolder, key, depPathToFilename, name) {
76
+ if (!key.startsWith('file:') && !name) {
77
+ const offset = key.startsWith('/') ? 1 : 0;
78
+ name = key.slice(offset, key.indexOf('@', offset + 1));
122
79
  }
123
80
  if (!name) {
124
81
  throw new Error(`Missing package name for ${key}`);
@@ -127,26 +84,31 @@ function getDescriptionFileRootFromKey(lockfileFolder, key, name) {
127
84
  const descriptionFileRoot = `${originFolder}/${name}`;
128
85
  return descriptionFileRoot;
129
86
  }
130
- function resolveDependencies(lockfileFolder, collection, context) {
87
+ function resolveDependencies(lockfileFolder, collection, context, helpers, packageKeys) {
131
88
  for (const [key, value] of Object.entries(collection)) {
132
89
  const version = typeof value === 'string' ? value : value.version;
133
- const resolved = resolveDependencyKey(lockfileFolder, key, version, context);
90
+ const resolved = resolveDependencyKey(lockfileFolder, key, version, context, helpers, packageKeys);
134
91
  context.deps.set(key, resolved);
135
92
  }
136
93
  }
137
94
  /**
138
- *
139
- * @param depPath - The path to the dependency
140
- * @returns The folder name for the dependency
95
+ * Extracts the package name and version from a lockfile package key.
96
+ * @param key - The lockfile package key (e.g. '/autoprefixer\@9.8.8', '\@scope/name\@1.0.0(peer\@2.0.0)')
97
+ * @returns The extracted name and version, or undefined for file: keys
141
98
  */
142
- function depPathToFilenameUnescaped(depPath) {
143
- if (depPath.indexOf('file:') !== 0) {
144
- if (depPath.startsWith('/')) {
145
- depPath = depPath.slice(1);
146
- }
147
- return depPath;
99
+ function extractNameAndVersionFromKey(key) {
100
+ if (key.startsWith('file:')) {
101
+ return undefined;
102
+ }
103
+ const offset = key.startsWith('/') ? 1 : 0;
104
+ const versionAtIndex = key.indexOf('@', offset + 1);
105
+ if (versionAtIndex === -1) {
106
+ return undefined;
148
107
  }
149
- return depPath.replace(':', '+');
108
+ const name = key.slice(offset, versionAtIndex);
109
+ const parenIndex = key.indexOf('(', versionAtIndex);
110
+ const version = parenIndex !== -1 ? key.slice(versionAtIndex + 1, parenIndex) : key.slice(versionAtIndex + 1);
111
+ return { name, version };
150
112
  }
151
113
  /**
152
114
  *
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAa3D,4CA4BC;AAGD,8CASC;AAUD,oDAmBC;AASD,sEAWC;AAED,kDAWC;AAOD,gEAQC;AASD,0DAoCC;AA7KD,6CAAyC;AACzC,gDAAkC;AAMlC,MAAM,uBAAuB,GAAW,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;AACrD,MAAM,MAAM,GAAa,kCAAkC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEtE,+GAA+G;AAC/G,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,MAAM,IAAI,GAAW,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAE9D,MAAM,IAAI,GAAS,IAAI,CAAC;IACxB,IAAI,GAAG,GAAW,EAAE,CAAC;IAErB,IAAI,IAAI,GAAW,CAAC,CAAC,CAAC,yCAAyC;IAC/D,IAAI,MAAM,GAAW,CAAC,CAAC,CAAC,4CAA4C;IACpE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,CAAC,mBAAmB,EAAE,OAAO,CAA6B,EAA6B,EAAE;QAC/F,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;QAElD,IAAI,UAAU,GAAY,KAAK,CAAC;QAChC,MAAM,cAAc,GAAsC,EAAE,CAAC;QAC7D,KAAK,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC;YACtC,IAAI,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACjD,SAAS;YACX,CAAC;YAED,MAAM,iBAAiB,GAAiC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAClF,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,uBAAuB,WAAW,GAAG,CAAC,CAAC;YACzD,CAAC;YACD,cAAc,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC;YAChD,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,oBAAoB,mBAAmB,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,iBAAiB,GAA8B;YACnD,IAAI;YACJ,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC;YACxD,YAAY,EAAE,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,EAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS;YACvE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;QAEF,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { createHash } from 'node:crypto';\nimport * as path from 'node:path';\n\nimport type { ISerializedResolveContext } from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport type { IDependencyEntry, IResolverContext } from './types';\n\nconst MAX_LENGTH_WITHOUT_HASH: number = 120 - 26 - 1;\nconst BASE32: string[] = 'abcdefghijklmnopqrstuvwxyz234567'.split('');\n\n// https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118\nexport function createBase32Hash(input: string): string {\n const data: Buffer = createHash('md5').update(input).digest();\n\n const mask: 0x1f = 0x1f;\n let out: string = '';\n\n let bits: number = 0; // Number of bits currently in the buffer\n let buffer: number = 0; // Bits waiting to be written out, MSB first\n for (let i: number = 0; i < data.length; ++i) {\n // eslint-disable-next-line no-bitwise\n buffer = (buffer << 8) | (0xff & data[i]);\n bits += 8;\n\n // Write out as much as we can:\n while (bits > 5) {\n bits -= 5;\n // eslint-disable-next-line no-bitwise\n out += BASE32[mask & (buffer >> bits)];\n }\n }\n\n // Partial character:\n if (bits) {\n // eslint-disable-next-line no-bitwise\n out += BASE32[mask & (buffer << (5 - bits))];\n }\n\n return out;\n}\n\n// https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/packages/dependency-path/src/index.ts#L167-L189\nexport function depPathToFilename(depPath: string): string {\n let filename: string = depPathToFilenameUnescaped(depPath).replace(/[\\\\/:*?\"<>|]/g, '+');\n if (filename.includes('(')) {\n filename = filename.replace(/(\\)\\()|\\(/g, '_').replace(/\\)$/, '');\n }\n if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {\n return `${filename.substring(0, MAX_LENGTH_WITHOUT_HASH)}_${createBase32Hash(filename)}`;\n }\n return filename;\n}\n\n/**\n * Computes the root folder for a dependency from a reference to it in another package\n * @param lockfileFolder - The folder that contains the lockfile\n * @param key - The key of the dependency\n * @param specifier - The specifier in the lockfile for the dependency\n * @param context - The owning package\n * @returns The identifier for the dependency\n */\nexport function resolveDependencyKey(\n lockfileFolder: string,\n key: string,\n specifier: string,\n context: IResolverContext\n): string {\n if (specifier.startsWith('/')) {\n return getDescriptionFileRootFromKey(lockfileFolder, specifier);\n } else if (specifier.startsWith('link:')) {\n if (context.isProject) {\n return path.posix.join(context.descriptionFileRoot, specifier.slice(5));\n } else {\n return path.posix.join(lockfileFolder, specifier.slice(5));\n }\n } else if (specifier.startsWith('file:')) {\n return getDescriptionFileRootFromKey(lockfileFolder, specifier, key);\n } else {\n return getDescriptionFileRootFromKey(lockfileFolder, `/${key}@${specifier}`);\n }\n}\n\n/**\n * Computes the physical path to a dependency based on its entry\n * @param lockfileFolder - The folder that contains the lockfile during installation\n * @param key - The key of the dependency\n * @param name - The name of the dependency, if provided\n * @returns The physical path to the dependency\n */\nexport function getDescriptionFileRootFromKey(lockfileFolder: string, key: string, name?: string): string {\n if (!key.startsWith('file:')) {\n name = key.slice(1, key.indexOf('@', 2));\n }\n if (!name) {\n throw new Error(`Missing package name for ${key}`);\n }\n\n const originFolder: string = `${lockfileFolder}/node_modules/.pnpm/${depPathToFilename(key)}/node_modules`;\n const descriptionFileRoot: string = `${originFolder}/${name}`;\n return descriptionFileRoot;\n}\n\nexport function resolveDependencies(\n lockfileFolder: string,\n collection: Record<string, IDependencyEntry>,\n context: IResolverContext\n): void {\n for (const [key, value] of Object.entries(collection)) {\n const version: string = typeof value === 'string' ? value : value.version;\n const resolved: string = resolveDependencyKey(lockfileFolder, key, version, context);\n\n context.deps.set(key, resolved);\n }\n}\n\n/**\n *\n * @param depPath - The path to the dependency\n * @returns The folder name for the dependency\n */\nexport function depPathToFilenameUnescaped(depPath: string): string {\n if (depPath.indexOf('file:') !== 0) {\n if (depPath.startsWith('/')) {\n depPath = depPath.slice(1);\n }\n return depPath;\n }\n return depPath.replace(':', '+');\n}\n\n/**\n *\n * @param missingOptionalDependencies - The set of optional dependencies that were not installed\n * @param contexts - The map of context roots to their respective contexts\n * @param commonPathPrefix - The common root path to trim\n * @returns A function that serializes a context into a format that can be written to disk\n */\nexport function createContextSerializer(\n missingOptionalDependencies: Set<string>,\n contexts: Map<string, IResolverContext>,\n commonPathPrefix: string\n): (entry: [string, IResolverContext]) => ISerializedResolveContext {\n return ([descriptionFileRoot, context]: [string, IResolverContext]): ISerializedResolveContext => {\n const { deps, name, nestedPackageDirs } = context;\n\n let hasAnyDeps: boolean = false;\n const serializedDeps: ISerializedResolveContext['deps'] = {};\n for (const [key, contextRoot] of deps) {\n if (missingOptionalDependencies.has(contextRoot)) {\n continue;\n }\n\n const resolutionContext: IResolverContext | undefined = contexts.get(contextRoot);\n if (!resolutionContext) {\n throw new Error(`Missing context for ${contextRoot}!`);\n }\n serializedDeps[key] = resolutionContext.ordinal;\n hasAnyDeps = true;\n }\n\n if (!name) {\n throw new Error(`Missing name for ${descriptionFileRoot}`);\n }\n\n const serializedContext: ISerializedResolveContext = {\n name,\n root: descriptionFileRoot.slice(commonPathPrefix.length),\n dirInfoFiles: nestedPackageDirs?.length ? nestedPackageDirs : undefined,\n deps: hasAnyDeps ? serializedDeps : undefined\n };\n\n return serializedContext;\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkB3D,oDAqBC;AAUD,sEAiBC;AAED,kDAoBC;AAOD,oEAcC;AASD,0DAoCC;AAxJD,gDAAkC;AAOlC;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAClC,cAAsB,EACtB,GAAW,EACX,SAAiB,EACjB,OAAyB,EACzB,OAA4B,EAC5B,WAA2C;IAE3C,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CACpB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,cAAc,E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,CAAC,CAAC,CAAC,SAAS;YACvE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;QAEF,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'node:path';\n\nimport type { ISerializedResolveContext } from '@rushstack/webpack-workspace-resolve-plugin';\n\nimport type { IDependencyEntry, IResolverContext } from './types';\nimport type { IPnpmVersionHelpers } from './pnpm/pnpmVersionHelpers';\n\n/**\n * Computes the root folder for a dependency from a reference to it in another package\n * @param lockfileFolder - The folder that contains the lockfile\n * @param key - The key of the dependency\n * @param specifier - The specifier in the lockfile for the dependency\n * @param context - The owning package\n * @param helpers - Version-specific pnpm helpers\n * @returns The identifier for the dependency\n */\nexport function resolveDependencyKey(\n lockfileFolder: string,\n key: string,\n specifier: string,\n context: IResolverContext,\n helpers: IPnpmVersionHelpers,\n packageKeys?: { has(key: string): boolean }\n): string {\n if (specifier.startsWith('link:')) {\n return path.posix.join(\n context.isProject ? context.descriptionFileRoot : lockfileFolder,\n specifier.slice(5)\n );\n } else if (specifier.startsWith('file:')) {\n return getDescriptionFileRootFromKey(lockfileFolder, specifier, helpers.depPathToFilename, key);\n } else {\n const resolvedKey: string = packageKeys?.has(specifier)\n ? specifier\n : helpers.buildDependencyKey(key, specifier);\n return getDescriptionFileRootFromKey(lockfileFolder, resolvedKey, helpers.depPathToFilename);\n }\n}\n\n/**\n * Computes the physical path to a dependency based on its entry\n * @param lockfileFolder - The folder that contains the lockfile during installation\n * @param key - The key of the dependency\n * @param depPathToFilename - Version-specific function to convert dep paths to filenames\n * @param name - The name of the dependency, if provided\n * @returns The physical path to the dependency\n */\nexport function getDescriptionFileRootFromKey(\n lockfileFolder: string,\n key: string,\n depPathToFilename: (depPath: string) => string,\n name?: string\n): string {\n if (!key.startsWith('file:') && !name) {\n const offset: number = key.startsWith('/') ? 1 : 0;\n name = key.slice(offset, key.indexOf('@', offset + 1));\n }\n if (!name) {\n throw new Error(`Missing package name for ${key}`);\n }\n\n const originFolder: string = `${lockfileFolder}/node_modules/.pnpm/${depPathToFilename(key)}/node_modules`;\n const descriptionFileRoot: string = `${originFolder}/${name}`;\n return descriptionFileRoot;\n}\n\nexport function resolveDependencies(\n lockfileFolder: string,\n collection: Record<string, IDependencyEntry>,\n context: IResolverContext,\n helpers: IPnpmVersionHelpers,\n packageKeys?: { has(key: string): boolean }\n): void {\n for (const [key, value] of Object.entries(collection)) {\n const version: string = typeof value === 'string' ? value : value.version;\n const resolved: string = resolveDependencyKey(\n lockfileFolder,\n key,\n version,\n context,\n helpers,\n packageKeys\n );\n\n context.deps.set(key, resolved);\n }\n}\n\n/**\n * Extracts the package name and version from a lockfile package key.\n * @param key - The lockfile package key (e.g. '/autoprefixer\\@9.8.8', '\\@scope/name\\@1.0.0(peer\\@2.0.0)')\n * @returns The extracted name and version, or undefined for file: keys\n */\nexport function extractNameAndVersionFromKey(key: string): { name: string; version: string } | undefined {\n if (key.startsWith('file:')) {\n return undefined;\n }\n const offset: number = key.startsWith('/') ? 1 : 0;\n const versionAtIndex: number = key.indexOf('@', offset + 1);\n if (versionAtIndex === -1) {\n return undefined;\n }\n const name: string = key.slice(offset, versionAtIndex);\n const parenIndex: number = key.indexOf('(', versionAtIndex);\n const version: string =\n parenIndex !== -1 ? key.slice(versionAtIndex + 1, parenIndex) : key.slice(versionAtIndex + 1);\n return { name, version };\n}\n\n/**\n *\n * @param missingOptionalDependencies - The set of optional dependencies that were not installed\n * @param contexts - The map of context roots to their respective contexts\n * @param commonPathPrefix - The common root path to trim\n * @returns A function that serializes a context into a format that can be written to disk\n */\nexport function createContextSerializer(\n missingOptionalDependencies: Set<string>,\n contexts: Map<string, IResolverContext>,\n commonPathPrefix: string\n): (entry: [string, IResolverContext]) => ISerializedResolveContext {\n return ([descriptionFileRoot, context]: [string, IResolverContext]): ISerializedResolveContext => {\n const { deps, name, nestedPackageDirs } = context;\n\n let hasAnyDeps: boolean = false;\n const serializedDeps: ISerializedResolveContext['deps'] = {};\n for (const [key, contextRoot] of deps) {\n if (missingOptionalDependencies.has(contextRoot)) {\n continue;\n }\n\n const resolutionContext: IResolverContext | undefined = contexts.get(contextRoot);\n if (!resolutionContext) {\n throw new Error(`Missing context for ${contextRoot}!`);\n }\n serializedDeps[key] = resolutionContext.ordinal;\n hasAnyDeps = true;\n }\n\n if (!name) {\n throw new Error(`Missing name for ${descriptionFileRoot}`);\n }\n\n const serializedContext: ISerializedResolveContext = {\n name,\n root: descriptionFileRoot.slice(commonPathPrefix.length),\n dirInfoFiles: nestedPackageDirs?.length ? nestedPackageDirs : undefined,\n deps: hasAnyDeps ? serializedDeps : undefined\n };\n\n return serializedContext;\n };\n}\n"]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.depPathToFilenameUnescaped = depPathToFilenameUnescaped;
6
+ exports.createDepPathToFilename = createDepPathToFilename;
7
+ // Shared logic for pnpm 9+ depPathToFilename implementations.
8
+ // The depPathToFilenameUnescaped function and overall depPathToFilename structure
9
+ // are identical between pnpm 9 and 10; only the hash function, hash length, and
10
+ // special-character regex differ.
11
+ const TRAILING_PAREN_REGEX = /\)$/;
12
+ const PARENS_REGEX = /\)\(|\(|\)/g;
13
+ function depPathToFilenameUnescaped(depPath) {
14
+ if (depPath.indexOf('file:') !== 0) {
15
+ if (depPath[0] === '/') {
16
+ depPath = depPath.substring(1);
17
+ }
18
+ const index = depPath.indexOf('@', 1);
19
+ if (index === -1)
20
+ return depPath;
21
+ return `${depPath.substring(0, index)}@${depPath.slice(index + 1)}`;
22
+ }
23
+ return depPath.replace(':', '+');
24
+ }
25
+ function createDepPathToFilename(options) {
26
+ const { specialCharsRegex, maxLengthWithoutHash, hashFn } = options;
27
+ return (depPath) => {
28
+ let filename = depPathToFilenameUnescaped(depPath).replace(specialCharsRegex, '+');
29
+ if (filename.includes('(')) {
30
+ filename = filename.replace(TRAILING_PAREN_REGEX, '').replace(PARENS_REGEX, '_');
31
+ }
32
+ if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {
33
+ return `${filename.substring(0, maxLengthWithoutHash)}_${hashFn(filename)}`;
34
+ }
35
+ return filename;
36
+ };
37
+ }
38
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/pnpm/depPath/common.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAU3D,gEAUC;AAQD,0DAYC;AAtCD,8DAA8D;AAC9D,kFAAkF;AAClF,gFAAgF;AAChF,kCAAkC;AAElC,MAAM,oBAAoB,GAAW,KAAK,CAAC;AAC3C,MAAM,YAAY,GAAW,aAAa,CAAC;AAE3C,SAAgB,0BAA0B,CAAC,OAAe;IACxD,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACvB,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,KAAK,GAAW,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC9C,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,OAAO,OAAO,CAAC;QACjC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;IACtE,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAQD,SAAgB,uBAAuB,CAAC,OAAkC;IACxE,MAAM,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACpE,OAAO,CAAC,OAAe,EAAU,EAAE;QACjC,IAAI,QAAQ,GAAW,0BAA0B,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAC3F,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;YACpG,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,oBAAoB,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9E,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// Shared logic for pnpm 9+ depPathToFilename implementations.\n// The depPathToFilenameUnescaped function and overall depPathToFilename structure\n// are identical between pnpm 9 and 10; only the hash function, hash length, and\n// special-character regex differ.\n\nconst TRAILING_PAREN_REGEX: RegExp = /\\)$/;\nconst PARENS_REGEX: RegExp = /\\)\\(|\\(|\\)/g;\n\nexport function depPathToFilenameUnescaped(depPath: string): string {\n if (depPath.indexOf('file:') !== 0) {\n if (depPath[0] === '/') {\n depPath = depPath.substring(1);\n }\n const index: number = depPath.indexOf('@', 1);\n if (index === -1) return depPath;\n return `${depPath.substring(0, index)}@${depPath.slice(index + 1)}`;\n }\n return depPath.replace(':', '+');\n}\n\nexport interface IDepPathToFilenameOptions {\n specialCharsRegex: RegExp;\n maxLengthWithoutHash: number;\n hashFn: (input: string) => string;\n}\n\nexport function createDepPathToFilename(options: IDepPathToFilenameOptions): (depPath: string) => string {\n const { specialCharsRegex, maxLengthWithoutHash, hashFn } = options;\n return (depPath: string): string => {\n let filename: string = depPathToFilenameUnescaped(depPath).replace(specialCharsRegex, '+');\n if (filename.includes('(')) {\n filename = filename.replace(TRAILING_PAREN_REGEX, '').replace(PARENS_REGEX, '_');\n }\n if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {\n return `${filename.substring(0, maxLengthWithoutHash)}_${hashFn(filename)}`;\n }\n return filename;\n };\n}\n"]}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createBase32Hash = createBase32Hash;
6
+ exports.createShortSha256Hash = createShortSha256Hash;
7
+ // Hash functions vendored from pnpm to avoid transitive dependencies.
8
+ //
9
+ // createBase32Hash (MD5 base32, used by pnpm 8 and 9):
10
+ // https://github.com/pnpm/pnpm/blob/afe8ecef1f24812845b699c141d52643d1524079/packages/crypto.base32-hash/src/index.ts
11
+ // base32 encoding (from rfc4648):
12
+ // https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118
13
+ //
14
+ // createShortSha256Hash (SHA-256 hex truncated to 32 chars, used by pnpm 10):
15
+ // https://github.com/pnpm/pnpm/blob/42ecf04fd0e442af8610ae4231855e004732dbf7/crypto/hash/src/index.ts
16
+ const node_crypto_1 = require("node:crypto");
17
+ const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567'.split('');
18
+ function createBase32Hash(input) {
19
+ const data = (0, node_crypto_1.createHash)('md5').update(input).digest();
20
+ const mask = 0x1f;
21
+ let out = '';
22
+ let bits = 0;
23
+ let buffer = 0;
24
+ for (let i = 0; i < data.length; ++i) {
25
+ // eslint-disable-next-line no-bitwise
26
+ buffer = (buffer << 8) | (0xff & data[i]);
27
+ bits += 8;
28
+ while (bits > 5) {
29
+ bits -= 5;
30
+ // eslint-disable-next-line no-bitwise
31
+ out += BASE32[mask & (buffer >> bits)];
32
+ }
33
+ }
34
+ if (bits) {
35
+ // eslint-disable-next-line no-bitwise
36
+ out += BASE32[mask & (buffer << (5 - bits))];
37
+ }
38
+ return out;
39
+ }
40
+ function createShortSha256Hash(input) {
41
+ return (0, node_crypto_1.createHash)('sha256').update(input).digest('hex').substring(0, 32);
42
+ }
43
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/pnpm/depPath/hash.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAgB3D,4CA0BC;AAED,sDAEC;AA5CD,sEAAsE;AACtE,EAAE;AACF,uDAAuD;AACvD,wHAAwH;AACxH,kCAAkC;AAClC,iHAAiH;AACjH,EAAE;AACF,8EAA8E;AAC9E,wGAAwG;AAExG,6CAAyC;AAEzC,MAAM,MAAM,GAAa,kCAAkC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEtE,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,MAAM,IAAI,GAAW,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAE9D,MAAM,IAAI,GAAS,IAAI,CAAC;IACxB,IAAI,GAAG,GAAW,EAAE,CAAC;IAErB,IAAI,IAAI,GAAW,CAAC,CAAC;IACrB,IAAI,MAAM,GAAW,CAAC,CAAC;IACvB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7C,sCAAsC;QACtC,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,IAAI,CAAC,CAAC;QAEV,OAAO,IAAI,GAAG,CAAC,EAAE,CAAC;YAChB,IAAI,IAAI,CAAC,CAAC;YACV,sCAAsC;YACtC,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,sCAAsC;QACtC,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,qBAAqB,CAAC,KAAa;IACjD,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// Hash functions vendored from pnpm to avoid transitive dependencies.\n//\n// createBase32Hash (MD5 base32, used by pnpm 8 and 9):\n// https://github.com/pnpm/pnpm/blob/afe8ecef1f24812845b699c141d52643d1524079/packages/crypto.base32-hash/src/index.ts\n// base32 encoding (from rfc4648):\n// https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118\n//\n// createShortSha256Hash (SHA-256 hex truncated to 32 chars, used by pnpm 10):\n// https://github.com/pnpm/pnpm/blob/42ecf04fd0e442af8610ae4231855e004732dbf7/crypto/hash/src/index.ts\n\nimport { createHash } from 'node:crypto';\n\nconst BASE32: string[] = 'abcdefghijklmnopqrstuvwxyz234567'.split('');\n\nexport function createBase32Hash(input: string): string {\n const data: Buffer = createHash('md5').update(input).digest();\n\n const mask: 0x1f = 0x1f;\n let out: string = '';\n\n let bits: number = 0;\n let buffer: number = 0;\n for (let i: number = 0; i < data.length; ++i) {\n // eslint-disable-next-line no-bitwise\n buffer = (buffer << 8) | (0xff & data[i]);\n bits += 8;\n\n while (bits > 5) {\n bits -= 5;\n // eslint-disable-next-line no-bitwise\n out += BASE32[mask & (buffer >> bits)];\n }\n }\n\n if (bits) {\n // eslint-disable-next-line no-bitwise\n out += BASE32[mask & (buffer << (5 - bits))];\n }\n\n return out;\n}\n\nexport function createShortSha256Hash(input: string): string {\n return createHash('sha256').update(input).digest('hex').substring(0, 32);\n}\n"]}