nx 24.0.4 → 24.0.6

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 (78) hide show
  1. package/dist/bin/nx.js +2 -8
  2. package/dist/bin/workspace-env.d.ts +7 -0
  3. package/dist/bin/workspace-env.js +20 -0
  4. package/dist/src/command-line/affected/affected.js +1 -0
  5. package/dist/src/command-line/migrate/migrate.js +23 -7
  6. package/dist/src/command-line/migrate/prompt-files.d.ts +4 -2
  7. package/dist/src/command-line/migrate/prompt-files.js +26 -5
  8. package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +1 -1
  9. package/dist/src/command-line/release/changelog.js +15 -12
  10. package/dist/src/command-line/reset/reset.js +13 -1
  11. package/dist/src/daemon/client/client.js +8 -7
  12. package/dist/src/daemon/client/daemon-environment.d.ts +43 -11
  13. package/dist/src/daemon/client/daemon-environment.js +139 -8
  14. package/dist/src/daemon/server/handle-client-env.d.ts +11 -1
  15. package/dist/src/daemon/server/handle-client-env.js +96 -5
  16. package/dist/src/daemon/server/handle-configure-ai-agents.js +2 -1
  17. package/dist/src/daemon/server/latest-nx.js +2 -1
  18. package/dist/src/daemon/server/server.js +1 -1
  19. package/dist/src/daemon/socket-utils.d.ts +9 -1
  20. package/dist/src/daemon/socket-utils.js +25 -0
  21. package/dist/src/executors/run-commands/running-tasks.d.ts +1 -0
  22. package/dist/src/executors/run-commands/running-tasks.js +69 -17
  23. package/dist/src/executors/run-script/run-script.impl.js +11 -3
  24. package/dist/src/native/index.d.ts +1 -1
  25. package/dist/src/native/index.js +31 -3
  26. package/dist/src/native/native-file-cache-location.js +10 -4
  27. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  28. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  29. package/dist/src/native/transform-objects.js +5 -1
  30. package/dist/src/nx-cloud/update-manager.d.ts +6 -1
  31. package/dist/src/nx-cloud/update-manager.js +39 -12
  32. package/dist/src/plugins/js/lock-file/pnpm-parser.js +22 -34
  33. package/dist/src/plugins/js/lock-file/project-graph-pruning.d.ts +7 -0
  34. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +31 -5
  35. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +1 -1
  36. package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +6 -5
  37. package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -1
  38. package/dist/src/plugins/js/package-json/create-package-json.js +53 -16
  39. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +7 -1
  40. package/dist/src/project-graph/affected/affected-tasks.js +29 -1
  41. package/dist/src/project-graph/plugins/get-plugins.d.ts +2 -0
  42. package/dist/src/project-graph/plugins/get-plugins.js +17 -2
  43. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +4 -2
  44. package/dist/src/tasks-runner/fork.js +4 -2
  45. package/dist/src/tasks-runner/run-command.d.ts +4 -1
  46. package/dist/src/tasks-runner/run-command.js +6 -4
  47. package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +3 -2
  48. package/dist/src/tasks-runner/running-tasks/batch-process.js +7 -3
  49. package/dist/src/tasks-runner/task-orchestrator.d.ts +1 -0
  50. package/dist/src/tasks-runner/task-orchestrator.js +12 -3
  51. package/dist/src/tasks-runner/tasks-runner.d.ts +5 -0
  52. package/dist/src/ultracache/overrides.d.ts +1 -1
  53. package/dist/src/ultracache/overrides.js +1 -1
  54. package/dist/src/ultracache/report.d.ts +1 -1
  55. package/dist/src/ultracache/report.js +4 -1
  56. package/dist/src/utils/cache-directory.d.ts +3 -0
  57. package/dist/src/utils/cache-directory.js +105 -25
  58. package/dist/src/utils/child-process.d.ts +8 -1
  59. package/dist/src/utils/child-process.js +24 -0
  60. package/dist/src/utils/compile-cache.d.ts +6 -8
  61. package/dist/src/utils/compile-cache.js +23 -16
  62. package/dist/src/utils/min-release-age/packument.d.ts +2 -1
  63. package/dist/src/utils/min-release-age/packument.js +5 -3
  64. package/dist/src/utils/nx-tmp-dir.d.ts +14 -2
  65. package/dist/src/utils/nx-tmp-dir.js +26 -2
  66. package/dist/src/utils/owned-private-dir.d.ts +22 -0
  67. package/dist/src/utils/owned-private-dir.js +148 -0
  68. package/dist/src/utils/package-json.d.ts +8 -1
  69. package/dist/src/utils/package-json.js +77 -34
  70. package/dist/src/utils/package-manager.d.ts +25 -0
  71. package/dist/src/utils/package-manager.js +244 -9
  72. package/dist/src/utils/path.d.ts +4 -0
  73. package/dist/src/utils/path.js +8 -0
  74. package/dist/src/utils/redact-url-credentials.js +3 -2
  75. package/dist/src/utils/wait-for-socket-connection.d.ts +2 -0
  76. package/dist/src/utils/wait-for-socket-connection.js +3 -3
  77. package/package.json +11 -11
  78. package/schemas/migrations-schema.json +1 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pruneProjectGraph = pruneProjectGraph;
4
4
  exports.isLocalPathSpecifier = isLocalPathSpecifier;
5
+ exports.isLinkNode = isLinkNode;
5
6
  exports.findLocalPathNode = findLocalPathNode;
