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
@@ -5,8 +5,10 @@ exports.stripPrunedLockfilePnpmConfig = stripPrunedLockfilePnpmConfig;
5
5
  exports.dropInheritedPnpmPatchedDependencies = dropInheritedPnpmPatchedDependencies;
6
6
  exports.getPrunedPnpmInstallSettingsYaml = getPrunedPnpmInstallSettingsYaml;
7
7
  exports.normalizePrunedPatchPath = normalizePrunedPatchPath;
8
+ exports.normalizePrunedPatchedDependencies = normalizePrunedPatchedDependencies;
8
9
  exports.getPrunedPnpmPackageJsonBuildSettings = getPrunedPnpmPackageJsonBuildSettings;
9
10
  exports.getPrunedPnpmPatchArtifacts = getPrunedPnpmPatchArtifacts;
11
+ exports.getPrunedPatchFiles = getPrunedPatchFiles;
10
12
  exports.containLocalPath = containLocalPath;
11
13
  exports.uncontainLocalPath = uncontainLocalPath;
12
14
  exports.normalizeLocalPathSpec = normalizeLocalPathSpec;
@@ -14,8 +16,12 @@ exports.uncontainLocalPathSpec = uncontainLocalPathSpec;
14
16
  exports.assertNoWorkspaceModulePathCollision = assertNoWorkspaceModulePathCollision;
15
17
  exports.containShippedLocalFilePaths = containShippedLocalFilePaths;
16
18
  exports.containShippedLocalLinkRefs = containShippedLocalLinkRefs;
19
+ exports.isUnderWorkspaceModules = isUnderWorkspaceModules;
17
20
  exports.getPrunedPnpmLocalPathArtifacts = getPrunedPnpmLocalPathArtifacts;
21
+ exports.getLocalPathArtifacts = getLocalPathArtifacts;
18
22
  exports.validatePrunedLocalPathClosure = validatePrunedLocalPathClosure;
23
+ exports.validateLocalPathClosures = validateLocalPathClosures;
24
+ exports.resolveWorkspaceModuleDependency = resolveWorkspaceModuleDependency;
19
25
  exports.relocatePrunedLocalPathSpec = relocatePrunedLocalPathSpec;
20
26
  exports.warnIncompletePrunedPnpmOutput = warnIncompletePrunedPnpmOutput;
21
27
  exports.warnUnshippableLocalPathSpec = warnUnshippableLocalPathSpec;
@@ -32,6 +38,7 @@ const output_1 = require("../../../utils/output");
32
38
  const package_manager_1 = require("../../../utils/package-manager");
33
39
  const path_2 = require("../../../utils/path");
34
40
  const workspace_root_1 = require("../../../utils/workspace-root");
41
+ const local_path_hashes_1 = require("./utils/local-path-hashes");
35
42
  const pnpm_normalizer_1 = require("./utils/pnpm-normalizer");
