nx 21.3.0-canary.20250621-57e70d0 → 21.3.0-canary.20250625-fe687a0
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/package.json +11 -11
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/plugins/js/lock-file/lock-file.d.ts +1 -0
- package/src/plugins/js/lock-file/lock-file.js +1 -0
- package/src/plugins/js/lock-file/npm-parser.js +42 -3
- package/src/plugins/js/lock-file/pnpm-parser.js +43 -16
- package/src/plugins/js/lock-file/project-graph-pruning.d.ts +4 -1
- package/src/plugins/js/lock-file/project-graph-pruning.js +32 -5
- package/src/plugins/js/lock-file/yarn-parser.js +19 -7
- package/src/plugins/js/utils/get-workspace-packages-from-graph.d.ts +2 -0
- package/src/plugins/js/utils/get-workspace-packages-from-graph.js +13 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "21.3.0-canary.
|
3
|
+
"version": "21.3.0-canary.20250625-fe687a0",
|
4
4
|
"private": false,
|
5
5
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
6
6
|
"repository": {
|
@@ -83,16 +83,16 @@
|
|
83
83
|
}
|
84
84
|
},
|
85
85
|
"optionalDependencies": {
|
86
|
-
"@nx/nx-darwin-arm64": "21.3.0-canary.
|
87
|
-
"@nx/nx-darwin-x64": "21.3.0-canary.
|
88
|
-
"@nx/nx-freebsd-x64": "21.3.0-canary.
|
89
|
-
"@nx/nx-linux-arm-gnueabihf": "21.3.0-canary.
|
90
|
-
"@nx/nx-linux-arm64-gnu": "21.3.0-canary.
|
91
|
-
"@nx/nx-linux-arm64-musl": "21.3.0-canary.
|
92
|
-
"@nx/nx-linux-x64-gnu": "21.3.0-canary.
|
93
|
-
"@nx/nx-linux-x64-musl": "21.3.0-canary.
|
94
|
-
"@nx/nx-win32-arm64-msvc": "21.3.0-canary.
|
95
|
-
"@nx/nx-win32-x64-msvc": "21.3.0-canary.
|
86
|
+
"@nx/nx-darwin-arm64": "21.3.0-canary.20250625-fe687a0",
|
87
|
+
"@nx/nx-darwin-x64": "21.3.0-canary.20250625-fe687a0",
|
88
|
+
"@nx/nx-freebsd-x64": "21.3.0-canary.20250625-fe687a0",
|
89
|
+
"@nx/nx-linux-arm-gnueabihf": "21.3.0-canary.20250625-fe687a0",
|
90
|
+
"@nx/nx-linux-arm64-gnu": "21.3.0-canary.20250625-fe687a0",
|
91
|
+
"@nx/nx-linux-arm64-musl": "21.3.0-canary.20250625-fe687a0",
|
92
|
+
"@nx/nx-linux-x64-gnu": "21.3.0-canary.20250625-fe687a0",
|
93
|
+
"@nx/nx-linux-x64-musl": "21.3.0-canary.20250625-fe687a0",
|
94
|
+
"@nx/nx-win32-arm64-msvc": "21.3.0-canary.20250625-fe687a0",
|
95
|
+
"@nx/nx-win32-x64-msvc": "21.3.0-canary.20250625-fe687a0"
|
96
96
|
},
|
97
97
|
"nx-migrations": {
|
98
98
|
"migrations": "./migrations.json",
|
Binary file
|
@@ -23,6 +23,7 @@ export declare function lockFileExists(packageManager: PackageManager): boolean;
|
|
23
23
|
* @returns
|
24
24
|
*/
|
25
25
|
export declare function getLockFileName(packageManager: PackageManager): string;
|
26
|
+
export declare function getLockFilePath(packageManager: PackageManager): string;
|
26
27
|
/**
|
27
28
|
* Create lock file based on the root level lock file and (pruned) package.json
|
28
29
|
*
|
@@ -9,6 +9,7 @@ exports.getLockFileNodes = getLockFileNodes;
|
|
9
9
|
exports.getLockFileDependencies = getLockFileDependencies;
|
10
10
|
exports.lockFileExists = lockFileExists;
|
11
11
|
exports.getLockFileName = getLockFileName;
|
12
|
+
exports.getLockFilePath = getLockFilePath;
|
12
13
|
exports.createLockFile = createLockFile;
|
13
14
|
const node_child_process_1 = require("node:child_process");
|
14
15
|
const node_fs_1 = require("node:fs");
|
@@ -10,6 +10,7 @@ const operators_1 = require("../../../project-graph/operators");
|
|
10
10
|
const project_graph_builder_1 = require("../../../project-graph/project-graph-builder");
|
11
11
|
const project_graph_1 = require("../../../config/project-graph");
|
12
12
|
const file_hasher_1 = require("../../../hasher/file-hasher");
|
13
|
+
const get_workspace_packages_from_graph_1 = require("../utils/get-workspace-packages-from-graph");
|
13
14
|
// we use key => node map to avoid duplicate work when parsing keys
|
14
15
|
let keyMap = new Map();
|
15
16
|
let currentLockFileHash;
|
@@ -236,7 +237,9 @@ function addV1NodeDependencies(path, snapshot, dependencies, keyMap, ctx) {
|
|
236
237
|
function stringifyNpmLockfile(graph, rootLockFileContent, packageJson) {
|
237
238
|
const rootLockFile = JSON.parse(rootLockFileContent);
|
238
239
|
const { lockfileVersion } = JSON.parse(rootLockFileContent);
|
240
|
+
const workspaceModulesFromGraph = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph);
|
239
241
|
const mappedPackages = mapSnapshots(rootLockFile, graph);
|
242
|
+
const workspaceModules = mapWorkspaceModules(packageJson, rootLockFile, workspaceModulesFromGraph);
|
240
243
|
const output = {
|
241
244
|
name: packageJson.name || rootLockFile.name,
|
242
245
|
version: packageJson.version || '0.0.1',
|
@@ -246,21 +249,57 @@ function stringifyNpmLockfile(graph, rootLockFileContent, packageJson) {
|
|
246
249
|
output.requires = rootLockFile.requires;
|
247
250
|
}
|
248
251
|
if (lockfileVersion > 1) {
|
249
|
-
|
252
|
+
const packages = mapV3Snapshots(mappedPackages, packageJson);
|
253
|
+
output.packages = { ...packages, ...workspaceModules };
|
250
254
|
}
|
251
255
|
if (lockfileVersion < 3) {
|
252
|
-
|
256
|
+
const dependencies = mapV1Snapshots(mappedPackages);
|
257
|
+
output.dependencies = { ...dependencies, ...workspaceModules };
|
253
258
|
}
|
254
259
|
return JSON.stringify(output, null, 2);
|
255
260
|
}
|
261
|
+
function mapWorkspaceModules(packageJson, rootLockFile, workspaceModules) {
|
262
|
+
const output = {};
|
263
|
+
for (const [pkgName, pkgVersion] of Object.entries(packageJson.dependencies)) {
|
264
|
+
if (workspaceModules.has(pkgName)) {
|
265
|
+
let workspaceModuleDefinition;
|
266
|
+
for (const [depName, depSnapshot] of Object.entries(rootLockFile.packages || rootLockFile.dependencies)) {
|
267
|
+
if (depSnapshot.name === pkgName) {
|
268
|
+
workspaceModuleDefinition = depSnapshot;
|
269
|
+
break;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
output[`node_modules/${pkgName}`] = {
|
273
|
+
version: `file:./workspace_modules/${pkgName}`,
|
274
|
+
resolved: `workspace_modules/${pkgName}`,
|
275
|
+
link: true,
|
276
|
+
};
|
277
|
+
output[`workspace_modules/${pkgName}`] = {
|
278
|
+
name: pkgName,
|
279
|
+
version: `0.0.1`,
|
280
|
+
dependencies: workspaceModuleDefinition.dependencies,
|
281
|
+
};
|
282
|
+
}
|
283
|
+
}
|
284
|
+
return output;
|
285
|
+
}
|
256
286
|
function mapV3Snapshots(mappedPackages, packageJson) {
|
257
287
|
const output = {};
|
258
|
-
|
288
|
+
const mappedPackageJson = mapPackageJsonWithWorkspaceModules(packageJson);
|
289
|
+
output[''] = mappedPackageJson;
|
259
290
|
mappedPackages.forEach((p) => {
|
260
291
|
output[p.path] = p.valueV3;
|
261
292
|
});
|
262
293
|
return output;
|
263
294
|
}
|
295
|
+
function mapPackageJsonWithWorkspaceModules(packageJson) {
|
296
|
+
for (const [pkgName, pkgVersion] of Object.entries(packageJson.dependencies)) {
|
297
|
+
if (pkgVersion.startsWith('workspace:') || pkgVersion.startsWith('file:')) {
|
298
|
+
packageJson.dependencies[pkgName] = `workspace_modules/${pkgName}`;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
return packageJson;
|
302
|
+
}
|
264
303
|
function mapV1Snapshots(mappedPackages) {
|
265
304
|
const output = {};
|
266
305
|
mappedPackages.forEach((p) => {
|
@@ -10,6 +10,8 @@ const project_graph_builder_1 = require("../../../project-graph/project-graph-bu
|
|
10
10
|
const project_graph_1 = require("../../../config/project-graph");
|
11
11
|
const file_hasher_1 = require("../../../hasher/file-hasher");
|
12
12
|
const project_graph_pruning_1 = require("./project-graph-pruning");
|
13
|
+
const path_1 = require("path");
|
14
|
+
const get_workspace_packages_from_graph_1 = require("../utils/get-workspace-packages-from-graph");
|
13
15
|
// we use key => node map to avoid duplicate work when parsing keys
|
14
16
|
let keyMap = new Map();
|
15
17
|
let currentLockFileHash;
|
@@ -278,14 +280,21 @@ function parseBaseVersion(rawVersion, isV5) {
|
|
278
280
|
}
|
279
281
|
function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson) {
|
280
282
|
const data = (0, pnpm_normalizer_1.parseAndNormalizePnpmLockfile)(rootLockFileContent);
|
281
|
-
const { lockfileVersion, packages } = data;
|
282
|
-
const rootSnapshot = mapRootSnapshot(packageJson, packages, graph, +lockfileVersion);
|
283
|
+
const { lockfileVersion, packages, importers } = data;
|
284
|
+
const { snapshot: rootSnapshot, importers: requiredImporters } = mapRootSnapshot(packageJson, importers, packages, graph, +lockfileVersion);
|
283
285
|
const snapshots = mapSnapshots(data.packages, graph.externalNodes, +lockfileVersion);
|
286
|
+
const workspaceDependencyImporters = {};
|
287
|
+
for (const [packageName, importerPath] of Object.entries(requiredImporters)) {
|
288
|
+
const baseImporter = importers[importerPath];
|
289
|
+
workspaceDependencyImporters[`workspace_modules/${packageName}`] =
|
290
|
+
baseImporter;
|
291
|
+
}
|
284
292
|
const output = {
|
285
293
|
...data,
|
286
294
|
lockfileVersion,
|
287
295
|
importers: {
|
288
296
|
'.': rootSnapshot,
|
297
|
+
...workspaceDependencyImporters,
|
289
298
|
},
|
290
299
|
packages: (0, object_sort_1.sortObjectByKeys)(snapshots),
|
291
300
|
};
|
@@ -398,8 +407,10 @@ function versionIsAlias(key, versionExpr, lockfileVersion) {
|
|
398
407
|
? key.startsWith(`${packageName}/${version}`)
|
399
408
|
: key.startsWith(`${packageName}@${version}`);
|
400
409
|
}
|
401
|
-
function mapRootSnapshot(packageJson, packages, graph, lockfileVersion) {
|
410
|
+
function mapRootSnapshot(packageJson, rootImporters, packages, graph, lockfileVersion) {
|
411
|
+
const workspaceModules = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph);
|
402
412
|
const snapshot = { specifiers: {} };
|
413
|
+
const importers = {};
|
403
414
|
[
|
404
415
|
'dependencies',
|
405
416
|
'optionalDependencies',
|
@@ -409,26 +420,42 @@ function mapRootSnapshot(packageJson, packages, graph, lockfileVersion) {
|
|
409
420
|
if (packageJson[depType]) {
|
410
421
|
Object.keys(packageJson[depType]).forEach((packageName) => {
|
411
422
|
const version = packageJson[depType][packageName];
|
412
|
-
|
413
|
-
(
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
423
|
+
if (workspaceModules.has(packageName)) {
|
424
|
+
for (const [importerPath, importerSnapshot] of Object.entries(rootImporters)) {
|
425
|
+
const workspaceDep = importerSnapshot.dependencies[packageName];
|
426
|
+
if (workspaceDep) {
|
427
|
+
const workspaceDepImporterPath = workspaceDep.replace('link:', '');
|
428
|
+
const importerKeyForPackage = (0, path_1.join)(importerPath, workspaceDepImporterPath);
|
429
|
+
importers[packageName] = importerKeyForPackage;
|
430
|
+
snapshot.specifiers[packageName] = `file:./workspace_modules/${packageName}`;
|
431
|
+
snapshot.dependencies = snapshot.dependencies || {};
|
432
|
+
snapshot.dependencies[packageName] = `link:./workspace_modules/${packageName}`;
|
433
|
+
break;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
else {
|
438
|
+
const node = graph.externalNodes[`npm:${packageName}@${version}`] ||
|
439
|
+
(graph.externalNodes[`npm:${packageName}`] &&
|
440
|
+
graph.externalNodes[`npm:${packageName}`].data.version === version
|
441
|
+
? graph.externalNodes[`npm:${packageName}`]
|
442
|
+
: (0, project_graph_pruning_1.findNodeMatchingVersion)(graph, packageName, version));
|
443
|
+
if (!node) {
|
444
|
+
throw new Error(`Could not find external node for package ${packageName}@${version}.`);
|
445
|
+
}
|
446
|
+
snapshot.specifiers[packageName] = version;
|
447
|
+
// peer dependencies are mapped to dependencies
|
448
|
+
let section = depType === 'peerDependencies' ? 'dependencies' : depType;
|
449
|
+
snapshot[section] = snapshot[section] || {};
|
450
|
+
snapshot[section][packageName] = findOriginalKeys(packages, node, lockfileVersion)[0][0];
|
419
451
|
}
|
420
|
-
snapshot.specifiers[packageName] = version;
|
421
|
-
// peer dependencies are mapped to dependencies
|
422
|
-
let section = depType === 'peerDependencies' ? 'dependencies' : depType;
|
423
|
-
snapshot[section] = snapshot[section] || {};
|
424
|
-
snapshot[section][packageName] = findOriginalKeys(packages, node, lockfileVersion)[0][0];
|
425
452
|
});
|
426
453
|
}
|
427
454
|
});
|
428
455
|
Object.keys(snapshot).forEach((key) => {
|
429
456
|
snapshot[key] = (0, object_sort_1.sortObjectByKeys)(snapshot[key]);
|
430
457
|
});
|
431
|
-
return snapshot;
|
458
|
+
return { snapshot, importers };
|
432
459
|
}
|
433
460
|
function findVersion(key, packageName, isV5, alias) {
|
434
461
|
if (isV5 && key.startsWith(`${packageName}/`)) {
|
@@ -1,8 +1,11 @@
|
|
1
|
-
import { ProjectGraph, ProjectGraphExternalNode } from '../../../config/project-graph';
|
1
|
+
import { ProjectGraph, ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../../config/project-graph';
|
2
2
|
import { PackageJson } from '../../../utils/package-json';
|
3
|
+
import { ProjectGraphBuilder } from '../../../project-graph/project-graph-builder';
|
3
4
|
/**
|
4
5
|
* Prune project graph's external nodes and their dependencies
|
5
6
|
* based on the pruned package.json
|
6
7
|
*/
|
7
8
|
export declare function pruneProjectGraph(graph: ProjectGraph, prunedPackageJson: PackageJson): ProjectGraph;
|
8
9
|
export declare function findNodeMatchingVersion(graph: ProjectGraph, packageName: string, versionExpr: string): ProjectGraphExternalNode;
|
10
|
+
export declare function addNodesAndDependencies(graph: ProjectGraph, packageJsonDeps: Record<string, string>, workspacePackages: Map<string, ProjectGraphProjectNode>, builder: ProjectGraphBuilder): void;
|
11
|
+
export declare function rehoistNodes(graph: ProjectGraph, packageJsonDeps: Record<string, string>, builder: ProjectGraphBuilder): void;
|
@@ -2,17 +2,25 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.pruneProjectGraph = pruneProjectGraph;
|
4
4
|
exports.findNodeMatchingVersion = findNodeMatchingVersion;
|
5
|
+
exports.addNodesAndDependencies = addNodesAndDependencies;
|
6
|
+
exports.rehoistNodes = rehoistNodes;
|
5
7
|
const semver_1 = require("semver");
|
6
8
|
const project_graph_builder_1 = require("../../../project-graph/project-graph-builder");
|
7
9
|
const operators_1 = require("../../../project-graph/operators");
|
10
|
+
const get_workspace_packages_from_graph_1 = require("../utils/get-workspace-packages-from-graph");
|
8
11
|
/**
|
9
12
|
* Prune project graph's external nodes and their dependencies
|
10
13
|
* based on the pruned package.json
|
11
14
|
*/
|
12
15
|
function pruneProjectGraph(graph, prunedPackageJson) {
|
13
16
|
const builder = new project_graph_builder_1.ProjectGraphBuilder();
|
14
|
-
const
|
15
|
-
|
17
|
+
const workspacePackages = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph);
|
18
|
+
const combinedDependencies = normalizeDependencies(prunedPackageJson, graph, workspacePackages);
|
19
|
+
addNodesAndDependencies(graph, combinedDependencies, workspacePackages, builder);
|
20
|
+
for (const nodeName of workspacePackages.keys()) {
|
21
|
+
const node = graph.nodes[nodeName];
|
22
|
+
builder.addNode(node);
|
23
|
+
}
|
16
24
|
// for NPM (as well as the graph consistency)
|
17
25
|
// we need to distinguish between hoisted and non-hoisted dependencies
|
18
26
|
rehoistNodes(graph, combinedDependencies, builder);
|
@@ -20,7 +28,7 @@ function pruneProjectGraph(graph, prunedPackageJson) {
|
|
20
28
|
}
|
21
29
|
// ensure that dependency ranges from package.json (e.g. ^1.0.0)
|
22
30
|
// are replaced with the actual version based on the available nodes (e.g. 1.0.1)
|
23
|
-
function normalizeDependencies(packageJson, graph) {
|
31
|
+
function normalizeDependencies(packageJson, graph, workspacePackages) {
|
24
32
|
const { dependencies, devDependencies, optionalDependencies, peerDependencies, } = packageJson;
|
25
33
|
const combinedDependencies = {
|
26
34
|
...dependencies,
|
@@ -41,6 +49,10 @@ function normalizeDependencies(packageJson, graph) {
|
|
41
49
|
if (node) {
|
42
50
|
combinedDependencies[packageName] = node.data.version;
|
43
51
|
}
|
52
|
+
else if (workspacePackages.has(packageName)) {
|
53
|
+
// workspace module, leave as is
|
54
|
+
combinedDependencies[packageName] = versionRange;
|
55
|
+
}
|
44
56
|
else {
|
45
57
|
throw new Error(`Pruned lock file creation failed. The following package was not found in the root lock file: ${packageName}@${versionRange}`);
|
46
58
|
}
|
@@ -63,11 +75,18 @@ function findNodeMatchingVersion(graph, packageName, versionExpr) {
|
|
63
75
|
}
|
64
76
|
return nodes.find((n) => (0, semver_1.satisfies)(n.data.version, versionExpr));
|
65
77
|
}
|
66
|
-
function addNodesAndDependencies(graph, packageJsonDeps, builder) {
|
78
|
+
function addNodesAndDependencies(graph, packageJsonDeps, workspacePackages, builder) {
|
67
79
|
Object.entries(packageJsonDeps).forEach(([name, version]) => {
|
68
80
|
const node = graph.externalNodes[`npm:${name}@${version}`] ||
|
69
81
|
graph.externalNodes[`npm:${name}`];
|
70
|
-
|
82
|
+
if (node) {
|
83
|
+
traverseNode(graph, builder, node);
|
84
|
+
}
|
85
|
+
else if (workspacePackages.has(name)) {
|
86
|
+
// Workspace Node
|
87
|
+
const node = graph.nodes[name];
|
88
|
+
traverseWorkspaceNode(graph, builder, node);
|
89
|
+
}
|
71
90
|
});
|
72
91
|
}
|
73
92
|
function traverseNode(graph, builder, node) {
|
@@ -81,6 +100,14 @@ function traverseNode(graph, builder, node) {
|
|
81
100
|
builder.addStaticDependency(node.name, dep.target);
|
82
101
|
});
|
83
102
|
}
|
103
|
+
function traverseWorkspaceNode(graph, builder, node) {
|
104
|
+
graph.dependencies[node.name]?.forEach((dep) => {
|
105
|
+
const depNode = graph.externalNodes[dep.target];
|
106
|
+
if (depNode) {
|
107
|
+
traverseNode(graph, builder, depNode);
|
108
|
+
}
|
109
|
+
});
|
110
|
+
}
|
84
111
|
function rehoistNodes(graph, packageJsonDeps, builder) {
|
85
112
|
const packagesToRehoist = new Map();
|
86
113
|
// find all packages that need to be rehoisted
|
@@ -9,6 +9,7 @@ const semver_1 = require("semver");
|
|
9
9
|
const project_graph_1 = require("../../../config/project-graph");
|
10
10
|
const file_hasher_1 = require("../../../hasher/file-hasher");
|
11
11
|
const object_sort_1 = require("../../../utils/object-sort");
|
12
|
+
const get_workspace_packages_from_graph_1 = require("../utils/get-workspace-packages-from-graph");
|
12
13
|
let currentLockFileHash;
|
13
14
|
let cachedParsedLockFile;
|
14
15
|
// we use key => node map to avoid duplicate work when parsing keys
|
@@ -244,7 +245,8 @@ function stringifyYarnLockfile(graph, rootLockFileContent, packageJson) {
|
|
244
245
|
const { parseSyml, stringifySyml } = require('@yarnpkg/parsers');
|
245
246
|
const { __metadata, ...dependencies } = parseSyml(rootLockFileContent);
|
246
247
|
const isBerry = !!__metadata;
|
247
|
-
const
|
248
|
+
const workspaceModules = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph);
|
249
|
+
const snapshots = mapSnapshots(dependencies, graph.externalNodes, packageJson, workspaceModules, isBerry);
|
248
250
|
if (isBerry) {
|
249
251
|
// add root workspace package
|
250
252
|
const workspacePackage = generateRootWorkspacePackage(packageJson);
|
@@ -293,7 +295,7 @@ function addPackageVersion(packageName, version, collection, isBerry) {
|
|
293
295
|
collection.get(packageName).add(`${packageName}@npm:${version}`);
|
294
296
|
}
|
295
297
|
}
|
296
|
-
function mapSnapshots(rootDependencies, nodes, packageJson, isBerry) {
|
298
|
+
function mapSnapshots(rootDependencies, nodes, packageJson, workspaceModules, isBerry) {
|
297
299
|
// map snapshot to set of keys (e.g. `eslint@^7.0.0, eslint@npm:^7.0.0`)
|
298
300
|
const snapshotMap = new Map();
|
299
301
|
// track all existing dependencies's keys
|
@@ -311,7 +313,7 @@ function mapSnapshots(rootDependencies, nodes, packageJson, isBerry) {
|
|
311
313
|
const groupedDependencies = groupDependencies(rootDependencies, isBerry);
|
312
314
|
// collect snapshots and their matching keys
|
313
315
|
Object.values(nodes).forEach((node) => {
|
314
|
-
const foundOriginalKeys = findOriginalKeys(groupedDependencies, node);
|
316
|
+
const foundOriginalKeys = findOriginalKeys(groupedDependencies, node, workspaceModules);
|
315
317
|
if (!foundOriginalKeys) {
|
316
318
|
throw new Error(`Original key(s) not found for "${node.data.packageName}@${node.data.version}" while pruning yarn.lock.`);
|
317
319
|
}
|
@@ -322,7 +324,7 @@ function mapSnapshots(rootDependencies, nodes, packageJson, isBerry) {
|
|
322
324
|
Object.entries(section || {}).forEach(([name, versionSpec]) => addPackageVersion(name, versionSpec, existingKeys, isBerry));
|
323
325
|
});
|
324
326
|
// add package.json requested version to keys
|
325
|
-
const requestedVersion = getPackageJsonVersion(combinedDependencies, node);
|
327
|
+
const requestedVersion = getPackageJsonVersion(combinedDependencies, node, workspaceModules);
|
326
328
|
if (requestedVersion) {
|
327
329
|
addPackageVersion(node.data.packageName, requestedVersion, existingKeys, isBerry);
|
328
330
|
const requestedKey = isBerry
|
@@ -332,7 +334,7 @@ function mapSnapshots(rootDependencies, nodes, packageJson, isBerry) {
|
|
332
334
|
snapshotMap.get(snapshot).add(requestedKey);
|
333
335
|
}
|
334
336
|
}
|
335
|
-
const requestedResolutionsVersion = getPackageJsonVersion(resolutions, node);
|
337
|
+
const requestedResolutionsVersion = getPackageJsonVersion(resolutions, node, workspaceModules);
|
336
338
|
if (requestedResolutionsVersion) {
|
337
339
|
addPackageVersion(node.data.packageName, requestedResolutionsVersion, existingKeys, isBerry);
|
338
340
|
const requestedKey = isBerry
|
@@ -394,8 +396,11 @@ function reverseMapBerryKey(node, version, snapshot) {
|
|
394
396
|
}
|
395
397
|
return `${node.data.packageName}@npm:${version}`;
|
396
398
|
}
|
397
|
-
function getPackageJsonVersion(dependencies, node) {
|
399
|
+
function getPackageJsonVersion(dependencies, node, workspaceModules) {
|
398
400
|
const { packageName, version } = node.data;
|
401
|
+
if (workspaceModules.has(packageName)) {
|
402
|
+
return `file:./workspace_modules/${packageName}`;
|
403
|
+
}
|
399
404
|
if (dependencies[packageName]) {
|
400
405
|
const patchRegex = new RegExp(`^patch:${packageName}@(.*)|#.*$`);
|
401
406
|
// extract the version from the patch or use the full version
|
@@ -416,13 +421,20 @@ function isClassicAlias(node, keys) {
|
|
416
421
|
return (node.data.version.startsWith('npm:') &&
|
417
422
|
keys.some((k) => k === `${node.data.packageName}@${node.data.version}`));
|
418
423
|
}
|
419
|
-
function findOriginalKeys(dependencies, node) {
|
424
|
+
function findOriginalKeys(dependencies, node, workspaceModules) {
|
420
425
|
for (const keyExpr of Object.keys(dependencies)) {
|
421
426
|
const snapshot = dependencies[keyExpr];
|
422
427
|
const keys = keyExpr.split(', ');
|
423
428
|
if (!keys.some((k) => k.startsWith(`${node.data.packageName}@`))) {
|
424
429
|
continue;
|
425
430
|
}
|
431
|
+
if (keys.some((k) => workspaceModules.has(k) || workspaceModules.has(k.split('@file:')[0]))) {
|
432
|
+
const packageName = keys[0].split('@file:')[0];
|
433
|
+
return [
|
434
|
+
[`${packageName}@file:./workspace_modules/${packageName}`],
|
435
|
+
snapshot,
|
436
|
+
];
|
437
|
+
}
|
426
438
|
if (isStandardPackage(snapshot, node.data.version) ||
|
427
439
|
isBerryAlias(snapshot, node.data.version) ||
|
428
440
|
isClassicAlias(node, keys)) {
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getWorkspacePackagesFromGraph = getWorkspacePackagesFromGraph;
|
4
|
+
function getWorkspacePackagesFromGraph(graph) {
|
5
|
+
const workspacePackages = new Map();
|
6
|
+
for (const [projectName, project] of Object.entries(graph.nodes)) {
|
7
|
+
const pkgName = project.data?.metadata?.js?.packageName;
|
8
|
+
if (pkgName) {
|
9
|
+
workspacePackages.set(pkgName, project);
|
10
|
+
}
|
11
|
+
}
|
12
|
+
return workspacePackages;
|
13
|
+
}
|