nx 21.0.0-beta.0 → 21.0.0-canary.20250205-45d5140
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 -12
- package/src/command-line/graph/graph.js +0 -2
- package/src/commands-runner/get-command-projects.js +2 -17
- package/src/config/task-graph.d.ts +0 -5
- package/src/config/workspace-json-project-json.d.ts +0 -4
- package/src/executors/run-commands/run-commands.impl.d.ts +13 -16
- package/src/executors/run-commands/run-commands.impl.js +263 -24
- package/src/native/index.d.ts +0 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/tasks-runner/create-task-graph.d.ts +0 -3
- package/src/tasks-runner/create-task-graph.js +5 -36
- package/src/tasks-runner/forked-process-task-runner.d.ts +12 -6
- package/src/tasks-runner/forked-process-task-runner.js +263 -110
- package/src/tasks-runner/init-tasks-runner.js +0 -4
- package/src/tasks-runner/pseudo-terminal.d.ts +1 -7
- package/src/tasks-runner/pseudo-terminal.js +12 -26
- package/src/tasks-runner/task-orchestrator.d.ts +1 -7
- package/src/tasks-runner/task-orchestrator.js +82 -137
- package/src/tasks-runner/tasks-schedule.js +1 -5
- package/src/tasks-runner/utils.d.ts +8 -0
- package/src/tasks-runner/utils.js +4 -12
- package/src/executors/run-commands/running-tasks.d.ts +0 -38
- package/src/executors/run-commands/running-tasks.js +0 -349
- package/src/tasks-runner/running-tasks/batch-process.d.ts +0 -14
- package/src/tasks-runner/running-tasks/batch-process.js +0 -70
- package/src/tasks-runner/running-tasks/node-child-process.d.ts +0 -36
- package/src/tasks-runner/running-tasks/node-child-process.js +0 -184
- package/src/tasks-runner/running-tasks/noop-child-process.d.ts +0 -15
- package/src/tasks-runner/running-tasks/noop-child-process.js +0 -19
- package/src/tasks-runner/running-tasks/running-task.d.ts +0 -8
- package/src/tasks-runner/running-tasks/running-task.js +0 -6
@@ -1,9 +1,7 @@
|
|
1
1
|
import { DefaultTasksRunnerOptions } from './default-tasks-runner';
|
2
2
|
import { Batch } from './tasks-schedule';
|
3
|
+
import { BatchResults } from './batch/batch-messages';
|
3
4
|
import { Task, TaskGraph } from '../config/task-graph';
|
4
|
-
import { PseudoTtyProcess } from './pseudo-terminal';
|
5
|
-
import { BatchProcess } from './running-tasks/batch-process';
|
6
|
-
import { RunningTask } from './running-tasks/running-task';
|
7
5
|
export declare class ForkedProcessTaskRunner {
|
8
6
|
private readonly options;
|
9
7
|
cliPath: string;
|
@@ -12,14 +10,17 @@ export declare class ForkedProcessTaskRunner {
|
|
12
10
|
private pseudoTerminal;
|
13
11
|
constructor(options: DefaultTasksRunnerOptions);
|
14
12
|
init(): Promise<void>;
|
15
|
-
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }: Batch, fullTaskGraph: TaskGraph, env: NodeJS.ProcessEnv): Promise<
|
13
|
+
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }: Batch, fullTaskGraph: TaskGraph, env: NodeJS.ProcessEnv): Promise<BatchResults>;
|
16
14
|
forkProcessLegacy(task: Task, { temporaryOutputPath, streamOutput, pipeOutput, taskGraph, env, }: {
|
17
15
|
temporaryOutputPath: string;
|
18
16
|
streamOutput: boolean;
|
19
17
|
pipeOutput: boolean;
|
20
18
|
taskGraph: TaskGraph;
|
21
19
|
env: NodeJS.ProcessEnv;
|
22
|
-
}): Promise<
|
20
|
+
}): Promise<{
|
21
|
+
code: number;
|
22
|
+
terminalOutput: string;
|
23
|
+
}>;
|
23
24
|
forkProcess(task: Task, { temporaryOutputPath, streamOutput, taskGraph, env, disablePseudoTerminal, }: {
|
24
25
|
temporaryOutputPath: string;
|
25
26
|
streamOutput: boolean;
|
@@ -27,10 +28,15 @@ export declare class ForkedProcessTaskRunner {
|
|
27
28
|
taskGraph: TaskGraph;
|
28
29
|
env: NodeJS.ProcessEnv;
|
29
30
|
disablePseudoTerminal: boolean;
|
30
|
-
}): Promise<
|
31
|
+
}): Promise<{
|
32
|
+
code: number;
|
33
|
+
terminalOutput: string;
|
34
|
+
}>;
|
31
35
|
private forkProcessWithPseudoTerminal;
|
36
|
+
private forkProcessPipeOutputCapture;
|
32
37
|
private forkProcessWithPrefixAndNotTTY;
|
33
38
|
private forkProcessDirectOutputCapture;
|
39
|
+
private readTerminalOutput;
|
34
40
|
private writeTerminalOutput;
|
35
41
|
private setupProcessEventListeners;
|
36
42
|
}
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForkedProcessTaskRunner = void 0;
|
4
4
|
const fs_1 = require("fs");
|
5
5
|
const child_process_1 = require("child_process");
|
6
|
+
const chalk = require("chalk");
|
6
7
|
const output_1 = require("../utils/output");
|
7
8
|
const utils_1 = require("./utils");
|
8
9
|
const path_1 = require("path");
|
9
10
|
const batch_messages_1 = require("./batch/batch-messages");
|
10
11
|
const strip_indents_1 = require("../utils/strip-indents");
|
12
|
+
const stream_1 = require("stream");
|
11
13
|
const pseudo_terminal_1 = require("./pseudo-terminal");
|
12
14
|
const exit_codes_1 = require("../utils/exit-codes");
|
13
|
-
const node_child_process_1 = require("./running-tasks/node-child-process");
|
14
|
-
const batch_process_1 = require("./running-tasks/batch-process");
|
15
15
|
const forkScript = (0, path_1.join)(__dirname, './fork.js');
|
16
16
|
const workerPath = (0, path_1.join)(__dirname, './batch/run-batch.js');
|
17
17
|
class ForkedProcessTaskRunner {
|
@@ -31,42 +31,76 @@ class ForkedProcessTaskRunner {
|
|
31
31
|
this.setupProcessEventListeners();
|
32
32
|
}
|
33
33
|
// TODO: vsavkin delegate terminal output printing
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
34
|
+
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }, fullTaskGraph, env) {
|
35
|
+
return new Promise((res, rej) => {
|
36
|
+
try {
|
37
|
+
const count = Object.keys(batchTaskGraph.tasks).length;
|
38
|
+
if (count > 1) {
|
39
|
+
output_1.output.logSingleLine(`Running ${output_1.output.bold(count)} ${output_1.output.bold('tasks')} with ${output_1.output.bold(executorName)}`);
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
const args = (0, utils_1.getPrintableCommandArgsForTask)(Object.values(batchTaskGraph.tasks)[0]);
|
43
|
+
output_1.output.logCommand(args.join(' '));
|
44
|
+
}
|
45
|
+
const p = (0, child_process_1.fork)(workerPath, {
|
46
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
47
|
+
env,
|
48
|
+
});
|
49
|
+
this.processes.add(p);
|
50
|
+
p.once('exit', (code, signal) => {
|
51
|
+
this.processes.delete(p);
|
52
|
+
if (code === null)
|
53
|
+
code = (0, exit_codes_1.signalToCode)(signal);
|
54
|
+
if (code !== 0) {
|
55
|
+
const results = {};
|
56
|
+
for (const rootTaskId of batchTaskGraph.roots) {
|
57
|
+
results[rootTaskId] = {
|
58
|
+
success: false,
|
59
|
+
terminalOutput: '',
|
60
|
+
};
|
61
|
+
}
|
62
|
+
rej(new Error(`"${executorName}" exited unexpectedly with code: ${code}`));
|
63
|
+
}
|
64
|
+
});
|
65
|
+
p.on('message', (message) => {
|
66
|
+
switch (message.type) {
|
67
|
+
case batch_messages_1.BatchMessageType.CompleteBatchExecution: {
|
68
|
+
res(message.results);
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
case batch_messages_1.BatchMessageType.RunTasks: {
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
default: {
|
75
|
+
// Re-emit any non-batch messages from the task process
|
76
|
+
if (process.send) {
|
77
|
+
process.send(message);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
});
|
82
|
+
// Start the tasks
|
83
|
+
p.send({
|
84
|
+
type: batch_messages_1.BatchMessageType.RunTasks,
|
85
|
+
executorName,
|
86
|
+
batchTaskGraph,
|
87
|
+
fullTaskGraph,
|
88
|
+
});
|
89
|
+
}
|
90
|
+
catch (e) {
|
91
|
+
rej(e);
|
92
|
+
}
|
58
93
|
});
|
59
|
-
return cp;
|
60
94
|
}
|
61
95
|
async forkProcessLegacy(task, { temporaryOutputPath, streamOutput, pipeOutput, taskGraph, env, }) {
|
62
96
|
return pipeOutput
|
63
|
-
? this.
|
97
|
+
? await this.forkProcessPipeOutputCapture(task, {
|
64
98
|
temporaryOutputPath,
|
65
99
|
streamOutput,
|
66
100
|
taskGraph,
|
67
101
|
env,
|
68
102
|
})
|
69
|
-
: this.forkProcessDirectOutputCapture(task, {
|
103
|
+
: await this.forkProcessDirectOutputCapture(task, {
|
70
104
|
temporaryOutputPath,
|
71
105
|
streamOutput,
|
72
106
|
taskGraph,
|
@@ -120,96 +154,158 @@ class ForkedProcessTaskRunner {
|
|
120
154
|
p.onOutput((msg) => {
|
121
155
|
terminalOutput += msg;
|
122
156
|
});
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
this.writeTerminalOutput(temporaryOutputPath, terminalOutput);
|
129
|
-
});
|
130
|
-
return p;
|
131
|
-
}
|
132
|
-
forkProcessWithPrefixAndNotTTY(task, { streamOutput, temporaryOutputPath, taskGraph, env, }) {
|
133
|
-
try {
|
134
|
-
const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
|
135
|
-
if (streamOutput) {
|
136
|
-
output_1.output.logCommand(args.join(' '));
|
137
|
-
}
|
138
|
-
const p = (0, child_process_1.fork)(this.cliPath, {
|
139
|
-
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
140
|
-
env,
|
141
|
-
});
|
142
|
-
// Send message to run the executor
|
143
|
-
p.send({
|
144
|
-
targetDescription: task.target,
|
145
|
-
overrides: task.overrides,
|
146
|
-
taskGraph,
|
147
|
-
isVerbose: this.verbose,
|
148
|
-
});
|
149
|
-
const cp = new node_child_process_1.NodeChildProcessWithNonDirectOutput(p, {
|
150
|
-
streamOutput,
|
151
|
-
prefix: task.target.project,
|
152
|
-
});
|
153
|
-
this.processes.add(cp);
|
154
|
-
cp.onExit((code, terminalOutput) => {
|
155
|
-
this.processes.delete(cp);
|
156
|
-
if (!streamOutput) {
|
157
|
-
this.options.lifeCycle.printTaskTerminalOutput(task, code === 0 ? 'success' : 'failure', terminalOutput);
|
157
|
+
return new Promise((res) => {
|
158
|
+
p.onExit((code) => {
|
159
|
+
// If the exit code is greater than 128, it's a special exit code for a signal
|
160
|
+
if (code >= 128) {
|
161
|
+
process.exit(code);
|
158
162
|
}
|
159
163
|
this.writeTerminalOutput(temporaryOutputPath, terminalOutput);
|
164
|
+
res({
|
165
|
+
code,
|
166
|
+
terminalOutput,
|
167
|
+
});
|
160
168
|
});
|
161
|
-
|
162
|
-
}
|
163
|
-
catch (e) {
|
164
|
-
console.error(e);
|
165
|
-
throw e;
|
166
|
-
}
|
169
|
+
});
|
167
170
|
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
171
|
+
forkProcessPipeOutputCapture(task, { streamOutput, temporaryOutputPath, taskGraph, env, }) {
|
172
|
+
return this.forkProcessWithPrefixAndNotTTY(task, {
|
173
|
+
streamOutput,
|
174
|
+
temporaryOutputPath,
|
175
|
+
taskGraph,
|
176
|
+
env,
|
177
|
+
});
|
178
|
+
}
|
179
|
+
forkProcessWithPrefixAndNotTTY(task, { streamOutput, temporaryOutputPath, taskGraph, env, }) {
|
180
|
+
return new Promise((res, rej) => {
|
181
|
+
try {
|
182
|
+
const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
|
183
|
+
if (streamOutput) {
|
184
|
+
output_1.output.logCommand(args.join(' '));
|
185
|
+
}
|
186
|
+
const p = (0, child_process_1.fork)(this.cliPath, {
|
187
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
188
|
+
env,
|
189
|
+
});
|
190
|
+
this.processes.add(p);
|
191
|
+
// Re-emit any messages from the task process
|
192
|
+
p.on('message', (message) => {
|
193
|
+
if (process.send) {
|
194
|
+
process.send(message);
|
195
|
+
}
|
196
|
+
});
|
197
|
+
// Send message to run the executor
|
198
|
+
p.send({
|
199
|
+
targetDescription: task.target,
|
200
|
+
overrides: task.overrides,
|
201
|
+
taskGraph,
|
202
|
+
isVerbose: this.verbose,
|
203
|
+
});
|
204
|
+
if (streamOutput) {
|
205
|
+
if (process.env.NX_PREFIX_OUTPUT === 'true') {
|
206
|
+
const color = getColor(task.target.project);
|
207
|
+
const prefixText = `${task.target.project}:`;
|
208
|
+
p.stdout
|
209
|
+
.pipe(logClearLineToPrefixTransformer(color.bold(prefixText) + ' '))
|
210
|
+
.pipe(addPrefixTransformer(color.bold(prefixText)))
|
211
|
+
.pipe(process.stdout);
|
212
|
+
p.stderr
|
213
|
+
.pipe(logClearLineToPrefixTransformer(color(prefixText) + ' '))
|
214
|
+
.pipe(addPrefixTransformer(color(prefixText)))
|
215
|
+
.pipe(process.stderr);
|
216
|
+
}
|
217
|
+
else {
|
218
|
+
p.stdout.pipe(addPrefixTransformer()).pipe(process.stdout);
|
219
|
+
p.stderr.pipe(addPrefixTransformer()).pipe(process.stderr);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
let outWithErr = [];
|
223
|
+
p.stdout.on('data', (chunk) => {
|
224
|
+
outWithErr.push(chunk.toString());
|
225
|
+
});
|
226
|
+
p.stderr.on('data', (chunk) => {
|
227
|
+
outWithErr.push(chunk.toString());
|
228
|
+
});
|
229
|
+
p.on('exit', (code, signal) => {
|
230
|
+
this.processes.delete(p);
|
231
|
+
if (code === null)
|
232
|
+
code = (0, exit_codes_1.signalToCode)(signal);
|
233
|
+
// we didn't print any output as we were running the command
|
234
|
+
// print all the collected output|
|
235
|
+
const terminalOutput = outWithErr.join('');
|
193
236
|
if (!streamOutput) {
|
194
237
|
this.options.lifeCycle.printTaskTerminalOutput(task, code === 0 ? 'success' : 'failure', terminalOutput);
|
195
238
|
}
|
239
|
+
this.writeTerminalOutput(temporaryOutputPath, terminalOutput);
|
240
|
+
res({ code, terminalOutput });
|
241
|
+
});
|
242
|
+
}
|
243
|
+
catch (e) {
|
244
|
+
console.error(e);
|
245
|
+
rej(e);
|
246
|
+
}
|
247
|
+
});
|
248
|
+
}
|
249
|
+
forkProcessDirectOutputCapture(task, { streamOutput, temporaryOutputPath, taskGraph, env, }) {
|
250
|
+
return new Promise((res, rej) => {
|
251
|
+
try {
|
252
|
+
const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
|
253
|
+
if (streamOutput) {
|
254
|
+
output_1.output.logCommand(args.join(' '));
|
196
255
|
}
|
197
|
-
|
198
|
-
|
256
|
+
const p = (0, child_process_1.fork)(this.cliPath, {
|
257
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
258
|
+
env,
|
259
|
+
});
|
260
|
+
this.processes.add(p);
|
261
|
+
// Re-emit any messages from the task process
|
262
|
+
p.on('message', (message) => {
|
263
|
+
if (process.send) {
|
264
|
+
process.send(message);
|
265
|
+
}
|
266
|
+
});
|
267
|
+
// Send message to run the executor
|
268
|
+
p.send({
|
269
|
+
targetDescription: task.target,
|
270
|
+
overrides: task.overrides,
|
271
|
+
taskGraph,
|
272
|
+
isVerbose: this.verbose,
|
273
|
+
});
|
274
|
+
p.on('exit', (code, signal) => {
|
275
|
+
if (code === null)
|
276
|
+
code = (0, exit_codes_1.signalToCode)(signal);
|
277
|
+
// we didn't print any output as we were running the command
|
278
|
+
// print all the collected output
|
279
|
+
let terminalOutput = '';
|
280
|
+
try {
|
281
|
+
terminalOutput = this.readTerminalOutput(temporaryOutputPath);
|
282
|
+
if (!streamOutput) {
|
283
|
+
this.options.lifeCycle.printTaskTerminalOutput(task, code === 0 ? 'success' : 'failure', terminalOutput);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
catch (e) {
|
287
|
+
console.log((0, strip_indents_1.stripIndents) `
|
199
288
|
Unable to print terminal output for Task "${task.id}".
|
200
289
|
Task failed with Exit Code ${code} and Signal "${signal}".
|
201
290
|
|
202
291
|
Received error message:
|
203
292
|
${e.message}
|
204
293
|
`);
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
294
|
+
}
|
295
|
+
res({
|
296
|
+
code,
|
297
|
+
terminalOutput,
|
298
|
+
});
|
299
|
+
});
|
300
|
+
}
|
301
|
+
catch (e) {
|
302
|
+
console.error(e);
|
303
|
+
rej(e);
|
304
|
+
}
|
305
|
+
});
|
306
|
+
}
|
307
|
+
readTerminalOutput(outputPath) {
|
308
|
+
return (0, fs_1.readFileSync)(outputPath).toString();
|
213
309
|
}
|
214
310
|
writeTerminalOutput(outputPath, content) {
|
215
311
|
(0, fs_1.writeFileSync)(outputPath, content);
|
@@ -222,11 +318,12 @@ class ForkedProcessTaskRunner {
|
|
222
318
|
}
|
223
319
|
// When the nx process gets a message, it will be sent into the task's process
|
224
320
|
process.on('message', (message) => {
|
321
|
+
// this.publisher.publish(message.toString());
|
225
322
|
if (this.pseudoTerminal) {
|
226
323
|
this.pseudoTerminal.sendMessageToChildren(message);
|
227
324
|
}
|
228
325
|
this.processes.forEach((p) => {
|
229
|
-
if ('
|
326
|
+
if ('connected' in p && p.connected) {
|
230
327
|
p.send(message);
|
231
328
|
}
|
232
329
|
});
|
@@ -234,26 +331,34 @@ class ForkedProcessTaskRunner {
|
|
234
331
|
// Terminate any task processes on exit
|
235
332
|
process.on('exit', () => {
|
236
333
|
this.processes.forEach((p) => {
|
237
|
-
p.
|
334
|
+
if ('connected' in p ? p.connected : p.isAlive) {
|
335
|
+
p.kill();
|
336
|
+
}
|
238
337
|
});
|
239
338
|
});
|
240
339
|
process.on('SIGINT', () => {
|
241
340
|
this.processes.forEach((p) => {
|
242
|
-
|
341
|
+
if ('connected' in p ? p.connected : p.isAlive) {
|
342
|
+
p.kill('SIGTERM');
|
343
|
+
}
|
243
344
|
});
|
244
345
|
// we exit here because we don't need to write anything to cache.
|
245
346
|
process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
|
246
347
|
});
|
247
348
|
process.on('SIGTERM', () => {
|
248
349
|
this.processes.forEach((p) => {
|
249
|
-
|
350
|
+
if ('connected' in p ? p.connected : p.isAlive) {
|
351
|
+
p.kill('SIGTERM');
|
352
|
+
}
|
250
353
|
});
|
251
354
|
// no exit here because we expect child processes to terminate which
|
252
355
|
// will store results to the cache and will terminate this process
|
253
356
|
});
|
254
357
|
process.on('SIGHUP', () => {
|
255
358
|
this.processes.forEach((p) => {
|
256
|
-
|
359
|
+
if ('connected' in p ? p.connected : p.isAlive) {
|
360
|
+
p.kill('SIGTERM');
|
361
|
+
}
|
257
362
|
});
|
258
363
|
// no exit here because we expect child processes to terminate which
|
259
364
|
// will store results to the cache and will terminate this process
|
@@ -261,3 +366,51 @@ class ForkedProcessTaskRunner {
|
|
261
366
|
}
|
262
367
|
}
|
263
368
|
exports.ForkedProcessTaskRunner = ForkedProcessTaskRunner;
|
369
|
+
const colors = [
|
370
|
+
chalk.green,
|
371
|
+
chalk.greenBright,
|
372
|
+
chalk.red,
|
373
|
+
chalk.redBright,
|
374
|
+
chalk.cyan,
|
375
|
+
chalk.cyanBright,
|
376
|
+
chalk.yellow,
|
377
|
+
chalk.yellowBright,
|
378
|
+
chalk.magenta,
|
379
|
+
chalk.magentaBright,
|
380
|
+
];
|
381
|
+
function getColor(projectName) {
|
382
|
+
let code = 0;
|
383
|
+
for (let i = 0; i < projectName.length; ++i) {
|
384
|
+
code += projectName.charCodeAt(i);
|
385
|
+
}
|
386
|
+
const colorIndex = code % colors.length;
|
387
|
+
return colors[colorIndex];
|
388
|
+
}
|
389
|
+
/**
|
390
|
+
* Prevents terminal escape sequence from clearing line prefix.
|
391
|
+
*/
|
392
|
+
function logClearLineToPrefixTransformer(prefix) {
|
393
|
+
let prevChunk = null;
|
394
|
+
return new stream_1.Transform({
|
395
|
+
transform(chunk, _encoding, callback) {
|
396
|
+
if (prevChunk && prevChunk.toString() === '\x1b[2K') {
|
397
|
+
chunk = chunk.toString().replace(/\x1b\[1G/g, (m) => m + prefix);
|
398
|
+
}
|
399
|
+
this.push(chunk);
|
400
|
+
prevChunk = chunk;
|
401
|
+
callback();
|
402
|
+
},
|
403
|
+
});
|
404
|
+
}
|
405
|
+
function addPrefixTransformer(prefix) {
|
406
|
+
const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';
|
407
|
+
return new stream_1.Transform({
|
408
|
+
transform(chunk, _encoding, callback) {
|
409
|
+
const list = chunk.toString().split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
|
410
|
+
list
|
411
|
+
.filter(Boolean)
|
412
|
+
.forEach((m) => this.push(prefix ? prefix + ' ' + m + newLineSeparator : m + newLineSeparator));
|
413
|
+
callback();
|
414
|
+
},
|
415
|
+
});
|
416
|
+
}
|
@@ -36,10 +36,6 @@ async function initTasksRunner(nxArgs) {
|
|
36
36
|
acc[task.id] = [];
|
37
37
|
return acc;
|
38
38
|
}, {}),
|
39
|
-
continuousDependencies: opts.tasks.reduce((acc, task) => {
|
40
|
-
acc[task.id] = [];
|
41
|
-
return acc;
|
42
|
-
}, {}),
|
43
39
|
};
|
44
40
|
const taskResults = await (0, run_command_1.invokeTasksRunner)({
|
45
41
|
tasks: opts.tasks,
|
@@ -31,14 +31,8 @@ export declare class PseudoTerminal {
|
|
31
31
|
export declare class PseudoTtyProcess {
|
32
32
|
private childProcess;
|
33
33
|
isAlive: boolean;
|
34
|
-
|
35
|
-
private outputCallbacks;
|
36
|
-
private terminalOutput;
|
34
|
+
exitCallbacks: any[];
|
37
35
|
constructor(childProcess: ChildProcess);
|
38
|
-
getResults(): Promise<{
|
39
|
-
code: number;
|
40
|
-
terminalOutput: string;
|
41
|
-
}>;
|
42
36
|
onExit(callback: (code: number) => void): void;
|
43
37
|
onOutput(callback: (message: string) => void): void;
|
44
38
|
kill(): void;
|
@@ -78,42 +78,28 @@ class PseudoTtyProcess {
|
|
78
78
|
this.childProcess = childProcess;
|
79
79
|
this.isAlive = true;
|
80
80
|
this.exitCallbacks = [];
|
81
|
-
this.outputCallbacks = [];
|
82
|
-
this.terminalOutput = '';
|
83
|
-
childProcess.onOutput((output) => {
|
84
|
-
this.terminalOutput += output;
|
85
|
-
this.outputCallbacks.forEach((cb) => cb(output));
|
86
|
-
});
|
87
81
|
childProcess.onExit((message) => {
|
88
82
|
this.isAlive = false;
|
89
|
-
const
|
90
|
-
|
91
|
-
this.exitCallbacks.forEach((cb) => cb(code));
|
92
|
-
});
|
93
|
-
}
|
94
|
-
async getResults() {
|
95
|
-
return new Promise((res) => {
|
96
|
-
this.onExit((code) => {
|
97
|
-
res({ code, terminalOutput: this.terminalOutput });
|
98
|
-
});
|
83
|
+
const exitCode = messageToCode(message);
|
84
|
+
this.exitCallbacks.forEach((cb) => cb(exitCode));
|
99
85
|
});
|
100
86
|
}
|
101
87
|
onExit(callback) {
|
102
88
|
this.exitCallbacks.push(callback);
|
103
89
|
}
|
104
90
|
onOutput(callback) {
|
105
|
-
this.
|
91
|
+
this.childProcess.onOutput(callback);
|
106
92
|
}
|
107
93
|
kill() {
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
94
|
+
try {
|
95
|
+
this.childProcess.kill();
|
96
|
+
}
|
97
|
+
catch {
|
98
|
+
// when the child process completes before we explicitly call kill, this will throw
|
99
|
+
// do nothing
|
100
|
+
}
|
101
|
+
finally {
|
102
|
+
if (this.isAlive == true) {
|
117
103
|
this.isAlive = false;
|
118
104
|
}
|
119
105
|
}
|
@@ -5,7 +5,6 @@ import { ProjectGraph } from '../config/project-graph';
|
|
5
5
|
import { TaskGraph } from '../config/task-graph';
|
6
6
|
import { DaemonClient } from '../daemon/client/client';
|
7
7
|
import { NxJsonConfiguration } from '../config/nx-json';
|
8
|
-
import { NxArgs } from '../utils/command-line-utils';
|
9
8
|
export declare class TaskOrchestrator {
|
10
9
|
private readonly hasher;
|
11
10
|
private readonly initiatingProject;
|
@@ -28,9 +27,7 @@ export declare class TaskOrchestrator {
|
|
28
27
|
private waitingForTasks;
|
29
28
|
private groups;
|
30
29
|
private bailed;
|
31
|
-
|
32
|
-
private cleaningUp;
|
33
|
-
constructor(hasher: TaskHasher, initiatingProject: string | undefined, projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: NxArgs & DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string);
|
30
|
+
constructor(hasher: TaskHasher, initiatingProject: string | undefined, projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string);
|
34
31
|
run(): Promise<{
|
35
32
|
[id: string]: TaskStatus;
|
36
33
|
}>;
|
@@ -43,9 +40,7 @@ export declare class TaskOrchestrator {
|
|
43
40
|
private applyFromCacheOrRunBatch;
|
44
41
|
private runBatch;
|
45
42
|
private applyFromCacheOrRunTask;
|
46
|
-
private runTask;
|
47
43
|
private runTaskInForkedProcess;
|
48
|
-
private startContinuousTask;
|
49
44
|
private preRunSteps;
|
50
45
|
private postRunSteps;
|
51
46
|
private complete;
|
@@ -55,5 +50,4 @@ export declare class TaskOrchestrator {
|
|
55
50
|
private openGroup;
|
56
51
|
private shouldCopyOutputsFromCache;
|
57
52
|
private recordOutputsHash;
|
58
|
-
private cleanup;
|
59
53
|
}
|