nx 24.1.0-beta.0 → 24.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/bin/init-local.js +2 -4
  2. package/dist/bin/nx-cloud.js +2 -1
  3. package/dist/bin/nx.js +12 -14
  4. package/dist/bin/run-executor.js +5 -0
  5. package/dist/src/adapter/compat.d.ts +1 -1
  6. package/dist/src/adapter/compat.js +1 -0
  7. package/dist/src/command-line/completion/scripts/bash.sh +9 -2
  8. package/dist/src/command-line/completion/scripts/fish.fish +10 -2
  9. package/dist/src/command-line/completion/scripts/zsh.zsh +8 -2
  10. package/dist/src/command-line/completion/scripts.js +18 -8
  11. package/dist/src/command-line/conformance/command-object.d.ts +3 -0
  12. package/dist/src/command-line/conformance/command-object.js +66 -0
  13. package/dist/src/command-line/generate/generate.js +2 -4
  14. package/dist/src/command-line/generate/generator-utils.d.ts +1 -0
  15. package/dist/src/command-line/generate/generator-utils.js +9 -0
  16. package/dist/src/command-line/import/import.js +26 -2
  17. package/dist/src/command-line/import/utils/ai-output.d.ts +9 -1
  18. package/dist/src/command-line/import/utils/ai-output.js +20 -1
  19. package/dist/src/command-line/nx-commands.d.ts +1 -1
  20. package/dist/src/command-line/nx-commands.js +82 -132
  21. package/dist/src/command-line/release/command-object.d.ts +1 -0
  22. package/dist/src/command-line/release/command-object.js +4 -0
  23. package/dist/src/command-line/release/release.js +6 -4
  24. package/dist/src/command-line/release/utils/repository-git-tags.js +3 -3
  25. package/dist/src/command-line/release/utils/resolve-nx-json-error-message.js +2 -24
  26. package/dist/src/command-line/report/report.js +1 -1
  27. package/dist/src/command-line/reset/reset.js +51 -2
  28. package/dist/src/config/nx-json.d.ts +117 -0
  29. package/dist/src/config/workspace-json-project-json.d.ts +6 -7
  30. package/dist/src/daemon/client/daemon-environment.js +15 -0
  31. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +13 -20
  32. package/dist/src/devkit-exports.d.ts +1 -1
  33. package/dist/src/devkit-internals.d.ts +14 -7
  34. package/dist/src/devkit-internals.js +29 -4
  35. package/dist/src/executors/run-commands/run-commands.impl.d.ts +1 -1
  36. package/dist/src/executors/run-commands/run-commands.impl.js +35 -13
  37. package/dist/src/generators/utils/glob.js +3 -3
  38. package/dist/src/hasher/hash-task.d.ts +3 -1
  39. package/dist/src/hasher/hash-task.js +3 -2
  40. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.d.ts +4 -0
  41. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.js +117 -0
  42. package/dist/src/migrations/update-24-1-0/replace-powerpack-conformance.md +38 -0
  43. package/dist/src/native/index.d.ts +6 -8
  44. package/dist/src/native/index.js +18 -0
  45. package/dist/src/native/native-bindings.js +1 -0
  46. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  47. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  48. package/dist/src/native/transform-objects.d.ts +2 -0
  49. package/dist/src/native/transform-objects.js +15 -0
  50. package/dist/src/plugins/js/index.js +24 -9
  51. package/dist/src/plugins/js/lock-file/bun-parser.d.ts +75 -4
  52. package/dist/src/plugins/js/lock-file/bun-parser.js +976 -142
  53. package/dist/src/plugins/js/lock-file/lock-file-names.d.ts +6 -0
  54. package/dist/src/plugins/js/lock-file/lock-file-names.js +16 -0
  55. package/dist/src/plugins/js/lock-file/lock-file.d.ts +33 -14
  56. package/dist/src/plugins/js/lock-file/lock-file.js +213 -74
  57. package/dist/src/plugins/js/lock-file/npm-parser.d.ts +1 -0
  58. package/dist/src/plugins/js/lock-file/npm-parser.js +66 -2
  59. package/dist/src/plugins/js/lock-file/pnpm-parser.d.ts +5 -1
  60. package/dist/src/plugins/js/lock-file/pnpm-parser.js +107 -54
  61. package/dist/src/plugins/js/lock-file/pruned-output.d.ts +52 -10
  62. package/dist/src/plugins/js/lock-file/pruned-output.js +132 -66
  63. package/dist/src/plugins/js/lock-file/utils/local-path-hashes.d.ts +27 -0
  64. package/dist/src/plugins/js/lock-file/utils/local-path-hashes.js +155 -0
  65. package/dist/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  66. package/dist/src/plugins/js/lock-file/utils/package-json.js +2 -1
  67. package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -0
  68. package/dist/src/plugins/js/package-json/create-package-json.js +197 -8
  69. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +50 -2
  70. package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  71. package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -2
  72. package/dist/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +16 -9
  73. package/dist/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +17 -28
  74. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +52 -1
  75. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +336 -28
  76. package/dist/src/plugins/js/utils/register.js +13 -6
  77. package/dist/src/project-graph/build-project-graph.js +5 -2
  78. package/dist/src/project-graph/error-types.d.ts +2 -2
  79. package/dist/src/project-graph/error-types.js +2 -2
  80. package/dist/src/project-graph/nx-deps-cache.d.ts +3 -2
  81. package/dist/src/project-graph/nx-deps-cache.js +8 -2
  82. package/dist/src/project-graph/utils/project-graph-paths.d.ts +8 -0
  83. package/dist/src/project-graph/utils/project-graph-paths.js +170 -0
  84. package/dist/src/tasks-runner/batch/run-batch.js +3 -13
  85. package/dist/src/tasks-runner/cache.js +19 -18
  86. package/dist/src/tasks-runner/init-tasks-runner.js +23 -17
  87. package/dist/src/tasks-runner/run-command.js +6 -3
  88. package/dist/src/tasks-runner/task-orchestrator.d.ts +1 -0
  89. package/dist/src/tasks-runner/task-orchestrator.js +29 -4
  90. package/dist/src/tasks-runner/tasks-schedule.js +1 -1
  91. package/dist/src/tasks-runner/utils.d.ts +2 -1
  92. package/dist/src/tasks-runner/utils.js +2 -1
  93. package/dist/src/utils/child-process.js +2 -1
  94. package/dist/src/utils/find-matching-projects.js +7 -9
  95. package/dist/src/utils/find-workspace-root.js +2 -4
  96. package/dist/src/utils/git-utils.d.ts +5 -0
  97. package/dist/src/utils/git-utils.js +23 -1
  98. package/dist/src/utils/handle-import.js +14 -2
  99. package/dist/src/utils/installation-directory.d.ts +16 -0
  100. package/dist/src/utils/installation-directory.js +96 -2
  101. package/dist/src/utils/json.d.ts +7 -0
  102. package/dist/src/utils/json.js +32 -0
  103. package/dist/src/utils/nx-key.js +11 -8
  104. package/dist/src/utils/output.d.ts +5 -0
  105. package/dist/src/utils/output.js +11 -4
  106. package/dist/src/utils/owned-private-dir.d.ts +10 -0
  107. package/dist/src/utils/owned-private-dir.js +28 -0
  108. package/dist/src/utils/package-json.d.ts +7 -0
  109. package/dist/src/utils/package-json.js +9 -0
  110. package/dist/src/utils/require-nx-key.js +6 -4
  111. package/dist/src/utils/workspace-root.d.ts +12 -0
  112. package/dist/src/utils/workspace-root.js +56 -7
  113. package/migrations.json +6 -0
  114. package/package.json +15 -12
  115. package/schemas/nx-schema.json +75 -9
  116. package/schemas/project-schema.json +5 -0
