@rushstack/rush-resolver-cache-plugin 5.173.0 → 5.175.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.
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-commonjs/afterInstallAsync.js +19 -6
- package/lib-commonjs/afterInstallAsync.js.map +1 -1
- package/lib-commonjs/computeResolverCacheFromLockfileAsync.js +17 -11
- package/lib-commonjs/computeResolverCacheFromLockfileAsync.js.map +1 -1
- package/lib-commonjs/helpers.js +32 -70
- package/lib-commonjs/helpers.js.map +1 -1
- package/lib-commonjs/pnpm/depPath/common.js +38 -0
- package/lib-commonjs/pnpm/depPath/common.js.map +1 -0
- package/lib-commonjs/pnpm/depPath/hash.js +43 -0
- package/lib-commonjs/pnpm/depPath/hash.js.map +1 -0
- package/lib-commonjs/pnpm/depPath/v10.js +15 -0
- package/lib-commonjs/pnpm/depPath/v10.js.map +1 -0
- package/lib-commonjs/pnpm/depPath/v8.js +26 -0
- package/lib-commonjs/pnpm/depPath/v8.js.map +1 -0
- package/lib-commonjs/pnpm/depPath/v9.js +15 -0
- package/lib-commonjs/pnpm/depPath/v9.js.map +1 -0
- package/lib-commonjs/pnpm/keys/v6.js +10 -0
- package/lib-commonjs/pnpm/keys/v6.js.map +1 -0
- package/lib-commonjs/pnpm/keys/v9.js +10 -0
- package/lib-commonjs/pnpm/keys/v9.js.map +1 -0
- package/lib-commonjs/pnpm/pnpmVersionHelpers.js +55 -0
- package/lib-commonjs/pnpm/pnpmVersionHelpers.js.map +1 -0
- package/lib-commonjs/pnpm/store/v10.js +38 -0
- package/lib-commonjs/pnpm/store/v10.js.map +1 -0
- package/lib-commonjs/pnpm/store/v3.js +10 -0
- package/lib-commonjs/pnpm/store/v3.js.map +1 -0
- package/lib-commonjs/pnpm/v10.js +14 -0
- package/lib-commonjs/pnpm/v10.js.map +1 -0
- package/lib-commonjs/pnpm/v8.js +14 -0
- package/lib-commonjs/pnpm/v8.js.map +1 -0
- package/lib-commonjs/pnpm/v9.js +16 -0
- package/lib-commonjs/pnpm/v9.js.map +1 -0
- package/lib-commonjs/types.js.map +1 -1
- package/lib-dts/afterInstallAsync.d.ts.map +1 -1
- package/lib-dts/computeResolverCacheFromLockfileAsync.d.ts +7 -0
- package/lib-dts/computeResolverCacheFromLockfileAsync.d.ts.map +1 -1
- package/lib-dts/helpers.d.ts +17 -9
- package/lib-dts/helpers.d.ts.map +1 -1
- package/lib-dts/pnpm/depPath/common.d.ts +8 -0
- package/lib-dts/pnpm/depPath/common.d.ts.map +1 -0
- package/lib-dts/pnpm/depPath/hash.d.ts +3 -0
- package/lib-dts/pnpm/depPath/hash.d.ts.map +1 -0
- package/lib-dts/pnpm/depPath/v10.d.ts +2 -0
- package/lib-dts/pnpm/depPath/v10.d.ts.map +1 -0
- package/lib-dts/pnpm/depPath/v8.d.ts +2 -0
- package/lib-dts/pnpm/depPath/v8.d.ts.map +1 -0
- package/lib-dts/pnpm/depPath/v9.d.ts +2 -0
- package/lib-dts/pnpm/depPath/v9.d.ts.map +1 -0
- package/lib-dts/pnpm/keys/v6.d.ts +2 -0
- package/lib-dts/pnpm/keys/v6.d.ts.map +1 -0
- package/lib-dts/pnpm/keys/v9.d.ts +2 -0
- package/lib-dts/pnpm/keys/v9.d.ts.map +1 -0
- package/lib-dts/pnpm/pnpmVersionHelpers.d.ts +38 -0
- package/lib-dts/pnpm/pnpmVersionHelpers.d.ts.map +1 -0
- package/lib-dts/pnpm/store/v10.d.ts +3 -0
- package/lib-dts/pnpm/store/v10.d.ts.map +1 -0
- package/lib-dts/pnpm/store/v3.d.ts +3 -0
- package/lib-dts/pnpm/store/v3.d.ts.map +1 -0
- package/lib-dts/pnpm/v10.d.ts +3 -0
- package/lib-dts/pnpm/v10.d.ts.map +1 -0
- package/lib-dts/pnpm/v8.d.ts +3 -0
- package/lib-dts/pnpm/v8.d.ts.map +1 -0
- package/lib-dts/pnpm/v9.d.ts +3 -0
- package/lib-dts/pnpm/v9.d.ts.map +1 -0
- package/lib-dts/types.d.ts +1 -0
- package/lib-dts/types.d.ts.map +1 -1
- package/lib-esm/afterInstallAsync.js +19 -6
- package/lib-esm/afterInstallAsync.js.map +1 -1
- package/lib-esm/computeResolverCacheFromLockfileAsync.js +18 -12
- package/lib-esm/computeResolverCacheFromLockfileAsync.js.map +1 -1
- package/lib-esm/helpers.js +31 -67
- package/lib-esm/helpers.js.map +1 -1
- package/lib-esm/pnpm/depPath/common.js +34 -0
- package/lib-esm/pnpm/depPath/common.js.map +1 -0
- package/lib-esm/pnpm/depPath/hash.js +39 -0
- package/lib-esm/pnpm/depPath/hash.js.map +1 -0
- package/lib-esm/pnpm/depPath/v10.js +12 -0
- package/lib-esm/pnpm/depPath/v10.js.map +1 -0
- package/lib-esm/pnpm/depPath/v8.js +23 -0
- package/lib-esm/pnpm/depPath/v8.js.map +1 -0
- package/lib-esm/pnpm/depPath/v9.js +12 -0
- package/lib-esm/pnpm/depPath/v9.js.map +1 -0
- package/lib-esm/pnpm/keys/v6.js +7 -0
- package/lib-esm/pnpm/keys/v6.js.map +1 -0
- package/lib-esm/pnpm/keys/v9.js +7 -0
- package/lib-esm/pnpm/keys/v9.js.map +1 -0
- package/lib-esm/pnpm/pnpmVersionHelpers.js +19 -0
- package/lib-esm/pnpm/pnpmVersionHelpers.js.map +1 -0
- package/lib-esm/pnpm/store/v10.js +35 -0
- package/lib-esm/pnpm/store/v10.js.map +1 -0
- package/lib-esm/pnpm/store/v3.js +7 -0
- package/lib-esm/pnpm/store/v3.js.map +1 -0
- package/lib-esm/pnpm/v10.js +11 -0
- package/lib-esm/pnpm/v10.js.map +1 -0
- package/lib-esm/pnpm/v8.js +11 -0
- package/lib-esm/pnpm/v8.js.map +1 -0
- package/lib-esm/pnpm/v9.js +13 -0
- package/lib-esm/pnpm/v9.js.map +1 -0
- package/lib-esm/types.js.map +1 -1
- package/package.json +7 -7
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// See LICENSE in the project root for license information.
|
|
3
3
|
import { Async, FileSystem, PnpmShrinkwrapFile } from './externals';
|
|
4
4
|
import { computeResolverCacheFromLockfileAsync } from './computeResolverCacheFromLockfileAsync';
|
|
5
|
+
import { getPnpmVersionHelpersAsync } from './pnpm/pnpmVersionHelpers';
|
|
5
6
|
/**
|
|
6
7
|
* Gets information used to determine compatibility of optional dependencies.
|
|
7
8
|
* @returns Information about the platform Rush is running on
|
|
@@ -34,9 +35,23 @@ export async function afterInstallAsync(rushSession, rushConfiguration, subspace
|
|
|
34
35
|
const { terminal } = logger;
|
|
35
36
|
const rushRoot = `${rushConfiguration.rushJsonFolder}/`;
|
|
36
37
|
const lockFilePath = subspace.getCommittedShrinkwrapFilePath(variant);
|
|
37
|
-
const
|
|
38
|
+
const pnpmStorePath = rushConfiguration.pnpmOptions.pnpmStorePath;
|
|
39
|
+
const pnpmMajorVersion = (() => {
|
|
40
|
+
const major = parseInt(rushConfiguration.packageManagerToolVersion, 10);
|
|
41
|
+
switch (major) {
|
|
42
|
+
case 10:
|
|
43
|
+
return 10;
|
|
44
|
+
case 9:
|
|
45
|
+
return 9;
|
|
46
|
+
case 8:
|
|
47
|
+
return 8;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unsupported pnpm major version: ${major}`);
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
const pnpmHelpers = await getPnpmVersionHelpersAsync(pnpmMajorVersion);
|
|
38
53
|
terminal.writeLine(`Using pnpm-lock from: ${lockFilePath}`);
|
|
39
|
-
terminal.writeLine(`Using pnpm store
|
|
54
|
+
terminal.writeLine(`Using pnpm ${pnpmMajorVersion} store at: ${pnpmStorePath}`);
|
|
40
55
|
const workspaceRoot = subspace.getSubspaceTempFolderPath();
|
|
41
56
|
const cacheFilePath = `${workspaceRoot}/resolver-cache.json`;
|
|
42
57
|
const lockFile = PnpmShrinkwrapFile.loadFromFile(lockFilePath, {
|
|
@@ -99,10 +114,7 @@ export async function afterInstallAsync(rushSession, rushConfiguration, subspace
|
|
|
99
114
|
// 0baba219027e1ade11c875d762dfaff5ff92375bfcdf1ebc511c20c4d43df1cbc7f24c62bb2c1618fe1778d675a5a3b367adda6377137220844093455258e52f
|
|
100
115
|
const prefixIndex = descriptionFileHash.indexOf('-');
|
|
101
116
|
const hash = Buffer.from(descriptionFileHash.slice(prefixIndex + 1), 'base64').toString('hex');
|
|
102
|
-
|
|
103
|
-
// <store>/v3/files/<hash (0-2)>/<hash (2-)>-index.json
|
|
104
|
-
// See https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/store/cafs/src/getFilePathInCafs.ts#L33
|
|
105
|
-
const indexPath = `${pnpmStoreDir}${hash.slice(0, 2)}/${hash.slice(2)}-index.json`;
|
|
117
|
+
const indexPath = pnpmHelpers.getStoreIndexPath(pnpmStorePath, context, hash);
|
|
106
118
|
try {
|
|
107
119
|
const indexContent = await FileSystem.readFileAsync(indexPath);
|
|
108
120
|
let endIndex = indexContent.lastIndexOf(END_TOKEN);
|
|
@@ -174,6 +186,7 @@ export async function afterInstallAsync(rushSession, rushConfiguration, subspace
|
|
|
174
186
|
platformInfo: getPlatformInfo(),
|
|
175
187
|
projectByImporterPath,
|
|
176
188
|
lockfile: lockFile,
|
|
189
|
+
pnpmVersion: pnpmMajorVersion,
|
|
177
190
|
afterExternalPackagesAsync
|
|
178
191
|
});
|
|
179
192
|
const extendedCacheFile = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"afterInstallAsync.js","sourceRoot":"","sources":["../src/afterInstallAsync.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAY3D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EACL,qCAAqC,EAEtC,MAAM,yCAAyC,CAAC;AAGjD;;;GAGG;AACH,SAAS,eAAe;;IACtB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,EACJ,QAAQ,EAAE,E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AE,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC;KAC3D,CAAC;IACF,MAAM,yBAAyB,GAAW,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,UAAU,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE;YACnD,kBAAkB,EAAE,IAAI;SACzB,CAAC;QACF,UAAU,CAAC,cAAc,CAAC,uBAAuB,EAAE,yBAAyB,EAAE;YAC5E,kBAAkB,EAAE,IAAI;SACzB,CAAC;KACH,CAAC,CAAC;IAEH,oGAAoG;IACpG,kBAAkB,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,"file":"afterInstallAsync.js","sourceRoot":"","sources":["../src/afterInstallAsync.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAY3D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EACL,qCAAqC,EAEtC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAGL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAGnC;;;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,MAAC,MAAA,OAAO,CAAC,MAAM,0CAAE,SAAS,EAAU,0CAAE,MAAM,mCAAI,OAAO,CAAC;IAC5D,MAAM,IAAI,GAAqB,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAEtE,OAAO;QACL,EAAE;QACF,GAAG;QACH,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAW,iBAAiB,CAAC;AAC5C,MAAM,2BAA2B,GAAM,CAAC,CAAC;AAkBzC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,WAAwB,EACxB,iBAAoC,EACpC,QAAkB,EAClB,OAA2B,EAC3B,MAAe;IAEf,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAC5B,MAAM,QAAQ,GAAW,GAAG,iBAAiB,CAAC,cAAc,GAAG,CAAC;IAEhE,MAAM,YAAY,GAAW,QAAQ,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC;IAE9E,MAAM,aAAa,GAAW,iBAAiB,CAAC,WAAW,CAAC,aAAa,CAAC;IAE1E,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EAAE;YAC5E,kBAAkB,EAAE,IAAI;SACzB,CAAC;KACH,CAAC,CAAC;IAEH,oGAAoG;IACpG,kBAAkB,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 {\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"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
2
|
// See LICENSE in the project root for license information.
|
|
3
|
-
import { getDescriptionFileRootFromKey, resolveDependencies, createContextSerializer } from './helpers';
|
|
3
|
+
import { getDescriptionFileRootFromKey, resolveDependencies, createContextSerializer, extractNameAndVersionFromKey } from './helpers';
|
|
4
|
+
import { getPnpmVersionHelpersAsync } from './pnpm/pnpmVersionHelpers';
|
|
4
5
|
function isPackageCompatible(pack, platformInfo) {
|
|
5
6
|
var _a, _b, _c;
|
|
6
7
|
if ((_a = pack.os) === null || _a === void 0 ? void 0 : _a.every((value) => value.toLowerCase() !== platformInfo.os)) {
|
|
@@ -64,13 +65,14 @@ function extractBundledDependencies(contexts, context) {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
67
69
|
/**
|
|
68
70
|
* Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency
|
|
69
71
|
* @param path - Path using backslashes as path separators
|
|
70
72
|
* @returns The same string using forward slashes as path separators
|
|
71
73
|
*/
|
|
72
74
|
function convertToSlashes(path) {
|
|
73
|
-
return path.replace(
|
|
75
|
+
return path.replace(BACKSLASH_REGEX, '/');
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Given a lockfile and information about the workspace and platform, computes the resolver cache file.
|
|
@@ -86,19 +88,22 @@ export async function computeResolverCacheFromLockfileAsync(params) {
|
|
|
86
88
|
const commonPrefixToTrim = convertToSlashes(params.commonPrefixToTrim);
|
|
87
89
|
const contexts = new Map();
|
|
88
90
|
const missingOptionalDependencies = new Set();
|
|
91
|
+
const helpers = await getPnpmVersionHelpersAsync(params.pnpmVersion);
|
|
92
|
+
const { packages } = lockfile;
|
|
89
93
|
// Enumerate external dependencies first, to simplify looping over them for store data
|
|
90
|
-
for (const [key, pack] of
|
|
94
|
+
for (const [key, pack] of packages) {
|
|
91
95
|
let name = pack.name;
|
|
92
|
-
const descriptionFileRoot = getDescriptionFileRootFromKey(workspaceRoot, key, name);
|
|
96
|
+
const descriptionFileRoot = getDescriptionFileRootFromKey(workspaceRoot, key, helpers.depPathToFilename, name);
|
|
93
97
|
// Skip optional dependencies that are incompatible with the current environment
|
|
94
98
|
if (pack.optional && !isPackageCompatible(pack, platformInfo)) {
|
|
95
99
|
missingOptionalDependencies.add(descriptionFileRoot);
|
|
96
100
|
continue;
|
|
97
101
|
}
|
|
98
102
|
const integrity = (_a = pack.resolution) === null || _a === void 0 ? void 0 : _a.integrity;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
// Extract name and version from the key if not already provided
|
|
104
|
+
const parsed = extractNameAndVersionFromKey(key);
|
|
105
|
+
if (parsed) {
|
|
106
|
+
name || (name = parsed.name);
|
|
102
107
|
}
|
|
103
108
|
if (!name) {
|
|
104
109
|
throw new Error(`Missing name for ${key}`);
|
|
@@ -108,16 +113,17 @@ export async function computeResolverCacheFromLockfileAsync(params) {
|
|
|
108
113
|
descriptionFileHash: integrity,
|
|
109
114
|
isProject: false,
|
|
110
115
|
name,
|
|
116
|
+
version: parsed === null || parsed === void 0 ? void 0 : parsed.version,
|
|
111
117
|
deps: new Map(),
|
|
112
118
|
ordinal: -1,
|
|
113
119
|
optional: pack.optional
|
|
114
120
|
};
|
|
115
121
|
contexts.set(descriptionFileRoot, context);
|
|
116
122
|
if (pack.dependencies) {
|
|
117
|
-
resolveDependencies(workspaceRoot, pack.dependencies, context);
|
|
123
|
+
resolveDependencies(workspaceRoot, pack.dependencies, context, helpers, packages);
|
|
118
124
|
}
|
|
119
125
|
if (pack.optionalDependencies) {
|
|
120
|
-
resolveDependencies(workspaceRoot, pack.optionalDependencies, context);
|
|
126
|
+
resolveDependencies(workspaceRoot, pack.optionalDependencies, context, helpers, packages);
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
if (afterExternalPackagesAsync) {
|
|
@@ -150,13 +156,13 @@ export async function computeResolverCacheFromLockfileAsync(params) {
|
|
|
150
156
|
};
|
|
151
157
|
contexts.set(descriptionFileRoot, context);
|
|
152
158
|
if (importer.dependencies) {
|
|
153
|
-
resolveDependencies(workspaceRoot, importer.dependencies, context);
|
|
159
|
+
resolveDependencies(workspaceRoot, importer.dependencies, context, helpers, packages);
|
|
154
160
|
}
|
|
155
161
|
if (importer.devDependencies) {
|
|
156
|
-
resolveDependencies(workspaceRoot, importer.devDependencies, context);
|
|
162
|
+
resolveDependencies(workspaceRoot, importer.devDependencies, context, helpers, packages);
|
|
157
163
|
}
|
|
158
164
|
if (importer.optionalDependencies) {
|
|
159
|
-
resolveDependencies(workspaceRoot, importer.optionalDependencies, context);
|
|
165
|
+
resolveDependencies(workspaceRoot, importer.optionalDependencies, context, helpers, packages);
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
168
|
let ordinal = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeResolverCacheFromLockfileAsync.js","sourceRoot":"","sources":["../src/computeResolverCacheFromLockfileAsync.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAU3D,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAoBxG,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,Y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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;AAU3D,OAAO,EACL,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAoBnC,SAAS,mBAAmB,CAC1B,IAAgE,EAChE,YAA2B;;IAE3B,IAAI,MAAA,IAAI,C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AAC,aAAa,EAAE,QAAQ,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,QAAQ,CAAC,oBAAoB,EAAE,CAAC;YAClC,mBAAmB,CAAC,aAAa,EAAE,QAAQ,CAAC,oBAAoB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAChG,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,uBAAuB,CAAC,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 {\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"]}
|
package/lib-esm/helpers.js
CHANGED
|
@@ -1,82 +1,41 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
2
|
// See LICENSE in the project root for license information.
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
3
|
import * as path from 'node:path';
|
|
5
|
-
const MAX_LENGTH_WITHOUT_HASH = 120 - 26 - 1;
|
|
6
|
-
const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567'.split('');
|
|
7
|
-
// https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118
|
|
8
|
-
export function createBase32Hash(input) {
|
|
9
|
-
const data = createHash('md5').update(input).digest();
|
|
10
|
-
const mask = 0x1f;
|
|
11
|
-
let out = '';
|
|
12
|
-
let bits = 0; // Number of bits currently in the buffer
|
|
13
|
-
let buffer = 0; // Bits waiting to be written out, MSB first
|
|
14
|
-
for (let i = 0; i < data.length; ++i) {
|
|
15
|
-
// eslint-disable-next-line no-bitwise
|
|
16
|
-
buffer = (buffer << 8) | (0xff & data[i]);
|
|
17
|
-
bits += 8;
|
|
18
|
-
// Write out as much as we can:
|
|
19
|
-
while (bits > 5) {
|
|
20
|
-
bits -= 5;
|
|
21
|
-
// eslint-disable-next-line no-bitwise
|
|
22
|
-
out += BASE32[mask & (buffer >> bits)];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// Partial character:
|
|
26
|
-
if (bits) {
|
|
27
|
-
// eslint-disable-next-line no-bitwise
|
|
28
|
-
out += BASE32[mask & (buffer << (5 - bits))];
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
// https://github.com/pnpm/pnpm/blob/f394cfccda7bc519ceee8c33fc9b68a0f4235532/packages/dependency-path/src/index.ts#L167-L189
|
|
33
|
-
export function depPathToFilename(depPath) {
|
|
34
|
-
let filename = depPathToFilenameUnescaped(depPath).replace(/[\\/:*?"<>|]/g, '+');
|
|
35
|
-
if (filename.includes('(')) {
|
|
36
|
-
filename = filename.replace(/(\)\()|\(/g, '_').replace(/\)$/, '');
|
|
37
|
-
}
|
|
38
|
-
if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {
|
|
39
|
-
return `${filename.substring(0, MAX_LENGTH_WITHOUT_HASH)}_${createBase32Hash(filename)}`;
|
|
40
|
-
}
|
|
41
|
-
return filename;
|
|
42
|
-
}
|
|
43
4
|
/**
|
|
44
5
|
* Computes the root folder for a dependency from a reference to it in another package
|
|
45
6
|
* @param lockfileFolder - The folder that contains the lockfile
|
|
46
7
|
* @param key - The key of the dependency
|
|
47
8
|
* @param specifier - The specifier in the lockfile for the dependency
|
|
48
9
|
* @param context - The owning package
|
|
10
|
+
* @param helpers - Version-specific pnpm helpers
|
|
49
11
|
* @returns The identifier for the dependency
|
|
50
12
|
*/
|
|
51
|
-
export function resolveDependencyKey(lockfileFolder, key, specifier, context) {
|
|
52
|
-
if (specifier.startsWith('
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
else if (specifier.startsWith('link:')) {
|
|
56
|
-
if (context.isProject) {
|
|
57
|
-
return path.posix.join(context.descriptionFileRoot, specifier.slice(5));
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return path.posix.join(lockfileFolder, specifier.slice(5));
|
|
61
|
-
}
|
|
13
|
+
export function resolveDependencyKey(lockfileFolder, key, specifier, context, helpers, packageKeys) {
|
|
14
|
+
if (specifier.startsWith('link:')) {
|
|
15
|
+
return path.posix.join(context.isProject ? context.descriptionFileRoot : lockfileFolder, specifier.slice(5));
|
|
62
16
|
}
|
|
63
17
|
else if (specifier.startsWith('file:')) {
|
|
64
|
-
return getDescriptionFileRootFromKey(lockfileFolder, specifier, key);
|
|
18
|
+
return getDescriptionFileRootFromKey(lockfileFolder, specifier, helpers.depPathToFilename, key);
|
|
65
19
|
}
|
|
66
20
|
else {
|
|
67
|
-
|
|
21
|
+
const resolvedKey = (packageKeys === null || packageKeys === void 0 ? void 0 : packageKeys.has(specifier))
|
|
22
|
+
? specifier
|
|
23
|
+
: helpers.buildDependencyKey(key, specifier);
|
|
24
|
+
return getDescriptionFileRootFromKey(lockfileFolder, resolvedKey, helpers.depPathToFilename);
|
|
68
25
|
}
|
|
69
26
|
}
|
|
70
27
|
/**
|
|
71
28
|
* Computes the physical path to a dependency based on its entry
|
|
72
29
|
* @param lockfileFolder - The folder that contains the lockfile during installation
|
|
73
30
|
* @param key - The key of the dependency
|
|
31
|
+
* @param depPathToFilename - Version-specific function to convert dep paths to filenames
|
|
74
32
|
* @param name - The name of the dependency, if provided
|
|
75
33
|
* @returns The physical path to the dependency
|
|
76
34
|
*/
|
|
77
|
-
export function getDescriptionFileRootFromKey(lockfileFolder, key, name) {
|
|
78
|
-
if (!key.startsWith('file:')) {
|
|
79
|
-
|
|
35
|
+
export function getDescriptionFileRootFromKey(lockfileFolder, key, depPathToFilename, name) {
|
|
36
|
+
if (!key.startsWith('file:') && !name) {
|
|
37
|
+
const offset = key.startsWith('/') ? 1 : 0;
|
|
38
|
+
name = key.slice(offset, key.indexOf('@', offset + 1));
|
|
80
39
|
}
|
|
81
40
|
if (!name) {
|
|
82
41
|
throw new Error(`Missing package name for ${key}`);
|
|
@@ -85,26 +44,31 @@ export function getDescriptionFileRootFromKey(lockfileFolder, key, name) {
|
|
|
85
44
|
const descriptionFileRoot = `${originFolder}/${name}`;
|
|
86
45
|
return descriptionFileRoot;
|
|
87
46
|
}
|
|
88
|
-
export function resolveDependencies(lockfileFolder, collection, context) {
|
|
47
|
+
export function resolveDependencies(lockfileFolder, collection, context, helpers, packageKeys) {
|
|
89
48
|
for (const [key, value] of Object.entries(collection)) {
|
|
90
49
|
const version = typeof value === 'string' ? value : value.version;
|
|
91
|
-
const resolved = resolveDependencyKey(lockfileFolder, key, version, context);
|
|
50
|
+
const resolved = resolveDependencyKey(lockfileFolder, key, version, context, helpers, packageKeys);
|
|
92
51
|
context.deps.set(key, resolved);
|
|
93
52
|
}
|
|
94
53
|
}
|
|
95
54
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @param
|
|
98
|
-
* @returns The
|
|
55
|
+
* Extracts the package name and version from a lockfile package key.
|
|
56
|
+
* @param key - The lockfile package key (e.g. '/autoprefixer\@9.8.8', '\@scope/name\@1.0.0(peer\@2.0.0)')
|
|
57
|
+
* @returns The extracted name and version, or undefined for file: keys
|
|
99
58
|
*/
|
|
100
|
-
export function
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
59
|
+
export function extractNameAndVersionFromKey(key) {
|
|
60
|
+
if (key.startsWith('file:')) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const offset = key.startsWith('/') ? 1 : 0;
|
|
64
|
+
const versionAtIndex = key.indexOf('@', offset + 1);
|
|
65
|
+
if (versionAtIndex === -1) {
|
|
66
|
+
return undefined;
|
|
106
67
|
}
|
|
107
|
-
|
|
68
|
+
const name = key.slice(offset, versionAtIndex);
|
|
69
|
+
const parenIndex = key.indexOf('(', versionAtIndex);
|
|
70
|
+
const version = parenIndex !== -1 ? key.slice(versionAtIndex + 1, parenIndex) : key.slice(versionAtIndex + 1);
|
|
71
|
+
return { name, version };
|
|
108
72
|
}
|
|
109
73
|
/**
|
|
110
74
|
*
|
package/lib-esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;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,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,IAAI,GAAW,UAAU,CAAC,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,K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,gBAAwB;IAExB,OAAO,CAAC,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;AAE3D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAOlC;;;;;;;;GAQG;AACH,MAAM,UAAU,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,EAChE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CACnB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ACvE,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,34 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
// Shared logic for pnpm 9+ depPathToFilename implementations.
|
|
4
|
+
// The depPathToFilenameUnescaped function and overall depPathToFilename structure
|
|
5
|
+
// are identical between pnpm 9 and 10; only the hash function, hash length, and
|
|
6
|
+
// special-character regex differ.
|
|
7
|
+
const TRAILING_PAREN_REGEX = /\)$/;
|
|
8
|
+
const PARENS_REGEX = /\)\(|\(|\)/g;
|
|
9
|
+
export function depPathToFilenameUnescaped(depPath) {
|
|
10
|
+
if (depPath.indexOf('file:') !== 0) {
|
|
11
|
+
if (depPath[0] === '/') {
|
|
12
|
+
depPath = depPath.substring(1);
|
|
13
|
+
}
|
|
14
|
+
const index = depPath.indexOf('@', 1);
|
|
15
|
+
if (index === -1)
|
|
16
|
+
return depPath;
|
|
17
|
+
return `${depPath.substring(0, index)}@${depPath.slice(index + 1)}`;
|
|
18
|
+
}
|
|
19
|
+
return depPath.replace(':', '+');
|
|
20
|
+
}
|
|
21
|
+
export function createDepPathToFilename(options) {
|
|
22
|
+
const { specialCharsRegex, maxLengthWithoutHash, hashFn } = options;
|
|
23
|
+
return (depPath) => {
|
|
24
|
+
let filename = depPathToFilenameUnescaped(depPath).replace(specialCharsRegex, '+');
|
|
25
|
+
if (filename.includes('(')) {
|
|
26
|
+
filename = filename.replace(TRAILING_PAREN_REGEX, '').replace(PARENS_REGEX, '_');
|
|
27
|
+
}
|
|
28
|
+
if (filename.length > 120 || (filename !== filename.toLowerCase() && !filename.startsWith('file+'))) {
|
|
29
|
+
return `${filename.substring(0, maxLengthWithoutHash)}_${hashFn(filename)}`;
|
|
30
|
+
}
|
|
31
|
+
return filename;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# 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;AAE3D,8DAA8D;AAC9D,kFAAkF;AAClF,gFAAgF;AAChF,kCAAkC;AAElC,MAAM,oBAAoB,GAAW,KAAK,CAAC;AAC3C,MAAM,YAAY,GAAW,aAAa,CAAC;AAE3C,MAAM,UAAU,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,MAAM,UAAU,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,39 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
// Hash functions vendored from pnpm to avoid transitive dependencies.
|
|
4
|
+
//
|
|
5
|
+
// createBase32Hash (MD5 base32, used by pnpm 8 and 9):
|
|
6
|
+
// https://github.com/pnpm/pnpm/blob/afe8ecef1f24812845b699c141d52643d1524079/packages/crypto.base32-hash/src/index.ts
|
|
7
|
+
// base32 encoding (from rfc4648):
|
|
8
|
+
// https://github.com/swansontec/rfc4648.js/blob/ead9c9b4b68e5d4a529f32925da02c02984e772c/src/codec.ts#L82-L118
|
|
9
|
+
//
|
|
10
|
+
// createShortSha256Hash (SHA-256 hex truncated to 32 chars, used by pnpm 10):
|
|
11
|
+
// https://github.com/pnpm/pnpm/blob/42ecf04fd0e442af8610ae4231855e004732dbf7/crypto/hash/src/index.ts
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
const BASE32 = 'abcdefghijklmnopqrstuvwxyz234567'.split('');
|
|
14
|
+
export function createBase32Hash(input) {
|
|
15
|
+
const data = createHash('md5').update(input).digest();
|
|
16
|
+
const mask = 0x1f;
|
|
17
|
+
let out = '';
|
|
18
|
+
let bits = 0;
|
|
19
|
+
let buffer = 0;
|
|
20
|
+
for (let i = 0; i < data.length; ++i) {
|
|
21
|
+
// eslint-disable-next-line no-bitwise
|
|
22
|
+
buffer = (buffer << 8) | (0xff & data[i]);
|
|
23
|
+
bits += 8;
|
|
24
|
+
while (bits > 5) {
|
|
25
|
+
bits -= 5;
|
|
26
|
+
// eslint-disable-next-line no-bitwise
|
|
27
|
+
out += BASE32[mask & (buffer >> bits)];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (bits) {
|
|
31
|
+
// eslint-disable-next-line no-bitwise
|
|
32
|
+
out += BASE32[mask & (buffer << (5 - bits))];
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
export function createShortSha256Hash(input) {
|
|
37
|
+
return createHash('sha256').update(input).digest('hex').substring(0, 32);
|
|
38
|
+
}
|
|
39
|
+
//# 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;AAE3D,sEAAsE;AACtE,EAAE;AACF,uDAAuD;AACvD,wHAAwH;AACxH,kCAAkC;AAClC,iHAAiH;AACjH,EAAE;AACF,8EAA8E;AAC9E,wGAAwG;AAExG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,GAAa,kCAAkC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEtE,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,IAAI,GAAW,UAAU,CAAC,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,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,OAAO,UAAU,CAAC,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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
// Vendored from \@pnpm/dependency-path\@1000.0.1 (pnpm v10.0.0).
|
|
4
|
+
// https://github.com/pnpm/pnpm/blob/42ecf04fd0e442af8610ae4231855e004732dbf7/packages/dependency-path/src/index.ts
|
|
5
|
+
import { createDepPathToFilename } from './common';
|
|
6
|
+
import { createShortSha256Hash } from './hash';
|
|
7
|
+
export const depPathToFilename = createDepPathToFilename({
|
|
8
|
+
specialCharsRegex: /[\\/:*?"<>|#]/g,
|
|
9
|
+
maxLengthWithoutHash: 120 - 32 - 1,
|
|
10
|
+
hashFn: createShortSha256Hash
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=v10.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v10.js","sourceRoot":"","sources":["../../../src/pnpm/depPath/v10.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,iEAAiE;AACjE,mHAAmH;AAEnH,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAgC,uBAAuB,CAAC;IACpF,iBAAiB,EAAE,gBAAgB;IACnC,oBAAoB,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,EAAE,qBAAqB;CAC9B,CAAC,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// Vendored from \\@pnpm/dependency-path\\@1000.0.1 (pnpm v10.0.0).\n// https://github.com/pnpm/pnpm/blob/42ecf04fd0e442af8610ae4231855e004732dbf7/packages/dependency-path/src/index.ts\n\nimport { createDepPathToFilename } from './common';\nimport { createShortSha256Hash } from './hash';\n\nexport const depPathToFilename: (depPath: string) => string = createDepPathToFilename({\n specialCharsRegex: /[\\\\/:*?\"<>|#]/g,\n maxLengthWithoutHash: 120 - 32 - 1,\n hashFn: createShortSha256Hash\n});\n"]}
|