36
43
  /**
37
44
  * The resolution-time pnpm config a pruned standalone output must not carry,
@@ -584,6 +591,21 @@ function getPrunedPnpmPatchArtifacts(workspaceRootPath = workspace_root_1.worksp
584
591
  if (Object.keys(patchedDependencies).length === 0) {
585
592
  return { patchFiles: [], packageJsonPatchedDependencies: null };
586
593
  }
594
+ const patchFiles = getPrunedPatchFiles(workspaceRootPath, patchedDependencies);
595
+ const pnpmMajor = resolvePnpmMajor(precomputed, workspaceRootPath);
596
+ return {
597
+ patchFiles,
598
+ packageJsonPatchedDependencies: pnpmMajor !== null && pnpmMajor < 11
599
+ ? normalizePrunedPatchedDependencies(patchedDependencies)
600
+ : null,
601
+ };
602
+ }
603
+ /**
604
+ * The `.patch` files a pruned output ships for `patchedDependencies` (package
605
+ * key -> patch file path), each at the `normalizePrunedPatchPath` path the
606
+ * output declares it under.
607
+ */
608
+ function getPrunedPatchFiles(workspaceRootPath, patchedDependencies) {
587
609
  const patchFiles = [];
588
610
  // normalizePrunedPatchPath collapses the path, so two distinct sources can
589
611
  // normalize to one shipped path, which would ship a single file for both
@@ -600,7 +622,7 @@ function getPrunedPnpmPatchArtifacts(workspaceRootPath = workspace_root_1.worksp
600
622
  const destination = normalizePrunedPatchPath(patchPath);
601
623
  const existingSource = shippedFrom.get(destination);
602
624
  if (existingSource !== undefined && existingSource !== source) {
603
- throw new Error(`Cannot prune pnpm patches: "${existingSource}" and "${source}" both ship to "${destination}" in the standalone output. Rename one so the patches do not collide.`);
625
+ throw new Error(`Cannot prune patches: "${existingSource}" and "${source}" both ship to "${destination}" in the standalone output. Rename one so the patches do not collide.`);
604
626
  }
605
627
  shippedFrom.set(destination, source);
606
628
  // A file check rather than a mere existence one: a path whose segments all
@@ -622,13 +644,7 @@ function getPrunedPnpmPatchArtifacts(workspaceRootPath = workspace_root_1.worksp
622
644
  logger_1.logger.warn(`Patch file "${patchPath}" referenced by patchedDependencies was not found; the pruned output declares the patch but cannot ship the file.`);
623
645
  }
624
646
  }
625
- const pnpmMajor = resolvePnpmMajor(precomputed, workspaceRootPath);
626
- return {
627
- patchFiles,
628
- packageJsonPatchedDependencies: pnpmMajor !== null && pnpmMajor < 11
629
- ? normalizePrunedPatchedDependencies(patchedDependencies)
630
- : null,
631
- };
647
+ return patchFiles;
632
648
  }
633
649
  const WORKSPACE_MODULES_DIR = 'workspace_modules';
634
650
  /**
@@ -975,13 +991,8 @@ function collectPrunedLinkTargetDirs(parsed) {
975
991
  * Three shapes ship: a `file:` tarball (the `.tgz`), a `file:` directory not
976
992
  * under `workspace_modules/` (copied workspace modules ship via
977
993
  * copy-workspace-modules and are skipped here), and a `link:` target directory
978
- * (a root importer `link:` version, or a package `link:` snapshot ref).
979
- * `node_modules` is filtered from every directory copy; a symlink inside a
980
- * shipped tree is skipped with a warning while a symlinked root ships when it
981
- * resolves under the workspace root; entries are deduped by destination; a
982
- * source missing on disk or resolving outside the workspace root is skipped
983
- * with a warning (not reproducibly deployable). Source paths rather than bytes
984
- * so the file-writing prune paths can copy without buffering whole trees.
994
+ * (a root importer `link:` version, or a package `link:` snapshot ref). See
995
+ * `getLocalPathArtifacts` for how each ships.
985
996
  */