@@ -33,6 +33,7 @@ function getNpmLockfileDependencies(lockFileContent, lockFileHash, ctx, keyMap)
33
33
  function getNodes(data) {
34
34
  const keyMap = new Map();
35
35
  const nodes = new Map();
36
+ const localPathPackageNames = new Set();
36
37
  if (data.lockfileVersion > 1) {
37
38
  Object.entries(data.packages).forEach(([path, snapshot]) => {
38
39
  // skip workspaces and snapshots bundled into their parent package
@@ -47,6 +48,9 @@ function getNodes(data) {
47
48
  // symlinked packages in workspaces do not have versions
48
49
  if (version) {
49
50
  createNode(packageName, version, path, nodes, keyMap, snapshot);
51
+ if (snapshot.resolved?.startsWith('file:')) {
52
+ localPathPackageNames.add(packageName);
53
+ }
50
54
  }
51
55
  });
52
56
  }
@@ -77,7 +81,63 @@ function getNodes(data) {
77
81
  results[node.name] = node;
78
82
  });
79
83
  }
80
- return { nodes: results, keyMap };
84
+ return {
85
+ nodes: results,
86
+ keyMap,
87
+ installedLocalPathNodes: localPathPackageNames.size
88
+ ? getInstalledLocalPathNodes(data, keyMap, localPathPackageNames)
89
+ : {},
90
+ };
91
+ }
92
+ function getInstalledLocalPathNodes(data, keyMap, localPathPackageNames) {
93
+ const installed = Object.create(null);
94
+ for (const importerPath in data.packages) {
95
+ if (importerPath !== '' && importerPath.includes('node_modules')) {
96
+ continue;
97
+ }
98
+ const importer = data.packages[importerPath];
99
+ for (const deps of [
100
+ importer.dependencies,
101
+ importer.devDependencies,
102
+ importer.optionalDependencies,
103
+ importer.peerDependencies,
104
+ ]) {
105
+ for (const depName of Object.keys(deps ?? {})) {
106
+ if (!localPathPackageNames.has(depName)) {
107
+ continue;
108
+ }
109
+ // Node loads the nearest copy, so a registry copy there wins
110
+ const key = findNearestNpmPackageKey(data, importerPath, depName);
111
+ const snapshot = key && data.packages[key];
112
+ if (!snapshot ||
113
+ snapshot.link ||
114
+ !snapshot.resolved?.startsWith('file:') ||
115
+ (snapshot.name && snapshot.name !== depName)) {
116
+ continue;
117
+ }
118
+ const node = keyMap.get(key);
119
+ if (node) {
120
+ (installed[importerPath || '.'] ??= Object.create(null))[depName] =
121
+ node.name;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return installed;
127
+ }
128
+ function findNearestNpmPackageKey(data, importerPath, packageName) {
129
+ let dir = importerPath;
130
+ while (true) {
131
+ const key = `${dir ? `${dir}/` : ''}node_modules/${packageName}`;
132
+ if (data.packages[key]) {
133
+ return key;
134
+ }
135
+ if (!dir) {
136
+ return undefined;
137
+ }
138
+ const slash = dir.lastIndexOf('/');
139
+ dir = slash === -1 ? '' : dir.slice(0, slash);
140
+ }
81
141
  }
82
142
  function addV1Node(packageName, snapshot, path, nodes, keyMap) {
83
143
  createNode(packageName, snapshot.version, path, nodes, keyMap, snapshot);
@@ -210,7 +270,11 @@ fallback) {
210
270
  return child;
211
271
  }
212
272
  }
213
- else if (child.data.version === versionRange ||
273
+ else if (
274
+ // A `file:` copy named by its path matches no range. Node loads the
275
+ // nearest copy, so it wins unless a nearer copy is already the fallback.
276
+ (!fallback && child.data.version.startsWith('file:')) ||
277
+ child.data.version === versionRange ||
214
278
  cachedSatisfies(child.data.version, versionRange)) {
215
279
  return child;
216
280
  }
@@ -5,6 +5,10 @@ import { CreateDependenciesContext } from '../../../project-graph/plugins';
5
5
  export declare function getPnpmLockfileNodes(lockFileContent: string, lockFileHash: string): {
6
6
  nodes: Record<string, ProjectGraphExternalNode>;
7
7
  keyMap: Map<string, Set<ProjectGraphExternalNode>>;
8
+ /** Workspace-relative local path sources per node name. */
9
+ localPathSources: Record<string, string[]>;
10
+ /** The `file:` node each importer installs, per importer path and name. */
11
+ installedLocalPathNodes: Record<string, Record<string, string>>;
8
12
  };
9
13
  export declare function getPnpmLockfileDependencies(lockFileContent: string, lockFileHash: string, ctx: CreateDependenciesContext, keyMap: Map<string, Set<ProjectGraphExternalNode>>): RawProjectGraphDependency[];
10
- export declare function stringifyPnpmLockfile(graph: ProjectGraph, rootLockFileContent: string, packageJson: NormalizedPackageJson, workspaceRoot: string): string;
14
+ export declare function stringifyPnpmLockfile(graph: ProjectGraph, rootLockFileContent: string, packageJson: NormalizedPackageJson, workspaceRoot: string, projectRoot?: string): string;
@@ -136,16 +136,20 @@ function findPatchHash(patchEntriesByPackage, packageName, version) {
136
136
  const nameOnlyMatch = entries.find((entry) => entry.versionSpecifier === null);
137
137
  return nameOnlyMatch?.hash;
138
138
  }
139
- // Segment-aware: `..` and `../x` escape, a directory literally named `..cache`
140
- // does not. Absolute targets are resolved against the workspace root.
141
- function linkTargetEscapesWorkspace(importerPath, depVersion) {
139
+ // The workspace-relative target of a `link:` version, or undefined when it
140
+ // escapes the workspace. Segment-aware: `..` and `../x` escape, a directory
141
+ // literally named `..cache` does not. Absolute targets are resolved against
142
+ // the workspace root.
143
+ function getLinkTargetInWorkspace(importerPath, depVersion) {
142
144
  const rawTarget = depVersion.slice('link:'.length);
143
145
  if (path_1.posix.isAbsolute(rawTarget) || (0, path_1.isAbsolute)(rawTarget)) {
144
146
  const rel = (0, path_1.relative)(workspace_root_1.workspaceRoot, rawTarget);
145
- return rel === '..' || rel.startsWith(`..${path_1.sep}`) || (0, path_1.isAbsolute)(rel);
147
+ return rel === '..' || rel.startsWith(`..${path_1.sep}`) || (0, path_1.isAbsolute)(rel)
148
+ ? undefined
149
+ : path_1.posix.normalize(rel.split(path_1.sep).join('/'));
146
150
  }
147
151
  const combined = path_1.posix.normalize(path_1.posix.join(importerPath === '.' ? '' : importerPath, rawTarget));
148
- return combined === '..' || combined.startsWith('../');
152
+ return combined === '..' || combined.startsWith('../') ? undefined : combined;
149
153
  }
150
154
  function getNodes(data, isV5) {
151
155
  cachedInvertedRecords.clear();
@@ -342,20 +346,38 @@ function getNodes(data, isV5) {
342
346
  results[node.name] = node;
343
347
  });
344
348
  }
345
- // `link:` dependencies pointing outside the workspace never appear in the
346
- // packages section, so nothing above minted a node for them — and a task
347
- // input naming one via `externalDependencies` fails hashing with "could not
348
- // be found". Mint a node under the bare `npm:<name>`, hashed on the link
349
- // path: the hash changes only when the path does, not when the linked
350
- // content does, which is how linked dependencies behave everywhere else in
351
- // Nx. Links that resolve inside the workspace are workspace projects, not
352
- // externals, and are skipped.
353
- //
354
- // One node per package name, chosen deterministically by visiting importers
355
- // root-first, then lexicographically. An `externalDependencies` input names
356
- // a package, not a link target, so it could not distinguish two linked
357
- // targets anyway.
349
+ // The sources of the packages installed from the local file tree, whose
350
+ // contents the lockfile does not record.
351
+ const localPathSources = {};
352
+ const addLocalPathSource = (nodeName, source) => {
353
+ const sources = (localPathSources[nodeName] ??= []);
354
+ if (!sources.includes(source)) {
355
+ sources.push(source);
356
+ sources.sort();
357
+ }
358
+ };
359
+ for (const [key, snapshot] of Object.entries(data.packages ?? {})) {
360
+ const resolution = snapshot.resolution;
361
+ const source = resolution?.directory ??
362
+ (resolution?.tarball?.startsWith('file:')
363
+ ? resolution.tarball.slice('file:'.length)
364
+ : undefined);
365
+ if (typeof source !== 'string') {
366
+ continue;
367
+ }
368
+ for (const node of keyMap.get(key) ?? []) {
369
+ addLocalPathSource(node.name, path_1.posix.normalize(source));
370
+ }
371
+ }
372
+ // `link:` dependencies have no packages entry, so an `externalDependencies`
373
+ // input naming one fails hashing with "could not be found". Mint one node per
374
+ // name under the bare `npm:<name>`, hashed on the link path, visiting
375
+ // importers root-first, then lexicographically. The input names a package,
376
+ // not a target, so one node per name loses nothing. Each importer loads its
377
+ // own link, so the node's sources cover every target inside the workspace.
378
+ // Links to importers are workspace projects and are skipped.
358
379
  const importerPaths = Object.keys(data.importers ?? {}).sort((a, b) => a === '.' ? -1 : b === '.' ? 1 : a.localeCompare(b));
380
+ const importerPathSet = new Set(importerPaths);
359
381
  for (const importerPath of importerPaths) {
360
382
  const importer = data.importers[importerPath];
361
383
  for (const depType of [
@@ -371,26 +393,56 @@ function getNodes(data, isV5) {
371
393
  if (typeof depVersion !== 'string' || !depVersion.startsWith('link:')) {
372
394
  continue;
373
395
  }
374
- if (!linkTargetEscapesWorkspace(importerPath, depVersion)) {
375
- continue; // inside the workspace -> a workspace project
396
+ const target = getLinkTargetInWorkspace(importerPath, depVersion);
397
+ if (target !== undefined && importerPathSet.has(target)) {
398
+ continue;
376
399
  }
377
400
  const bareName = `npm:${depName}`;
378
- if (results[bareName]) {
379
- continue; // a hoisted registry version or an earlier link wins
401
+ if (!results[bareName]) {
402
+ results[bareName] = {
403
+ type: 'npm',
404
+ name: bareName,
405
+ data: {
406
+ version: depVersion,
407
+ packageName: depName,
408
+ hash: (0, file_hasher_1.hashArray)([depName, depVersion]),
409
+ },
410
+ };
411
+ }
412
+ else if (!results[bareName].data.version.startsWith('link:')) {
413
+ continue; // a hoisted registry version wins
414
+ }
415
+ if (target !== undefined) {
416
+ addLocalPathSource(bareName, target);
417
+ }
418
+ }
419
+ }
420
+ }
421
+ // An override can install a registry copy for a `file:` spec, so the
422
+ // version each importer records decides
423
+ const installedLocalPathNodes = Object.create(null);
424
+ for (const importerPath of importerPaths) {
425
+ const importer = data.importers[importerPath];
426
+ for (const depType of [
427
+ 'dependencies',
428
+ 'devDependencies',
429
+ 'optionalDependencies',
430
+ ]) {
431
+ const deps = importer[depType];
432
+ for (const [depName, depVersion] of Object.entries(deps ?? {})) {
433
+ if (typeof depVersion !== 'string' || !depVersion.startsWith('file:')) {
434
+ continue;
435
+ }
436
+ for (const node of keyMap.get(`${depName}@${depVersion}`) ?? []) {
437
+ if (node.data.packageName === depName) {
438
+ (installedLocalPathNodes[importerPath] ??= Object.create(null))[depName] = node.name;
439
+ break;
440
+ }
380
441
  }
381
- results[bareName] = {
382
- type: 'npm',
383
- name: bareName,
384
- data: {
385
- version: depVersion,
386
- packageName: depName,
387
- hash: (0, file_hasher_1.hashArray)([depName, depVersion]),
388
- },
389
- };
390
442
  }
391
443
  }
392
444
  }
393
- return { nodes: results, keyMap };
445
+ return { nodes: results, keyMap, localPathSources, installedLocalPathNodes };
394
446
  }
395
447
  // The version that gets the bare `npm:<name>` node when a package has several
396
448
  // versions: the one the root importer declares, read from the lockfile. Other
@@ -448,13 +500,14 @@ function getDependencies(data, keyMap, isV5, ctx) {
448
500
  function parseBaseVersion(rawVersion, isV5) {
449
501
  return isV5 ? rawVersion.split('_')[0] : rawVersion.split('(')[0];
450
502
  }
451
- function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspaceRoot) {
503
+ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspaceRoot, projectRoot) {
452
504
  const data = (0, pnpm_normalizer_1.parseAndNormalizePnpmLockfile)(rootLockFileContent);
453
505
  const { lockfileVersion, importers } = data;
454
506
  // pnpm omits the packages block for workspace-only lockfiles (no external deps)
455
507
  const packages = data.packages ?? {};
456
508
  const packageIndex = indexPackagesByName(packages, +lockfileVersion);
457
509
  const workspaceModules = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph);
510
+ const isImporterWorkspaceModule = (importerPath, importer, depName) => !!(0, pruned_output_1.resolveWorkspaceModuleDependency)(workspaceModules, depName, importer.specifiers?.[depName] ?? '', importerPath, workspaceRoot);
458
511
  const manifestPeersCache = new Map();
459
512
  const getManifestPeers = (importerPath) => {
460
513
  let peers = manifestPeersCache.get(importerPath);
@@ -467,7 +520,7 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
467
520
  try {
468
521
  const manifest = JSON.parse((0, node_fs_1.readFileSync)(manifestPath, 'utf-8'));
469
522
  for (const [name, spec] of Object.entries(manifest.peerDependencies ?? {})) {
470
- if (workspaceModules.has(name)) {
523
+ if ((0, pruned_output_1.resolveWorkspaceModuleDependency)(workspaceModules, name, String(spec), importerPath, workspaceRoot)) {
471
524
  peers.workspaceSiblings.push(name);
472
525
  }
473
526
  else if (typeof spec === 'string' && (0, project_graph_pruning_1.isLocalPathSpecifier)(spec)) {
@@ -483,7 +536,7 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
483
536
  manifestPeersCache.set(importerPath, peers);
484
537
  return peers;
485
538
  };
486
- const { snapshot: rootSnapshot, importers: requiredImporters } = mapRootSnapshot(packageJson, importers, packages, packageIndex, graph, workspaceModules, +lockfileVersion, workspaceRoot);
539
+ const { snapshot: rootSnapshot, importers: requiredImporters } = mapRootSnapshot(packageJson, importers, packages, packageIndex, graph, workspaceModules, +lockfileVersion, workspaceRoot, projectRoot);
487
540
  const snapshots = mapSnapshots(packages, packageIndex, graph.externalNodes, +lockfileVersion);
488
541
  // Walk transitive workspace deps so every module copy-workspace-modules
489
542
  // writes to disk gets a matching directory-package entry. Without this, pnpm
@@ -491,7 +544,7 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
491
544
  const allRequiredImporters = { ...requiredImporters };
492
545
  const queue = Object.keys(requiredImporters);
493
546
  const enqueueWorkspaceModule = (depName) => {
494
- if (workspaceModules.has(depName) && !(depName in allRequiredImporters)) {
547
+ if (!(depName in allRequiredImporters)) {
495
548
  allRequiredImporters[depName] = workspaceModules.get(depName).data.root;
496
549
  queue.push(depName);
497
550
  }
@@ -506,7 +559,9 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
506
559
  if (!deps)
507
560
  continue;
508
561
  for (const depName of Object.keys(deps)) {
509
- enqueueWorkspaceModule(depName);
562
+ if (isImporterWorkspaceModule(importerPath, importer, depName)) {
563
+ enqueueWorkspaceModule(depName);
564
+ }
510
565
  }
511
566
  }
512
567
  }
@@ -553,7 +608,7 @@ function stringifyPnpmLockfile(graph, rootLockFileContent, packageJson, workspac
553
608
  for (const [depName, ref] of Object.entries(deps)) {
554
609
  // Sibling workspace modules resolve to their own directory package; npm
555
610
  // deps (resolved peers included) keep the ref from the source importer.
556
- if (workspaceModules.has(depName)) {
611
+ if (isImporterWorkspaceModule(importerPath, baseImporter, depName)) {
557
612
  resolved[depName] = `file:workspace_modules/${depName}`;
558
613
  }
559
614
  else if (ref.startsWith('link:')) {
@@ -890,7 +945,7 @@ function versionIsAlias(key, versionExpr, lockfileVersion) {
890
945
  ? key.startsWith(`${packageName}/${version}`)
891
946
  : key.startsWith(`${packageName}@${version}`);
892
947
  }
893
- function mapRootSnapshot(packageJson, rootImporters, packages, packageIndex, graph, workspaceModules, lockfileVersion, workspaceRoot) {
948
+ function mapRootSnapshot(packageJson, rootImporters, packages, packageIndex, graph, workspaceModules, lockfileVersion, workspaceRoot, projectRoot) {
894
949
  const catalogManager = (0, catalog_1.getCatalogManager)(workspaceRoot);
895
950
  const snapshot = { specifiers: {} };
896
951
  const importers = {};
@@ -910,7 +965,7 @@ function mapRootSnapshot(packageJson, rootImporters, packages, packageIndex, gra
910
965
  }
911
966
  version = resolved;
912
967
  }
913
- if (workspaceModules.has(packageName)) {
968
+ if ((0, pruned_output_1.resolveWorkspaceModuleDependency)(workspaceModules, packageName, version, projectRoot, workspaceRoot)) {
914
969
  // The app may declare the module under dependencies,
915
970
  // optionalDependencies, devDependencies, or peerDependencies. Route
916
971
  // the lockfile entry into the matching section; peerDependencies
@@ -953,29 +1008,27 @@ function mapRootSnapshot(packageJson, rootImporters, packages, packageIndex, gra
953
1008
  }
954
1009
  }
955
1010
  else {
1011
+ // peer dependencies are mapped to dependencies
1012
+ const section = depType === 'peerDependencies' ? 'dependencies' : depType;
1013
+ if (version.startsWith('link:')) {
1014
+ // A link: has no packages: entry, even when the graph has a node
1015
+ // for it, so the importer records the manifest value as is.
1016
+ snapshot.specifiers[packageName] = version;
1017
+ snapshot[section] = snapshot[section] || {};
1018
+ snapshot[section][packageName] = version;
1019
+ return;
1020
+ }
956
1021
  let node = graph.externalNodes[`npm:${packageName}@${version}`] ||
957
1022
  (graph.externalNodes[`npm:${packageName}`] &&
958
1023
  graph.externalNodes[`npm:${packageName}`].data.version === version
959
1024
  ? graph.externalNodes[`npm:${packageName}`]
960
1025
  : (0, project_graph_pruning_1.findNodeMatchingVersion)(graph, packageName, version));
961
- // A file:/link: local-path dependency records a path where a version
962
- // would go, so the lookups above never match it; findLocalPathNode
963
- // matches it on that path instead.
1026
+ // findLocalPathNode matches a `file:` dependency that the lookups
1027
+ // above miss, such as one relocated into the output
964
1028
  if (!node && (0, project_graph_pruning_1.isLocalPathSpecifier)(version)) {
965
1029
  node = (0, project_graph_pruning_1.findLocalPathNode)(graph, packageName, version);
966
1030
  }
967
- // peer dependencies are mapped to dependencies
968
- const section = depType === 'peerDependencies' ? 'dependencies' : depType;
969
1031
  if (!node) {
970
- if (version.startsWith('link:')) {
971
- // A link: needs no packages: entry; emit the manifest value
972
- // (relocated to its shipped location by the pre-lockfile rewrite)
973
- // directly.
974
- snapshot.specifiers[packageName] = version;
975
- snapshot[section] = snapshot[section] || {};
976
- snapshot[section][packageName] = version;
977
- return;
978
- }
979
1032
  throw new Error(`Could not find external node for package ${packageName}@${version}.`);
980
1033
  }
981
1034
  snapshot.specifiers[packageName] = version;
@@ -1,3 +1,4 @@
1
+ import type { ProjectGraphProjectNode } from '../../../config/project-graph';
1
2
  import type { Lockfile } from '@pnpm/lockfile-types';
2
3
  import type { PackageJson } from '../../../utils/package-json';
3
4
  export type PnpmLockfileConfigField = keyof Lockfile | 'catalogs';
@@ -75,6 +76,7 @@ export declare function getPrunedPnpmInstallSettingsYaml(workspaceRootPath?: str
75
76
  * shipping one file for both.
76
77
  */
77
78
  export declare function normalizePrunedPatchPath(patchPath: string): string;
79
+ export declare function normalizePrunedPatchedDependencies(patchedDependencies: Record<string, string>): Record<string, string>;
78
80
  type PrunedPnpmPackageJsonBuildSettings = Pick<NonNullable<PackageJson['pnpm']>, 'onlyBuiltDependencies' | 'neverBuiltDependencies' | 'supportedArchitectures'>;
79
81
  /**
80
82
  * The pnpm build-script approvals a standalone pruned output declares in its
@@ -107,6 +109,15 @@ export declare function getPrunedPnpmPatchArtifacts(workspaceRootPath?: string,
107
109
  }>;
108
110
  packageJsonPatchedDependencies: Record<string, string> | null;
109
111
  };
112
+ /**
113
+ * The `.patch` files a pruned output ships for `patchedDependencies` (package
114
+ * key -> patch file path), each at the `normalizePrunedPatchPath` path the
115
+ * output declares it under.
116
+ */
117
+ export declare function getPrunedPatchFiles(workspaceRootPath: string, patchedDependencies: Record<string, string>): Array<{
118
+ path: string;
119
+ content: string;
120
+ }>;
110
121
  /**
111
122
  * Non-workspace local-path deps (`file:` tarballs/dirs, `link:` targets) ship
112
123
  * under this single output directory rather than at their workspace-relative
@@ -187,6 +198,8 @@ export declare function containShippedLocalFilePaths(lockfile: Partial<Pick<Lock
187
198
  * the shipped directory's name. Mutates the snapshots in place.
188
199
  */
189
200
  export declare function containShippedLocalLinkRefs(sourceSnapshots: Record<string, unknown> | undefined): void;
201
+ /** True when a resolution `directory` points at a copied workspace module. */
202
+ export declare function isUnderWorkspaceModules(directory: string): boolean;
190
203
  /**
191
204
  * The non-workspace local-path packages a standalone pruned output must ship so
192
205
  * `pnpm install` can resolve them. The pruned lockfile records each path
@@ -195,7 +208,21 @@ export declare function containShippedLocalLinkRefs(sourceSnapshots: Record<stri
195
208
  * Three shapes ship: a `file:` tarball (the `.tgz`), a `file:` directory not
196
209
  * under `workspace_modules/` (copied workspace modules ship via
197
210
  * copy-workspace-modules and are skipped here), and a `link:` target directory
198
- * (a root importer `link:` version, or a package `link:` snapshot ref).
211
+ * (a root importer `link:` version, or a package `link:` snapshot ref). See
212
+ * `getLocalPathArtifacts` for how each ships.
213
+ */
214
+ export declare function getPrunedPnpmLocalPathArtifacts(workspaceRootPath?: string, prunedLockfileContent?: string): Array<{
215
+ path: string;
216
+ sourcePath: string;
217
+ }>;
218
+ export type LocalPathArtifactTarget = {
219
+ kind: 'file' | 'directory';
220
+ shippedPath: string;
221
+ origin: string;
222
+ };
223
+ /**
224
+ * The files a pruned output ships for its local-path `targets`, each read from
225
+ * the workspace location `uncontainLocalPath` recovers from its shipped path.
199
226
  * `node_modules` is filtered from every directory copy; a symlink inside a
200
227
  * shipped tree is skipped with a warning while a symlinked root ships when it
201
228
  * resolves under the workspace root; entries are deduped by destination; a
@@ -203,7 +230,7 @@ export declare function containShippedLocalLinkRefs(sourceSnapshots: Record<stri
203
230
  * with a warning (not reproducibly deployable). Source paths rather than bytes
204
231
  * so the file-writing prune paths can copy without buffering whole trees.
205
232
  */
206
- export declare function getPrunedPnpmLocalPathArtifacts(workspaceRootPath?: string, prunedLockfileContent?: string): Array<{
233
+ export declare function getLocalPathArtifacts(workspaceRootPath: string, targets: Iterable<LocalPathArtifactTarget>): Array<{
207
234
  path: string;
208
235
  sourcePath: string;
209
236
  }>;
@@ -228,6 +255,22 @@ export declare function getPrunedPnpmLocalPathArtifacts(workspaceRootPath?: stri
228
255
  * call sites gate on the package manager.
229
256
  */
230
257
  export declare function validatePrunedLocalPathClosure(packageJson: PackageJson, workspaceRootPath: string, prunedLockfileContent?: string): void;
258
+ /**
259
+ * Fails the pruned build when a shipped local-path target, keyed by its
260
+ * workspace source path, has a required dependency the app does not install
261
+ * (see `validatePrunedLocalPathClosure` for the rules). A `link:` target is a
262
+ * symlink, so no package manager installs its dependencies; a `directory` one
263
+ * is a `file:` package installed without them.
264
+ */
265
+ export declare function validateLocalPathClosures(packageJson: PackageJson, workspaceRootPath: string, targets: ReadonlyMap<string, 'link' | 'directory'>): void;
266
+ /**
267
+ * The workspace package a dependency of the manifest at `dependentRoot`
268
+ * resolves to. A `file:`/`link:` spec resolves by path, so a vendored package
269
+ * named like a workspace package is not that package. Any other spec resolves
270
+ * by name, and so does every spec when `dependentRoot` is undefined (the
271
+ * manifest's location is unknown).
272
+ */
273
+ export declare function resolveWorkspaceModuleDependency(workspacePackages: Map<string, ProjectGraphProjectNode>, name: string, spec: string, dependentRoot: string | undefined, workspaceRootPath: string): ProjectGraphProjectNode | undefined;
231
274
  /**
232
275
  * Relocates a `file:`/`link:` specifier recorded relative to `sourceDir` so it
233
276
  * resolves from `destDir` (both workspace-root-relative posix paths, '' meaning
@@ -284,22 +327,21 @@ export declare function dropEmptyPeerDependencySections(packageJson: PeerDepende
284
327
  /**
285
328
  * Rewrites a standalone pruned manifest's non-workspace local-path specifiers
286
329
  * (`file:` tarball/dir, `link:` dir) to their shipped location under
287
- * `LOCAL_PATH_MODULES_DIR`, so a non-frozen `pnpm install` of the deploy
288
- * output resolves them from where the shipped source sits (see
289
- * `getPrunedPnpmLocalPathArtifacts`). Mutates `packageJson` in place.
290
- * pnpm-only; call sites gate on the package manager.
330
+ * `LOCAL_PATH_MODULES_DIR`, so an install of the deploy output resolves them
331
+ * from where the shipped source sits (see `getLocalPathArtifacts`). Mutates
332
+ * `packageJson` in place.
291
333
  *
292
334
  * Per specifier, in order: resolve a `catalog:` reference first (the bundler's
293
335
  * `createPackageJson` does not), skip a workspace package (copied to
294
336
  * `workspace_modules/`), then relocate from `projectRoot`-relative to the
295
- * shipped location. A `file:`/`link:` peer dependency is moved into
337
+ * shipped location. For pnpm, a `file:`/`link:` peer dependency is moved into
296
338
  * `dependencies` with its `peerDependenciesMeta` entry dropped even when the
297
339
  * target cannot ship (pnpm rejects such a spec under peerDependencies
298
340
  * outright, so leaving it would fail the whole install), mirroring the
299
- * workspace-module handling. An unshippable target otherwise keeps its
300
- * specifier, with a warning.
341
+ * workspace-module handling. Bun installs such a peer where it is. An
342
+ * unshippable target otherwise keeps its specifier, with a warning.
301
343
  */
302
- export declare function rewritePrunedLocalPathSpecifiers(packageJson: PackageJson, projectRoot: string, workspaceRootPath: string, workspacePackageNames: Set<string>): void;
344
+ export declare function rewritePrunedLocalPathSpecifiers(packageJson: PackageJson, projectRoot: string, workspaceRootPath: string, workspacePackages: Map<string, ProjectGraphProjectNode>, packageManager?: 'pnpm' | 'bun'): void;
303
345
  export type PrunedDeployArtifact = {
304
346
  path: string;
305
347
  content: string | Buffer;