nx 24.0.0 → 24.0.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 (51) hide show
  1. package/dist/src/ai/clone-ai-config-repo.js +49 -12
  2. package/dist/src/command-line/migrate/migrate-commits.d.ts +17 -7
  3. package/dist/src/command-line/migrate/migrate-commits.js +57 -17
  4. package/dist/src/command-line/migrate/run/clean-retry.js +4 -2
  5. package/dist/src/command-line/migrate/run/orchestrator.js +19 -13
  6. package/dist/src/daemon/client/client.d.ts +4 -0
  7. package/dist/src/daemon/client/client.js +67 -12
  8. package/dist/src/daemon/server/handle-process-in-background.js +21 -9
  9. package/dist/src/daemon/server/native-js-loader.d.ts +1 -0
  10. package/dist/src/daemon/server/native-js-loader.js +21 -0
  11. package/dist/src/daemon/server/project-graph-incremental-recomputation.js +4 -8
  12. package/dist/src/daemon/server/server.d.ts +2 -1
  13. package/dist/src/daemon/server/server.js +16 -3
  14. package/dist/src/daemon/server/start.d.ts +1 -0
  15. package/dist/src/daemon/server/start.js +2 -0
  16. package/dist/src/executors/run-commands/run-commands.impl.d.ts +1 -1
  17. package/dist/src/executors/run-commands/run-commands.impl.js +14 -8
  18. package/dist/src/executors/run-commands/running-tasks.d.ts +1 -1
  19. package/dist/src/executors/run-commands/running-tasks.js +126 -77
  20. package/dist/src/executors/run-commands/schema.json +1 -1
  21. package/dist/src/native/index.d.ts +1 -1
  22. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  23. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  24. package/dist/src/plugins/js/lock-file/pnpm-parser.js +2 -1
  25. package/dist/src/tasks-runner/init-tasks-runner.js +103 -61
  26. package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +5 -2
  27. package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +4 -1
  28. package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +5 -1
  29. package/dist/src/tasks-runner/pseudo-terminal.d.ts +1 -1
  30. package/dist/src/tasks-runner/pseudo-terminal.js +2 -2
  31. package/dist/src/tasks-runner/readiness/probes.js +2 -2
  32. package/dist/src/tasks-runner/readiness/ready-when.d.ts +22 -1
  33. package/dist/src/tasks-runner/readiness/ready-when.js +25 -2
  34. package/dist/src/tasks-runner/run-command.d.ts +6 -2
  35. package/dist/src/tasks-runner/run-command.js +14 -25
  36. package/dist/src/tasks-runner/run-outcome.d.ts +16 -0
  37. package/dist/src/tasks-runner/run-outcome.js +39 -0
  38. package/dist/src/tasks-runner/running-tasks/running-task.d.ts +1 -1
  39. package/dist/src/tasks-runner/task-orchestrator.d.ts +4 -2
  40. package/dist/src/tasks-runner/task-orchestrator.js +92 -21
  41. package/dist/src/tasks-runner/tasks-schedule.js +4 -5
  42. package/dist/src/utils/child-process.js +1 -1
  43. package/dist/src/utils/find-matching-projects.js +9 -6
  44. package/dist/src/utils/git-utils.d.ts +6 -4
  45. package/dist/src/utils/git-utils.js +43 -6
  46. package/dist/src/utils/output.d.ts +4 -3
  47. package/dist/src/utils/output.js +4 -3
  48. package/dist/src/utils/package-manager.js +5 -0
  49. package/package.json +11 -11
  50. package/schemas/nx-schema.json +6 -0
  51. package/schemas/project-schema.json +6 -0
@@ -11,7 +11,7 @@ const create_task_hasher_1 = require("../hasher/create-task-hasher");
11
11
  const client_1 = require("../daemon/client/client");
12
12
  const shared_running_task_1 = require("./running-tasks/shared-running-task");
13
13
  const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
14
- async function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations) {
14
+ function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations) {
15
15
  (0, dotenv_1.loadRootEnvFiles)();
16
16
  fullTaskGraph = withEdgeObjects(fullTaskGraph);
17
17
  const invokeRunnerTerminalLifecycle = new invoke_runner_terminal_output_life_cycle_1.InvokeRunnerTerminalOutputLifeCycle(tasks);
@@ -44,13 +44,11 @@ async function createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, li
44
44
  lifeCycle: compositedLifeCycle,
45
45
  };