6
7
  exports.findNodeMatchingVersion = findNodeMatchingVersion;
7
8
  exports.addNodesAndDependencies = addNodesAndDependencies;
@@ -114,6 +115,15 @@ function normalizeDependencies(packageJson, graph, workspacePackages, workspaceR
114
115
  function isLocalPathSpecifier(versionExpr) {
115
116
  return versionExpr.startsWith('file:') || versionExpr.startsWith('link:');
116
117
  }
118
+ /**
119
+ * The pnpm parser gives the bare `npm:<name>` to an outside `link:` when no
120
+ * registry version holds it. Such a node says nothing about which registry
121
+ * version a project resolves, so lookups that fall back to registry versions
122
+ * skip it.
123
+ */
124
+ function isLinkNode(node) {
125
+ return node.data.version.startsWith('link:');
126
+ }
117
127
  /**
118
128
  * The external node for a `file:`/`link:` local-path dependency.
119
129
  *
@@ -147,14 +157,20 @@ function findLocalPathNode(graph, packageName, versionExpr) {
147
157
  return matches[0];
148
158
  }
149
159
  function findNodeMatchingVersion(graph, packageName, versionExpr) {
150
- if (versionExpr === '*') {
151
- return graph.externalNodes[`npm:${packageName}`];
160
+ const bareNode = graph.externalNodes[`npm:${packageName}`];
161
+ if (versionExpr === '*' && bareNode && !isLinkNode(bareNode)) {
162
+ return bareNode;
152
163
  }
153
164
  const nodes = Object.values(graph.externalNodes)
154
165
  .filter((n) => n.data.packageName === packageName)
155
- .sort((a, b) => ((0, semver_1.gte)(b.data.version, a.data.version) ? 1 : -1));
156
- if (versionExpr === 'latest') {
157
- return nodes.sort((a, b) => +(0, semver_1.gte)(b.data.version, a.data.version))[0];
166
+ .sort(compareVersionsDescending);
167
+ // A package with several versions can have no bare registry node, for
168
+ // example when the pnpm root importer does not declare it. An outside
169
+ // `link:` can then hold the bare name; it sorts last, so any registry
170
+ // version wins over it. A stable version wins over a prerelease, which
171
+ // `*` does not match.
172
+ if (versionExpr === '*' || versionExpr === 'latest') {
173
+ return nodes.find((n) => (0, semver_1.satisfies)(n.data.version, '*')) ?? nodes[0];
158
174
  }
159
175
  if (graph.externalNodes[`npm:${packageName}`] &&
160
176
  (0, semver_1.satisfies)(graph.externalNodes[`npm:${packageName}`].data.version, versionExpr)) {
@@ -162,6 +178,16 @@ function findNodeMatchingVersion(graph, packageName, versionExpr) {
162
178
  }
163
179
  return nodes.find((n) => (0, semver_1.satisfies)(n.data.version, versionExpr));
164
180
  }
181
+ // Local-path and other non-semver versions, such as file:vendor/foo.tgz,
182
+ // sort after every semver version.
183
+ function compareVersionsDescending(a, b) {
184
+ const aIsSemver = (0, semver_1.valid)(a.data.version) !== null;
185
+ const bIsSemver = (0, semver_1.valid)(b.data.version) !== null;
186
+ if (aIsSemver && bIsSemver) {
187
+ return (0, semver_1.rcompare)(a.data.version, b.data.version);
188
+ }
189
+ return Number(bIsSemver) - Number(aIsSemver);
190
+ }
165
191
  function addNodesAndDependencies(graph, packageJsonDeps, workspacePackages, builder) {
166
192
  Object.entries(packageJsonDeps).forEach(([name, version]) => {
167
193
  const node = graph.externalNodes[`npm:${name}@${version}`] ||
@@ -9,7 +9,7 @@ export declare function isV5Syntax(data: {
9
9
  export declare function usesLeadingDash(data: {
10
10
  lockfileVersion: number | string;
11
11
  }): boolean;
12
- export declare function loadPnpmHoistedDepsDefinition(): any;
12
+ export declare function assertPnpmModulesManifest(): void;
13
13
  /**
14
14
  * Parsing and mapping logic from pnpm lockfile `read` function
15
15
  */
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.isV5Syntax = isV5Syntax;
8
8
  exports.usesLeadingDash = usesLeadingDash;
9
- exports.loadPnpmHoistedDepsDefinition = loadPnpmHoistedDepsDefinition;
9
+ exports.assertPnpmModulesManifest = assertPnpmModulesManifest;
10
10
  exports.parseAndNormalizePnpmLockfile = parseAndNormalizePnpmLockfile;
11
11
  exports.extractMainLockfileDocument = extractMainLockfileDocument;
12
12
  exports.extractEnvLockfileDocument = extractEnvLockfileDocument;
@@ -32,12 +32,13 @@ function usesLeadingDash(data) {
32
32
  return true;
33
33
  }
34
34
  }
