nx 21.0.0-beta.6 → 21.0.0-beta.7
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/init/configure-plugins.js +5 -3
- package/src/command-line/init/implementation/utils.d.ts +2 -1
- package/src/command-line/init/implementation/utils.js +2 -1
- package/src/command-line/init/init-v2.js +8 -7
- package/src/core/graph/main.js +1 -1
- package/src/executors/run-commands/run-commands.impl.d.ts +1 -2
- package/src/executors/run-commands/run-commands.impl.js +1 -1
- package/src/executors/run-commands/running-tasks.d.ts +5 -2
- package/src/executors/run-commands/running-tasks.js +42 -6
- package/src/native/index.d.ts +2 -0
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/tasks-runner/life-cycle.d.ts +4 -0
- package/src/tasks-runner/life-cycle.js +14 -0
- package/src/tasks-runner/running-tasks/running-task.d.ts +1 -0
- package/src/tasks-runner/task-orchestrator.js +22 -6
- package/src/tasks-runner/utils.js +2 -0
@@ -1,5 +1,4 @@
|
|
1
1
|
import { ExecutorContext } from '../../config/misc-interfaces';
|
2
|
-
import { PseudoTtyProcess } from '../../tasks-runner/pseudo-terminal';
|
3
2
|
import { ParallelRunningTasks, SeriallyRunningTasks } from './running-tasks';
|
4
3
|
export declare const LARGE_BUFFER: number;
|
5
4
|
export type Json = {
|
@@ -55,5 +54,5 @@ export default function (options: RunCommandsOptions, context: ExecutorContext):
|
|
55
54
|
success: boolean;
|
56
55
|
terminalOutput: string;
|
57
56
|
}>;
|
58
|
-
export declare function runCommands(options: RunCommandsOptions, context: ExecutorContext): Promise<PseudoTtyProcess | ParallelRunningTasks | SeriallyRunningTasks>;
|
57
|
+
export declare function runCommands(options: RunCommandsOptions, context: ExecutorContext): Promise<import("../../tasks-runner/pseudo-terminal").PseudoTtyProcess | ParallelRunningTasks | SeriallyRunningTasks>;
|
59
58
|
export declare function interpolateArgsIntoCommand(command: string, opts: Pick<NormalizedRunCommandsOptions, 'args' | 'parsedArgs' | '__unparsed__' | 'unknownOptions' | 'unparsedCommandArgs'>, forwardAllArgs: boolean): string;
|
@@ -57,7 +57,7 @@ async function runCommands(options, context) {
|
|
57
57
|
const runningTask = isSingleCommandAndCanUsePseudoTerminal
|
58
58
|
? await (0, running_tasks_1.runSingleCommandWithPseudoTerminal)(normalized, context)
|
59
59
|
: options.parallel
|
60
|
-
? new running_tasks_1.ParallelRunningTasks(normalized, context
|
60
|
+
? new running_tasks_1.ParallelRunningTasks(normalized, context)
|
61
61
|
: new running_tasks_1.SeriallyRunningTasks(normalized, context, tuiEnabled);
|
62
62
|
return runningTask;
|
63
63
|
}
|
@@ -4,16 +4,17 @@ import { PseudoTtyProcess } from '../../tasks-runner/pseudo-terminal';
|
|
4
4
|
import { RunningTask } from '../../tasks-runner/running-tasks/running-task';
|
5
5
|
import { NormalizedRunCommandsOptions } from './run-commands.impl';
|
6
6
|
export declare class ParallelRunningTasks implements RunningTask {
|
7
|
-
private readonly tuiEnabled;
|
8
7
|
private readonly childProcesses;
|
9
8
|
private readyWhenStatus;
|
10
9
|
private readonly streamOutput;
|
11
10
|
private exitCallbacks;
|
12
|
-
|
11
|
+
private outputCallbacks;
|
12
|
+
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext);
|
13
13
|
getResults(): Promise<{
|
14
14
|
code: number;
|
15
15
|
terminalOutput: string;
|
16
16
|
}>;
|
17
|
+
onOutput(cb: (terminalOutput: string) => void): void;
|
17
18
|
onExit(cb: (code: number, terminalOutput: string) => void): void;
|
18
19
|
send(message: Serializable): void;
|
19
20
|
kill(signal?: NodeJS.Signals | number): Promise<void>;
|
@@ -26,12 +27,14 @@ export declare class SeriallyRunningTasks implements RunningTask {
|
|
26
27
|
private exitCallbacks;
|
27
28
|
private code;
|
28
29
|
private error;
|
30
|
+
private outputCallbacks;
|
29
31
|
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext, tuiEnabled: boolean);
|
30
32
|
getResults(): Promise<{
|
31
33
|
code: number;
|
32
34
|
terminalOutput: string;
|
33
35
|
}>;
|
34
36
|
onExit(cb: (code: number, terminalOutput: string) => void): void;
|
37
|
+
onOutput(cb: (terminalOutput: string) => void): void;
|
35
38
|
send(message: Serializable): void;
|
36
39
|
kill(signal?: NodeJS.Signals | number): void | Promise<void>;
|
37
40
|
private run;
|
@@ -12,9 +12,9 @@ const task_env_1 = require("../../tasks-runner/task-env");
|
|
12
12
|
const exit_codes_1 = require("../../utils/exit-codes");
|
13
13
|
const run_commands_impl_1 = require("./run-commands.impl");
|
14
14
|
class ParallelRunningTasks {
|
15
|
-
constructor(options, context
|
16
|
-
this.tuiEnabled = tuiEnabled;
|
15
|
+
constructor(options, context) {
|
17
16
|
this.exitCallbacks = [];
|
17
|
+
this.outputCallbacks = [];
|
18
18
|
this.childProcesses = options.commands.map((commandConfig) => new RunningNodeProcess(commandConfig, options.color, calculateCwd(options.cwd, context), options.env ?? {}, options.readyWhenStatus, options.streamOutput, options.envFile));
|
19
19
|
this.readyWhenStatus = options.readyWhenStatus;
|
20
20
|
this.streamOutput = options.streamOutput;
|
@@ -27,6 +27,9 @@ class ParallelRunningTasks {
|
|
27
27
|
});
|
28
28
|
});
|
29
29
|
}
|
30
|
+
onOutput(cb) {
|
31
|
+
this.outputCallbacks.push(cb);
|
32
|
+
}
|
30
33
|
onExit(cb) {
|
31
34
|
this.exitCallbacks.push(cb);
|
32
35
|
}
|
@@ -48,6 +51,11 @@ class ParallelRunningTasks {
|
|
48
51
|
async run() {
|
49
52
|
if (this.readyWhenStatus.length) {
|
50
53
|
let { childProcess, result: { code, terminalOutput }, } = await Promise.race(this.childProcesses.map((childProcess) => new Promise((res) => {
|
54
|
+
childProcess.onOutput((terminalOutput) => {
|
55
|
+
for (const cb of this.outputCallbacks) {
|
56
|
+
cb(terminalOutput);
|
57
|
+
}
|
58
|
+
});
|
51
59
|
childProcess.onExit((code, terminalOutput) => {
|
52
60
|
res({
|
53
61
|
childProcess,
|
@@ -67,10 +75,18 @@ class ParallelRunningTasks {
|
|
67
75
|
}
|
68
76
|
}
|
69
77
|
else {
|
70
|
-
const results = await Promise.all(this.childProcesses.map((childProcess) =>
|
71
|
-
childProcess
|
72
|
-
|
73
|
-
|
78
|
+
const results = await Promise.all(this.childProcesses.map(async (childProcess) => {
|
79
|
+
childProcess.onOutput((terminalOutput) => {
|
80
|
+
for (const cb of this.outputCallbacks) {
|
81
|
+
cb(terminalOutput);
|
82
|
+
}
|
83
|
+
});
|
84
|
+
const result = await childProcess.getResults();
|
85
|
+
return {
|
86
|
+
childProcess,
|
87
|
+
result,
|
88
|
+
};
|
89
|
+
}));
|
74
90
|
let terminalOutput = results
|
75
91
|
.map((r) => r.result.terminalOutput)
|
76
92
|
.join('\r\n');
|
@@ -103,6 +119,7 @@ class SeriallyRunningTasks {
|
|
103
119
|
this.currentProcess = null;
|
104
120
|
this.exitCallbacks = [];
|
105
121
|
this.code = 0;
|
122
|
+
this.outputCallbacks = [];
|
106
123
|
this.run(options, context)
|
107
124
|
.catch((e) => {
|
108
125
|
this.error = e;
|
@@ -128,6 +145,9 @@ class SeriallyRunningTasks {
|
|
128
145
|
onExit(cb) {
|
129
146
|
this.exitCallbacks.push(cb);
|
130
147
|
}
|
148
|
+
onOutput(cb) {
|
149
|
+
this.outputCallbacks.push(cb);
|
150
|
+
}
|
131
151
|
send(message) {
|
132
152
|
throw new Error('Not implemented');
|
133
153
|
}
|
@@ -138,6 +158,11 @@ class SeriallyRunningTasks {
|
|
138
158
|
for (const c of options.commands) {
|
139
159
|
const childProcess = await this.createProcess(c, options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, options.usePty, options.streamOutput, options.tty, options.envFile);
|
140
160
|
this.currentProcess = childProcess;
|
161
|
+
childProcess.onOutput((output) => {
|
162
|
+
for (const cb of this.outputCallbacks) {
|
163
|
+
cb(output);
|
164
|
+
}
|
165
|
+
});
|
141
166
|
let { code, terminalOutput } = await childProcess.getResults();
|
142
167
|
this.terminalOutput += terminalOutput;
|
143
168
|
this.code = code;
|
@@ -173,6 +198,7 @@ class RunningNodeProcess {
|
|
173
198
|
this.readyWhenStatus = readyWhenStatus;
|
174
199
|
this.terminalOutput = '';
|
175
200
|
this.exitCallbacks = [];
|
201
|
+
this.outputCallbacks = [];
|
176
202
|
env = processEnv(color, cwd, env, envFile);
|
177
203
|
this.command = commandConfig.command;
|
178
204
|
this.terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
|
@@ -194,6 +220,9 @@ class RunningNodeProcess {
|
|
194
220
|
});
|
195
221
|
});
|
196
222
|
}
|
223
|
+
onOutput(cb) {
|
224
|
+
this.outputCallbacks.push(cb);
|
225
|
+
}
|
197
226
|
onExit(cb) {
|
198
227
|
this.exitCallbacks.push(cb);
|
199
228
|
}
|
@@ -212,10 +241,16 @@ class RunningNodeProcess {
|
|
212
241
|
});
|
213
242
|
});
|
214
243
|
}
|
244
|
+
triggerOutputListeners(output) {
|
245
|
+
for (const cb of this.outputCallbacks) {
|
246
|
+
cb(output);
|
247
|
+
}
|
248
|
+
}
|
215
249
|
addListeners(commandConfig, streamOutput) {
|
216
250
|
this.childProcess.stdout.on('data', (data) => {
|
217
251
|
const output = addColorAndPrefix(data, commandConfig);
|
218
252
|
this.terminalOutput += output;
|
253
|
+
this.triggerOutputListeners(output);
|
219
254
|
if (streamOutput) {
|
220
255
|
process.stdout.write(output);
|
221
256
|
}
|
@@ -229,6 +264,7 @@ class RunningNodeProcess {
|
|
229
264
|
this.childProcess.stderr.on('data', (err) => {
|
230
265
|
const output = addColorAndPrefix(err, commandConfig);
|
231
266
|
this.terminalOutput += output;
|
267
|
+
this.triggerOutputListeners(output);
|
232
268
|
if (streamOutput) {
|
233
269
|
process.stderr.write(output);
|
234
270
|
}
|
package/src/native/index.d.ts
CHANGED
@@ -17,6 +17,8 @@ export declare class AppLifeCycle {
|
|
17
17
|
endCommand(): void
|
18
18
|
__init(doneCallback: () => any): void
|
19
19
|
registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[ParserArc, WriterArc]>): void
|
20
|
+
registerRunningTaskWithEmptyParser(taskId: string): void
|
21
|
+
appendTaskOutput(taskId: string, output: string): void
|
20
22
|
setTaskStatus(taskId: string, status: TaskStatus): void
|
21
23
|
registerForcedShutdownCallback(forcedShutdownCallback: () => any): void
|
22
24
|
__setCloudMessage(message: string): Promise<void>
|
Binary file
|
@@ -37,6 +37,8 @@ export interface LifeCycle {
|
|
37
37
|
endTasks?(taskResults: TaskResult[], metadata: TaskMetadata): void | Promise<void>;
|
38
38
|
printTaskTerminalOutput?(task: Task, status: TaskStatus, output: string): void;
|
39
39
|
registerRunningTask?(taskId: string, parserAndWriter: ExternalObject<[any, any]>): void;
|
40
|
+
registerRunningTaskWithEmptyParser?(taskId: string): void;
|
41
|
+
appendTaskOutput?(taskId: string, output: string): void;
|
40
42
|
setTaskStatus?(taskId: string, status: NativeTaskStatus): void;
|
41
43
|
registerForcedShutdownCallback?(callback: () => void): void;
|
42
44
|
}
|
@@ -52,6 +54,8 @@ export declare class CompositeLifeCycle implements LifeCycle {
|
|
52
54
|
endTasks(taskResults: TaskResult[], metadata: TaskMetadata): Promise<void>;
|
53
55
|
printTaskTerminalOutput(task: Task, status: TaskStatus, output: string): void;
|
54
56
|
registerRunningTask(taskId: string, parserAndWriter: ExternalObject<[any, any]>): void;
|
57
|
+
registerRunningTaskWithEmptyParser(taskId: string): void;
|
58
|
+
appendTaskOutput(taskId: string, output: string): void;
|
55
59
|
setTaskStatus(taskId: string, status: NativeTaskStatus): void;
|
56
60
|
registerForcedShutdownCallback(callback: () => void): void;
|
57
61
|
}
|
@@ -74,6 +74,20 @@ class CompositeLifeCycle {
|
|
74
74
|
}
|
75
75
|
}
|
76
76
|
}
|
77
|
+
registerRunningTaskWithEmptyParser(taskId) {
|
78
|
+
for (let l of this.lifeCycles) {
|
79
|
+
if (l.registerRunningTaskWithEmptyParser) {
|
80
|
+
l.registerRunningTaskWithEmptyParser(taskId);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
appendTaskOutput(taskId, output) {
|
85
|
+
for (let l of this.lifeCycles) {
|
86
|
+
if (l.appendTaskOutput) {
|
87
|
+
l.appendTaskOutput(taskId, output);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
77
91
|
setTaskStatus(taskId, status) {
|
78
92
|
for (let l of this.lifeCycles) {
|
79
93
|
if (l.setTaskStatus) {
|
@@ -6,5 +6,6 @@ export declare abstract class RunningTask {
|
|
6
6
|
}>;
|
7
7
|
abstract onExit(cb: (code: number) => void): void;
|
8
8
|
abstract kill(signal?: NodeJS.Signals | number): Promise<void> | void;
|
9
|
+
abstract onOutput?(cb: (output: string) => void): void;
|
9
10
|
abstract send?(message: Serializable): void;
|
10
11
|
}
|
@@ -302,9 +302,17 @@ class TaskOrchestrator {
|
|
302
302
|
const runningTask = await (0, run_commands_impl_1.runCommands)(runCommandsOptions, {
|
303
303
|
root: workspace_root_1.workspaceRoot, // only root is needed in runCommands
|
304
304
|
});
|
305
|
-
if (this.tuiEnabled
|
306
|
-
|
307
|
-
|
305
|
+
if (this.tuiEnabled) {
|
306
|
+
if (runningTask instanceof pseudo_terminal_1.PseudoTtyProcess) {
|
307
|
+
// This is an external of a the pseudo terminal where a task is running and can be passed to the TUI
|
308
|
+
this.options.lifeCycle.registerRunningTask(task.id, runningTask.getParserAndWriter());
|
309
|
+
}
|
310
|
+
else {
|
311
|
+
this.options.lifeCycle.registerRunningTaskWithEmptyParser(task.id);
|
312
|
+
runningTask.onOutput((output) => {
|
313
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output);
|
314
|
+
});
|
315
|
+
}
|
308
316
|
}
|
309
317
|
if (!streamOutput) {
|
310
318
|
if (runningTask instanceof pseudo_terminal_1.PseudoTtyProcess) {
|
@@ -352,9 +360,17 @@ class TaskOrchestrator {
|
|
352
360
|
else {
|
353
361
|
// cache prep
|
354
362
|
const runningTask = await this.runTaskInForkedProcess(task, env, pipeOutput, temporaryOutputPath, streamOutput);
|
355
|
-
if (this.tuiEnabled
|
356
|
-
|
357
|
-
|
363
|
+
if (this.tuiEnabled) {
|
364
|
+
if (runningTask instanceof pseudo_terminal_1.PseudoTtyProcess) {
|
365
|
+
// This is an external of a the pseudo terminal where a task is running and can be passed to the TUI
|
366
|
+
this.options.lifeCycle.registerRunningTask(task.id, runningTask.getParserAndWriter());
|
367
|
+
}
|
368
|
+
else if ('onOutput' in runningTask) {
|
369
|
+
this.options.lifeCycle.registerRunningTaskWithEmptyParser(task.id);
|
370
|
+
runningTask.onOutput((output) => {
|
371
|
+
this.options.lifeCycle.appendTaskOutput(task.id, output);
|
372
|
+
});
|
373
|
+
}
|
358
374
|
}
|
359
375
|
return runningTask;
|
360
376
|
}
|
@@ -374,6 +374,8 @@ function shouldStreamOutput(task, initiatingProject) {
|
|
374
374
|
return false;
|
375
375
|
if (process.env.NX_STREAM_OUTPUT === 'true')
|
376
376
|
return true;
|
377
|
+
if (process.env.NX_STREAM_OUTPUT === 'false')
|
378
|
+
return false;
|
377
379
|
if (longRunningTask(task))
|
378
380
|
return true;
|
379
381
|
if (task.target.project === initiatingProject)
|