nx 24.0.1 → 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.
@@ -53,6 +53,7 @@ export declare class DaemonClient {
53
53
  private fileWatcherMessenger;
54
54
  private fileWatcherReconnecting;
55
55
  private fileWatcherFramingFailures;
56
+ private fileWatcherRegistrations;
56
57
  private fileWatcherCallbacks;
57
58
  private fileWatcherConfigs;
58
59
  private projectGraphListenerMessenger;
@@ -81,6 +82,9 @@ export declare class DaemonClient {
81
82
  changedProjects: string[];
82
83
  changedFiles: ChangedFile[];
83
84
  } | null) => void): Promise<UnregisterCallback>;
85
+ private sendFileWatcherRegistration;
86
+ private handleFileWatcherRegistration;
87
+ private rejectFileWatcherRegistrations;
84
88
  private reconnectFileWatcher;
85
89
  registerProjectGraphRecomputationListener(callback: (error: Error | null | 'reconnecting' | 'reconnected' | 'closed', data: {
86
90
  projectGraph: ProjectGraph;
@@ -100,6 +100,7 @@ class DaemonClient {
100
100
  this._pluginWorkerConnectionLost = null;
101
101
  this.fileWatcherReconnecting = false;
102
102
  this.fileWatcherFramingFailures = 0;
103
+ this.fileWatcherRegistrations = new Map();
103
104
  this.fileWatcherCallbacks = new Map();
104
105
  this.fileWatcherConfigs = new Map();
105
106
  this.projectGraphListenerReconnecting = false;
@@ -156,6 +157,7 @@ class DaemonClient {
156
157
  return this._enabled;
157
158
  }
158
159
  reset() {
160
+ this.rejectFileWatcherRegistrations(new Error('Daemon client reset'));
159
161
  this.socketMessenger?.close();
160
162
  this.socketMessenger = null;
161
163
  this.queue = new promised_based_queue_1.PromisedBasedQueue();
@@ -263,16 +265,15 @@ class DaemonClient {
263
265
  }
264
266
  // Generate unique ID for this callback
265
267
  const callbackId = Math.random().toString(36).substring(2, 11);
266
- // Store callback and config for reconnection
267
- this.fileWatcherCallbacks.set(callbackId, callback);
268
- this.fileWatcherConfigs.set(callbackId, config);
269
- await this.queue.sendToQueue(async () => {
268
+ await this.queue
269
+ .sendToQueue(async () => {
270
+ // Only registrations whose queue entry has started belong to this
271
+ // connection. A failed earlier entry must not reconnect a queued one.
272
+ this.fileWatcherCallbacks.set(callbackId, callback);
273
+ this.fileWatcherConfigs.set(callbackId, config);
270
274
  // If we already have a connection, just register the new config
271
275
  if (this.fileWatcherMessenger) {
272
- this.fileWatcherMessenger.sendMessage({
273
- type: 'REGISTER_FILE_WATCHER',
274
- config,
275
- });
276
+ await this.sendFileWatcherRegistration(callbackId);
276
277
  return;
277
278
  }
278
279
  await this.startDaemonIfNecessary();
@@ -280,6 +281,8 @@ class DaemonClient {
280
281
  this.fileWatcherMessenger = new daemon_socket_messenger_1.DaemonSocketMessenger((0, net_1.connect)(socketPath)).listen((message) => {
281
282
  try {
282
283
  const parsedMessage = (0, consume_messages_from_socket_1.parseMessage)(message);
284
+ if (this.handleFileWatcherRegistration(parsedMessage))
285
+ return;
283
286
  // A delivered message means the stream is healthy again.
284
287
  this.fileWatcherFramingFailures = 0;
285
288
  if (parsedMessage?.watcherError) {
@@ -303,6 +306,7 @@ class DaemonClient {
303
306
  // Connection closed - trigger reconnection
304
307
  logger_1.clientLogger.log(`[FileWatcher] Socket closed, triggering reconnection`);
305
308
  this.fileWatcherMessenger = undefined;
309
+ this.rejectFileWatcherRegistrations(new Error('Daemon disconnected before watcher registration completed'));
306
310
  for (const cb of this.fileWatcherCallbacks.values()) {
307
311
  cb('reconnecting', null);
308
312
  }
@@ -324,10 +328,12 @@ class DaemonClient {
324
328
  // failure would otherwise leave this channel silent forever.
325
329
  this.fileWatcherMessenger?.close();
326
330
  });
327
- this.fileWatcherMessenger.sendMessage({
328
- type: 'REGISTER_FILE_WATCHER',
329
- config,
330
- });
331
+ await this.sendFileWatcherRegistration(callbackId);
332
+ })
333
+ .catch((error) => {
334
+ this.fileWatcherCallbacks.delete(callbackId);
335
+ this.fileWatcherConfigs.delete(callbackId);
336
+ throw error;
331
337
  });
332
338
  // Return unregister function
333
339
  return () => {
@@ -340,6 +346,52 @@ class DaemonClient {
340
346
  }
341
347
  };
342
348
  }
349
+ sendFileWatcherRegistration(callbackId) {
350
+ return new Promise((resolve, reject) => {
351
+ const cleanup = () => {
352
+ clearTimeout(timeout);
353
+ this.fileWatcherRegistrations.delete(callbackId);
354
+ };
355
+ const fail = (error) => {
356
+ cleanup();
357
+ this.fileWatcherCallbacks.delete(callbackId);
358
+ this.fileWatcherConfigs.delete(callbackId);
359
+ reject(error);
360
+ if (this.fileWatcherCallbacks.size === 0) {
361
+ this.fileWatcherMessenger?.close();
362
+ }
363
+ };
364
+ const timeout = setTimeout(() => fail(new Error('Timed out waiting for daemon watcher registration')), WAIT_FOR_SERVER_CONFIG.maxAttempts * WAIT_FOR_SERVER_CONFIG.delayMs);
365
+ this.fileWatcherRegistrations.set(callbackId, {
366
+ resolve: () => {
367
+ cleanup();
368
+ resolve();
369
+ },
370
+ reject: fail,
371
+ });
372
+ try {
373
+ this.fileWatcherMessenger.sendMessage({
374
+ type: 'REGISTER_FILE_WATCHER',
375
+ config: this.fileWatcherConfigs.get(callbackId),
376
+ registrationId: callbackId,
377
+ });
378
+ }
379
+ catch (error) {
380
+ fail(error);
381
+ }
382
+ });
383
+ }
384
+ handleFileWatcherRegistration(message) {
385
+ if (message?.type !== 'FILE_WATCHER_REGISTERED')
386
+ return false;
387
+ this.fileWatcherRegistrations.get(message.registrationId)?.resolve();
388
+ return true;
389
+ }
390
+ rejectFileWatcherRegistrations(error) {
391
+ for (const registration of [...this.fileWatcherRegistrations.values()]) {
392
+ registration.reject(error);
393
+ }
394
+ }
343
395
  async reconnectFileWatcher() {
344
396
  // Guard against concurrent reconnection attempts
345
397
  if (this.fileWatcherReconnecting) {
@@ -394,6 +446,8 @@ class DaemonClient {
394
446
  this.fileWatcherMessenger = new daemon_socket_messenger_1.DaemonSocketMessenger((0, net_1.connect)(socketPath)).listen((message) => {
395
447
  try {
396
448
  const parsedMessage = (0, consume_messages_from_socket_1.parseMessage)(message);
449
+ if (this.handleFileWatcherRegistration(parsedMessage))
450
+ return;
397
451
  // A delivered message means the stream is healthy again.
398
452
  this.fileWatcherFramingFailures = 0;
399
453
  for (const cb of this.fileWatcherCallbacks.values()) {
@@ -408,6 +462,7 @@ class DaemonClient {
408
462
  }, () => {
409
463
  // Connection closed - trigger reconnection again
410
464
  this.fileWatcherMessenger = undefined;
465
+ this.rejectFileWatcherRegistrations(new Error('Daemon disconnected before watcher registration completed'));
411
466
  // Reset reconnection flag before triggering reconnection
412
467
  this.fileWatcherReconnecting = false;
413
468
  for (const cb of this.fileWatcherCallbacks.values()) {
@@ -170,6 +170,17 @@ async function handleMessage(socket, data) {
170
170
  }
171
171
  else if (payload.type === 'REGISTER_FILE_WATCHER') {
172
172
  file_watcher_sockets_1.registeredFileWatcherSockets.push({ socket, config: payload.config });
173
+ // A client must not announce readiness until this socket is subscribed.
174
+ // Older clients do not request an acknowledgement and expect only changes.
175
+ if (payload.registrationId) {
176
+ await handleResult(socket, 'REGISTER_FILE_WATCHER', async () => ({
177
+ description: 'File watcher registered',
178
+ response: {
179
+ type: 'FILE_WATCHER_REGISTERED',
180
+ registrationId: payload.registrationId,
181
+ },
182
+ }), mode);
183
+ }
173
184
  }
174
185
  else if ((0, register_project_graph_listener_1.isRegisterProjectGraphListenerMessage)(payload)) {
175
186
  project_graph_listener_sockets_1.registeredProjectGraphListenerSockets.push(socket);
@@ -56,7 +56,7 @@ export default function (options: RunCommandsOptions, context: ExecutorContext):
56
56
  success: boolean;
57
57
  terminalOutput: string;
58
58
  }>;
59
- export declare function runCommands(options: RunCommandsOptions, context: ExecutorContext, task?: Pick<Task, 'id' | 'ultracache'>, baseEnv?: NodeJS.ProcessEnv): Promise<NoopChildProcess | ParallelRunningTasks | import("../../tasks-runner/pseudo-terminal").PseudoTtyProcess | SeriallyRunningTasks>;
59
+ export declare function runCommands(options: RunCommandsOptions, context: ExecutorContext, task?: Pick<Task, 'id' | 'ultracache' | 'continuous'>, baseEnv?: NodeJS.ProcessEnv): Promise<NoopChildProcess | ParallelRunningTasks | import("../../tasks-runner/pseudo-terminal").PseudoTtyProcess | SeriallyRunningTasks>;
60
60
  /** The options `interpolateArgsIntoCommand` reads, from the task's options. */
61
61
  export declare function normalizeArgs(options: RunCommandsOptions): Pick<NormalizedRunCommandsOptions, 'args' | 'parsedArgs' | '__unparsed__' | 'unknownOptions' | 'unparsedCommandArgs'>;
62
62
  export declare function interpolateArgsIntoCommand(command: string, opts: Pick<NormalizedRunCommandsOptions, 'args' | 'parsedArgs' | '__unparsed__' | 'unknownOptions' | 'unparsedCommandArgs'>, forwardAllArgs: boolean, env?: () => NodeJS.ProcessEnv): string;
@@ -68,20 +68,26 @@ async function runCommands(options, context, task, baseEnv) {
68
68
  // The orchestrator's in-process path passes the task with a stub context,
69
69
  // so prefer it. `runExecutor` can name a target the task graph does not
70
70
  // hold, hence the project lookup; `convert-nx-executor` has neither graph,
71
- // and only then is the config unknowable, which counts as tracked.
71
+ // and only then is the config unknowable, which counts as tracked and
72
+ // discrete.
72
73
  const resolvedTaskId = task?.id ??
73
74
  (0, utils_1.createTaskId)(context.projectName, context.targetName, context.configurationName);
75
+ // `projectGraph` is typed as present, but `convert-nx-executor` passes
76
+ // null for both graphs.
77
+ const targetConfiguration = context.projectName && context.targetName
78
+ ? context.projectGraph?.nodes?.[context.projectName]?.data.targets?.[context.targetName]
79
+ : undefined;
74
80
  const resolvedTask = task ??
75
81
  context.taskGraph?.tasks?.[resolvedTaskId] ?? {
76
82
  id: resolvedTaskId,
77
- // Both graphs are typed as present, but `convert-nx-executor` passes
78
- // null for each.
79
- ultracache: context.projectName && context.targetName
80
- ? context.projectGraph?.nodes?.[context.projectName]?.data
81
- .targets?.[context.targetName]?.ultracache
82
- : undefined,
83
+ ultracache: targetConfiguration?.ultracache,
84
+ continuous: targetConfiguration?.continuous,
83
85
  };
84
- const runningTask = isSingleCommandAndCanUsePseudoTerminal
86
+ // The pseudo terminal runner ignores readyWhen, which keeps a continuous
87
+ // task running past the match. A discrete task must end there.
88
+ const usePtyRunner = isSingleCommandAndCanUsePseudoTerminal &&
89
+ (!normalized.readyWhenStatus.length || resolvedTask.continuous === true);
90
+ const runningTask = usePtyRunner
85
91
  ? await (0, running_tasks_1.runSingleCommandWithPseudoTerminal)(normalized, context, resolvedTask, baseEnv)
86
92
  : options.parallel
87
93
  ? new running_tasks_1.ParallelRunningTasks(normalized, context, resolvedTask, baseEnv)
@@ -41,6 +41,14 @@ function streamChunk(chunk, streamOutput, target = process.stdout) {
41
41
  function commandExitedNonZeroWarning(command) {
42
42
  return `Warning: command "${command}" exited with non-zero status code`;
43
43
  }
44
+ function commandsExitedBeforeReadyWarning(commands, readyWhenStatus) {
45
+ const exited = commands.length === 1 ? `command "${commands[0].command}"` : 'all commands';
46
+ const missing = readyWhenStatus
47
+ .filter(({ found }) => !found)
48
+ .map(({ stringToMatch }) => `"${stringToMatch}"`)
49
+ .join(', ');
50
+ return `Warning: ${exited} exited before printing the readyWhen text ${missing}`;
51
+ }
44
52
  class ParallelRunningTasks {
45
53
  constructor(options, context, task, baseEnv) {
46
54
  this.exitCallbacks = [];
@@ -94,19 +102,32 @@ class ParallelRunningTasks {
94
102
  }
95
103
  async run() {
96
104
  if (this.readyWhenStatus.length) {
97
- let { childProcess, result: { code, terminalOutput }, } = await Promise.race(this.childProcesses.map((childProcess) => new Promise((res) => {
98
- childProcess.onOutput((terminalOutput) => {
99
- for (const cb of this.outputCallbacks) {
100
- cb(terminalOutput);
101
- }
102
- });
103
- childProcess.onExit((code, terminalOutput) => {
104
- res({
105
- childProcess,
106
- result: { code, terminalOutput },
105
+ const settled = await Promise.race([
106
+ ...this.childProcesses.map((childProcess) => new Promise((res) => {
107
+ childProcess.onOutput((terminalOutput) => {
108
+ for (const cb of this.outputCallbacks) {
109
+ cb(terminalOutput);
110
+ }
107
111
  });
108
- });
109
- })));
112
+ childProcess.onExit((code, terminalOutput) => {
113
+ res({
114
+ childProcess,
115
+ result: { code, terminalOutput },
116
+ });
117
+ });
118
+ })),
119
+ Promise.all(this.childProcesses.map((childProcess) => childProcess.outputWhenClosed())).then((outputs) => ({ outputsOfExitedCommands: outputs })),
120
+ ]);
121
+ if ('outputsOfExitedCommands' in settled) {
122
+ const warning = commandsExitedBeforeReadyWarning(this.childProcesses, this.readyWhenStatus);
123
+ for (const cb of this.outputCallbacks) {
124
+ cb(warning);
125
+ }
126
+ streamChunk(warning, this.streamOutput, process.stderr);
127
+ this.emitExit(1, settled.outputsOfExitedCommands.join('\r\n') + warning);
128
+ return;
129
+ }
130
+ let { childProcess, result: { code, terminalOutput }, } = settled;
110
131
  if (code !== 0) {
111
132
  const warning = commandExitedNonZeroWarning(childProcess.command);
112
133
  terminalOutput += warning;
@@ -377,6 +398,10 @@ class RunningNodeProcess {
377
398
  send(message) {
378
399
  this.childProcess.send(message);
379
400
  }
401
+ async outputWhenClosed() {
402
+ await this.closedPromise;
403
+ return this.terminalOutputChunks.join('');
404
+ }
380
405
  emitExit(code, terminalOutput) {
381
406
  if (this.exited)
382
407
  return;
@@ -419,12 +444,15 @@ class RunningNodeProcess {
419
444
  addListeners(commandConfig) {
420
445
  this.childProcess.stdout.setEncoding('utf8');
421
446
  this.childProcess.stderr.setEncoding('utf8');
447
+ // Separate matchers, so a ready string never spans stdout and stderr
448
+ const stdoutReady = readyWhenMatcher(this.readyWhenStatus);
449
+ const stderrReady = readyWhenMatcher(this.readyWhenStatus);
422
450
  this.childProcess.stdout.on('data', (data) => {
423
451
  const output = addColorAndPrefix(data, commandConfig);
424
452
  this.terminalOutputChunks.push(output);
425
453
  this.triggerOutputListeners(output);
426
454
  this.stream(output);
427
- if (this.readyWhenStatus.length && isReady(this.readyWhenStatus, data)) {
455
+ if (this.readyWhenStatus.length && stdoutReady(data)) {
428
456
  for (const cb of this.exitCallbacks) {
429
457
  cb(0, this.terminalOutputChunks.join(''));
430
458
  }
@@ -435,7 +463,7 @@ class RunningNodeProcess {
435
463
  this.terminalOutputChunks.push(output);
436
464
  this.triggerOutputListeners(output);
437
465
  this.stream(output, process.stderr);
438
- if (this.readyWhenStatus.length && isReady(this.readyWhenStatus, err)) {
466
+ if (this.readyWhenStatus.length && stderrReady(err)) {
439
467
  for (const cb of this.exitCallbacks) {
440
468
  cb(0, this.terminalOutputChunks.join(''));
441
469
  }
@@ -455,17 +483,16 @@ class RunningNodeProcess {
455
483
  code = (0, exit_codes_1.signalToCode)(signal);
456
484
  }
457
485
  untrackRunningNodeProcess(this);
486
+ if (code === 0 &&
487
+ this.readyWhenStatus.length &&
488
+ !isReady(this.readyWhenStatus)) {
489
+ // A parallel companion may still print the readyWhen text. Keep the
490
+ // output for ParallelRunningTasks, which decides once all have closed.
491
+ return;
492
+ }
458
493
  const terminalOutput = this.terminalOutputChunks.join('');
459
494
  this.terminalOutputChunks = [];
460
- if (!this.readyWhenStatus.length || isReady(this.readyWhenStatus)) {
461
- this.emitExit(code, terminalOutput);
462
- }
463
- else if (code !== 0) {
464
- // Process crashed before readyWhen matched; surface the failure so
465
- // awaiters unblock. A clean exit (code 0) is left as-is — a parallel
466
- // companion command may still produce the readyWhen output.
467
- this.emitExit(code, terminalOutput);
468
- }
495
+ this.emitExit(code, terminalOutput);
469
496
  });
470
497
  trackRunningNodeProcess(this);
471
498
  }
@@ -551,16 +578,31 @@ function processEnv(color, cwd, envOptionFromExecutor, envFile, baseEnv = proces
551
578
  delete res.NX_PREFIX_OUTPUT;
552
579
  return res;
553
580
  }
554
- function isReady(readyWhenStatus = [], data) {
555
- if (data) {
556
- for (const readyWhenElement of readyWhenStatus) {
557
- if (data.toString().indexOf(readyWhenElement.stringToMatch) > -1) {
558
- readyWhenElement.found = true;
559
- }
560
- }
561
- }
581
+ function isReady(readyWhenStatus) {
562
582
  return readyWhenStatus.every((readyWhenElement) => readyWhenElement.found);
563
583
  }
584
+ // The output as printed, kept across chunks, matches strings that hold escape
585
+ // sequences. LogMatcher, absent from the WASM binding, matches text with
586
+ // escapes inside it.
587
+ function readyWhenMatcher(readyWhenStatus) {
588
+ const matchers = readyWhenStatus.map((status) => ({
589
+ status,
590
+ matcher: native_1.IS_WASM ? null : new native_1.LogMatcher([status.stringToMatch]),
591
+ tail: '',
592
+ }));
593
+ return (chunk) => {
594
+ for (const entry of matchers) {
595
+ const { status, matcher } = entry;
596
+ if (status.found)
597
+ continue;
598
+ const printed = entry.tail + chunk;
599
+ status.found =
600
+ printed.includes(status.stringToMatch) || !!matcher?.feed(chunk);
601
+ entry.tail = printed.slice(Math.max(0, printed.length - status.stringToMatch.length + 1));
602
+ }
603
+ return isReady(readyWhenStatus);
604
+ };
605
+ }
564
606
  function loadEnvVarsFile(path, env = {}) {
565
607
  (0, task_env_1.unloadDotEnvFile)(path, env);
566
608
  const result = (0, task_env_1.loadAndExpandDotEnvFile)(path, env);
@@ -123,7 +123,7 @@
123
123
  "x-priority": "important"
124
124
  },
125
125
  "readyWhen": {
126
- "description": "String or array of strings to appear in `stdout` or `stderr` that indicate that the task is done. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.",
126
+ "description": "String or array of strings to appear in `stdout` or `stderr` that indicate that the task is done. Unless the target is `continuous`, the task fails if every command exits before printing them. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.",
127
127
  "oneOf": [
128
128
  { "type": "string" },
129
129
  { "type": "array", "items": { "type": "string" } }
Binary file
@@ -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 {
@@ -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
@@ -40,6 +40,28 @@ const utils_1 = require("./utils");
40
40
  function resolveBatchTaskStatus(result) {
41
41
  return result.status ?? (result.success ? 'success' : 'failure');
42
42
  }
43
+ function batchWorkerLogExplains(status) {
44
+ switch (status) {
45
+ case 'failure':
46
+ case 'stopped':
47
+ // The worker never reached it, e.g. `@nx/gradle` after a build failure
48
+ // outside the batch's own tasks
49
+ case 'skipped':
50
+ return true;
51
+ case 'success':
52
+ case 'local-cache':
53
+ case 'local-cache-kept-existing':
54
+ case 'remote-cache':
55
+ return false;
56
+ default: {
57
+ const unhandled = status;
58
+ void unhandled;
59
+ // Batch executors report their statuses untyped, so an unknown one can
60
+ // still arrive here. Nx can't tell it succeeded, so its log is shown
61
+ return true;
62
+ }
63
+ }
64
+ }
43
65
  /** Whether a path names a file with bytes in it. */
44
66
  function hasContent(path) {
45
67
  try {
@@ -253,8 +275,21 @@ class TaskOrchestrator {
253
275
  */
254
276
  async executeCoordinatorLoop(doNotSkipCache, parallelism) {
255
277
  while (true) {
256
- if (this.bailed || this.stopRequested)
278
+ if (this.stopRequested)
257
279
  break;
280
+ // On bail, start nothing new but let running tasks finish. Skip unstarted
281
+ // discrete tasks unless stopped, so the run still reads as interrupted
282
+ if (this.bailed) {
283
+ await Promise.allSettled(this.pendingDiscreteWorkers);
284
+ if (this.stopRequested)
285
+ break;
286
+ for (const task of Object.values(this.taskGraph.tasks)) {
287
+ if (!task.continuous && !this.completedTasks.has(task.id)) {
288
+ this.completedTasks.set(task.id, 'skipped');
289
+ }
290
+ }
291
+ break;
292
+ }
258
293
  await this.scheduleAfterReadiness();
259
294
  // 1. Hash BEFORE processAll so processTask sees hashes set, and so
260
295
  // resolveCachedTasksBulk can look them up in the cache. Each task
@@ -298,6 +333,9 @@ class TaskOrchestrator {
298
333
  this.openGroup(groupId);
299
334
  continue;
300
335
  }
336
+ // A task may have failed during one of the awaits above
337
+ if (this.bailed)
338
+ continue;
301
339
  // 5. Dispatch cache misses as individual workers
302
340
  while (this.pendingDiscreteWorkers.size < parallelism) {
303
341
  const task = this.tasksSchedule.nextTask((t) => !t.continuous);
@@ -767,7 +805,8 @@ class TaskOrchestrator {
767
805
  // When the batch is being folded, printing is deferred to batch end
768
806
  // (printGroupedBatchOutput), which always renders each task through the
769
807
  // life cycle and adds the worker's whole log as a fold when the run
770
- // asked for full output or any task failed or was stopped.
808
+ // asked for full output or any task failed, was stopped or was never
809
+ // reached.
771
810
  if (status !== 'skipped' && !(0, output_1.shouldGroupBatchOutput)()) {
772
811
  this.options.lifeCycle.printTaskTerminalOutput(task, status, result.terminalOutput ?? '');
773
812
  }
@@ -862,7 +901,7 @@ class TaskOrchestrator {
862
901
  if (!capturedOutputPath || (0, output_1.printsTaskOutput)(this.resolvedOutputStyle)) {
863
902
  return;
864
903
  }
865
- const failed = results.some((r) => r.status === 'failure' || r.status === 'stopped');
904
+ const failed = results.some((r) => batchWorkerLogExplains(r.status));
866
905
  if (!failed) {
867
906
  return;
868
907
  }
@@ -912,8 +951,9 @@ class TaskOrchestrator {
912
951
  * those per-project summaries to the worker's stdio at all.
913
952
  *
914
953
  * The worker's whole captured log is rendered as a fold above them when the
915
- * run asked for full output, or when any task failed or was stopped. A
916
- * diagnostic that explains a failure is routinely one no task claimed:
954
+ * run asked for full output, or when any task failed, was stopped or was
955
+ * never reached.
956
+ * A diagnostic that explains a failure is routinely one no task claimed:
917
957
  * `@nx/maven`'s batch impl writes its exit-code dump and failed-task outputs
918
958
  * to the worker's stderr via `console.error`, and the Maven JVM it spawns
919
959
  * points slf4j at `System.out` because its own stderr carries the result
@@ -949,7 +989,7 @@ class TaskOrchestrator {
949
989
  verbose: this.options.verbose,
950
990
  outputStyle: this.resolvedOutputStyle,
951
991
  });
952
- const batchOwnsTheDiagnostic = taskResults.some((r) => r.status === 'failure' || r.status === 'stopped');
992
+ const batchOwnsTheDiagnostic = taskResults.some((r) => batchWorkerLogExplains(r.status));
953
993
  if ((0, output_1.printsTaskOutput)(this.resolvedOutputStyle) &&
954
994
  (printsFullOutput || batchOwnsTheDiagnostic) &&
955
995
  capturedOutputPath) {
@@ -983,7 +1023,9 @@ class TaskOrchestrator {
983
1023
  ? 'failure'
984
1024
  : taskResults.some((r) => r.status === 'stopped')
985
1025
  ? 'stopped'
986
- : 'success';
1026
+ : taskResults.some((r) => r.status === 'skipped')
1027
+ ? 'skipped'
1028
+ : 'success';
987
1029
  output_1.output.logBatchGroup(label, body, worst);
988
1030
  if (!redirectLines) {
989
1031
  return;
@@ -224,9 +224,10 @@ declare class CLIOutput {
224
224
  * The batch's own output is copied straight from the file it was captured
225
225
  * into, so an arbitrarily long log costs a fixed amount of memory here.
226
226
  * Nothing is withheld: this rendering is chosen because the whole log was
227
- * asked for, because no task claimed any of it, or because a task failed or
228
- * was stopped — in which case repeating claimed bytes beside the per-task
229
- * blocks is deliberate (see TaskOrchestrator.printGroupedBatchOutput).
227
+ * asked for, because no task claimed any of it, or because a task failed,
228
+ * was stopped or was never reached — in which case repeating claimed bytes
229
+ * beside the per-task blocks is deliberate (see
230
+ * TaskOrchestrator.printGroupedBatchOutput).
230
231
  */
231
232
  logBatchGroup(label: string, body: {
232
233
  capturedOutputPath?: string;
@@ -422,9 +422,10 @@ class CLIOutput {
422
422
  * The batch's own output is copied straight from the file it was captured
423
423
  * into, so an arbitrarily long log costs a fixed amount of memory here.
424
424
  * Nothing is withheld: this rendering is chosen because the whole log was
425
- * asked for, because no task claimed any of it, or because a task failed or
426
- * was stopped — in which case repeating claimed bytes beside the per-task
427
- * blocks is deliberate (see TaskOrchestrator.printGroupedBatchOutput).
425
+ * asked for, because no task claimed any of it, or because a task failed,
426
+ * was stopped or was never reached — in which case repeating claimed bytes
427
+ * beside the per-task blocks is deliberate (see
428
+ * TaskOrchestrator.printGroupedBatchOutput).
428
429
  */
429
430
  logBatchGroup(label, body, taskStatus) {
430
431
  const grouped = isLogGroupingEnabled();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "24.0.1",
3
+ "version": "24.0.2",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
@@ -150,16 +150,16 @@
150
150
  }
151
151
  },
152
152
  "optionalDependencies": {
153
- "@nx/nx-darwin-arm64": "24.0.1",
154
- "@nx/nx-darwin-x64": "24.0.1",
155
- "@nx/nx-freebsd-x64": "24.0.1",
156
- "@nx/nx-linux-arm-gnueabihf": "24.0.1",
157
- "@nx/nx-linux-arm64-gnu": "24.0.1",
158
- "@nx/nx-linux-arm64-musl": "24.0.1",
159
- "@nx/nx-linux-x64-gnu": "24.0.1",
160
- "@nx/nx-linux-x64-musl": "24.0.1",
161
- "@nx/nx-win32-arm64-msvc": "24.0.1",
162
- "@nx/nx-win32-x64-msvc": "24.0.1"
153
+ "@nx/nx-darwin-arm64": "24.0.2",
154
+ "@nx/nx-darwin-x64": "24.0.2",
155
+ "@nx/nx-freebsd-x64": "24.0.2",
156
+ "@nx/nx-linux-arm-gnueabihf": "24.0.2",
157
+ "@nx/nx-linux-arm64-gnu": "24.0.2",
158
+ "@nx/nx-linux-arm64-musl": "24.0.2",
159
+ "@nx/nx-linux-x64-gnu": "24.0.2",
160
+ "@nx/nx-linux-x64-musl": "24.0.2",
161
+ "@nx/nx-win32-arm64-msvc": "24.0.2",
162
+ "@nx/nx-win32-x64-msvc": "24.0.2"
163
163
  },
164
164
  "nx-migrations": {
165
165
  "migrations": "./migrations.json",
@@ -1122,6 +1122,12 @@
1122
1122
  "enum": ["ignore", "forward"],
1123
1123
  "default": "ignore"
1124
1124
  },
1125
+ "options": {
1126
+ "type": "string",
1127
+ "description": "Whether to forward task options to the dependency target.",
1128
+ "enum": ["ignore", "forward"],
1129
+ "default": "ignore"
1130
+ },
1125
1131
  "inputs": {
1126
1132
  "type": "boolean",
1127
1133
  "description": "Set to false to keep a continuous dependency's inputs out of this target's hash and affected calculation. Has no effect on dependencies that are not continuous.",
@@ -103,6 +103,12 @@
103
103
  "enum": ["ignore", "forward"],
104
104
  "default": "ignore"
105
105
  },
106
+ "options": {
107
+ "type": "string",
108
+ "description": "Whether to forward task options to the dependency target.",
109
+ "enum": ["ignore", "forward"],
110
+ "default": "ignore"
111
+ },
106
112
  "inputs": {
107
113
  "type": "boolean",
108
114
  "description": "Set to false to keep a continuous dependency's inputs out of this target's hash and affected calculation. Has no effect on dependencies that are not continuous.",