35
- function loadPnpmHoistedDepsDefinition() {
35
+ // The parser no longer reads hoisted versions from this file, but a pnpm
36
+ // install always writes it, so its absence still means node_modules was
37
+ // installed with another package manager.
38
+ function assertPnpmModulesManifest() {
36
39
  const fullPath = `${workspace_root_1.workspaceRoot}/node_modules/.modules.yaml`;
37
40
  if ((0, node_fs_1.existsSync)(fullPath)) {
38
- const content = (0, node_fs_1.readFileSync)(fullPath, 'utf-8');
39
- const { load } = require('@zkochan/js-yaml');
40
- return load(content)?.hoistedDependencies ?? {};
41
+ return;
41
42
  }
42
43
  throw new Error(`pnpm lockfile detected, but "${fullPath}" is missing. This usually means that "node_modules" was not installed with pnpm. Run "pnpm install" or use a single package manager for this workspace.`);
43
44
  }
@@ -25,5 +25,5 @@ export declare function findProjectsNpmDependencies(projectNode: ProjectGraphPro
25
25
  helperDependencies?: string[];
26
26
  ignoredDependencies?: string[];
27
27
  isProduction?: boolean;
28
- }, fileMap?: ProjectFileMap): NpmDeps;
28
+ }, fileMap?: ProjectFileMap, root?: string): NpmDeps;
29
29
  export {};
@@ -13,6 +13,8 @@ const nx_deps_cache_1 = require("../../../project-graph/nx-deps-cache");
13
13
  const path_1 = require("path");
14
14
  const task_hasher_1 = require("../../../hasher/task-hasher");
15
15
  const output_1 = require("../../../utils/output");
