nx 24.0.1 → 24.0.3
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.
- package/dist/bin/nx-cloud.js +9 -0
- package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +12 -1
- package/dist/src/command-line/migrate/migrate-analytics.js +2 -2
- package/dist/src/command-line/migrate/migrate.d.ts +3 -0
- package/dist/src/command-line/migrate/migrate.js +34 -15
- package/dist/src/command-line/migrate/workspace-installation.d.ts +15 -0
- package/dist/src/command-line/migrate/workspace-installation.js +73 -0
- package/dist/src/command-line/nx-cloud/complete-run/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/fix-ci/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/logout/command-object.js +11 -2
- package/dist/src/command-line/nx-cloud/record/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/start-ci-run/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +1 -1
- package/dist/src/command-line/release/changelog.js +6 -2
- package/dist/src/command-line/release/version/version-actions.js +2 -1
- package/dist/src/command-line/show/show-target/info.d.ts +1 -1
- package/dist/src/command-line/show/show-target/info.js +4 -4
- package/dist/src/core/graph/favicon.ico +0 -0
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/daemon/client/client.d.ts +4 -0
- package/dist/src/daemon/client/client.js +67 -12
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +3 -1
- package/dist/src/daemon/server/server.js +11 -0
- package/dist/src/executors/run-commands/run-commands.impl.d.ts +1 -1
- package/dist/src/executors/run-commands/run-commands.impl.js +14 -8
- package/dist/src/executors/run-commands/running-tasks.js +80 -31
- package/dist/src/executors/run-commands/schema.json +2 -2
- package/dist/src/native/index.js +12 -17
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/update-manager.d.ts +2 -0
- package/dist/src/nx-cloud/utilities/client.d.ts +1 -0
- package/dist/src/nx-cloud/utilities/client.js +5 -0
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -1
- package/dist/src/plugins/js/utils/register.js +3 -2
- package/dist/src/plugins/js/utils/typescript.js +3 -2
- package/dist/src/project-graph/utils/retrieve-workspace-files.js +2 -2
- package/dist/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +34 -13
- package/dist/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +26 -5
- package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +6 -3
- package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +5 -2
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +8 -4
- package/dist/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +76 -39
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +2 -2
- package/dist/src/tasks-runner/running-tasks/batch-process.js +1 -1
- package/dist/src/tasks-runner/task-orchestrator.d.ts +9 -5
- package/dist/src/tasks-runner/task-orchestrator.js +110 -36
- package/dist/src/utils/installation-directory.d.ts +8 -0
- package/dist/src/utils/installation-directory.js +13 -0
- package/dist/src/utils/output.d.ts +4 -3
- package/dist/src/utils/output.js +4 -3
- package/dist/src/utils/package-manager.d.ts +2 -1
- package/dist/src/utils/package-manager.js +42 -12
- package/package.json +12 -12
- package/schemas/nx-schema.json +6 -0
- package/schemas/project-schema.json +6 -0
|
@@ -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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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.
|
|
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.
|
|
328
|
-
|
|
329
|
-
|
|
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()) {
|
|
@@ -88,6 +88,9 @@ function kickOffRecompute() {
|
|
|
88
88
|
return chainToSuccessor(myPromise);
|
|
89
89
|
if (cachedSerializedProjectGraphPromise === myPromise &&
|
|
90
90
|
result.projectGraph) {
|
|
91
|
+
if (result.projectFileMapCache) {
|
|
92
|
+
exports.currentProjectFileMapCache = result.projectFileMapCache;
|
|
93
|
+
}
|
|
91
94
|
// The graph identity ties the candidate's generation to exactly this
|
|
92
95
|
// result; a chained result never matches (its computation's kickoff
|
|
93
96
|
// replaced the cached pointer, failing the identity check above).
|
|
@@ -606,7 +609,6 @@ async function createAndSerializeProjectGraph({ projects, externalNodes, sourceM
|
|
|
606
609
|
const fileMap = copyFileMap(exports.fileMapWithFiles.fileMap);
|
|
607
610
|
const rustReferences = exports.fileMapWithFiles.rustReferences;
|
|
608
611
|
const { projectGraph, projectFileMapCache } = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, rustReferences, exports.currentProjectFileMapCache || (0, nx_deps_cache_1.readFileMapCache)(), await (0, get_plugins_1.getPlugins)((0, nx_json_1.readNxJson)(workspace_root_1.workspaceRoot)), sourceMaps);
|
|
609
|
-
exports.currentProjectFileMapCache = projectFileMapCache;
|
|
610
612
|
exports.currentProjectGraph = projectGraph;
|
|
611
613
|
exports.currentSourceMaps = sourceMaps;
|
|
612
614
|
perf_hooks_1.performance.mark('create-project-graph-end');
|
|
@@ -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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
cb
|
|
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;
|
|
@@ -174,6 +195,13 @@ class SeriallyRunningTasks {
|
|
|
174
195
|
this.run(options, context)
|
|
175
196
|
.catch((e) => {
|
|
176
197
|
this.error = e;
|
|
198
|
+
this.code = 1;
|
|
199
|
+
const message = e?.message ?? String(e);
|
|
200
|
+
this.terminalOutputChunks.push(message);
|
|
201
|
+
for (const cb of this.outputCallbacks) {
|
|
202
|
+
cb(message);
|
|
203
|
+
}
|
|
204
|
+
streamChunk(message, options.streamOutput, process.stderr);
|
|
177
205
|
})
|
|
178
206
|
.finally(() => {
|
|
179
207
|
const terminalOutput = this.terminalOutputChunks.join('');
|
|
@@ -377,6 +405,10 @@ class RunningNodeProcess {
|
|
|
377
405
|
send(message) {
|
|
378
406
|
this.childProcess.send(message);
|
|
379
407
|
}
|
|
408
|
+
async outputWhenClosed() {
|
|
409
|
+
await this.closedPromise;
|
|
410
|
+
return this.terminalOutputChunks.join('');
|
|
411
|
+
}
|
|
380
412
|
emitExit(code, terminalOutput) {
|
|
381
413
|
if (this.exited)
|
|
382
414
|
return;
|
|
@@ -419,12 +451,15 @@ class RunningNodeProcess {
|
|
|
419
451
|
addListeners(commandConfig) {
|
|
420
452
|
this.childProcess.stdout.setEncoding('utf8');
|
|
421
453
|
this.childProcess.stderr.setEncoding('utf8');
|
|
454
|
+
// Separate matchers, so a ready string never spans stdout and stderr
|
|
455
|
+
const stdoutReady = readyWhenMatcher(this.readyWhenStatus);
|
|
456
|
+
const stderrReady = readyWhenMatcher(this.readyWhenStatus);
|
|
422
457
|
this.childProcess.stdout.on('data', (data) => {
|
|
423
458
|
const output = addColorAndPrefix(data, commandConfig);
|
|
424
459
|
this.terminalOutputChunks.push(output);
|
|
425
460
|
this.triggerOutputListeners(output);
|
|
426
461
|
this.stream(output);
|
|
427
|
-
if (this.readyWhenStatus.length &&
|
|
462
|
+
if (this.readyWhenStatus.length && stdoutReady(data)) {
|
|
428
463
|
for (const cb of this.exitCallbacks) {
|
|
429
464
|
cb(0, this.terminalOutputChunks.join(''));
|
|
430
465
|
}
|
|
@@ -435,7 +470,7 @@ class RunningNodeProcess {
|
|
|
435
470
|
this.terminalOutputChunks.push(output);
|
|
436
471
|
this.triggerOutputListeners(output);
|
|
437
472
|
this.stream(output, process.stderr);
|
|
438
|
-
if (this.readyWhenStatus.length &&
|
|
473
|
+
if (this.readyWhenStatus.length && stderrReady(err)) {
|
|
439
474
|
for (const cb of this.exitCallbacks) {
|
|
440
475
|
cb(0, this.terminalOutputChunks.join(''));
|
|
441
476
|
}
|
|
@@ -455,17 +490,16 @@ class RunningNodeProcess {
|
|
|
455
490
|
code = (0, exit_codes_1.signalToCode)(signal);
|
|
456
491
|
}
|
|
457
492
|
untrackRunningNodeProcess(this);
|
|
493
|
+
if (code === 0 &&
|
|
494
|
+
this.readyWhenStatus.length &&
|
|
495
|
+
!isReady(this.readyWhenStatus)) {
|
|
496
|
+
// A parallel companion may still print the readyWhen text. Keep the
|
|
497
|
+
// output for ParallelRunningTasks, which decides once all have closed.
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
458
500
|
const terminalOutput = this.terminalOutputChunks.join('');
|
|
459
501
|
this.terminalOutputChunks = [];
|
|
460
|
-
|
|
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
|
-
}
|
|
502
|
+
this.emitExit(code, terminalOutput);
|
|
469
503
|
});
|
|
470
504
|
trackRunningNodeProcess(this);
|
|
471
505
|
}
|
|
@@ -551,16 +585,31 @@ function processEnv(color, cwd, envOptionFromExecutor, envFile, baseEnv = proces
|
|
|
551
585
|
delete res.NX_PREFIX_OUTPUT;
|
|
552
586
|
return res;
|
|
553
587
|
}
|
|
554
|
-
function isReady(readyWhenStatus
|
|
555
|
-
if (data) {
|
|
556
|
-
for (const readyWhenElement of readyWhenStatus) {
|
|
557
|
-
if (data.toString().indexOf(readyWhenElement.stringToMatch) > -1) {
|
|
558
|
-
readyWhenElement.found = true;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
588
|
+
function isReady(readyWhenStatus) {
|
|
562
589
|
return readyWhenStatus.every((readyWhenElement) => readyWhenElement.found);
|
|
563
590
|
}
|
|
591
|
+
// The output as printed, kept across chunks, matches strings that hold escape
|
|
592
|
+
// sequences. LogMatcher, absent from the WASM binding, matches text with
|
|
593
|
+
// escapes inside it.
|
|
594
|
+
function readyWhenMatcher(readyWhenStatus) {
|
|
595
|
+
const matchers = readyWhenStatus.map((status) => ({
|
|
596
|
+
status,
|
|
597
|
+
matcher: native_1.IS_WASM ? null : new native_1.LogMatcher([status.stringToMatch]),
|
|
598
|
+
tail: '',
|
|
599
|
+
}));
|
|
600
|
+
return (chunk) => {
|
|
601
|
+
for (const entry of matchers) {
|
|
602
|
+
const { status, matcher } = entry;
|
|
603
|
+
if (status.found)
|
|
604
|
+
continue;
|
|
605
|
+
const printed = entry.tail + chunk;
|
|
606
|
+
status.found =
|
|
607
|
+
printed.includes(status.stringToMatch) || !!matcher?.feed(chunk);
|
|
608
|
+
entry.tail = printed.slice(Math.max(0, printed.length - status.stringToMatch.length + 1));
|
|
609
|
+
}
|
|
610
|
+
return isReady(readyWhenStatus);
|
|
611
|
+
};
|
|
612
|
+
}
|
|
564
613
|
function loadEnvVarsFile(path, env = {}) {
|
|
565
614
|
(0, task_env_1.unloadDotEnvFile)(path, env);
|
|
566
615
|
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" } }
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"type": "string"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"description": "Extra arguments. You can pass them as follows: nx run project:target --args='--wait=100'. You can then use {args.wait} syntax to interpolate them in the workspace config file. See example [above](#
|
|
144
|
+
"description": "Extra arguments. You can pass them as follows: nx run project:target --args='--wait=100'. You can then use {args.wait} syntax to interpolate them in the workspace config file. See example [above](#interpolating-args)"
|
|
145
145
|
},
|
|
146
146
|
"envFile": {
|
|
147
147
|
"type": "string",
|
package/dist/src/native/index.js
CHANGED
|
@@ -77,10 +77,6 @@ function removeIfPresent(path) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function isNoExecError(e) {
|
|
81
|
-
return e.code === 'EACCES' || e.code === 'EPERM';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
80
|
// We override the _load function so that when a native file is required,
|
|
85
81
|
// we copy it to a cache directory and require it from there.
|
|
86
82
|
// This prevents the file being loaded from node_modules and causing file locking issues.
|
|
@@ -135,17 +131,24 @@ Module._load = function (request, parent, isMain) {
|
|
|
135
131
|
existingFileStats?.size === expectedFileSize &&
|
|
136
132
|
existingFileStats.mtimeMs >= sourceStats.mtimeMs;
|
|
137
133
|
|
|
138
|
-
|
|
139
|
-
if (isFresh) {
|
|
134
|
+
const loadFromCache = () => {
|
|
140
135
|
try {
|
|
141
136
|
return originalLoad.apply(this, [tmpFile, parent, isMain]);
|
|
142
137
|
} catch (e) {
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
if (
|
|
139
|
+
e.code === 'EACCES' ||
|
|
140
|
+
e.code === 'EPERM' ||
|
|
141
|
+
e.code === 'MODULE_NOT_FOUND' ||
|
|
142
|
+
e.code === 'ERR_DLOPEN_FAILED'
|
|
143
|
+
) {
|
|
145
144
|
return originalLoad.apply(this, [nativeLocation, parent, isMain]);
|
|
146
145
|
}
|
|
147
146
|
throw e;
|
|
148
147
|
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
if (isFresh) {
|
|
151
|
+
return loadFromCache();
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
// Retry copying up to 3 times, validating after each copy
|
|
@@ -177,15 +180,7 @@ Module._load = function (request, parent, isMain) {
|
|
|
177
180
|
removeIfPresent(tmpTmpFile);
|
|
178
181
|
break;
|
|
179
182
|
}
|
|
180
|
-
|
|
181
|
-
return originalLoad.apply(this, [tmpFile, parent, isMain]);
|
|
182
|
-
} catch (e) {
|
|
183
|
-
// If loading from cache fails due to noexec, fall back to original location
|
|
184
|
-
if (isNoExecError(e)) {
|
|
185
|
-
return originalLoad.apply(this, [nativeLocation, parent, isMain]);
|
|
186
|
-
}
|
|
187
|
-
throw e;
|
|
188
|
-
}
|
|
183
|
+
return loadFromCache();
|
|
189
184
|
}
|
|
190
185
|
|
|
191
186
|
// Copy failed validation, clean up the malformed file
|
|
Binary file
|
|
Binary file
|
|
@@ -27,6 +27,8 @@ export interface NxCloudClient {
|
|
|
27
27
|
}) => Promise<{
|
|
28
28
|
enabled: boolean;
|
|
29
29
|
}>;
|
|
30
|
+
/** Clients that dispatch a whole `nx-cloud` command line; resolves to the exit code. */
|
|
31
|
+
runCLI?: (args: string[]) => Promise<number>;
|
|
30
32
|
}
|
|
31
33
|
export declare function verifyOrUpdateNxCloudClient(options?: {
|
|
32
34
|
url?: string;
|
|
@@ -7,4 +7,5 @@ export declare class UnknownCommandError extends Error {
|
|
|
7
7
|
export declare function getCloudClient(options: CloudTaskRunnerOptions): Promise<{
|
|
8
8
|
invoke: (command: string, exit?: boolean) => Promise<void>;
|
|
9
9
|
availableCommands: string[];
|
|
10
|
+
runCLI: (args: string[]) => Promise<number>;
|
|
10
11
|
}>;
|
|
@@ -38,5 +38,10 @@ async function getCloudClient(options) {
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
availableCommands: Object.keys(nxCloudClient.commands),
|
|
41
|
+
// Bundles that export runCLI own dispatch, help, output and the exit code.
|
|
42
|
+
// Older bundles only export `commands`.
|
|
43
|
+
runCLI: typeof nxCloudClient.runCLI === 'function'
|
|
44
|
+
? (args) => nxCloudClient.runCLI(args)
|
|
45
|
+
: undefined,
|
|
41
46
|
};
|
|
42
47
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildExplicitDependencies = buildExplicitDependencies;
|
|
4
|
+
const installation_directory_1 = require("../../../../utils/installation-directory");
|
|
4
5
|
const explicit_package_json_dependencies_1 = require("./explicit-package-json-dependencies");
|
|
5
6
|
const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
|
|
6
7
|
const target_project_locator_1 = require("./target-project-locator");
|
|
@@ -24,7 +25,7 @@ function buildExplicitDependencies(jsPluginConfig, ctx) {
|
|
|
24
25
|
jsPluginConfig.analyzeSourceFiles === true) {
|
|
25
26
|
let tsExists = false;
|
|
26
27
|
try {
|
|
27
|
-
|
|
28
|
+
(0, installation_directory_1.resolveFromWorkspace)('typescript');
|
|
28
29
|
tsExists = true;
|
|
29
30
|
}
|
|
30
31
|
catch { }
|
|
@@ -25,6 +25,7 @@ exports.getTsNodeCompilerOptions = getTsNodeCompilerOptions;
|
|
|
25
25
|
const path_1 = require("path");
|
|
26
26
|
const fs_1 = require("fs");
|
|
27
27
|
const fileutils_1 = require("../../../utils/fileutils");
|
|
28
|
+
const installation_directory_1 = require("../../../utils/installation-directory");
|
|
28
29
|
const logger_1 = require("../../../utils/logger");
|
|
29
30
|
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
30
31
|
const typescript_1 = require("./typescript");
|
|
@@ -664,7 +665,7 @@ const registered = new Map();
|
|
|
664
665
|
function getTranspiler(compilerOptions, tsConfigRaw) {
|
|
665
666
|
const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true';
|
|
666
667
|
if (!ts) {
|
|
667
|
-
ts = require('typescript');
|
|
668
|
+
ts = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
668
669
|
}
|
|
669
670
|
compilerOptions.lib = ['es2021'];
|
|
670
671
|
compilerOptions.module = ts.ModuleKind.CommonJS;
|
|
@@ -1181,7 +1182,7 @@ function packageIsInstalled(m) {
|
|
|
1181
1182
|
*/
|
|
1182
1183
|
function getTsNodeCompilerOptions(compilerOptions) {
|
|
1183
1184
|
if (!ts) {
|
|
1184
|
-
ts = require('typescript');
|
|
1185
|
+
ts = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
1185
1186
|
}
|
|
1186
1187
|
const flagMap = {
|
|
1187
1188
|
module: 'ModuleKind',
|
|
@@ -10,6 +10,7 @@ exports.getRootTsConfigCustomConditions = getRootTsConfigCustomConditions;
|
|
|
10
10
|
exports.getRootTsConfigResolveExportsConditions = getRootTsConfigResolveExportsConditions;
|
|
11
11
|
exports.getPluginResolveConditionNodeArgs = getPluginResolveConditionNodeArgs;
|
|
12
12
|
exports.findNodes = findNodes;
|
|
13
|
+
const installation_directory_1 = require("../../../utils/installation-directory");
|
|
13
14
|
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
14
15
|
const fs_1 = require("fs");
|
|
15
16
|
const path_1 = require("path");
|
|
@@ -17,7 +18,7 @@ const normalizedAppRoot = workspace_root_1.workspaceRoot.replace(/\\/g, '/');
|
|
|
17
18
|
let tsModule;
|
|
18
19
|
function readTsConfig(tsConfigPath, sys) {
|
|
19
20
|
if (!tsModule) {
|
|
20
|
-
tsModule = require('typescript');
|
|
21
|
+
tsModule = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
21
22
|
}
|
|
22
23
|
sys ??= tsModule.sys;
|
|
23
24
|
const readResult = tsModule.readConfigFile(tsConfigPath, sys.readFile);
|
|
@@ -25,7 +26,7 @@ function readTsConfig(tsConfigPath, sys) {
|
|
|
25
26
|
}
|
|
26
27
|
function readTsConfigWithoutFiles(tsConfigPath) {
|
|
27
28
|
if (!tsModule) {
|
|
28
|
-
tsModule = require('typescript');
|
|
29
|
+
tsModule = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
29
30
|
}
|
|
30
31
|
// We only care about options, so we don't need to scan source files, and thus
|
|
31
32
|
// `readDirectory` is stubbed for performance.
|
|
@@ -59,13 +59,13 @@ async function retrieveProjectConfigurations(separatedPlugins, workspaceRoot, nx
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
|
|
62
|
-
const pluginsToLoad = nxJson?.plugins ?? [];
|
|
62
|
+
const pluginsToLoad = [...(nxJson?.plugins ?? [])];
|
|
63
63
|
if ((0, angular_json_1.shouldMergeAngularProjects)(workspaceRoot, true) &&
|
|
64
64
|
!pluginsToLoad.some((p) => p === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME ||
|
|
65
65
|
(typeof p === 'object' && p.plugin === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME))) {
|
|
66
66
|
pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
|
|
67
67
|
}
|
|
68
|
-
const separatedPlugins = await (0, get_plugins_1.getPluginsSeparated)(nxJson, workspaceRoot);
|
|
68
|
+
const separatedPlugins = await (0, get_plugins_1.getPluginsSeparated)({ ...nxJson, plugins: pluginsToLoad }, workspaceRoot);
|
|
69
69
|
const res = await retrieveProjectConfigurations(separatedPlugins, workspaceRoot, nxJson);
|
|
70
70
|
return res;
|
|
71
71
|
}
|