nx 21.0.0 → 21.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.
- package/package.json +11 -11
- package/src/command-line/release/release.js +6 -1
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/styles.js +1 -1
- package/src/executors/run-commands/running-tasks.js +1 -1
- package/src/executors/run-script/run-script.impl.js +16 -1
- package/src/native/index.d.ts +1 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/tasks-runner/forked-process-task-runner.d.ts +1 -0
- package/src/tasks-runner/forked-process-task-runner.js +15 -12
- package/src/tasks-runner/life-cycle.d.ts +2 -2
- package/src/tasks-runner/life-cycle.js +2 -2
- package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +23 -9
- package/src/tasks-runner/task-orchestrator.js +9 -2
package/src/core/graph/styles.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[869],{
|
1
|
+
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[869],{2259:()=>{}},s=>{var e;e=2259,s(s.s=e)}]);
|
@@ -231,7 +231,7 @@ class RunningNodeProcess {
|
|
231
231
|
}
|
232
232
|
kill(signal) {
|
233
233
|
return new Promise((res, rej) => {
|
234
|
-
if (process.platform === 'win32'
|
234
|
+
if (process.platform === 'win32') {
|
235
235
|
if (this.childProcess.kill(signal)) {
|
236
236
|
res();
|
237
237
|
}
|
@@ -5,6 +5,7 @@ const child_process_1 = require("child_process");
|
|
5
5
|
const path = require("path");
|
6
6
|
const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
|
7
7
|
const package_manager_1 = require("../../utils/package-manager");
|
8
|
+
const exit_codes_1 = require("../../utils/exit-codes");
|
8
9
|
async function default_1(options, context) {
|
9
10
|
const pm = (0, package_manager_1.getPackageManagerCommand)();
|
10
11
|
try {
|
@@ -38,11 +39,12 @@ function nodeProcess(command, cwd, env) {
|
|
38
39
|
windowsHide: false,
|
39
40
|
});
|
40
41
|
}
|
42
|
+
let cp;
|
41
43
|
async function ptyProcess(command, cwd, env) {
|
42
44
|
const terminal = (0, pseudo_terminal_1.createPseudoTerminal)();
|
43
45
|
await terminal.init();
|
44
46
|
return new Promise((res, rej) => {
|
45
|
-
|
47
|
+
cp = terminal.runCommand(command, { cwd, jsEnv: env });
|
46
48
|
cp.onExit((code) => {
|
47
49
|
if (code === 0) {
|
48
50
|
res();
|
@@ -56,3 +58,16 @@ async function ptyProcess(command, cwd, env) {
|
|
56
58
|
});
|
57
59
|
});
|
58
60
|
}
|
61
|
+
// TODO: This only works because pseudo terminal registers signal handlers first but we need a service to handle this
|
62
|
+
process.on('SIGHUP', () => {
|
63
|
+
cp.kill('SIGHUP');
|
64
|
+
process.exit((0, exit_codes_1.signalToCode)('SIGHUP'));
|
65
|
+
});
|
66
|
+
process.on('SIGTERM', () => {
|
67
|
+
cp.kill('SIGTERM');
|
68
|
+
process.exit((0, exit_codes_1.signalToCode)('SIGTERM'));
|
69
|
+
});
|
70
|
+
process.on('SIGINT', () => {
|
71
|
+
cp.kill('SIGINT');
|
72
|
+
process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
|
73
|
+
});
|
package/src/native/index.d.ts
CHANGED
@@ -18,7 +18,7 @@ export declare class AppLifeCycle {
|
|
18
18
|
__init(doneCallback: () => any): void
|
19
19
|
registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[ParserArc, WriterArc]>): void
|
20
20
|
registerRunningTaskWithEmptyParser(taskId: string): void
|
21
|
-
appendTaskOutput(taskId: string, output: string): void
|
21
|
+
appendTaskOutput(taskId: string, output: string, isPtyOutput: boolean): void
|
22
22
|
setTaskStatus(taskId: string, status: TaskStatus): void
|
23
23
|
registerForcedShutdownCallback(forcedShutdownCallback: () => any): void
|
24
24
|
__setCloudMessage(message: string): Promise<void>
|
Binary file
|
@@ -136,7 +136,7 @@ class ForkedProcessTaskRunner {
|
|
136
136
|
terminalOutput += msg;
|
137
137
|
});
|
138
138
|
p.onExit((code) => {
|
139
|
-
if (code > 128) {
|
139
|
+
if (!this.tuiEnabled && code > 128) {
|
140
140
|
process.exit(code);
|
141
141
|
}
|
142
142
|
this.pseudoTerminals.delete(pseudoTerminal);
|
@@ -233,6 +233,12 @@ class ForkedProcessTaskRunner {
|
|
233
233
|
writeTerminalOutput(outputPath, content) {
|
234
234
|
(0, fs_1.writeFileSync)(outputPath, content);
|
235
235
|
}
|
236
|
+
cleanup(signal) {
|
237
|
+
this.processes.forEach((p) => {
|
238
|
+
p.kill(signal);
|
239
|
+
});
|
240
|
+
this.cleanUpBatchProcesses();
|
241
|
+
}
|
236
242
|
setupProcessEventListeners() {
|
237
243
|
const messageHandler = (message) => {
|
238
244
|
this.pseudoTerminals.forEach((p) => {
|
@@ -246,29 +252,26 @@ class ForkedProcessTaskRunner {
|
|
246
252
|
};
|
247
253
|
// When the nx process gets a message, it will be sent into the task's process
|
248
254
|
process.on('message', messageHandler);
|
249
|
-
const cleanUp = (signal) => {
|
250
|
-
this.processes.forEach((p) => {
|
251
|
-
p.kill(signal);
|
252
|
-
});
|
253
|
-
process.off('message', messageHandler);
|
254
|
-
this.cleanUpBatchProcesses();
|
255
|
-
};
|
256
255
|
// Terminate any task processes on exit
|
257
256
|
process.once('exit', () => {
|
258
|
-
|
257
|
+
this.cleanup();
|
258
|
+
process.off('message', messageHandler);
|
259
259
|
});
|
260
260
|
process.once('SIGINT', () => {
|
261
|
-
|
261
|
+
this.cleanup('SIGTERM');
|
262
|
+
process.off('message', messageHandler);
|
262
263
|
// we exit here because we don't need to write anything to cache.
|
263
264
|
process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
|
264
265
|
});
|
265
266
|
process.once('SIGTERM', () => {
|
266
|
-
|
267
|
+
this.cleanup('SIGTERM');
|
268
|
+
process.off('message', messageHandler);
|
267
269
|
// no exit here because we expect child processes to terminate which
|
268
270
|
// will store results to the cache and will terminate this process
|
269
271
|
});
|
270
272
|
process.once('SIGHUP', () => {
|
271
|
-
|
273
|
+
this.cleanup('SIGTERM');
|
274
|
+
process.off('message', messageHandler);
|
272
275
|
// no exit here because we expect child processes to terminate which
|
273
276
|
// will store results to the cache and will terminate this process
|
274
277
|
});
|
@@ -38,7 +38,7 @@ export interface LifeCycle {
|
|
38
38
|
printTaskTerminalOutput?(task: Task, status: TaskStatus, output: string): void;
|
39
39
|
registerRunningTask?(taskId: string, parserAndWriter: ExternalObject<[any, any]>): void;
|
40
40
|
registerRunningTaskWithEmptyParser?(taskId: string): void;
|
41
|
-
appendTaskOutput?(taskId: string, output: string): void;
|
41
|
+
appendTaskOutput?(taskId: string, output: string, isPtyTask: boolean): void;
|
42
42
|
setTaskStatus?(taskId: string, status: NativeTaskStatus): void;
|
43
43
|
registerForcedShutdownCallback?(callback: () => void): void;
|
44
44
|
}
|
@@ -55,7 +55,7 @@ export declare class CompositeLifeCycle implements LifeCycle {
|
|
55
55
|
printTaskTerminalOutput(task: Task, status: TaskStatus, output: string): void;
|
56
56
|
registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[any, any]>): void;
|
57
57
|
registerRunningTaskWithEmptyParser(taskId: string): void;
|
58
|
-
appendTaskOutput(taskId: string, output: string): void;
|
58
|
+
appendTaskOutput(taskId: string, output: string, isPtyTask: boolean): void;
|
59
59
|
setTaskStatus(taskId: string, status: NativeTaskStatus): void;
|
60
60
|
registerForcedShutdownCallback(callback: () => void): void;
|
61
61
|
}
|
@@ -81,10 +81,10 @@ class CompositeLifeCycle {
|
|
81
81
|
}
|
82
82
|
}
|
83
83
|
}
|
84
|
-
appendTaskOutput(taskId, output) {
|
84
|
+
appendTaskOutput(taskId, output, isPtyTask) {
|
85
85
|
for (let l of this.lifeCycles) {
|
86
86
|
if (l.appendTaskOutput) {
|
87
|
-
l.appendTaskOutput(taskId, output);
|
87
|
+
l.appendTaskOutput(taskId, output, isPtyTask);
|
88
88
|
}
|
89
89
|
}
|
90
90
|
}
|
@@ -26,15 +26,21 @@ function getTuiTerminalSummaryLifeCycle({ projectNames, tasks, taskGraph, args,
|
|
26
26
|
const inProgressTasks = new Set();
|
27
27
|
const stoppedTasks = new Set();
|
28
28
|
const tasksToTerminalOutputs = {};
|
29
|
-
const
|
29
|
+
const tasksToTaskStatus = {};
|
30
|
+
const taskIdsInTheOrderTheyStart = [];
|
30
31
|
lifeCycle.startTasks = (tasks) => {
|
31
32
|
for (let t of tasks) {
|
33
|
+
tasksToTerminalOutputs[t.id] ??= '';
|
34
|
+
taskIdsInTheOrderTheyStart.push(t.id);
|
32
35
|
inProgressTasks.add(t.id);
|
33
36
|
}
|
34
37
|
};
|
35
|
-
lifeCycle.
|
36
|
-
|
37
|
-
|
38
|
+
lifeCycle.appendTaskOutput = (taskId, output) => {
|
39
|
+
tasksToTerminalOutputs[taskId] += output;
|
40
|
+
};
|
41
|
+
// TODO(@AgentEnder): The following 2 methods should be one but will need more refactoring
|
42
|
+
lifeCycle.printTaskTerminalOutput = (task, taskStatus) => {
|
43
|
+
tasksToTaskStatus[task.id] = taskStatus;
|
38
44
|
};
|
39
45
|
lifeCycle.setTaskStatus = (taskId, taskStatus) => {
|
40
46
|
if (taskStatus === 9 /* NativeTaskStatus.Stopped */) {
|
@@ -103,8 +109,9 @@ function getTuiTerminalSummaryLifeCycle({ projectNames, tasks, taskGraph, args,
|
|
103
109
|
let lines = [];
|
104
110
|
// Prints task outputs in the order they were completed
|
105
111
|
// above the summary, since run-one should print all task results.
|
106
|
-
for (const taskId of
|
107
|
-
const
|
112
|
+
for (const taskId of taskIdsInTheOrderTheyStart) {
|
113
|
+
const taskStatus = tasksToTaskStatus[taskId];
|
114
|
+
const terminalOutput = tasksToTerminalOutputs[taskId];
|
108
115
|
output_1.output.logCommandOutput(taskId, taskStatus, terminalOutput);
|
109
116
|
}
|
110
117
|
lines.push(...output_1.output.getVerticalSeparatorLines(failure ? 'red' : 'green'));
|
@@ -157,9 +164,16 @@ function getTuiTerminalSummaryLifeCycle({ projectNames, tasks, taskGraph, args,
|
|
157
164
|
const printRunManySummary = ({ failure, cancelled, }) => {
|
158
165
|
console.log('');
|
159
166
|
const lines = [''];
|
160
|
-
for (const taskId of
|
161
|
-
const
|
162
|
-
|
167
|
+
for (const taskId of taskIdsInTheOrderTheyStart) {
|
168
|
+
const taskStatus = tasksToTaskStatus[taskId];
|
169
|
+
const terminalOutput = tasksToTerminalOutputs[taskId];
|
170
|
+
// Task Status is null?
|
171
|
+
if (!taskStatus) {
|
172
|
+
output_1.output.logCommandOutput(taskId, taskStatus, terminalOutput);
|
173
|
+
output_1.output.addNewline();
|
174
|
+
lines.push(`${LEFT_PAD}${output_1.output.colors.cyan(figures.squareSmallFilled)}${SPACER}${output_1.output.colors.gray('nx run ')}${taskId}`);
|
175
|
+
}
|
176
|
+
else if (taskStatus === 'failure') {
|
163
177
|
output_1.output.logCommandOutput(taskId, taskStatus, terminalOutput);
|
164
178
|
output_1.output.addNewline();
|
165
179
|
lines.push(`${LEFT_PAD}${output_1.output.colors.red(figures.cross)}${SPACER}${output_1.output.colors.gray('nx run ')}${taskId}`);
|
@@ -333,11 +333,14 @@ class TaskOrchestrator {
|
|
333
333
|
if (runningTask instanceof pseudo_terminal_1.PseudoTtyProcess) {
|
334
334
|
// This is an external of a the pseudo terminal where a task is running and can be passed to the TUI
|
335
335
|
this.options.lifeCycle.registerRunningTask(task.id, runningTask.getParserAndWriter());
|
336
|
+
runningTask.onOutput((output) => {
|
337
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output, true);
|
338
|
+
});
|
336
339
|
}
|
337
340
|
else {
|
338
341
|
this.options.lifeCycle.registerRunningTaskWithEmptyParser(task.id);
|
339
342
|
runningTask.onOutput((output) => {
|
340
|
-
this.options.lifeCycle.appendTaskOutput(task.id, output);
|
343
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output, false);
|
341
344
|
});
|
342
345
|
}
|
343
346
|
}
|
@@ -391,11 +394,14 @@ class TaskOrchestrator {
|
|
391
394
|
if (runningTask instanceof pseudo_terminal_1.PseudoTtyProcess) {
|
392
395
|
// This is an external of a the pseudo terminal where a task is running and can be passed to the TUI
|
393
396
|
this.options.lifeCycle.registerRunningTask(task.id, runningTask.getParserAndWriter());
|
397
|
+
runningTask.onOutput((output) => {
|
398
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output, true);
|
399
|
+
});
|
394
400
|
}
|
395
401
|
else if ('onOutput' in runningTask) {
|
396
402
|
this.options.lifeCycle.registerRunningTaskWithEmptyParser(task.id);
|
397
403
|
runningTask.onOutput((output) => {
|
398
|
-
this.options.lifeCycle.appendTaskOutput(task.id, output);
|
404
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output, false);
|
399
405
|
});
|
400
406
|
}
|
401
407
|
}
|
@@ -645,6 +651,7 @@ class TaskOrchestrator {
|
|
645
651
|
}
|
646
652
|
// endregion utils
|
647
653
|
async cleanup() {
|
654
|
+
this.forkedProcessTaskRunner.cleanup();
|
648
655
|
await Promise.all([
|
649
656
|
...Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
|
650
657
|
try {
|