16
+ const project_graph_pruning_1 = require("../lock-file/project-graph-pruning");
17
+ const logger_1 = require("../../../utils/logger");
16
18
  /**
17
19
  * Creates a package.json in the output directory for support to install dependencies within containers.
18
20
  *
@@ -27,7 +29,7 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
27
29
  const npmDeps = findProjectsNpmDependencies(projectNode, graph, options.target, rootPackageJson, {
28
30
  helperDependencies: options.helperDependencies,
29
31
  isProduction: options.isProduction,
30
- }, fileMap);
32
+ }, fileMap, root);
31
33
  // default package.json if one does not exist
32
34
  let packageJson = {
33
35
  name: projectName,
@@ -210,7 +212,7 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
210
212
  // endregion Overrides/Resolutions
211
213
  return packageJson;
212
214
  }
213
- function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson, options, fileMap) {
215
+ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson, options, fileMap, root = workspace_root_1.workspaceRoot) {
214
216
  if (fileMap == null) {
215
217
  fileMap = (0, nx_deps_cache_1.readFileMapCache)()?.fileMap?.projectFileMap || {};
216
218
  }
@@ -224,10 +226,13 @@ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson
224
226
  };
225
227
  const seen = new Set();
226
228
  options.helperDependencies?.forEach((dep) => {
227
- seen.add(dep);
228
- npmDeps.dependencies[graph.externalNodes[dep].data.packageName] =
229
- graph.externalNodes[dep].data.version;
230
- recursivelyCollectPeerDependencies(dep, graph, npmDeps, seen);
229
+ const node = findHelperDependencyNode(graph, projectNode.name, dep);
230
+ if (!node) {
231
+ return;
232
+ }
233
+ seen.add(node.name);
234
+ npmDeps.dependencies[node.data.packageName] = node.data.version;
235
+ recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
231
236
  });
232
237
  // if it's production, we want to ignore all found devDependencies
233
238
  const ignoredDependencies = options.isProduction && rootPackageJson.devDependencies
@@ -236,10 +241,10 @@ function findProjectsNpmDependencies(projectNode, graph, target, rootPackageJson
236
241
  ...Object.keys(rootPackageJson.devDependencies),
237
242
  ]
238
243
  : options.ignoredDependencies || [];
239
- findAllNpmDeps(fileMap, projectNode, graph, npmDeps, seen, ignoredDependencies, dependencyInputs, selfInputs, false);
244
+ findAllNpmDeps(fileMap, projectNode, graph, npmDeps, seen, root, ignoredDependencies, dependencyInputs, selfInputs, false);
240
245
  return npmDeps;
241
246
  }
242
- function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, ignoredDependencies, dependencyPatterns, rootPatterns, isTransitiveDependency = false) {
247
+ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, root, ignoredDependencies, dependencyPatterns, rootPatterns, isTransitiveDependency = false) {
243
248
  if (seen.has(projectNode.name))
244
249
  return;
245
250
  seen.add(projectNode.name);
@@ -267,22 +272,37 @@ function findAllNpmDeps(projectFileMap, projectNode, graph, npmDeps, seen, ignor
267
272
  continue;
268
273
  }
269
274
  npmDeps.dependencies[node.data.packageName] = node.data.version;
270
- recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen);
275
+ recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
271
276
  }
272
277
  else if (graph.nodes[dep]) {
273
- findAllNpmDeps(projectFileMap, graph.nodes[dep], graph, npmDeps, seen, ignoredDependencies, dependencyPatterns, undefined, true);
278
+ findAllNpmDeps(projectFileMap, graph.nodes[dep], graph, npmDeps, seen, root, ignoredDependencies, dependencyPatterns, undefined, true);
274
279
  }
275
280
  }
276
281
  }
277
282
  }
278
- function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen) {
283
+ function findHelperDependencyNode(graph, projectName, dep) {
284
+ const bareNode = graph.externalNodes[dep];
285
+ if (bareNode && !(0, project_graph_pruning_1.isLinkNode)(bareNode)) {
286
+ return bareNode;
287
+ }
288
+ // A helper with several versions can have only versioned nodes, for
289
+ // example when the pnpm root importer does not declare it, and an outside
290
+ // `link:` can then hold the bare name. Prefer the version that the project
291
+ // depends on, else the highest registry version, else the link.
292
+ const packageName = dep.replace(/^npm:/, '');
293
+ const projectDependency = graph.dependencies[projectName]?.find((d) => graph.externalNodes[d.target]?.data.packageName === packageName);
294
+ return projectDependency
295
+ ? graph.externalNodes[projectDependency.target]
296
+ : (0, project_graph_pruning_1.findNodeMatchingVersion)(graph, packageName, '*');
297
+ }
298
+ function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen, root) {
279
299
  const npmPackage = graph.externalNodes[projectName];
280
300
  if (!npmPackage) {
281
301
  return npmDeps;
282
302
  }
283
303
  const packageName = npmPackage.data.packageName;
284
304
  try {
285
- const packageJson = require(`${packageName}/package.json`);
305
+ const packageJson = readDependencyPackageJson(packageName, root);
286
306
  if (!packageJson.peerDependencies) {
287
307
  return npmDeps;
288
308
  }
@@ -291,22 +311,39 @@ function recursivelyCollectPeerDependencies(projectName, graph, npmDeps, seen) {
291
311
  .map((dependency) => graph.externalNodes[dependency])
292
312
  .filter(Boolean)
293
313
  .forEach((node) => {
314
+ const isOptional = packageJson.peerDependenciesMeta?.[node.data.packageName]?.optional;
294
315
  if (!seen.has(node.name)) {
295
316
  seen.add(node.name);
296
317
  npmDeps.peerDependencies[node.data.packageName] = node.data.version;
297
- if (packageJson.peerDependenciesMeta &&
298
- packageJson.peerDependenciesMeta[node.data.packageName] &&
299
- packageJson.peerDependenciesMeta[node.data.packageName].optional) {
318
+ if (isOptional) {
300
319
  npmDeps.peerDependenciesMeta[node.data.packageName] = {
301
320
  optional: true,
302
321
  };
303
322
  }
304
- recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen);
323
+ recursivelyCollectPeerDependencies(node.name, graph, npmDeps, seen, root);
324
+ }
325
+ else if (!isOptional) {
326
+ // A peer stays optional only while every host declaring it says so.
327
+ delete npmDeps.peerDependenciesMeta[node.data.packageName];
305
328
  }
306
329
  });
307
330
  return npmDeps;
308
331
  }
309
332
  catch (e) {
333
+ logger_1.logger.verbose(`Could not read the package.json of ${packageName}, so its peer dependencies were not collected: ${e.message}`);
310
334
  return npmDeps;
311
335
  }
312
336
  }
337
+ // Watch builds collect peers on every compilation, so read each manifest once.
338
+ const dependencyPackageJsonCache = new Map();
339
+ function readDependencyPackageJson(packageName, root) {
340
+ const cacheKey = `${root}\0${packageName}`;
341
+ let packageJson = dependencyPackageJsonCache.get(cacheKey);
342
+ if (!packageJson) {
343
+ // nx's own location first: under pnpm it reaches the hidden hoisted
344
+ // .pnpm/node_modules, which the workspace root does not.
345
+ ({ packageJson } = (0, package_json_1.readModulePackageJson)(packageName, [__dirname, root]));
346
+ dependencyPackageJsonCache.set(cacheKey, packageJson);
347
+ }
348
+ return packageJson;
349
+ }
@@ -19,9 +19,15 @@ const typescript_1 = require("../../utils/typescript");
19
19
  const defaultNpmResolutionCache = new Map();
20
20
  const defaultPackageJsonResolutionCache = new Map();
21
21
  const experimentalNodeModules = new Set(['node:sqlite']);
22
+ // Node's isBuiltin is false for Bun's runtime modules (`bun`, `bun:*`).
23
+ function isBunModuleImport(importExpr) {
24
+ return importExpr === 'bun' || importExpr.startsWith('bun:');
25
+ }
22
26
  function isBuiltinModuleImport(importExpr) {
23
27
  const packageName = (0, get_package_name_from_import_path_1.getPackageNameFromImportPath)(importExpr);
24
- return (0, node_module_1.isBuiltin)(packageName) || experimentalNodeModules.has(packageName);
28
+ return ((0, node_module_1.isBuiltin)(packageName) ||
29
+ experimentalNodeModules.has(packageName) ||
30
+ isBunModuleImport(importExpr));
25
31
  }
26
32
  // TypeScript matches the `${configDir}` template case-insensitively and only as a
27
33
  // prefix (commandLineParser.ts `startsWithConfigDirTemplate`).
@@ -149,7 +149,12 @@ async function matchAffectedTasks(projectGraph, nxJson, planningContext, request
149
149
  return {
150
150
  affectedTaskIds: new Set(),
151
151
  taskGraph: empty,
152
- taskSelection: { taskGraph: empty, initiatingTaskIds: [], taskIds: [] },
152
+ taskSelection: {
153
+ taskGraph: empty,
154
+ initiatingTaskIds: [],
155
+ taskIds: [],
156
+ ultracacheSkippedTaskIds: [],
157
+ },
153
158
  explanation: request.explain
154
159
  ? {
155
160
  inputs: [],
@@ -200,6 +205,28 @@ async function matchAffectedTasks(projectGraph, nxJson, planningContext, request
200
205
  const keep = request.excludeTaskDependencies
201
206
  ? selection.required.filter((id) => initial.has(id))
202
207
  : selection.required;
208
+ let ultracacheSkippedTaskIds = [];
209
+ if (ultracacheConfigurations) {
210
+ // `--exclude` and `--exclude-task-dependencies` drop tasks with or without Ultracache.
211
+ const runnable = new Set(taskIds.filter((id) => {
212
+ const { project, target } = taskGraph.tasks[id].target;
213
+ return (targets.includes(target) &&
214
+ !options.excludedProjects.includes(project));
215
+ }));
216
+ if (!request.excludeTaskDependencies) {
217
+ // A Set visits what is added while iterating it.
218
+ for (const id of runnable) {
219
+ for (const dep of [
220
+ ...(taskGraph.dependencies[id] ?? []),
221
+ ...(taskGraph.continuousDependencies[id] ?? []),
222
+ ]) {
223
+ runnable.add(dep.id);
224
+ }
225
+ }
226
+ }
227
+ const kept = new Set(keep);
228
+ ultracacheSkippedTaskIds = (0, overrides_1.buildUltracacheOverrides)(projectGraph, taskGraph, ultracacheConfigurations).used.filter((id) => runnable.has(id) && !kept.has(id));
229
+ }
203
230
  return {
204
231
  affectedTaskIds: new Set(selection.affected),
205
232
  taskGraph,
@@ -214,6 +241,7 @@ async function matchAffectedTasks(projectGraph, nxJson, planningContext, request
214
241
  (0, utils_1.pruneToSelectedTasks)((0, create_task_graph_1.createTaskGraph)(projectGraph, request.extraTargetDependencies, [...owning], targets, request.configuration, request.overrides, request.excludeTaskDependencies), keep),
215
242
  initiatingTaskIds: keep.filter((id) => initial.has(id)),
216
243
  taskIds: keep,
244
+ ultracacheSkippedTaskIds,
217
245
  },
218
246
  };
219
247
  }
@@ -7,6 +7,8 @@ export interface SeparatedPlugins {
7
7
  }
8
8
  /** Exported for tests: the fallback latch is process-scoped by design. */
