@rushstack/rush-resolver-cache-plugin 5.167.0 → 5.169.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-esm/afterInstallAsync.js +202 -0
- package/lib-esm/afterInstallAsync.js.map +1 -0
- package/lib-esm/computeResolverCacheFromLockfileAsync.js +174 -0
- package/lib-esm/computeResolverCacheFromLockfileAsync.js.map +1 -0
- package/lib-esm/externals.js +22 -0
- package/lib-esm/externals.js.map +1 -0
- package/lib-esm/helpers.js +145 -0
- package/lib-esm/helpers.js.map +1 -0
- package/lib-esm/index.js +33 -0
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/types.js +4 -0
- package/lib-esm/types.js.map +1 -0
- package/package.json +23 -11
- package/rush-plugin-manifest.json +1 -1
- /package/{lib → lib-commonjs}/afterInstallAsync.js +0 -0
- /package/{lib → lib-commonjs}/afterInstallAsync.js.map +0 -0
- /package/{lib → lib-commonjs}/computeResolverCacheFromLockfileAsync.js +0 -0
- /package/{lib → lib-commonjs}/computeResolverCacheFromLockfileAsync.js.map +0 -0
- /package/{lib → lib-commonjs}/externals.js +0 -0
- /package/{lib → lib-commonjs}/externals.js.map +0 -0
- /package/{lib → lib-commonjs}/helpers.js +0 -0
- /package/{lib → lib-commonjs}/helpers.js.map +0 -0
- /package/{lib → lib-commonjs}/index.js +0 -0
- /package/{lib → lib-commonjs}/index.js.map +0 -0
- /package/{lib → lib-commonjs}/types.js +0 -0
- /package/{lib → lib-commonjs}/types.js.map +0 -0
- /package/{lib → lib-dts}/afterInstallAsync.d.ts +0 -0
- /package/{lib → lib-dts}/afterInstallAsync.d.ts.map +0 -0
- /package/{lib → lib-dts}/computeResolverCacheFromLockfileAsync.d.ts +0 -0
- /package/{lib → lib-dts}/computeResolverCacheFromLockfileAsync.d.ts.map +0 -0
- /package/{lib → lib-dts}/externals.d.ts +0 -0
- /package/{lib → lib-dts}/externals.d.ts.map +0 -0
- /package/{lib → lib-dts}/helpers.d.ts +0 -0
- /package/{lib → lib-dts}/helpers.d.ts.map +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts.map +0 -0
- /package/{lib → lib-dts}/types.d.ts +0 -0
- /package/{lib → lib-dts}/types.d.ts.map +0 -0
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { Async, FileSystem, PnpmShrinkwrapFile } from './externals';
|
|
4
|
+
import { computeResolverCacheFromLockfileAsync } from './computeResolverCacheFromLockfileAsync';
|
|
5
|
+
/**
|
|
6
|
+
* Gets information used to determine compatibility of optional dependencies.
|
|
7
|
+
* @returns Information about the platform Rush is running on
|
|
8
|
+
*/
|
|
9
|
+
function getPlatformInfo() {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
// Acquiring the libc version is a bit more obnoxious than platform and arch,
|
|
12
|
+
// but all of them are ultimately on the same object.
|
|
13
|
+
const { platform: os, arch: cpu, glibcVersionRuntime
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
} = (_c = (_b = (_a = process.report) === null || _a === void 0 ? void 0 : _a.getReport()) === null || _b === void 0 ? void 0 : _b.header) !== null && _c !== void 0 ? _c : process;
|
|
16
|
+
const libc = glibcVersionRuntime ? 'glibc' : 'musl';
|
|
17
|
+
return {
|
|
18
|
+
os,
|
|
19
|
+
cpu,
|
|
20
|
+
libc
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const END_TOKEN = '/package.json":';
|
|
24
|
+
const RESOLVER_CACHE_FILE_VERSION = 2;
|
|
25
|
+
/**
|
|
26
|
+
* Plugin entry point for after install.
|
|
27
|
+
* @param rushSession - The Rush Session
|
|
28
|
+
* @param rushConfiguration - The Rush Configuration
|
|
29
|
+
* @param subspace - The subspace that was just installed
|
|
30
|
+
* @param variant - The variant that was just installed
|
|
31
|
+
* @param logger - The initialized logger
|
|
32
|
+
*/
|
|
33
|
+
export async function afterInstallAsync(rushSession, rushConfiguration, subspace, variant, logger) {
|
|
34
|
+
const { terminal } = logger;
|
|
35
|
+
const rushRoot = `${rushConfiguration.rushJsonFolder}/`;
|
|
36
|
+
const lockFilePath = subspace.getCommittedShrinkwrapFilePath(variant);
|
|
37
|
+
const pnpmStoreDir = `${rushConfiguration.pnpmOptions.pnpmStorePath}/v3/files/`;
|
|
38
|
+
terminal.writeLine(`Using pnpm-lock from: ${lockFilePath}`);
|
|
39
|
+
terminal.writeLine(`Using pnpm store folder: ${pnpmStoreDir}`);
|
|
40
|
+
const workspaceRoot = subspace.getSubspaceTempFolderPath();
|
|
41
|
+
const cacheFilePath = `${workspaceRoot}/resolver-cache.json`;
|
|
42
|
+
const lockFile = PnpmShrinkwrapFile.loadFromFile(lockFilePath, {
|
|
43
|
+
withCaching: true,
|
|
44
|
+
subspaceHasNoProjects: subspace.getProjects().length === 0
|
|
45
|
+
});
|
|
46
|
+
if (!lockFile) {
|
|
47
|
+
throw new Error(`Failed to load shrinkwrap file: ${lockFilePath}`);
|
|
48
|
+
}
|
|
49
|
+
if (!lockFile.hash) {
|
|
50
|
+
throw new Error(`Shrinkwrap file does not have a hash. This indicates linking to an old version of Rush.`);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const oldCacheFileContent = await FileSystem.readFileAsync(cacheFilePath);
|
|
54
|
+
const oldCache = JSON.parse(oldCacheFileContent);
|
|
55
|
+
if (oldCache.version === RESOLVER_CACHE_FILE_VERSION && oldCache.shrinkwrapHash === lockFile.hash) {
|
|
56
|
+
// Cache is valid, use it
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
// Ignore
|
|
62
|
+
}
|
|
63
|
+
const projectByImporterPath = rushConfiguration.getProjectLookupForRoot(workspaceRoot);
|
|
64
|
+
const subPackageCacheFilePath = `${workspaceRoot}/subpackage-entry-cache.json`;
|
|
65
|
+
terminal.writeLine(`Resolver cache will be written at ${cacheFilePath}`);
|
|
66
|
+
let oldSubPackagesByIntegrity;
|
|
67
|
+
const subPackagesByIntegrity = new Map();
|
|
68
|
+
try {
|
|
69
|
+
const cacheContent = await FileSystem.readFileAsync(subPackageCacheFilePath);
|
|
70
|
+
const cacheJson = JSON.parse(cacheContent);
|
|
71
|
+
if (cacheJson.version !== RESOLVER_CACHE_FILE_VERSION) {
|
|
72
|
+
terminal.writeLine(`Expected subpackage cache version ${RESOLVER_CACHE_FILE_VERSION}, got ${cacheJson.version}`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
oldSubPackagesByIntegrity = new Map(cacheJson.subPackagesByIntegrity);
|
|
76
|
+
terminal.writeLine(`Loaded subpackage cache from ${subPackageCacheFilePath}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
// Ignore
|
|
81
|
+
}
|
|
82
|
+
async function afterExternalPackagesAsync(contexts, missingOptionalDependencies) {
|
|
83
|
+
/**
|
|
84
|
+
* Loads the index file from the pnpm store to discover nested package.json files in an external package
|
|
85
|
+
* For internal packages, assumes there are no nested package.json files.
|
|
86
|
+
* @param context - The context to find nested package.json files for
|
|
87
|
+
* @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.
|
|
88
|
+
*/
|
|
89
|
+
async function tryFindNestedPackageJsonsForContextAsync(context) {
|
|
90
|
+
const { descriptionFileRoot, descriptionFileHash } = context;
|
|
91
|
+
if (descriptionFileHash === undefined) {
|
|
92
|
+
// Assume this package has no nested package json files for now.
|
|
93
|
+
terminal.writeDebugLine(`Package at ${descriptionFileRoot} does not have a file list. Assuming no nested "package.json" files.`);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
// Convert an integrity hash like
|
|
97
|
+
// sha512-C6uiGQJ+Gt4RyHXXYt+v9f+SN1v83x68URwgxNQ98cvH8kxiuywWGP4XeNZ1paOzZ63aY3cTciCEQJNFUljlLw==
|
|
98
|
+
// To its hex representation, e.g.
|
|
99
|
+
// 0baba219027e1ade11c875d762dfaff5ff92375bfcdf1ebc511c20c4d43df1cbc7f24c62bb2c1618fe1778d675a5a3b367adda6377137220844093455258e52f
|
|
100
|
+
const prefixIndex = descriptionFileHash.indexOf('-');
|
|
101
|
+
const hash = Buffer.from(descriptionFileHash.slice(prefixIndex + 1), 'base64').toString('hex');
|
|
102
|
+
// The pnpm store directory has index files of package contents at paths:
|
|
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`;
|
|
106
|
+
try {
|
|
107
|
+
const indexContent = await FileSystem.readFileAsync(indexPath);
|
|
108
|
+
let endIndex = indexContent.lastIndexOf(END_TOKEN);
|
|
109
|
+
if (endIndex > 0) {
|
|
110
|
+
const nestedPackageDirs = [];
|
|
111
|
+
do {
|
|
112
|
+
const startIndex = indexContent.lastIndexOf('"', endIndex);
|
|
113
|
+
if (startIndex < 0) {
|
|
114
|
+
throw new Error(`Malformed index file at ${indexPath}: missing starting quote for nested package.json path`);
|
|
115
|
+
}
|
|
116
|
+
const nestedPath = indexContent.slice(startIndex + 1, endIndex);
|
|
117
|
+
nestedPackageDirs.push(nestedPath);
|
|
118
|
+
endIndex = indexContent.lastIndexOf(END_TOKEN, startIndex - 1);
|
|
119
|
+
} while (endIndex > 0);
|
|
120
|
+
return nestedPackageDirs;
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (!context.optional) {
|
|
126
|
+
throw new Error(`Error reading index file for: "${context.descriptionFileRoot}" (${descriptionFileHash}): ${error.toString()}`);
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Loads the index file from the pnpm store to discover nested package.json files in an external package
|
|
133
|
+
* For internal packages, assumes there are no nested package.json files.
|
|
134
|
+
* @param context - The context to find nested package.json files for
|
|
135
|
+
* @returns A promise that resolves when the nested package.json files are found, if applicable
|
|
136
|
+
*/
|
|
137
|
+
async function findNestedPackageJsonsForContextAsync(context) {
|
|
138
|
+
var _a;
|
|
139
|
+
const { descriptionFileRoot, descriptionFileHash } = context;
|
|
140
|
+
if (descriptionFileHash === undefined) {
|
|
141
|
+
// Assume this package has no nested package json files for now.
|
|
142
|
+
terminal.writeDebugLine(`Package at ${descriptionFileRoot} does not have a file list. Assuming no nested "package.json" files.`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let result = (_a = oldSubPackagesByIntegrity === null || oldSubPackagesByIntegrity === void 0 ? void 0 : oldSubPackagesByIntegrity.get(descriptionFileHash)) !== null && _a !== void 0 ? _a : subPackagesByIntegrity.get(descriptionFileHash);
|
|
146
|
+
if (result === undefined) {
|
|
147
|
+
result = await tryFindNestedPackageJsonsForContextAsync(context);
|
|
148
|
+
}
|
|
149
|
+
subPackagesByIntegrity.set(descriptionFileHash, result);
|
|
150
|
+
if (result === true) {
|
|
151
|
+
// Default case. Do nothing.
|
|
152
|
+
}
|
|
153
|
+
else if (result === false) {
|
|
154
|
+
terminal.writeLine(`Trimming missing optional dependency at: ${descriptionFileRoot}`);
|
|
155
|
+
contexts.delete(descriptionFileRoot);
|
|
156
|
+
missingOptionalDependencies.add(descriptionFileRoot);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
terminal.writeDebugLine(`Nested "package.json" files found for package at ${descriptionFileRoot}: ${result.join(', ')}`);
|
|
160
|
+
// eslint-disable-next-line require-atomic-updates
|
|
161
|
+
context.nestedPackageDirs = result;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// For external packages, update the contexts with data from the pnpm store
|
|
165
|
+
// This gives us the list of nested package.json files, as well as the actual package name
|
|
166
|
+
// We could also cache package.json contents, but that proves to be inefficient.
|
|
167
|
+
await Async.forEachAsync(contexts.values(), findNestedPackageJsonsForContextAsync, {
|
|
168
|
+
concurrency: 20
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const rawCacheFile = await computeResolverCacheFromLockfileAsync({
|
|
172
|
+
workspaceRoot,
|
|
173
|
+
commonPrefixToTrim: rushRoot,
|
|
174
|
+
platformInfo: getPlatformInfo(),
|
|
175
|
+
projectByImporterPath,
|
|
176
|
+
lockfile: lockFile,
|
|
177
|
+
afterExternalPackagesAsync
|
|
178
|
+
});
|
|
179
|
+
const extendedCacheFile = {
|
|
180
|
+
version: RESOLVER_CACHE_FILE_VERSION,
|
|
181
|
+
shrinkwrapHash: lockFile.hash,
|
|
182
|
+
...rawCacheFile
|
|
183
|
+
};
|
|
184
|
+
const newSubPackageCache = {
|
|
185
|
+
version: RESOLVER_CACHE_FILE_VERSION,
|
|
186
|
+
subPackagesByIntegrity: Array.from(subPackagesByIntegrity)
|
|
187
|
+
};
|
|
188
|
+
const serializedSubpackageCache = JSON.stringify(newSubPackageCache);
|
|
189
|
+
const serialized = JSON.stringify(extendedCacheFile);
|
|
190
|
+
await Promise.all([
|
|
191
|
+
FileSystem.writeFileAsync(cacheFilePath, serialized, {
|
|
192
|
+
ensureFolderExists: true
|
|
193
|
+
}),
|
|
194
|
+
FileSystem.writeFileAsync(subPackageCacheFilePath, serializedSubpackageCache, {
|
|
195
|
+
ensureFolderExists: true
|
|
196
|
+
})
|
|
197
|
+
]);
|
|
198
|
+
// Free the memory used by the lockfiles, since nothing should read the lockfile from this point on.
|
|
199
|
+
PnpmShrinkwrapFile.clearCache();
|
|
200
|
+
terminal.writeLine(`Resolver cache written.`);
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL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ED,MAAM,YAAY,GAAuB,MAAM,qCAAqC,CAAC;QACnF,aAAa;QACb,kBAAkB,EAAE,QAAQ;QAC5B,YAAY,EAAE,eAAe,EAAE;QAC/B,qBAAqB;QACrB,QAAQ,EAAE,QAAQ;QAClB,0BAA0B;KAC3B,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAA+B;QACpD,OAAO,EAAE,2BAA2B;QACpC,cAAc,EAAE,QAAQ,CAAC,IAAI;QAC7B,GAAG,YAAY;KAChB,CAAC;IAEF,MAAM,kBAAkB,GAA4B;QAClD,OAAO,EAAE,2BAA2B;QACpC,sBAAsB,EAAE,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"]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { getDescriptionFileRootFromKey, resolveDependencies, createContextSerializer } from './helpers';
|
|
4
|
+
function isPackageCompatible(pack, platformInfo) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
if ((_a = pack.os) === null || _a === void 0 ? void 0 : _a.every((value) => value.toLowerCase() !== platformInfo.os)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if ((_b = pack.cpu) === null || _b === void 0 ? void 0 : _b.every((value) => value.toLowerCase() !== platformInfo.cpu)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if ((_c = pack.libc) === null || _c === void 0 ? void 0 : _c.every((value) => value.toLowerCase() !== platformInfo.libc)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
function extractBundledDependencies(contexts, context) {
|
|
18
|
+
var _a;
|
|
19
|
+
let { nestedPackageDirs } = context;
|
|
20
|
+
if (!nestedPackageDirs) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let foundBundledDependencies = false;
|
|
24
|
+
for (let i = nestedPackageDirs.length - 1; i >= 0; i--) {
|
|
25
|
+
const nestedDir = nestedPackageDirs[i];
|
|
26
|
+
if (!nestedDir.startsWith('node_modules/')) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const isScoped = nestedDir.charAt(/* 'node_modules/'.length */ 13) === '@';
|
|
30
|
+
let index = nestedDir.indexOf('/', 13);
|
|
31
|
+
if (isScoped) {
|
|
32
|
+
index = nestedDir.indexOf('/', index + 1);
|
|
33
|
+
}
|
|
34
|
+
const name = index === -1 ? nestedDir.slice(13) : nestedDir.slice(13, index);
|
|
35
|
+
if (name.startsWith('.')) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!foundBundledDependencies) {
|
|
39
|
+
foundBundledDependencies = true;
|
|
40
|
+
// Make a copy of the nestedPackageDirs array so that we don't mutate the version being
|
|
41
|
+
// saved into the subpackage index cache.
|
|
42
|
+
context.nestedPackageDirs = nestedPackageDirs = nestedPackageDirs.slice(0);
|
|
43
|
+
}
|
|
44
|
+
// Remove this nested package from the list
|
|
45
|
+
nestedPackageDirs.splice(i, 1);
|
|
46
|
+
const remainder = index === -1 ? '' : nestedDir.slice(index + 1);
|
|
47
|
+
const nestedRoot = `${context.descriptionFileRoot}/node_modules/${name}`;
|
|
48
|
+
let nestedContext = contexts.get(nestedRoot);
|
|
49
|
+
if (!nestedContext) {
|
|
50
|
+
nestedContext = {
|
|
51
|
+
descriptionFileRoot: nestedRoot,
|
|
52
|
+
descriptionFileHash: undefined,
|
|
53
|
+
isProject: false,
|
|
54
|
+
name,
|
|
55
|
+
deps: new Map(),
|
|
56
|
+
ordinal: -1
|
|
57
|
+
};
|
|
58
|
+
contexts.set(nestedRoot, nestedContext);
|
|
59
|
+
}
|
|
60
|
+
context.deps.set(name, nestedRoot);
|
|
61
|
+
if (remainder) {
|
|
62
|
+
(_a = nestedContext.nestedPackageDirs) !== null && _a !== void 0 ? _a : (nestedContext.nestedPackageDirs = []);
|
|
63
|
+
nestedContext.nestedPackageDirs.push(remainder);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Copied from `@rushstack/node-core-library/src/Path.ts` to avoid expensive dependency
|
|
69
|
+
* @param path - Path using backslashes as path separators
|
|
70
|
+
* @returns The same string using forward slashes as path separators
|
|
71
|
+
*/
|
|
72
|
+
function convertToSlashes(path) {
|
|
73
|
+
return path.replace(/\\/g, '/');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Given a lockfile and information about the workspace and platform, computes the resolver cache file.
|
|
77
|
+
* @param params - The options for computing the resolver cache
|
|
78
|
+
* @returns A promise that resolves with the resolver cache file
|
|
79
|
+
*/
|
|
80
|
+
export async function computeResolverCacheFromLockfileAsync(params) {
|
|
81
|
+
var _a;
|
|
82
|
+
const { platformInfo, projectByImporterPath, lockfile, afterExternalPackagesAsync } = params;
|
|
83
|
+
// Needs to be normalized to `/` for path.posix.join to work correctly
|
|
84
|
+
const workspaceRoot = convertToSlashes(params.workspaceRoot);
|
|
85
|
+
// Needs to be normalized to `/` for path.posix.join to work correctly
|
|
86
|
+
const commonPrefixToTrim = convertToSlashes(params.commonPrefixToTrim);
|
|
87
|
+
const contexts = new Map();
|
|
88
|
+
const missingOptionalDependencies = new Set();
|
|
89
|
+
// Enumerate external dependencies first, to simplify looping over them for store data
|
|
90
|
+
for (const [key, pack] of lockfile.packages) {
|
|
91
|
+
let name = pack.name;
|
|
92
|
+
const descriptionFileRoot = getDescriptionFileRootFromKey(workspaceRoot, key, name);
|
|
93
|
+
// Skip optional dependencies that are incompatible with the current environment
|
|
94
|
+
if (pack.optional && !isPackageCompatible(pack, platformInfo)) {
|
|
95
|
+
missingOptionalDependencies.add(descriptionFileRoot);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const integrity = (_a = pack.resolution) === null || _a === void 0 ? void 0 : _a.integrity;
|
|
99
|
+
if (!name && key.startsWith('/')) {
|
|
100
|
+
const versionIndex = key.indexOf('@', 2);
|
|
101
|
+
name = key.slice(1, versionIndex);
|
|
102
|
+
}
|
|
103
|
+
if (!name) {
|
|
104
|
+
throw new Error(`Missing name for ${key}`);
|
|
105
|
+
}
|
|
106
|
+
const context = {
|
|
107
|
+
descriptionFileRoot,
|
|
108
|
+
descriptionFileHash: integrity,
|
|
109
|
+
isProject: false,
|
|
110
|
+
name,
|
|
111
|
+
deps: new Map(),
|
|
112
|
+
ordinal: -1,
|
|
113
|
+
optional: pack.optional
|
|
114
|
+
};
|
|
115
|
+
contexts.set(descriptionFileRoot, context);
|
|
116
|
+
if (pack.dependencies) {
|
|
117
|
+
resolveDependencies(workspaceRoot, pack.dependencies, context);
|
|
118
|
+
}
|
|
119
|
+
if (pack.optionalDependencies) {
|
|
120
|
+
resolveDependencies(workspaceRoot, pack.optionalDependencies, context);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (afterExternalPackagesAsync) {
|
|
124
|
+
await afterExternalPackagesAsync(contexts, missingOptionalDependencies);
|
|
125
|
+
}
|
|
126
|
+
for (const context of contexts.values()) {
|
|
127
|
+
if (context.nestedPackageDirs) {
|
|
128
|
+
extractBundledDependencies(contexts, context);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Add the data for workspace projects
|
|
132
|
+
for (const [importerPath, importer] of lockfile.importers) {
|
|
133
|
+
// Ignore the root project. This plugin assumes you don't have one.
|
|
134
|
+
// A non-empty root project results in global dependency hoisting, and that's bad for strictness.
|
|
135
|
+
if (importerPath === '.') {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const project = projectByImporterPath.findChildPath(importerPath);
|
|
139
|
+
if (!project) {
|
|
140
|
+
throw new Error(`Missing project for importer ${importerPath}`);
|
|
141
|
+
}
|
|
142
|
+
const descriptionFileRoot = convertToSlashes(project.projectFolder);
|
|
143
|
+
const context = {
|
|
144
|
+
descriptionFileRoot,
|
|
145
|
+
descriptionFileHash: undefined, // Not needed anymore
|
|
146
|
+
name: project.packageJson.name,
|
|
147
|
+
isProject: true,
|
|
148
|
+
deps: new Map(),
|
|
149
|
+
ordinal: -1
|
|
150
|
+
};
|
|
151
|
+
contexts.set(descriptionFileRoot, context);
|
|
152
|
+
if (importer.dependencies) {
|
|
153
|
+
resolveDependencies(workspaceRoot, importer.dependencies, context);
|
|
154
|
+
}
|
|
155
|
+
if (importer.devDependencies) {
|
|
156
|
+
resolveDependencies(workspaceRoot, importer.devDependencies, context);
|
|
157
|
+
}
|
|
158
|
+
if (importer.optionalDependencies) {
|
|
159
|
+
resolveDependencies(workspaceRoot, importer.optionalDependencies, context);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
let ordinal = 0;
|
|
163
|
+
for (const context of contexts.values()) {
|
|
164
|
+
context.ordinal = ordinal++;
|
|
165
|
+
}
|
|
166
|
+
// Convert the intermediate representation to the final cache file
|
|
167
|
+
const serializedContexts = Array.from(contexts, createContextSerializer(missingOptionalDependencies, contexts, commonPrefixToTrim));
|
|
168
|
+
const cacheFile = {
|
|
169
|
+
basePath: commonPrefixToTrim,
|
|
170
|
+
contexts: serializedContexts
|
|
171
|
+
};
|
|
172
|
+
return cacheFile;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=computeResolverCacheFromLockfileAsync.js.map
|
|
@@ -0,0 +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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O,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 { 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"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
const { Operation, OperationStatus } = ___rush___rushLibModule;
|
|
4
|
+
export { Operation, OperationStatus };
|
|
5
|
+
// Support this plugin being webpacked.
|
|
6
|
+
const req = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
|
|
7
|
+
const rushLibPath = process.env._RUSH_LIB_PATH;
|
|
8
|
+
function importDependency(name) {
|
|
9
|
+
if (!rushLibPath) {
|
|
10
|
+
throw new Error(`_RUSH_LIB_PATH variable is not set, cannot resolve rush-lib.`);
|
|
11
|
+
}
|
|
12
|
+
const externalPath = req.resolve(name, {
|
|
13
|
+
paths: [rushLibPath]
|
|
14
|
+
});
|
|
15
|
+
return req(externalPath);
|
|
16
|
+
}
|
|
17
|
+
// Private Rush APIs
|
|
18
|
+
export const { PnpmShrinkwrapFile } = importDependency('@microsoft/rush-lib/lib/logic/pnpm/PnpmShrinkwrapFile');
|
|
19
|
+
// Avoid bundling expensive stuff that's already part of Rush.
|
|
20
|
+
export const { Async } = importDependency(`@rushstack/node-core-library/lib/Async`);
|
|
21
|
+
export const { FileSystem } = importDependency(`@rushstack/node-core-library/lib/FileSystem`);
|
|
22
|
+
//# sourceMappingURL=externals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externals.js","sourceRoot":"","sources":["../src/externals.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAS3D,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,uBAAuB,CAAC;AAM/D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;AAEtC,uCAAuC;AACvC,MAAM,GAAG,GAAmB,OAAO,uBAAuB,KAAK,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,CAAC;AAE9G,MAAM,WAAW,GAAuB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AAEnE,SAAS,gBAAgB,CAAU,IAAY;IAC7C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,YAAY,GAAW,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;QAC7C,KAAK,EAAE,CAAC,WAAW,CAAC;KACrB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,YAAY,CAAC,CAAC;AAC3B,CAAC;AAED,oBAAoB;AACpB,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,CAEpD,uDAAuD,CAAC,CAAC;AAI3D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,gBAAgB,CACvC,wCAAwC,CACzC,CAAC;AACF,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAC5C,6CAA6C,CAC9C,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 { Operation as OperationType, OperationStatus as OperationStatusType } from '@rushstack/rush-sdk';\nimport type { PnpmShrinkwrapFile as PnpmShrinkwrapFileType } from '@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile';\n\n// Ultra-cheap \"I am a Rush plugin\" import of rush-lib\n// eslint-disable-next-line @typescript-eslint/naming-convention\ndeclare const ___rush___rushLibModule: typeof import('@rushstack/rush-sdk');\n\nconst { Operation, OperationStatus } = ___rush___rushLibModule;\n// eslint-disable-next-line @typescript-eslint/no-redeclare\ntype Operation = OperationType;\n// eslint-disable-next-line @typescript-eslint/no-redeclare\ntype OperationStatus = OperationStatusType;\n\nexport { Operation, OperationStatus };\n\n// Support this plugin being webpacked.\nconst req: typeof require = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;\n\nconst rushLibPath: string | undefined = process.env._RUSH_LIB_PATH;\n\nfunction importDependency<TResult>(name: string): TResult {\n if (!rushLibPath) {\n throw new Error(`_RUSH_LIB_PATH variable is not set, cannot resolve rush-lib.`);\n }\n const externalPath: string = req.resolve(name, {\n paths: [rushLibPath]\n });\n\n return req(externalPath);\n}\n\n// Private Rush APIs\nexport const { PnpmShrinkwrapFile } = importDependency<\n typeof import('@rushstack/rush-sdk/lib/logic/pnpm/PnpmShrinkwrapFile')\n>('@microsoft/rush-lib/lib/logic/pnpm/PnpmShrinkwrapFile');\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type PnpmShrinkwrapFile = PnpmShrinkwrapFileType;\n\n// Avoid bundling expensive stuff that's already part of Rush.\nexport const { Async } = importDependency<typeof import('@rushstack/node-core-library/lib/Async')>(\n `@rushstack/node-core-library/lib/Async`\n);\nexport const { FileSystem } = importDependency<typeof import('@rushstack/node-core-library/lib/FileSystem')>(\n `@rushstack/node-core-library/lib/FileSystem`\n);\n"]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
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
|
+
/**
|
|
44
|
+
* Computes the root folder for a dependency from a reference to it in another package
|
|
45
|
+
* @param lockfileFolder - The folder that contains the lockfile
|
|
46
|
+
* @param key - The key of the dependency
|
|
47
|
+
* @param specifier - The specifier in the lockfile for the dependency
|
|
48
|
+
* @param context - The owning package
|
|
49
|
+
* @returns The identifier for the dependency
|
|
50
|
+
*/
|
|
51
|
+
export function resolveDependencyKey(lockfileFolder, key, specifier, context) {
|
|
52
|
+
if (specifier.startsWith('/')) {
|
|
53
|
+
return getDescriptionFileRootFromKey(lockfileFolder, specifier);
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (specifier.startsWith('file:')) {
|
|
64
|
+
return getDescriptionFileRootFromKey(lockfileFolder, specifier, key);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return getDescriptionFileRootFromKey(lockfileFolder, `/${key}@${specifier}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Computes the physical path to a dependency based on its entry
|
|
72
|
+
* @param lockfileFolder - The folder that contains the lockfile during installation
|
|
73
|
+
* @param key - The key of the dependency
|
|
74
|
+
* @param name - The name of the dependency, if provided
|
|
75
|
+
* @returns The physical path to the dependency
|
|
76
|
+
*/
|
|
77
|
+
export function getDescriptionFileRootFromKey(lockfileFolder, key, name) {
|
|
78
|
+
if (!key.startsWith('file:')) {
|
|
79
|
+
name = key.slice(1, key.indexOf('@', 2));
|
|
80
|
+
}
|
|
81
|
+
if (!name) {
|
|
82
|
+
throw new Error(`Missing package name for ${key}`);
|
|
83
|
+
}
|
|
84
|
+
const originFolder = `${lockfileFolder}/node_modules/.pnpm/${depPathToFilename(key)}/node_modules`;
|
|
85
|
+
const descriptionFileRoot = `${originFolder}/${name}`;
|
|
86
|
+
return descriptionFileRoot;
|
|
87
|
+
}
|
|
88
|
+
export function resolveDependencies(lockfileFolder, collection, context) {
|
|
89
|
+
for (const [key, value] of Object.entries(collection)) {
|
|
90
|
+
const version = typeof value === 'string' ? value : value.version;
|
|
91
|
+
const resolved = resolveDependencyKey(lockfileFolder, key, version, context);
|
|
92
|
+
context.deps.set(key, resolved);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param depPath - The path to the dependency
|
|
98
|
+
* @returns The folder name for the dependency
|
|
99
|
+
*/
|
|
100
|
+
export function depPathToFilenameUnescaped(depPath) {
|
|
101
|
+
if (depPath.indexOf('file:') !== 0) {
|
|
102
|
+
if (depPath.startsWith('/')) {
|
|
103
|
+
depPath = depPath.slice(1);
|
|
104
|
+
}
|
|
105
|
+
return depPath;
|
|
106
|
+
}
|
|
107
|
+
return depPath.replace(':', '+');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param missingOptionalDependencies - The set of optional dependencies that were not installed
|
|
112
|
+
* @param contexts - The map of context roots to their respective contexts
|
|
113
|
+
* @param commonPathPrefix - The common root path to trim
|
|
114
|
+
* @returns A function that serializes a context into a format that can be written to disk
|
|
115
|
+
*/
|
|
116
|
+
export function createContextSerializer(missingOptionalDependencies, contexts, commonPathPrefix) {
|
|
117
|
+
return ([descriptionFileRoot, context]) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const { deps } = context;
|
|
120
|
+
let hasAnyDeps = false;
|
|
121
|
+
const serializedDeps = {};
|
|
122
|
+
for (const [key, contextRoot] of deps) {
|
|
123
|
+
if (missingOptionalDependencies.has(contextRoot)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const resolutionContext = contexts.get(contextRoot);
|
|
127
|
+
if (!resolutionContext) {
|
|
128
|
+
throw new Error(`Missing context for ${contextRoot}!`);
|
|
129
|
+
}
|
|
130
|
+
serializedDeps[key] = resolutionContext.ordinal;
|
|
131
|
+
hasAnyDeps = true;
|
|
132
|
+
}
|
|
133
|
+
if (!context.name) {
|
|
134
|
+
throw new Error(`Missing name for ${descriptionFileRoot}`);
|
|
135
|
+
}
|
|
136
|
+
const serializedContext = {
|
|
137
|
+
name: context.name,
|
|
138
|
+
root: descriptionFileRoot.slice(commonPathPrefix.length),
|
|
139
|
+
dirInfoFiles: ((_a = context.nestedPackageDirs) === null || _a === void 0 ? void 0 : _a.length) ? context.nestedPackageDirs : undefined,
|
|
140
|
+
deps: hasAnyDeps ? serializedDeps : undefined
|
|
141
|
+
};
|
|
142
|
+
return serializedContext;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +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,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,+BAA+B;QAC/B,OAAO,IAAI,GAAG,CAAC,EAAE,CAAC;YAChB,IAAI,IAAI,CAAC,CAAC;YACV,sCAAsC;YACtC,GAAG,IAAI,MAAM,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iB,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,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,oBAAoB,mBAAmB,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,iBAAiB,GAA8B;YACnD,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC;YACxD,YAAY,EAAE,CAAA,MAAA,OAAO,CAAC,iBAAiB,0CAAE,MAAM,EAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS;YACvF,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 } = 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 (!context.name) {\n throw new Error(`Missing name for ${descriptionFileRoot}`);\n }\n\n const serializedContext: ISerializedResolveContext = {\n name: context.name,\n root: descriptionFileRoot.slice(commonPathPrefix.length),\n dirInfoFiles: context.nestedPackageDirs?.length ? context.nestedPackageDirs : undefined,\n deps: hasAnyDeps ? serializedDeps : undefined\n };\n\n return serializedContext;\n };\n}\n"]}
|
package/lib-esm/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
/**
|
|
4
|
+
* Plugin that caches information from the package manager after installation to speed up resolution of imports.
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export default class RushResolverCachePlugin {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.pluginName = 'RushResolverCachePlugin';
|
|
10
|
+
}
|
|
11
|
+
apply(rushSession, rushConfiguration) {
|
|
12
|
+
rushSession.hooks.afterInstall.tapPromise(this.pluginName, async (command, subspace, variant) => {
|
|
13
|
+
const logger = rushSession.getLogger('RushResolverCachePlugin');
|
|
14
|
+
if (rushConfiguration.packageManager !== 'pnpm') {
|
|
15
|
+
logger.emitError(new Error('The RushResolverCachePlugin currently only supports the "pnpm" package manager'));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const pnpmMajorVersion = parseInt(rushConfiguration.packageManagerToolVersion, 10);
|
|
19
|
+
// Lockfile format parsing logic changed in pnpm v8.
|
|
20
|
+
if (pnpmMajorVersion < 8) {
|
|
21
|
+
logger.emitError(new Error('The RushResolverCachePlugin currently only supports pnpm version >=8'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// This plugin is not currently webpacked, but these comments are here for future proofing.
|
|
25
|
+
const { afterInstallAsync } = await import(
|
|
26
|
+
/* webpackChunkMode: 'eager' */
|
|
27
|
+
/* webpackExports: ["afterInstallAsync"] */
|
|
28
|
+
'./afterInstallAsync');
|
|
29
|
+
await afterInstallAsync(rushSession, rushConfiguration, subspace, variant, logger);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAW3D;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAA5C;QACkB,eAAU,GAA8B,yBAAyB,CAAC;IAiCpF,CAAC;IA/BQ,KAAK,CAAC,WAAwB,EAAE,iBAAoC;QACzE,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CACvC,IAAI,CAAC,UAAU,EACf,KAAK,EAAE,OAAqB,EAAE,QAAkB,EAAE,OAA2B,EAAE,EAAE;YAC/E,MAAM,MAAM,GAAY,WAAW,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC;YAEzE,IAAI,iBAAiB,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;gBAChD,MAAM,CAAC,SAAS,CACd,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAC5F,CAAC;gBACF,OAAO;YACT,CAAC;YAED,MAAM,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;YAC3F,oDAAoD;YACpD,IAAI,gBAAgB,GAAG,CAAC,EAAE,CAAC;gBACzB,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC,CAAC;gBACpG,OAAO;YACT,CAAC;YAED,2FAA2F;YAC3F,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM;YACxC,+BAA+B;YAC/B,2CAA2C;YAC3C,qBAAqB,CACtB,CAAC;YAEF,MAAM,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACrF,CAAC,CACF,CAAC;IACJ,CAAC;CACF","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 IRushPlugin,\n RushSession,\n RushConfiguration,\n IRushCommand,\n ILogger,\n Subspace\n} from '@rushstack/rush-sdk';\n\n/**\n * Plugin that caches information from the package manager after installation to speed up resolution of imports.\n * @beta\n */\nexport default class RushResolverCachePlugin implements IRushPlugin {\n public readonly pluginName: 'RushResolverCachePlugin' = 'RushResolverCachePlugin';\n\n public apply(rushSession: RushSession, rushConfiguration: RushConfiguration): void {\n rushSession.hooks.afterInstall.tapPromise(\n this.pluginName,\n async (command: IRushCommand, subspace: Subspace, variant: string | undefined) => {\n const logger: ILogger = rushSession.getLogger('RushResolverCachePlugin');\n\n if (rushConfiguration.packageManager !== 'pnpm') {\n logger.emitError(\n new Error('The RushResolverCachePlugin currently only supports the \"pnpm\" package manager')\n );\n return;\n }\n\n const pnpmMajorVersion: number = parseInt(rushConfiguration.packageManagerToolVersion, 10);\n // Lockfile format parsing logic changed in pnpm v8.\n if (pnpmMajorVersion < 8) {\n logger.emitError(new Error('The RushResolverCachePlugin currently only supports pnpm version >=8'));\n return;\n }\n\n // This plugin is not currently webpacked, but these comments are here for future proofing.\n const { afterInstallAsync } = await import(\n /* webpackChunkMode: 'eager' */\n /* webpackExports: [\"afterInstallAsync\"] */\n './afterInstallAsync'\n );\n\n await afterInstallAsync(rushSession, rushConfiguration, subspace, variant, logger);\n }\n );\n }\n}\n"]}
|
package/lib-esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport interface IResolverContext {\n descriptionFileRoot: string;\n descriptionFileHash: string | undefined;\n name: string;\n deps: Map<string, string>;\n isProject: boolean;\n ordinal: number;\n parent?: IResolverContext | undefined;\n optional?: boolean;\n nestedPackageDirs?: string[];\n}\n\nexport type IDependencyEntry =\n | string\n | {\n version: string;\n specifier: string;\n };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/rush-resolver-cache-plugin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.169.0",
|
|
4
4
|
"description": "A Rush plugin that generates a resolver cache file after successful install.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,35 +8,47 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"directory": "rush-plugins/rush-resolver-cache-plugin"
|
|
10
10
|
},
|
|
11
|
-
"main": "lib-commonjs/index.js",
|
|
12
|
-
"
|
|
11
|
+
"main": "./lib-commonjs/index.js",
|
|
12
|
+
"module": "./lib-esm/index.js",
|
|
13
|
+
"types": "./dist/rush-resolver-cache-plugin.d.ts",
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@rushstack/rush-sdk": "5.
|
|
15
|
+
"@rushstack/rush-sdk": "5.169.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@types/webpack-env": "1.18.8",
|
|
18
19
|
"eslint": "~9.37.0",
|
|
19
|
-
"@rushstack/lookup-by-path": "0.
|
|
20
|
-
"@rushstack/
|
|
21
|
-
"@rushstack/terminal": "0.
|
|
22
|
-
"@rushstack/
|
|
23
|
-
"@rushstack/
|
|
20
|
+
"@rushstack/lookup-by-path": "0.9.0",
|
|
21
|
+
"@rushstack/node-core-library": "5.20.0",
|
|
22
|
+
"@rushstack/terminal": "0.22.0",
|
|
23
|
+
"@rushstack/heft": "1.2.0",
|
|
24
|
+
"@rushstack/webpack-workspace-resolve-plugin": "0.6.0",
|
|
24
25
|
"local-node-rig": "1.0.0"
|
|
25
26
|
},
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"types": "./dist/rush-resolver-cache-plugin.d.ts",
|
|
30
|
+
"import": "./lib-esm/index.js",
|
|
31
|
+
"require": "./lib-commonjs/index.js"
|
|
30
32
|
},
|
|
33
|
+
"./lib/*": {
|
|
34
|
+
"types": "./lib-dts/*.d.ts",
|
|
35
|
+
"import": "./lib-esm/*.js",
|
|
36
|
+
"require": "./lib-commonjs/*.js"
|
|
37
|
+
},
|
|
38
|
+
"./rush-plugin-manifest.json": "./rush-plugin-manifest.json",
|
|
31
39
|
"./package.json": "./package.json"
|
|
32
40
|
},
|
|
33
41
|
"typesVersions": {
|
|
34
42
|
"*": {
|
|
35
43
|
".": [
|
|
36
44
|
"dist/rush-resolver-cache-plugin.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"lib/*": [
|
|
47
|
+
"lib-dts/*"
|
|
37
48
|
]
|
|
38
49
|
}
|
|
39
50
|
},
|
|
51
|
+
"sideEffects": false,
|
|
40
52
|
"scripts": {
|
|
41
53
|
"build": "heft test --clean",
|
|
42
54
|
"_phase:build": "heft run --only build -- --clean",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|