46
46
  (0, run_command_1.setEnvVarsBasedOnArgs)(nxArgs, true);
47
- const orchestrator = new task_orchestrator_1.TaskOrchestrator(hasher, null, tasks, projectGraph, taskGraph, nxJson, nxArgs, false, client_1.daemonClient,
47
+ return new task_orchestrator_1.TaskOrchestrator(hasher, null, tasks, projectGraph, taskGraph, nxJson, nxArgs, false, client_1.daemonClient,
48
48
  // No argv on this path, so the output-style middleware never ran and both
49
49
  // fields are unset - this always renders `static-failures-only`. `nx.json`'s
50
50
  // `outputStyle` does not reach them; it merges under its own name.
51
51
  nxArgs.specifiedOutputStyle, nxArgs.resolvedOutputStyle ?? 'static-failures-only', fullTaskGraph);
52
- await orchestrator.init();
53
- return orchestrator;
54
52
  }
55
53
  // A client bundle built before edges became objects hands plain task ids
56
54
  function withEdgeObjects(taskGraph) {
@@ -69,71 +67,115 @@ function withEdgeObjects(taskGraph) {
69
67
  function logDisposeFailure(e) {
70
68
  console.error('Failed to dispose the task orchestrator:', e);
71
69
  }
70
+ // Agents never call `TaskOrchestrator.run()`, which sizes these limits for a CLI
71
+ // run. A call starts all its tasks at once while other calls' orchestrators stay
72
+ // alive, so each adds room for its tasks and its own orchestrator until disposed.
73
+ function reserveProcessListeners(tasks) {
74
+ const room = tasks.length + 1;
75
+ const adjust = (delta) => {
76
+ for (const emitter of [process, process.stdout, process.stderr]) {
77
+ const limit = emitter.getMaxListeners();
78
+ // 0 is unlimited
79
+ if (limit !== 0) {
80
+ emitter.setMaxListeners(limit + delta);
81
+ }
82
+ }
83
+ };
84
+ adjust(room);
85
+ return () => adjust(-room);
86
+ }
72
87
  async function runDiscreteTasks(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle,
73
88
  /** The set to hash from, e.g. from `importUltracacheConfigurations`; omitted hashes natively. */
74
89
  ultracacheConfigurations) {
75
- const orchestrator = await createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
76
- let groupId = 0;
77
- let nextBatch = orchestrator.nextBatch();
90
+ const orchestrator = createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
91
+ const releaseProcessListeners = reserveProcessListeners(tasks);
78
92
  const batchResults = [];
79
- /**
80
- * Set of task ids that were part of batches
81
- */
82
- const batchTasks = new Set();
83
- while (nextBatch) {
84
- for (const task in nextBatch.taskGraph.tasks) {
85
- batchTasks.add(task);
93
+ try {
94
+ await orchestrator.init();
95
+ let groupId = 0;
96
+ let nextBatch = orchestrator.nextBatch();
97
+ /**
98
+ * Set of task ids that were part of batches
99
+ */
100
+ const batchTasks = new Set();
101
+ while (nextBatch) {
102
+ for (const task in nextBatch.taskGraph.tasks) {
103
+ batchTasks.add(task);
104
+ }
105
+ batchResults.push(orchestrator.applyFromCacheOrRunBatch(true, nextBatch, groupId++));
106
+ nextBatch = orchestrator.nextBatch();
86
107
  }
87
- batchResults.push(orchestrator.applyFromCacheOrRunBatch(true, nextBatch, groupId++));
88
- nextBatch = orchestrator.nextBatch();
108
+ const discreteTasks = tasks.filter((task) => !batchTasks.has(task.id));
109
+ // Every task here starts directly, but the schedule hashes only the tasks it admits
110
+ orchestrator.processTasks(discreteTasks.map((task) => task.id));
111
+ // Bulk-resolve every discrete task's cache state in one shot —
112
+ // single SQL call plus parallel remote retrievals. Batches kicked
113
+ // off above continue running concurrently while we await this.
114
+ const cacheHits = await orchestrator.resolveCachedTasks(true, discreteTasks, groupId++);
115
+ const cacheHitsById = new Map(cacheHits.map((h) => [h.task.id, h]));
116
+ const taskResults = discreteTasks.map(async (task) => {
117
+ const hit = cacheHitsById.get(task.id);
118
+ if (hit)
119
+ return [hit];
120
+ return [await orchestrator.runTaskDirectly(true, task, groupId++)];
121
+ });
122
+ const results = [...batchResults, ...taskResults];
123
+ // Callers like Nx Cloud agents create an orchestrator per invocation in a
124
+ // long-lived process; release its process-level listeners once all tasks
125
+ // settle, otherwise every invocation's orchestrator stays reachable forever.
126
+ // Not awaited, so callers keep consuming handles as they settle; the forked
127
+ // runner's exit handler still reaps children until dispose() runs.
128
+ Promise.allSettled(results)
129
+ .then(() => orchestrator.dispose())
130
+ .finally(releaseProcessListeners)
131
+ .catch(logDisposeFailure);
132
+ return results;
133
+ }
134
+ catch (e) {
135
+ // A batch started before the failure can still fork a child, which only
136
+ // the orchestrator's exit handler reaps, so dispose once batches settle
137
+ Promise.allSettled(batchResults)
138
+ .then(() => orchestrator.dispose())
139
+ .finally(releaseProcessListeners)
140
+ .catch(logDisposeFailure);
141
+ throw e;
89
142
  }
90
- const discreteTasks = tasks.filter((task) => !batchTasks.has(task.id));
91
- // Every task here starts directly, but the schedule hashes only the tasks it admits
92
- orchestrator.processTasks(discreteTasks.map((task) => task.id));
93
- // Bulk-resolve every discrete task's cache state in one shot —
94
- // single SQL call plus parallel remote retrievals. Batches kicked
95
- // off above continue running concurrently while we await this.
96
- const cacheHits = await orchestrator.resolveCachedTasks(true, discreteTasks, groupId++);
97
- const cacheHitsById = new Map(cacheHits.map((h) => [h.task.id, h]));
98
- const taskResults = discreteTasks.map(async (task) => {
99
- const hit = cacheHitsById.get(task.id);
100
- if (hit)
101
- return [hit];
102
- return [await orchestrator.runTaskDirectly(true, task, groupId++)];
103
- });
104
- const results = [...batchResults, ...taskResults];
105
- // Callers like Nx Cloud agents create an orchestrator per invocation in a
106
- // long-lived process; release its process-level listeners once all tasks
107
- // settle, otherwise every invocation's orchestrator stays reachable forever.
108
- // Not awaited, so callers keep consuming handles as they settle; the forked
109
- // runner's exit handler still reaps children until dispose() runs.
110
- Promise.allSettled(results)
111
- .then(() => orchestrator.dispose())
112
- .catch(logDisposeFailure);
113
- return results;
114
143
  }
115
144
  async function runContinuousTasks(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle,
116
145
  /** The set to hash from, e.g. from `importUltracacheConfigurations`; omitted hashes natively. */
117
146
  ultracacheConfigurations) {
118
- const orchestrator = await createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
119
- orchestrator.processTasks(tasks.map((task) => task.id));
120
- const runningTasks = tasks.reduce((current, task, index) => {
121
- current[task.id] = orchestrator.startContinuousTask(task, index);
122
- return current;
123
- }, {});
124
- // Unlike runDiscreteTasks, this must resolve at task start: callers keep
125
- // the RunningTask handles to kill later, so disposal has to be deferred
126
- // until every task actually exits.
127
- Promise.allSettled(Object.entries(runningTasks).map(async ([taskId, promise]) => {
128
- const runningTask = await promise;
129
- // A shared task is owned by another nx process; this orchestrator has
130
- // no child to protect for it, so disposal does not wait on it.
131
- if (runningTask instanceof shared_running_task_1.SharedRunningTask) {
132
- return;
133
- }
134
- await orchestrator.waitForContinuousTaskExit(taskId);
135
- }))
136
- .then(() => orchestrator.dispose())
137
- .catch(logDisposeFailure);
138
- return runningTasks;
147
+ const orchestrator = createOrchestrator(tasks, projectGraph, fullTaskGraph, nxJson, lifeCycle, ultracacheConfigurations);
148
+ const releaseProcessListeners = reserveProcessListeners(tasks);
149
+ try {
150
+ await orchestrator.init();
151
+ orchestrator.processTasks(tasks.map((task) => task.id));
152
+ const runningTasks = tasks.reduce((current, task, index) => {
153
+ current[task.id] = orchestrator.startContinuousTask(task, index);
154
+ return current;
155
+ }, {});
156
+ // Unlike runDiscreteTasks, this must resolve at task start: callers keep
157
+ // the RunningTask handles to kill later, so disposal has to be deferred
158
+ // until every task actually exits.
159
+ Promise.allSettled(Object.entries(runningTasks).map(async ([taskId, promise]) => {
160
+ const runningTask = await promise;
161
+ // A shared task is owned by another nx process; this orchestrator has
162
+ // no child to protect for it, so disposal does not wait on it.
163
+ if (runningTask instanceof shared_running_task_1.SharedRunningTask) {
164
+ return;
165
+ }
166
+ await orchestrator.waitForContinuousTaskExit(taskId);
167
+ }))
168
+ .then(() => orchestrator.dispose())
169
+ .finally(releaseProcessListeners)
170
+ .catch(logDisposeFailure);
171
+ return runningTasks;
172
+ }
173
+ catch (e) {
174
+ // A failure before the disposal chain above never reaches it
175
+ orchestrator
176
+ .dispose()
177
+ .finally(releaseProcessListeners)
178
+ .catch(logDisposeFailure);
179
+ throw e;
180
+ }
139
181
  }
@@ -61,8 +61,11 @@ class StaticRunManyTerminalOutputLifeCycle {
61
61
  }
62
62
  // A stopped task was killed mid-flight, so the run did not complete even
63
63
  // though nothing outright failed. `didCommandComplete` already treats it
64
- // that way; reporting "Successfully ran" here would contradict it.
65
- if (this.failedTasks.length === 0 && this.stoppedTasks.length === 0) {
64
+ // that way; reporting "Successfully ran" here would contradict it. A
65
+ // discrete task that never reported was skipped, which fails the run too.
66
+ if (this.failedTasks.length === 0 &&
67
+ this.stoppedTasks.length === 0 &&
68
+ !this.skippedTasks().some((t) => !t.continuous)) {
66
69
  output_1.output.addVerticalSeparatorWithoutNewLines('green');
67
70
  const bodyLines = this.cachedTasks.length > 0
68
71
  ? [
@@ -71,7 +71,10 @@ class StaticRunOneTerminalOutputLifeCycle {
71
71
  output_1.output.addNewline();
72
72
  // A stopped task was killed mid-flight, so the run did not complete even
73
73
  // though nothing outright failed — matching run-many and didCommandComplete.
74
- if (this.failedTasks.length === 0 && this.stoppedTasks.length === 0) {
74
+ // A discrete task that never reported was skipped, which fails the run too.
75
+ if (this.failedTasks.length === 0 &&
76
+ this.stoppedTasks.length === 0 &&
77
+ !this.skippedTasks().some((t) => !t.continuous)) {
75
78
  output_1.output.addVerticalSeparatorWithoutNewLines('green');
76
79
  const bodyLines = this.cachedTasks.length > 0
77
80
  ? [
@@ -100,7 +100,11 @@ class SummaryTerminalOutputLifeCycle {
100
100
  }
101
101
  bodyLines.push('', output_1.output.dim('Re-run with --output-style=static to inline logs.'));
102
102
  const title = this.countsLine(skipped);
103
- if (this.failed.length > 0 || this.stopped.length > 0) {
103
+ // A discrete task that never reported was skipped, which fails the run; a
104
+ // continuous one nothing needed is never started
105
+ if (this.failed.length > 0 ||
106
+ this.stopped.length > 0 ||
107
+ this.tasks.some((t) => !t.continuous && !this.completed.has(t.id))) {
104
108
  output_1.output.error({ title, bodyLines });
105
109
  }
106
110
  else {
@@ -58,7 +58,7 @@ export declare class PseudoTtyProcess implements RunningTask {
58
58
  terminalOutput: string;
59
59
  }>;
60
60
  onExit(callback: (code: number, terminalOutput: string) => void): void;
61
- onOutput(callback: (message: string) => void): void;
61
+ onOutput(callback: (message: string, isCommandHeader: boolean) => void): void;
62
62
  getPid(): number | undefined;
63
63
  kill(s?: NodeJS.Signals): Promise<void>;
64
64
  getPtyHandles(): import("../native").ExternalObject<[import("../native").ParserArc, import("../native").WriterArc, import("../native").MasterArc]>;
@@ -109,12 +109,12 @@ class PseudoTtyProcess {
109
109
  this.exitCallbacks = [];
110
110
  this.outputCallbacks = [];
111
111
  this.terminalOutputChunks = [];
112
- childProcess.onOutput((chunk) => {
112
+ childProcess.onOutput((chunk, isCommandHeader) => {
113
113
  if (!this.quiet) {
114
114
  output_1.output.noteExternalWrite(chunk);
115
115
  }
116
116
  this.terminalOutputChunks.push(chunk);
117
- this.outputCallbacks.forEach((cb) => cb(chunk));
117
+ this.outputCallbacks.forEach((cb) => cb(chunk, isCommandHeader));
118
118
  });
119
119
  childProcess.onExit((message) => {
120
120
  this.isAlive = false;
@@ -92,8 +92,8 @@ function waitForLogMatch(readyWhen, context) {
92
92
  const timer = setTimeout(() => settle((0, ready_when_1.readinessTimeoutError)(context.taskId, readyWhen)), readyWhen.timeout);
93
93
  timer.unref();
94
94
  context.signal.addEventListener('abort', onAbort);
95
- context.runningTask.onOutput((chunk) => {
96
- if (!settled && matcher.feed(chunk)) {
95
+ context.runningTask.onOutput((chunk, isCommandHeader) => {
96
+ if (!settled && !isCommandHeader && matcher.feed(chunk)) {
97
97
  settle();
98
98
  }
99
99
  });
@@ -55,9 +55,30 @@ export declare function getReadyWhenConfig(task: Task, projectGraph: ProjectGrap
55
55
  * The probe of a producer this process starts with `taskEnv`. Env tokens read
56
56
  * `taskEnv`, or for run-commands the env its command runs with
57
57
  */
58
- export declare function getReadyWhen(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string, taskEnv: NodeJS.ProcessEnv): NormalizedReadyWhen | null;
58
+ export declare function getReadyWhen(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string, taskEnv: NodeJS.ProcessEnv, inputs?: {
59
+ readyWhen: ReadyWhen;
60
+ executor: string;
61
+ data: {
62
+ workspaceRoot: string;
63
+ projectRoot: string;
64
+ projectName: string;
65
+ options: any;
66
+ };
67
+ }): NormalizedReadyWhen | null;
59
68
  export declare const TASK_OPTIONS_ENV = "NX_TASK_OPTIONS";
60
69
  export declare function getReadyWhenWait(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string): ReadyWhenWait | null;
70
+ export type ReadyWhenInputs = ReturnType<typeof getReadyWhenInputs>;
71
+ export declare function getReadyWhenInputs(task: Task, projectGraph: ProjectGraph, projects: Record<string, ProjectConfiguration>, workspaceRoot: string): {
72
+ readyWhen: ReadyWhen;
73
+ executor: string;
74
+ data: {
75
+ workspaceRoot: string;
76
+ projectRoot: string;
77
+ projectName: string;
78
+ options: any;
79
+ };
80
+ };
81
+ export declare function mayReportReadyUrl(task: Task, projectGraph: ProjectGraph): boolean;
61
82
  export declare function getReadyProducerIds(task: Task, taskGraph: TaskGraph): string[];
62
83
  export declare function getReadyDependencies(taskGraph: TaskGraph, projectGraph: ProjectGraph): Record<string, string[]>;
63
84
  export {};
@@ -8,6 +8,8 @@ exports.notReadyError = notReadyError;
8
8
  exports.getReadyWhenConfig = getReadyWhenConfig;
9
9
  exports.getReadyWhen = getReadyWhen;
10
10
  exports.getReadyWhenWait = getReadyWhenWait;
11
+ exports.getReadyWhenInputs = getReadyWhenInputs;
12
+ exports.mayReportReadyUrl = mayReportReadyUrl;
11
13
  exports.getReadyProducerIds = getReadyProducerIds;
12
14
  exports.getReadyDependencies = getReadyDependencies;
13
15
  const path_1 = require("path");
@@ -260,8 +262,7 @@ function getReadyWhenConfig(task, projectGraph) {
260
262
  * The probe of a producer this process starts with `taskEnv`. Env tokens read
261
263
  * `taskEnv`, or for run-commands the env its command runs with
262
264
  */
263
- function getReadyWhen(task, projectGraph, projects, workspaceRoot, taskEnv) {
264
- const inputs = getReadyWhenInputs(task, projectGraph, projects, workspaceRoot);
265
+ function getReadyWhen(task, projectGraph, projects, workspaceRoot, taskEnv, inputs = getReadyWhenInputs(task, projectGraph, projects, workspaceRoot)) {
265
266
  if (!inputs) {
266
267
  return null;
267
268
  }
@@ -321,6 +322,28 @@ function getReadyWhenInputs(task, projectGraph, projects, workspaceRoot) {
321
322
  },
322
323
  };
323
324
  }
325
+ // Only a signal check reports a URL, which its waiters get as NX_READY_URL
326
+ function mayReportReadyUrl(task, projectGraph) {
327
+ const readyWhen = getReadyWhenConfig(task, projectGraph);
328
+ if (typeof readyWhen !== 'object' || readyWhen === null) {
329
+ return false;
330
+ }
331
+ const kind = PROBE_KEYS.find((key) => readyWhen[key] != null);
332
+ switch (kind) {
333
+ case 'signal':
334
+ return true;
335
+ case 'url':
336
+ case 'port':
337
+ case 'command':
338
+ case 'logMatches':
339
+ case undefined:
340
+ return false;
341
+ default: {
342
+ const unhandled = kind;
343
+ throw new Error(`Unhandled readyWhen check: ${unhandled}`);
344
+ }
345
+ }
346
+ }
324
347
  function getReadyProducerIds(task, taskGraph) {
325
348
  return (taskGraph.continuousDependencies[task.id] ?? [])
326
349
  .filter((edge) => edge.waitFor === 'ready')
@@ -24,7 +24,7 @@ export interface TaskSelection {
24
24
  ultracacheConfigurationOutcome?: UltracacheConfigurationOutcome | null;
25
25
  }
26
26
  import { LifeCycle, TaskResult, TaskResults } from './life-cycle';
27
- import { TasksRunner } from './tasks-runner';
27
+ import { TasksRunner, TaskStatus } from './tasks-runner';
28
28
  /**
29
29
  * `targets` on whole projects, as `run-many` runs them: every task of the
30
30
  * projects' targets and what they depend on, with those tasks initiating.
@@ -43,6 +43,7 @@ export declare function runTasksForCommand(taskSelection: TaskSelection, current
43
43
  loadDotEnvFiles: boolean;
44
44
  }): Promise<{
45
45
  taskResults: TaskResults;
46
+ taskStatuses?: Record<string, TaskStatus>;
46
47
  completed: boolean;
47
48
  }>;
48
49
  export declare function setEnvVarsBasedOnArgs(nxArgs: NxArgs, loadDotEnvFiles: boolean): void;
@@ -60,7 +61,10 @@ export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, life
60
61
  /** Already loaded for this command; `undefined` loads it here. */
61
62
  ultracacheConfigurationOutcome?: UltracacheConfigurationOutcome | null;
62
63
  }): Promise<{
63
- [id: string]: TaskResult;
64
+ taskResults: {
65
+ [id: string]: TaskResult;
66
+ };
67
+ taskStatuses?: Record<string, TaskStatus>;
64
68
  }>;
65
69
  export declare function constructLifeCycles(lifeCycle: LifeCycle, taskGraph: TaskGraph, nxJson?: NxJsonConfiguration, skipNxCache?: boolean): LifeCycle[];
66
70
  /**
@@ -53,7 +53,7 @@ const tui_summary_life_cycle_1 = require("./life-cycles/tui-summary-life-cycle")
53
53
  const ready_when_1 = require("./readiness/ready-when");
54
54
  const task_graph_utils_1 = require("./task-graph-utils");
55
55
  const utils_1 = require("./utils");
56
- const exit_codes_1 = require("../utils/exit-codes");
56
+ const run_outcome_1 = require("./run-outcome");
57
57
  const handle_import_1 = require("../utils/handle-import");
58
58
  const pc = tslib_1.__importStar(require("picocolors"));
59
59
  const originalStdoutWrite = process.stdout.write.bind(process.stdout);
@@ -362,19 +362,14 @@ async function runCommand(taskSelection, currentProjectGraph, { nxJson }, nxArgs
362
362
  argv: process.argv,
363
363
  });
364
364
  const startTime = Date.now();
365
- const { taskResults, completed } = await runTasksForCommand(taskSelection, currentProjectGraph, { nxJson }, {
365
+ const { taskResults, taskStatuses, completed } = await runTasksForCommand(taskSelection, currentProjectGraph, { nxJson }, {
366
366
  ...nxArgs,
367
367
  skipNxCache: nxArgs.skipNxCache ||
368
368
  process.env.NX_SKIP_NX_CACHE === 'true' ||
369
369
  process.env.NX_DISABLE_NX_CACHE === 'true',
370
370
  }, overrides, initiatingProject, extraTargetDependencies, extraOptions);
371
371
  const endTime = Date.now();
372
- const exitCode = !completed
373
- ? (0, exit_codes_1.signalToCode)('SIGINT')
374
- : Object.values(taskResults).some((taskResult) => taskResult.status === 'failure' ||
375
- taskResult.status === 'skipped')
376
- ? 1
377
- : 0;
372
+ const exitCode = (0, run_outcome_1.getRunExitCode)(completed, taskResults, taskStatuses);
378
373
  await (0, tasks_execution_hooks_1.runPostTasksExecution)({
379
374
  id,
380
375
  taskResults,
@@ -404,7 +399,7 @@ async function runTasksForCommand(taskSelection, currentProjectGraph, { nxJson }
404
399
  ];
405
400
  const { lifeCycle, renderIsDone, printSummary, restoreTerminal } = await getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, projectNames, tasks, taskGraph, projectGraph, nxArgs, nxJson, overrides);
406
401
  try {
407
- const taskResults = await invokeTasksRunner({
402
+ const { taskResults, taskStatuses } = await invokeTasksRunner({
408
403
  tasks,
409
404
  projectGraph,
410
405
  taskGraph,
@@ -427,7 +422,8 @@ async function runTasksForCommand(taskSelection, currentProjectGraph, { nxJson }
427
422
  logger_1.logger.log((0, nx_key_1.createNxKeyLicenseeInformation)(nxKey));
428
423
  return {
429
424
  taskResults,
430
- completed: didCommandComplete(tasks, taskResults),
425
+ taskStatuses,
426
+ completed: (0, run_outcome_1.didCommandComplete)(tasks, taskResults, taskStatuses),
431
427
  };
432
428
  }
433
429
  catch (e) {
@@ -459,19 +455,6 @@ async function printConfigureAiAgentsDisclaimer() {
459
455
  // Silently ignore errors
460
456
  }
461
457
  }
462
- function didCommandComplete(tasks, taskResults) {
463
- if (tasks.length === 0)
464
- return true;
465
- for (const task of tasks) {
466
- if (!task.continuous) {
467
- // Discrete task must have a result (was started and finished)
468
- if (!taskResults[task.id])
469
- return false;
470
- }
471
- }
472
- // Any stopped task means the run was interrupted
473
- return !Object.values(taskResults).some((r) => r.status === 'stopped');
474
- }
475
458
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, nxArgs, overrides, extraTargetDependencies, extraOptions, taskSelection) {
476
459
  let taskGraph = runValidations(projectGraph, taskSelection.taskGraph, nxArgs);
477
460
  if (nxArgs.skipSync || (0, is_ci_1.isCI)()) {
@@ -796,8 +779,14 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
796
779
  if (promiseOrObservable.subscribe) {
797
780
  promiseOrObservable = convertObservableToPromise(promiseOrObservable);
798
781
  }
799
- await promiseOrObservable;
800
- return taskResultsLifecycle.getTaskResults();
782
+ const taskStatuses = await promiseOrObservable;
783
+ return {
784
+ taskResults: taskResultsLifecycle.getTaskResults(),
785
+ // Custom runners are not guaranteed to resolve to a status map.
786
+ taskStatuses: taskStatuses && typeof taskStatuses === 'object'
787
+ ? taskStatuses
788
+ : undefined,
789
+ };
801
790
  }
802
791
  function constructLifeCycles(lifeCycle, taskGraph, nxJson, skipNxCache) {
803
792
  const lifeCycles = [];
@@ -0,0 +1,16 @@
1
+ import type { Task } from '../config/task-graph';
2
+ import type { TaskResults } from './life-cycle';
3
+ import type { TaskStatus } from './tasks-runner';
4
+ /**
5
+ * Whether the run got to the end, as opposed to being interrupted.
6
+ *
7
+ * A discrete task skipped because a dependency failed has no `TaskResult`,
8
+ * but the runner still settled it, so it must not make the run look
9
+ * interrupted.
10
+ */
11
+ export declare function didCommandComplete(tasks: Task[], taskResults: TaskResults, taskStatuses?: Record<string, TaskStatus>): boolean;
12
+ /**
13
+ * Exit code for a run: 130 (SIGINT) when it was interrupted, 1 when any task
14
+ * failed or was skipped, 0 otherwise.
15
+ */
16
+ export declare function getRunExitCode(completed: boolean, taskResults: TaskResults, taskStatuses?: Record<string, TaskStatus>): number;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.didCommandComplete = didCommandComplete;
4
+ exports.getRunExitCode = getRunExitCode;
5
+ const exit_codes_1 = require("../utils/exit-codes");
6
+ /**
7
+ * Whether the run got to the end, as opposed to being interrupted.
8
+ *
9
+ * A discrete task skipped because a dependency failed has no `TaskResult`,
10
+ * but the runner still settled it, so it must not make the run look
11
+ * interrupted.
12
+ */
13
+ function didCommandComplete(tasks, taskResults, taskStatuses) {
14
+ if (tasks.length === 0)
15
+ return true;
16
+ for (const task of tasks) {
17
+ if (!task.continuous) {
18
+ // Discrete task must have been settled by the runner
19
+ if (!taskResults[task.id] && !taskStatuses?.[task.id])
20
+ return false;
21
+ }
22
+ }
23
+ // Any stopped task means the run was interrupted
24
+ return (!Object.values(taskResults).some((r) => r.status === 'stopped') &&
25
+ !Object.values(taskStatuses ?? {}).some((s) => s === 'stopped'));
26
+ }
27
+ /**
28
+ * Exit code for a run: 130 (SIGINT) when it was interrupted, 1 when any task
29
+ * failed or was skipped, 0 otherwise.
30
+ */
31
+ function getRunExitCode(completed, taskResults, taskStatuses) {
32
+ if (!completed)
33
+ return (0, exit_codes_1.signalToCode)('SIGINT');
34
+ const failedOrSkipped = (status) => status === 'failure' || status === 'skipped';
35
+ return Object.values(taskResults).some((r) => failedOrSkipped(r.status)) ||
36
+ Object.values(taskStatuses ?? {}).some(failedOrSkipped)
37
+ ? 1
38
+ : 0;
39
+ }
@@ -6,6 +6,6 @@ export declare abstract class RunningTask {
6
6
  }>;
7
7
  abstract onExit(cb: (code: number) => void): void;
8
8
  abstract kill(signal?: NodeJS.Signals): Promise<void> | void;
9
- abstract onOutput?(cb: (output: string) => void): void;
9
+ abstract onOutput?(cb: (output: string, isCommandHeader?: boolean) => void): void;
10
10
  abstract send?(message: Serializable): void;
11
11
  }
@@ -197,8 +197,9 @@ export declare class TaskOrchestrator {
197
197
  * those per-project summaries to the worker's stdio at all.
198
198
  *
199
199
  * The worker's whole captured log is rendered as a fold above them when the
200
- * run asked for full output, or when any task failed or was stopped. A
201
- * diagnostic that explains a failure is routinely one no task claimed:
200
+ * run asked for full output, or when any task failed, was stopped or was
201
+ * never reached.
202
+ * A diagnostic that explains a failure is routinely one no task claimed:
202
203
  * `@nx/maven`'s batch impl writes its exit-code dump and failed-task outputs
203
204
  * to the worker's stderr via `console.error`, and the Maven JVM it spawns
204
205
  * points slf4j at `System.out` because its own stderr carries the result
@@ -274,6 +275,7 @@ export declare class TaskOrchestrator {
274
275
  private runTaskInForkedProcess;
275
276
  startContinuousTask(task: Task, groupId: number): Promise<NoopChildProcess | RunningTask | SharedRunningTask>;
276
277
  private getReadyWhen;
278
+ private checkReadyWhenBeforeWait;
277
279
  private getReadyWhenWait;
278
280
  private getReadinessCheck;
279
281
  private warnUncheckedReadiness;