9
9
  export declare function resetIsolationFallbackForTesting(): void;
10
+ /** Whether this daemon has loaded a plugin into its own process. */
11
+ export declare function daemonHostsPluginsInProcess(): boolean;
10
12
  /**
11
13
  * Loads a plugin in a worker, falling back to this process when the worker's
12
14
  * socket was refused.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadingMethod = void 0;
4
4
  exports.resetIsolationFallbackForTesting = resetIsolationFallbackForTesting;
5
+ exports.daemonHostsPluginsInProcess = daemonHostsPluginsInProcess;
5
6
  exports.getPlugins = getPlugins;
6
7
  exports.getPluginsSeparated = getPluginsSeparated;
7
8
  exports.getOnlyDefaultPlugins = getOnlyDefaultPlugins;
@@ -17,6 +18,7 @@ const in_process_loader_1 = require("./in-process-loader");
17
18
  const isolation_1 = require("./isolation");
18
19
  const resolve_plugin_1 = require("./resolve-plugin");
19
20
  const is_on_daemon_1 = require("../../daemon/is-on-daemon");
21
+ const daemon_environment_1 = require("../../daemon/client/daemon-environment");
20
22
  const client_1 = require("../../daemon/client/client");
21
23
  const nx_plugin_capabilities_1 = require("./nx-plugin-capabilities");
22
24
  const enabled_1 = require("./isolation/enabled");
@@ -64,6 +66,19 @@ let isolationRefusedInThisProcess = false;
64
66
  function resetIsolationFallbackForTesting() {
65
67
  isolationRefusedInThisProcess = false;
66
68
  }
69
+ let daemonHostsPlugins = false;
70
+ /** Whether this daemon has loaded a plugin into its own process. */
71
+ function daemonHostsPluginsInProcess() {
72
+ return daemonHostsPlugins;
73
+ }
74
+ function loadNxPluginInProcess(plugin, root, index) {
75
+ if ((0, is_on_daemon_1.isOnDaemon)() && !daemonHostsPlugins) {
76
+ daemonHostsPlugins = true;
77
+ // Later client envs keep this in sync; see handleClientEnv.
78
+ (0, daemon_environment_1.adoptBerryBinFoldersOnPath)((0, daemon_environment_1.withTrustedBerryBinFolders)((0, daemon_environment_1.getLiveClientBerryEnv)()));
79
+ }
80
+ return (0, in_process_loader_1.loadNxPlugin)(plugin, root, index);
81
+ }
67
82
  /**
68
83
  * Loads a plugin in a worker, falling back to this process when the worker's
69
84
  * socket was refused.
@@ -81,7 +96,7 @@ function resetIsolationFallbackForTesting() {
81
96
  */
82
97
  const loadingMethod = async (plugin, root, index) => {
83
98
  if (!(0, enabled_1.isIsolationEnabled)() || isolationRefusedInThisProcess) {
84
- return (0, in_process_loader_1.loadNxPlugin)(plugin, root, index);
99
+ return loadNxPluginInProcess(plugin, root, index);
85
100
  }
86
101
  // Awaited here rather than handed on, because the worker failure surfaces on
87
102
  // this promise and the fallback has to happen before the caller sees it.
@@ -123,7 +138,7 @@ const loadingMethod = async (plugin, root, index) => {
123
138
  ],
124
139
  });
125
140
  }
126
- return (0, in_process_loader_1.loadNxPlugin)(plugin, root, index);
141
+ return loadNxPluginInProcess(plugin, root, index);
127
142
  }