986
997
  function getPrunedPnpmLocalPathArtifacts(workspaceRootPath = workspace_root_1.workspaceRoot, prunedLockfileContent) {
987
998
  if (!prunedLockfileContent) {
@@ -991,6 +1002,44 @@ function getPrunedPnpmLocalPathArtifacts(workspaceRootPath = workspace_root_1.wo
991
1002
  if (!parsed) {
992
1003
  return [];
993
1004
  }
1005
+ const targets = [];
1006
+ // file: tarball + file: directory resolutions (resolutions live in `packages`).
1007
+ for (const snapshot of Object.values(parsed.packages ?? {})) {
1008
+ const tarball = snapshot?.resolution?.tarball;
1009
+ if (tarball?.startsWith('file:')) {
1010
+ targets.push({
1011
+ kind: 'file',
1012
+ shippedPath: tarball.slice('file:'.length),
1013
+ origin: tarball,
1014
+ });
1015
+ continue;
1016
+ }
1017
+ const directory = snapshot?.resolution?.directory;
1018
+ if (directory && !isUnderWorkspaceModules(directory)) {
1019
+ targets.push({
1020
+ kind: 'directory',
1021
+ shippedPath: (0, path_2.normalizePath)(directory),
1022
+ origin: `file:${directory}`,
1023
+ });
1024
+ }
1025
+ }
1026
+ // link: targets (root importer versions + directory-package snapshot refs).
1027
+ for (const { target, ref } of collectPrunedLinkTargetDirs(parsed)) {
1028
+ targets.push({ kind: 'directory', shippedPath: target, origin: ref });
1029
+ }
1030
+ return getLocalPathArtifacts(workspaceRootPath, targets);
1031
+ }
1032
+ /**
1033
+ * The files a pruned output ships for its local-path `targets`, each read from
1034
+ * the workspace location `uncontainLocalPath` recovers from its shipped path.
1035
+ * `node_modules` is filtered from every directory copy; a symlink inside a
1036
+ * shipped tree is skipped with a warning while a symlinked root ships when it
1037
+ * resolves under the workspace root; entries are deduped by destination; a
1038
+ * source missing on disk or resolving outside the workspace root is skipped
1039
+ * with a warning (not reproducibly deployable). Source paths rather than bytes
1040
+ * so the file-writing prune paths can copy without buffering whole trees.
1041
+ */
1042
+ function getLocalPathArtifacts(workspaceRootPath, targets) {
994
1043
  const artifacts = [];
995
1044
  const shippedRoots = new Set();
996
1045
  const seenDestinations = new Set();
@@ -1025,9 +1074,8 @@ function getPrunedPnpmLocalPathArtifacts(workspaceRootPath = workspace_root_1.wo
1025
1074
  }
1026
1075
  return null;
1027
1076
  };
1028
- // Callers pass the shipped path (relocated under LOCAL_PATH_MODULES_DIR, as the
1029
- // pruned lockfile records it); it is the artifact destination, while the source
1030
- // is read from the original workspace location.
1077
+ // The shipped path is the artifact destination, while the source is read
1078
+ // from the original workspace location.
1031
1079
  const shipFile = (shippedPath, origin) => {
1032
1080
  if (shippedRoots.has(shippedPath)) {
1033
1081
  return;
@@ -1053,49 +1101,28 @@ function getPrunedPnpmLocalPathArtifacts(workspaceRootPath = workspace_root_1.wo
1053
1101
  logger_1.logger.warn(`Local-path dependency "${origin}" is not a directory at ${source}; the pruned output references it but cannot ship it.`);
1054
1102
  return;
1055
1103
  }
1056
- // Walk the tree, skipping node_modules, deduping by destination.
1057
- const walk = (absoluteDir, destinationDir) => {
1058
- for (const entry of (0, fs_1.readdirSync)(absoluteDir, { withFileTypes: true })) {
1059
- if (entry.name === 'node_modules') {
1060
- continue;
1061
- }
1062
- const absoluteEntry = (0, path_1.join)(absoluteDir, entry.name);
1063
- const destinationEntry = `${destinationDir}/${entry.name}`;
1064
- if (entry.isDirectory()) {
1065
- walk(absoluteEntry, destinationEntry);
1066
- }
1067
- else if (entry.isFile()) {
1068
- if (seenDestinations.has(destinationEntry)) {
1069
- continue;
1070
- }
1071
- seenDestinations.add(destinationEntry);
1072
- artifacts.push({ path: destinationEntry, sourcePath: absoluteEntry });
1073
- }
1074
- else if (entry.isSymbolicLink()) {
1075
- // Following links risks cycles and machine-specific targets, so they
1076
- // are not shipped; surface the gap instead of silently dropping it.
1077
- logger_1.logger.warn(`Local-path dependency "${origin}" contains a symbolic link at ${absoluteEntry}, which is not shipped into the pruned output.`);
1078
- }
1104
+ // Following links risks cycles and machine-specific targets, so they are
1105
+ // not shipped; surface the gap instead of silently dropping it.
1106
+ const files = (0, local_path_hashes_1.listLocalPathFiles)(source, {
1107
+ onSymbolicLink: (link) => logger_1.logger.warn(`Local-path dependency "${origin}" contains a symbolic link at ${link}, which is not shipped into the pruned output.`),
1108
+ });
1109
+ for (const { relativePath, absolutePath } of files) {
1110
+ const destination = `${shippedPath}/${relativePath}`;
1111
+ if (seenDestinations.has(destination)) {
1112
+ continue;
1079
1113
  }
1080
- };
1081
- walk(source, shippedPath);
1114
+ seenDestinations.add(destination);
1115
+ artifacts.push({ path: destination, sourcePath: absolutePath });
1116
+ }
1082
1117
  };
1083
- // file: tarball + file: directory resolutions (resolutions live in `packages`).
1084
- for (const snapshot of Object.values(parsed.packages ?? {})) {
1085
- const tarball = snapshot?.resolution?.tarball;
1086
- if (tarball?.startsWith('file:')) {
1087
- shipFile(tarball.slice('file:'.length), tarball);
1088
- continue;
1118
+ for (const { kind, shippedPath, origin } of targets) {
1119
+ if (kind === 'file') {
1120
+ shipFile(shippedPath, origin);
1089
1121
  }
1090
- const directory = snapshot?.resolution?.directory;
1091
- if (directory && !isUnderWorkspaceModules(directory)) {
1092
- shipDirectory((0, path_2.normalizePath)(directory), `file:${directory}`);
1122
+ else {
1123
+ shipDirectory(shippedPath, origin);
1093
1124
  }
1094
1125
  }
1095
- // link: targets (root importer versions + directory-package snapshot refs).
1096
- for (const { target, ref } of collectPrunedLinkTargetDirs(parsed)) {
1097
- shipDirectory(target, ref);
1098
- }
1099
1126
  return artifacts;
1100
1127
  }
1101
1128
  /**
@@ -1178,6 +1205,16 @@ function validatePrunedLocalPathClosure(packageJson, workspaceRootPath, prunedLo
1178
1205
  targets.set(source, 'link');
1179
1206
  }
1180
1207
  }
1208
+ validateLocalPathClosures(packageJson, workspaceRootPath, targets);
1209
+ }
1210
+ /**
1211
+ * Fails the pruned build when a shipped local-path target, keyed by its
1212
+ * workspace source path, has a required dependency the app does not install
1213
+ * (see `validatePrunedLocalPathClosure` for the rules). A `link:` target is a
1214
+ * symlink, so no package manager installs its dependencies; a `directory` one
1215
+ * is a `file:` package installed without them.
1216
+ */
1217
+ function validateLocalPathClosures(packageJson, workspaceRootPath, targets) {
1181
1218
  if (targets.size === 0) {
1182
1219
  return;
1183
1220
  }
@@ -1241,6 +1278,36 @@ function validatePrunedLocalPathClosure(packageJson, workspaceRootPath, prunedLo
1241
1278
  }
1242
1279
  }
1243
1280
  }
1281
+ /**
1282
+ * The workspace package a dependency of the manifest at `dependentRoot`
1283
+ * resolves to. A `file:`/`link:` spec resolves by path, so a vendored package
1284
+ * named like a workspace package is not that package. Any other spec resolves
1285
+ * by name, and so does every spec when `dependentRoot` is undefined (the
1286
+ * manifest's location is unknown).
1287
+ */
1288
+ function resolveWorkspaceModuleDependency(workspacePackages, name, spec, dependentRoot, workspaceRootPath) {
1289
+ const project = workspacePackages.get(name);
1290
+ const protocol = spec.startsWith('link:')
1291
+ ? 'link:'
1292
+ : spec.startsWith('file:')
1293
+ ? 'file:'
1294
+ : null;
1295
+ if (!project || !protocol || dependentRoot === undefined) {
1296
+ return project;
1297
+ }
1298
+ const toWorkspacePath = (path) => {
1299
+ const normalized = (0, path_2.normalizePath)(path);
1300
+ return path_1.posix
1301
+ .normalize((0, path_1.isAbsolute)(normalized)
1302
+ ? (0, path_2.normalizePath)((0, path_1.relative)(workspaceRootPath, normalized))
1303
+ : normalized)
1304
+ .replace(/(?<=.)\/$/, '');
1305
+ };
1306
+ const root = toWorkspacePath(dependentRoot);
1307
+ const path = (0, path_2.normalizePath)(spec.slice(protocol.length));
1308
+ const target = toWorkspacePath((0, path_1.isAbsolute)(path) ? path : path_1.posix.join(root, path));
1309
+ return target === toWorkspacePath(project.data.root) ? project : undefined;
1310
+ }
1244
1311
  /**
1245
1312
  * Relocates a `file:`/`link:` specifier recorded relative to `sourceDir` so it
1246
1313
  * resolves from `destDir` (both workspace-root-relative posix paths, '' meaning
@@ -1370,22 +1437,21 @@ function dropEmptyPeerDependencySections(packageJson) {
1370
1437
  /**
1371
1438
  * Rewrites a standalone pruned manifest's non-workspace local-path specifiers
1372
1439
  * (`file:` tarball/dir, `link:` dir) to their shipped location under
1373
- * `LOCAL_PATH_MODULES_DIR`, so a non-frozen `pnpm install` of the deploy
1374
- * output resolves them from where the shipped source sits (see
1375
- * `getPrunedPnpmLocalPathArtifacts`). Mutates `packageJson` in place.
1376
- * pnpm-only; call sites gate on the package manager.
1440
+ * `LOCAL_PATH_MODULES_DIR`, so an install of the deploy output resolves them
1441
+ * from where the shipped source sits (see `getLocalPathArtifacts`). Mutates
1442
+ * `packageJson` in place.
1377
1443
  *
1378
1444
  * Per specifier, in order: resolve a `catalog:` reference first (the bundler's
1379
1445
  * `createPackageJson` does not), skip a workspace package (copied to
1380
1446
  * `workspace_modules/`), then relocate from `projectRoot`-relative to the
1381
- * shipped location. A `file:`/`link:` peer dependency is moved into
1447
+ * shipped location. For pnpm, a `file:`/`link:` peer dependency is moved into
1382
1448
  * `dependencies` with its `peerDependenciesMeta` entry dropped even when the
1383
1449
  * target cannot ship (pnpm rejects such a spec under peerDependencies
1384
1450
  * outright, so leaving it would fail the whole install), mirroring the
1385
- * workspace-module handling. An unshippable target otherwise keeps its
1386
- * specifier, with a warning.
1451
+ * workspace-module handling. Bun installs such a peer where it is. An
1452
+ * unshippable target otherwise keeps its specifier, with a warning.
1387
1453
  */
1388
- function rewritePrunedLocalPathSpecifiers(packageJson, projectRoot, workspaceRootPath, workspacePackageNames) {
1454
+ function rewritePrunedLocalPathSpecifiers(packageJson, projectRoot, workspaceRootPath, workspacePackages, packageManager = 'pnpm') {
1389
1455
  const catalogManager = (0, catalog_1.getCatalogManager)(workspaceRootPath);
1390
1456
  const sections = [
1391
1457
  'dependencies',
@@ -1407,7 +1473,7 @@ function rewritePrunedLocalPathSpecifiers(packageJson, projectRoot, workspaceRoo
1407
1473
  deps[name] = resolvedCatalog;
1408
1474
  }
1409
1475
  }
1410
- if (workspacePackageNames.has(name)) {
1476
+ if (resolveWorkspaceModuleDependency(workspacePackages, name, resolved, projectRoot, workspaceRootPath)) {
1411
1477
  continue;
1412
1478
  }
1413
1479
  const relocation = relocatePrunedLocalPathSpec(resolved, projectRoot, '');
@@ -1417,7 +1483,7 @@ function rewritePrunedLocalPathSpecifiers(packageJson, projectRoot, workspaceRoo
1417
1483
  if (relocation.reason) {
1418
1484
  warnUnshippableLocalPathSpec(`"${name}": "${resolved}"`, relocation.reason);
1419
1485
  }
1420
- if (section === 'peerDependencies') {
1486
+ if (section === 'peerDependencies' && packageManager === 'pnpm') {
1421
1487
  // Moved even when the target cannot ship: pnpm rejects the spec here
1422
1488
  // either way, so leaving it would fail the whole install.
1423
1489
  movePeerDependencyToDependencies(packageJson, name, relocation.spec);
@@ -0,0 +1,27 @@
1
+ import type { ProjectGraphExternalNode } from '../../../../config/project-graph';
2
+ /**
3
+ * Folds the contents of the local-path packages' sources into the hashes of
4
+ * their external nodes. `nodeSources` maps a node name to its sources, relative
5
+ * to `workspaceRoot`. Returns new node objects for the folded nodes, so a parser
6
+ * that reuses its nodes keeps their lockfile hashes.
7
+ *
8
+ * A directory in the workspace hashes the files Nx's workspace index lists in
9
+ * it, so files that git or `.nxignore` ignores and symbolic links don't count.
10
+ * A missing source hashes like an empty directory, so a link to ignored output
11
+ * that isn't built yet keeps its hash once it is. A source outside the
12
+ * workspace keeps its lockfile hash, as linked packages do elsewhere in Nx.
13
+ */
14
+ export declare function foldLocalPathHashes(nodes: Record<string, ProjectGraphExternalNode>, nodeSources: Record<string, string[]>, workspaceRoot: string): Promise<Record<string, ProjectGraphExternalNode>>;
15
+ /**
16
+ * Lists the files a local-path directory ships, sorted: every file outside
17
+ * `node_modules`, whether or not git ignores it. Symbolic links are neither
18
+ * followed nor listed; `onSymbolicLink` receives each one. A directory that
19
+ * cannot be read throws unless `onUnreadableDirectory` is given.
20
+ */
21
+ export declare function listLocalPathFiles(directory: string, callbacks?: {
22
+ onSymbolicLink?: (absolutePath: string) => void;
23
+ onUnreadableDirectory?: (relativePath: string) => void;
24
+ }): {
25
+ relativePath: string;
26
+ absolutePath: string;
27
+ }[];
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.foldLocalPathHashes = foldLocalPathHashes;
4
+ exports.listLocalPathFiles = listLocalPathFiles;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const file_hasher_1 = require("../../../../hasher/file-hasher");
8
+ const workspace_context_1 = require("../../../../utils/workspace-context");
9
+ const path_1 = require("../../../../utils/path");
10
+ /**
11
+ * Folds the contents of the local-path packages' sources into the hashes of
12
+ * their external nodes. `nodeSources` maps a node name to its sources, relative
13
+ * to `workspaceRoot`. Returns new node objects for the folded nodes, so a parser
14
+ * that reuses its nodes keeps their lockfile hashes.
15
+ *
16
+ * A directory in the workspace hashes the files Nx's workspace index lists in
17
+ * it, so files that git or `.nxignore` ignores and symbolic links don't count.
18
+ * A missing source hashes like an empty directory, so a link to ignored output
19
+ * that isn't built yet keeps its hash once it is. A source outside the
20
+ * workspace keeps its lockfile hash, as linked packages do elsewhere in Nx.
21
+ */
22
+ async function foldLocalPathHashes(nodes, nodeSources, workspaceRoot) {
23
+ const nodeNames = Object.keys(nodeSources).filter((name) => nodes[name]);
24
+ if (!nodeNames.length) {
25
+ return nodes;
26
+ }
27
+ const hashes = await hashLocalPathSources(nodeNames.flatMap((name) => nodeSources[name]), workspaceRoot);
28
+ const folded = { ...nodes };
29
+ for (const name of nodeNames) {
30
+ const sourceHashes = nodeSources[name]
31
+ .map((source) => hashes.get(source))
32
+ .filter((hash) => hash !== undefined);
33
+ if (!sourceHashes.length) {
34
+ continue;
35
+ }
36
+ const node = nodes[name];
37
+ folded[name] = {
38
+ ...node,
39
+ data: {
40
+ ...node.data,
41
+ hash: (0, file_hasher_1.hashArray)([node.data.hash ?? '', ...sourceHashes]),
42
+ },
43
+ };
44
+ }
45
+ return folded;
46
+ }
47
+ async function hashLocalPathSources(sources, workspaceRoot) {
48
+ const hashes = new Map();
49
+ let realWorkspaceRoot;
50
+ for (const source of new Set(sources)) {
51
+ if ((0, node_path_1.isAbsolute)(source) || source === '..' || source.startsWith('../')) {
52
+ continue;
53
+ }
54
+ const absolutePath = (0, node_path_1.join)(workspaceRoot, source);
55
+ let realPath;
56
+ try {
57
+ const stats = (0, node_fs_1.statSync)(absolutePath);
58
+ if (stats.isFile()) {
59
+ hashes.set(source, (0, file_hasher_1.hashFile)(absolutePath));
60
+ continue;
61
+ }
62
+ if (stats.isDirectory()) {
63
+ realPath = (0, node_fs_1.realpathSync)(absolutePath);
64
+ }
65
+ }
66
+ catch { }
67
+ if (!realPath) {
68
+ hashes.set(source, (0, file_hasher_1.hashArray)([]));
69
+ continue;
70
+ }
71
+ realWorkspaceRoot ??= (0, node_fs_1.realpathSync)(workspaceRoot);
72
+ const indexDir = (0, node_path_1.relative)(realWorkspaceRoot, realPath);
73
+ hashes.set(source, (0, path_1.isContainedRelativePath)(indexDir)
74
+ ? await hashIndexedDirectory(workspaceRoot, realWorkspaceRoot, (0, path_1.normalizePath)(indexDir))
75
+ : hashLocalPathDirectory(realPath));
76
+ }
77
+ return hashes;
78
+ }
79
+ // Mirrors the copier, which skips symbolic links inside a directory
80
+ async function hashIndexedDirectory(workspaceRoot, realWorkspaceRoot, indexDir) {
81
+ const prefix = indexDir ? `${indexDir}/` : '';
82
+ const files = (await (0, workspace_context_1.getFilesInDirectoryUsingContext)(workspaceRoot, indexDir)).sort();
83
+ return (0, file_hasher_1.hashArray)(files.flatMap((file) => {
84
+ const absolutePath = (0, node_path_1.join)(realWorkspaceRoot, file);
85
+ return isRegularFile(absolutePath)
86
+ ? [file.slice(prefix.length), (0, file_hasher_1.hashFile)(absolutePath) ?? 'unreadable']
87
+ : [];
88
+ }));
89
+ }
90
+ function isRegularFile(path) {
91
+ try {
92
+ return (0, node_fs_1.lstatSync)(path, { throwIfNoEntry: false })?.isFile() === true;
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ }
98
+ // An unreadable directory fails the copy, not the project graph.
99
+ function hashLocalPathDirectory(directory) {
100
+ const unreadable = [];
101
+ const files = listLocalPathFiles(directory, {
102
+ onUnreadableDirectory: (relativePath) => unreadable.push(`unreadable directory ${relativePath}`),
103
+ });
104
+ return (0, file_hasher_1.hashArray)([
105
+ ...files.flatMap((file) => [
106
+ file.relativePath,
107
+ (0, file_hasher_1.hashFile)(file.absolutePath),
108
+ ]),
109
+ ...unreadable,
110
+ ]);
111
+ }
112
+ /**
113
+ * Lists the files a local-path directory ships, sorted: every file outside
114
+ * `node_modules`, whether or not git ignores it. Symbolic links are neither
115
+ * followed nor listed; `onSymbolicLink` receives each one. A directory that
116
+ * cannot be read throws unless `onUnreadableDirectory` is given.
117
+ */
118
+ function listLocalPathFiles(directory, callbacks = {}) {
119
+ const files = [];
120
+ const walk = (absoluteDir, relativeDir) => {
121
+ let dirEntries;
122
+ try {
123
+ dirEntries = (0, node_fs_1.readdirSync)(absoluteDir, { withFileTypes: true });
124
+ }
125
+ catch (e) {
126
+ if (!callbacks.onUnreadableDirectory) {
127
+ throw e;
128
+ }
129
+ callbacks.onUnreadableDirectory(relativeDir);
130
+ return;
131
+ }
132
+ // Listing order depends on the filesystem.
133
+ dirEntries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
134
+ for (const entry of dirEntries) {
135
+ if (entry.name === 'node_modules') {
136
+ continue;
137
+ }
138
+ const relativePath = relativeDir
139
+ ? `${relativeDir}/${entry.name}`
140
+ : entry.name;
141
+ const absolutePath = (0, node_path_1.join)(absoluteDir, entry.name);
142
+ if (entry.isDirectory()) {
143
+ walk(absolutePath, relativePath);
144
+ }
145
+ else if (entry.isFile()) {
146
+ files.push({ relativePath, absolutePath });
147
+ }
148
+ else if (entry.isSymbolicLink()) {
149
+ callbacks.onSymbolicLink?.(absolutePath);
150
+ }
151
+ }
152
+ };
153
+ walk(directory, '');
154
+ return files;
155
+ }
@@ -3,7 +3,7 @@ import { PackageJson } from '../../../../utils/package-json';
3
3
  * Get version of hoisted package if available
4
4
  */
5
5
  export declare function getHoistedPackageVersion(packageName: string): string;
6
- export type NormalizedPackageJson = Pick<PackageJson, 'name' | 'version' | 'license' | 'dependencies' | 'devDependencies' | 'peerDependencies' | 'peerDependenciesMeta' | 'optionalDependencies' | 'packageManager' | 'resolutions' | 'overrides' | 'pnpm'>;
6
+ export type NormalizedPackageJson = Pick<PackageJson, 'name' | 'version' | 'license' | 'dependencies' | 'devDependencies' | 'peerDependencies' | 'peerDependenciesMeta' | 'optionalDependencies' | 'packageManager' | 'resolutions' | 'overrides' | 'pnpm' | 'trustedDependencies'>;
7
7
  /**
8
8
  * Strip off non-pruning related fields from package.json
9
9
  */
@@ -20,7 +20,7 @@ function getHoistedPackageVersion(packageName) {
20
20
  * Strip off non-pruning related fields from package.json
21
21
  */
22
22
  function normalizePackageJson(packageJson) {
23
- const { name, version, license, dependencies, devDependencies, peerDependencies, peerDependenciesMeta, optionalDependencies, packageManager, resolutions, overrides, pnpm, } = packageJson;
23
+ const { name, version, license, dependencies, devDependencies, peerDependencies, peerDependenciesMeta, optionalDependencies, packageManager, resolutions, overrides, pnpm, trustedDependencies, } = packageJson;
24
24
  return {
25
25
  name,
26
26
  version,
@@ -34,5 +34,6 @@ function normalizePackageJson(packageJson) {
34
34
  resolutions,
35
35
  overrides,
36
36
  pnpm,
37
+ trustedDependencies,
37
38
  };
38
39
  }
@@ -6,6 +6,7 @@ interface NpmDeps {
6
6
  readonly peerDependenciesMeta: Record<string, {
7
7
  optional: boolean;
8
8
  }>;
9
+ readonly importingProjects: Record<string, string>;
9
10
  }
10
11
  /**
11
12
  * Creates a package.json in the output directory for support to install dependencies within containers.