128
143
  };
129
144
  exports.loadingMethod = loadingMethod;
@@ -10,6 +10,7 @@ const child_process_1 = require("child_process");
10
10
  const crypto_1 = require("crypto");
11
11
  const net_1 = require("net");
12
12
  const path = require("path");
13
+ const daemon_environment_1 = require("../../../daemon/client/daemon-environment");
13
14
  const logger_1 = require("../../../daemon/logger");
14
15
  const sandbox_socket_hint_1 = require("../../../daemon/sandbox-socket-hint");
15
16
  const socket_refused_exit_code_1 = require("../../../utils/socket-refused-exit-code");
@@ -432,14 +433,15 @@ async function startPluginWorker(name) {
432
433
  performance.mark(`start-plugin-worker:${name}`);
433
434
  const isWorkerTypescript = path.extname(__filename) === '.ts';
434
435
  const workerPath = path.join(__dirname, isWorkerTypescript ? 'plugin-worker.ts' : 'plugin-worker.js');
435
- const env = {
436
+ const env = (0, daemon_environment_1.withTrustedBerryBinFolders)({
436
437
  ...process.env,
438
+ ...(0, daemon_environment_1.getLiveClientBerryEnv)(),
437
439
  ...(isWorkerTypescript
438
440
  ? {
439
441
  SWC_NODE_PROJECT: path.join(__dirname, '../../../../tsconfig.lib.json'),
440
442
  }
441
443
  : {}),
442
- };
444
+ });
443
445
  // Keep the host pid readable for diagnostics, the counter collision-free
444
446
  // within this process, and entropy for a reused pid across process runs. The
445
447
  // suffix is a base36 counter plus four random bytes: eleven characters after
@@ -4,8 +4,10 @@ const child_process_1 = require("child_process");
4
4
  const path_1 = require("path");
5
5
  const pseudo_ipc_1 = require("./pseudo-ipc");
6
6
  const exit_codes_1 = require("../utils/exit-codes");
7
- const pseudoIPCPath = process.argv[2];
8
- const forkId = process.argv[3];
7
+ const pseudoIPCPath = process.env['NX_PSEUDO_IPC_PATH'];
8
+ const forkId = process.env['NX_PSEUDO_IPC_FORK_ID'];
9
+ delete process.env['NX_PSEUDO_IPC_PATH'];
10
+ delete process.env['NX_PSEUDO_IPC_FORK_ID'];
9
11
  const script = (0, path_1.join)(__dirname, '../../bin/run-executor.js');
10
12
  let execArgv;
11
13
  if (process.env['NX_PSEUDO_TERMINAL_EXEC_ARGV']) {
@@ -22,6 +22,8 @@ export interface TaskSelection {
22
22
  planningContext?: TaskPlanningContext;
23
23
  /** The Ultracache configurations selection planned with; the run hashes with the same ones. */
24
24
  ultracacheConfigurationOutcome?: UltracacheConfigurationOutcome | null;
25
+ /** What `nx affected` dropped from tasks hashed from a configuration. Unset for commands that do not select. */
26
+ ultracacheSkippedTaskIds?: string[];
25
27
  }
26
28
  import { LifeCycle, TaskResult, TaskResults } from './life-cycle';
27
29
  import { TasksRunner, TaskStatus } from './tasks-runner';
@@ -47,7 +49,7 @@ export declare function runTasksForCommand(taskSelection: TaskSelection, current
47
49
  completed: boolean;
48
50
  }>;
49
51
  export declare function setEnvVarsBasedOnArgs(nxArgs: NxArgs, loadDotEnvFiles: boolean): void;
50
- export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, planningContext, ultracacheConfigurationOutcome: loadedUltracacheConfigurationOutcome, }: {
52
+ export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, planningContext, ultracacheConfigurationOutcome: loadedUltracacheConfigurationOutcome, ultracacheSkippedTaskIds, }: {
51
53
  tasks: Task[];
52
54
  projectGraph: ProjectGraph;
53
55
  taskGraph: TaskGraph;
@@ -60,6 +62,7 @@ export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, life
60
62
  planningContext?: TaskPlanningContext;
61
63
  /** Already loaded for this command; `undefined` loads it here. */
62
64
  ultracacheConfigurationOutcome?: UltracacheConfigurationOutcome | null;
65
+ ultracacheSkippedTaskIds?: string[];
63
66
  }): Promise<{
64
67
  taskResults: {
65
68
  [id: string]: TaskResult;
@@ -411,6 +411,7 @@ async function runTasksForCommand(taskSelection, currentProjectGraph, { nxJson }
411
411
  initiatingTasks,
412
412
  planningContext: taskSelection.planningContext,
413
413
  ultracacheConfigurationOutcome: taskSelection.ultracacheConfigurationOutcome,
414
+ ultracacheSkippedTaskIds: taskSelection.ultracacheSkippedTaskIds,
414
415
  });
415
416
  await renderIsDone.finally(() => restoreTerminal?.());
416
417
  if (printSummary) {
@@ -689,7 +690,7 @@ function setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles) {
689
690
  process.env.NX_LOAD_DOT_ENV_FILES = 'true';
690
691
  }
691
692
  }
692
- async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, planningContext, ultracacheConfigurationOutcome: loadedUltracacheConfigurationOutcome, }) {
693
+ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, planningContext, ultracacheConfigurationOutcome: loadedUltracacheConfigurationOutcome, ultracacheSkippedTaskIds, }) {
693
694
  setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
694
695
  // this needs to be done before we start to run the tasks
695
696
  const taskDetails = (0, hash_task_1.getTaskDetails)();
@@ -704,7 +705,7 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
704
705
  // to submit everything that is known in advance to Nx Cloud to run in
705
706
  // a distributed fashion
706
707
  const hashingDeferredTaskIds = await (0, hash_task_1.hashTasksThatDoNotDependOnOutputsOfOtherTasks)(hasher, projectGraph, taskGraph, nxJson, taskDetails, ultracacheConfigurations);
707
- reportUltracacheConfigurations(ultracacheConfigurationOutcome, projectGraph, taskGraph, nxArgs);
708
+ reportUltracacheConfigurations(ultracacheConfigurationOutcome, projectGraph, taskGraph, nxArgs, ultracacheSkippedTaskIds);
708
709
  const taskResultsLifecycle = new task_results_life_cycle_1.TaskResultsLifeCycle();
709
710
  const compositedLifeCycle = new life_cycle_1.CompositeLifeCycle([
710
711
  ...constructLifeCycles(lifeCycle, taskGraph, nxJson, nxArgs.skipNxCache),
@@ -775,6 +776,7 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
775
776
  },
776
777
  daemon: client_1.daemonClient,
777
778
  hashingDeferredTaskIds,
779
+ ultracacheSkippedTaskIds: ultracacheSkippedTaskIds && new Set(ultracacheSkippedTaskIds),
778
780
  });
779
781
  if (promiseOrObservable.subscribe) {
780
782
  promiseOrObservable = convertObservableToPromise(promiseOrObservable);
@@ -858,12 +860,12 @@ function loadTasksRunner(modulePath) {
858
860
  throw e;
859
861
  }
860
862
  }
861
- function reportUltracacheConfigurations(outcome, projectGraph, taskGraph, nxArgs) {
863
+ function reportUltracacheConfigurations(outcome, projectGraph, taskGraph, nxArgs, ultracacheSkippedTaskIds) {
862
864
  if (!outcome || outcome.status === 'skipped')
863
865
  return;
864
866
  if (!nxArgs.verbose && process.env.NX_VERBOSE_LOGGING !== 'true')
865
867
  return;
866
- const summary = (0, report_1.formatUltracacheSummary)((0, overrides_1.buildUltracacheOverrides)(projectGraph, taskGraph, outcome.configurations), outcome.status);
868
+ const summary = (0, report_1.formatUltracacheSummary)((0, overrides_1.buildUltracacheOverrides)(projectGraph, taskGraph, outcome.configurations), outcome.status, ultracacheSkippedTaskIds?.length);
867
869
  output_1.output.note({ title: summary.line, bodyLines: summary.bodyLines });
868
870
  }
869
871
  /**
@@ -77,6 +77,7 @@ export declare class BatchProcess {
77
77
  * summary is still pointing at.
78
78
  */
79
79
  private readonly captureNonce;
80
+ private readonly stdioClosed;
80
81
  constructor(childProcess: ChildProcess, executorName: string,
81
82
  /**
82
83
  * Whether the worker's output is written to the terminal as it streams.
@@ -128,8 +129,8 @@ export declare class BatchProcess {
128
129
  * batch as one fold, so output no task claimed is not lost.
129
130
  *
130
131
  * Not valid to read before `flushCapturedOutput`; that flush ends the stream,
131
- * so a chunk arriving afterwards - a worker's stdout can deliver past the
132
- * exit event `getResults()` settles on - is dropped rather than appended.
132
+ * so a chunk arriving afterwards - a worker can still write after the
133
+ * results message `getResults()` settles on - is dropped rather than appended.
133
134
  */
134
135
  getCapturedOutputPath(): string | undefined;
135
136
  /** Releases the capture file. Safe to call more than once. */
@@ -6,6 +6,7 @@ const crypto_1 = require("crypto");
6
6
  const path_1 = require("path");
7
7
  const native_1 = require("../../native");
8
8
  const cache_1 = require("../cache");
9
+ const child_process_1 = require("../../utils/child-process");
9
10
  const exit_codes_1 = require("../../utils/exit-codes");
10
11
  const output_1 = require("../../utils/output");
11
12
  const batch_messages_1 = require("../batch/batch-messages");
@@ -68,6 +69,7 @@ class BatchProcess {
68
69
  * summary is still pointing at.
69
70
  */
70
71
  this.captureNonce = (0, crypto_1.randomBytes)(4).toString('hex');
72
+ this.stdioClosed = (0, child_process_1.whenStdioClosed)(this.childProcess);
71
73
  this.childProcess.on('message', (message) => {
72
74
  switch (message.type) {
73
75
  case batch_messages_1.BatchMessageType.CompleteTask: {
@@ -294,8 +296,8 @@ class BatchProcess {
294
296
  * batch as one fold, so output no task claimed is not lost.
295
297
  *
296
298
  * Not valid to read before `flushCapturedOutput`; that flush ends the stream,
297
- * so a chunk arriving afterwards - a worker's stdout can deliver past the
298
- * exit event `getResults()` settles on - is dropped rather than appended.
299
+ * so a chunk arriving afterwards - a worker can still write after the
300
+ * results message `getResults()` settles on - is dropped rather than appended.
299
301
  */
300
302
  getCapturedOutputPath() {
301
303
  return this.capturedOutputPath;
@@ -341,7 +343,9 @@ class BatchProcess {
341
343
  new Promise((_, rej) => {
342
344
  this.onExit((code) => {
343
345
  if (code !== 0) {
344
- rej(new Error(`"${this.executorName}" exited unexpectedly with code: ${code}`));
346
+ // A rejection makes the caller flush the capture, which drops
347
+ // whatever the crashed worker wrote that has not been read yet.
348
+ this.stdioClosed.then(() => rej(new Error(`"${this.executorName}" exited unexpectedly with code: ${code}`)));
345
349
  }
346
350
  });
347
351
  }),
@@ -362,6 +362,7 @@ export declare class TaskOrchestrator {
362
362
  private recordOutputsHashBatch;
363
363
  private handleContinuousTaskExit;
364
364
  private isContinuousTaskNeeded;
365
+ private isInitiatingTaskFailure;
365
366
  private completeContinuousTask;
366
367
  private cleanup;
367
368
  private performCleanup;
@@ -2148,9 +2148,10 @@ class TaskOrchestrator {
2148
2148
  const reason = stoppingReason === 'fulfilled' ? 'fulfilled' : 'interrupted';
2149
2149
  await this.completeContinuousTask(task, groupId, ownsRunningTasksService, reason);
2150
2150
  }
2151
- else if (!this.isContinuousTaskNeeded(task.id)) {
2152
- // No remaining tasks depend on this — the task was about to be
2153
- // killed by cleanUpUnneededContinuousTasks anyway.
2151
+ else if (!this.isContinuousTaskNeeded(task.id) &&
2152
+ !this.isInitiatingTaskFailure(task.id, code)) {
2153
+ // No remaining tasks depend on this: a dependency was about to be killed
2154
+ // by cleanUpUnneededContinuousTasks anyway, an initiating task exited cleanly.
2154
2155
  await this.completeContinuousTask(task, groupId, ownsRunningTasksService, 'fulfilled');
2155
2156
  }
2156
2157
  else {
@@ -2163,6 +2164,14 @@ class TaskOrchestrator {
2163
2164
  .getIncompleteTasks()
2164
2165
  .some((t) => this.taskGraph.continuousDependencies[t.id]?.some((edge) => edge.id === taskId));
2165
2166
  }
2167
+ // Nothing kills a task the user asked for, so a non-zero exit before the
2168
+ // run stops is the task failing on its own.
2169
+ isInitiatingTaskFailure(taskId, code) {
2170
+ return (code !== 0 &&
2171
+ this.initializingTaskIds.has(taskId) &&
2172
+ !this.stopRequested &&
2173
+ !this.cleanupPromise);
2174
+ }
2166
2175
  async completeContinuousTask(task, groupId, ownsRunningTasksService, reason) {
2167
2176
  await this.readinessFailures.get(task.id);
2168
2177
  this.runningContinuousTasks.delete(task.id);
@@ -21,6 +21,11 @@ export type TasksRunner<T = unknown> = (tasks: Task[], options: T, context?: {
21
21
  daemon?: DaemonClient;
22
22
  /** Tasks hashed only once the tasks they read outputs from have run. */
23
23
  hashingDeferredTaskIds?: ReadonlySet<string>;
24
+ /**
25
+ * Tasks hashed from an Ultracache configuration that `nx affected` selection
26
+ * dropped. Empty when nothing was, unset for commands that do not select.
27
+ */
28
+ ultracacheSkippedTaskIds?: ReadonlySet<string>;
24
29
  }) => any | Promise<{
25
30
  [id: string]: TaskStatus;
26
31
  }>;
@@ -12,6 +12,6 @@ export declare function ultracacheEligibilityOptions(projectGraph: ProjectGraph,
12
12
  * Reports which tasks in `taskGraph` hash from `configurations` and why the rest
13
13
  * do not, with the same eligibility walk the planner uses, without building a
14
14
  * planner (no project-graph transfer). Never fetches, never throws. Feeds
15
- * the `--verbose` run summary.
15
+ * the `--verbose` run summary and the tasks `nx affected` reports as skipped.
16
16
  */
17
17
  export declare function buildUltracacheOverrides(projectGraph: ProjectGraph, taskGraph: TaskGraph, configurations: UltracacheConfigurations): UltracacheReport;
@@ -58,7 +58,7 @@ function ultracacheEligibilityOptions(projectGraph, taskGraph) {
58
58
  * Reports which tasks in `taskGraph` hash from `configurations` and why the rest
59
59
  * do not, with the same eligibility walk the planner uses, without building a
60
60
  * planner (no project-graph transfer). Never fetches, never throws. Feeds
61
- * the `--verbose` run summary.
61
+ * the `--verbose` run summary and the tasks `nx affected` reports as skipped.
62
62
  */
63
63
  function buildUltracacheOverrides(projectGraph, taskGraph, configurations) {
64
64
  return (0, native_1.getUltracacheReport)(configurations, getUltracacheSettings(taskGraph), ultracacheEligibilityOptions(projectGraph, taskGraph));
@@ -10,4 +10,4 @@ export interface UltracacheSummary {
10
10
  * configurations: `result` is what hashing used, `status` whether they were
11
11
  * fetched or already stored.
12
12
  */
13
- export declare function formatUltracacheSummary(result: UltracacheReport, status: 'fetched' | 'cached'): UltracacheSummary;
13
+ export declare function formatUltracacheSummary(result: UltracacheReport, status: 'fetched' | 'cached', skipped?: number): UltracacheSummary;