nx 20.5.0-canary.20250204-bc4ded0 → 21.0.0-beta.0
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 +12 -11
- package/src/command-line/graph/graph.js +2 -0
- package/src/commands-runner/get-command-projects.js +17 -2
- package/src/config/task-graph.d.ts +5 -0
- package/src/config/workspace-json-project-json.d.ts +4 -0
- package/src/executors/run-commands/run-commands.impl.d.ts +16 -13
- package/src/executors/run-commands/run-commands.impl.js +24 -263
- package/src/executors/run-commands/running-tasks.d.ts +38 -0
- package/src/executors/run-commands/running-tasks.js +349 -0
- package/src/native/index.d.ts +1 -0
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/tasks-runner/create-task-graph.d.ts +3 -0
- package/src/tasks-runner/create-task-graph.js +36 -5
- package/src/tasks-runner/forked-process-task-runner.d.ts +6 -12
- package/src/tasks-runner/forked-process-task-runner.js +110 -263
- package/src/tasks-runner/init-tasks-runner.js +4 -0
- package/src/tasks-runner/pseudo-terminal.d.ts +7 -1
- package/src/tasks-runner/pseudo-terminal.js +26 -12
- package/src/tasks-runner/running-tasks/batch-process.d.ts +14 -0
- package/src/tasks-runner/running-tasks/batch-process.js +70 -0
- package/src/tasks-runner/running-tasks/node-child-process.d.ts +36 -0
- package/src/tasks-runner/running-tasks/node-child-process.js +184 -0
- package/src/tasks-runner/running-tasks/noop-child-process.d.ts +15 -0
- package/src/tasks-runner/running-tasks/noop-child-process.js +19 -0
- package/src/tasks-runner/running-tasks/running-task.d.ts +8 -0
- package/src/tasks-runner/running-tasks/running-task.js +6 -0
- package/src/tasks-runner/task-orchestrator.d.ts +7 -1
- package/src/tasks-runner/task-orchestrator.js +137 -82
- package/src/tasks-runner/tasks-schedule.js +5 -1
- package/src/tasks-runner/utils.d.ts +0 -8
- package/src/tasks-runner/utils.js +12 -4
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "
|
3
|
+
"version": "21.0.0-beta.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
6
6
|
"repository": {
|
@@ -63,6 +63,7 @@
|
|
63
63
|
"string-width": "^4.2.3",
|
64
64
|
"tar-stream": "~2.2.0",
|
65
65
|
"tmp": "~0.2.1",
|
66
|
+
"tree-kill": "^1.2.2",
|
66
67
|
"tsconfig-paths": "^4.1.2",
|
67
68
|
"tslib": "^2.3.0",
|
68
69
|
"yaml": "^2.6.0",
|
@@ -82,16 +83,16 @@
|
|
82
83
|
}
|
83
84
|
},
|
84
85
|
"optionalDependencies": {
|
85
|
-
"@nx/nx-darwin-arm64": "
|
86
|
-
"@nx/nx-darwin-x64": "
|
87
|
-
"@nx/nx-freebsd-x64": "
|
88
|
-
"@nx/nx-linux-arm-gnueabihf": "
|
89
|
-
"@nx/nx-linux-arm64-gnu": "
|
90
|
-
"@nx/nx-linux-arm64-musl": "
|
91
|
-
"@nx/nx-linux-x64-gnu": "
|
92
|
-
"@nx/nx-linux-x64-musl": "
|
93
|
-
"@nx/nx-win32-arm64-msvc": "
|
94
|
-
"@nx/nx-win32-x64-msvc": "
|
86
|
+
"@nx/nx-darwin-arm64": "21.0.0-beta.0",
|
87
|
+
"@nx/nx-darwin-x64": "21.0.0-beta.0",
|
88
|
+
"@nx/nx-freebsd-x64": "21.0.0-beta.0",
|
89
|
+
"@nx/nx-linux-arm-gnueabihf": "21.0.0-beta.0",
|
90
|
+
"@nx/nx-linux-arm64-gnu": "21.0.0-beta.0",
|
91
|
+
"@nx/nx-linux-arm64-musl": "21.0.0-beta.0",
|
92
|
+
"@nx/nx-linux-x64-gnu": "21.0.0-beta.0",
|
93
|
+
"@nx/nx-linux-x64-musl": "21.0.0-beta.0",
|
94
|
+
"@nx/nx-win32-arm64-msvc": "21.0.0-beta.0",
|
95
|
+
"@nx/nx-win32-x64-msvc": "21.0.0-beta.0"
|
95
96
|
},
|
96
97
|
"nx-migrations": {
|
97
98
|
"migrations": "./migrations.json",
|
@@ -629,6 +629,7 @@ function getAllTaskGraphsForWorkspace(projectGraph) {
|
|
629
629
|
taskGraphs[taskId] = {
|
630
630
|
tasks: {},
|
631
631
|
dependencies: {},
|
632
|
+
continuousDependencies: {},
|
632
633
|
roots: [],
|
633
634
|
};
|
634
635
|
taskGraphErrors[taskId] = err.message;
|
@@ -644,6 +645,7 @@ function getAllTaskGraphsForWorkspace(projectGraph) {
|
|
644
645
|
taskGraphs[taskId] = {
|
645
646
|
tasks: {},
|
646
647
|
dependencies: {},
|
648
|
+
continuousDependencies: {},
|
647
649
|
roots: [],
|
648
650
|
};
|
649
651
|
taskGraphErrors[taskId] = err.message;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getCommandProjects = getCommandProjects;
|
4
|
-
const utils_1 = require("../tasks-runner/utils");
|
5
4
|
const create_command_graph_1 = require("./create-command-graph");
|
6
5
|
function getCommandProjects(projectGraph, projects, nxArgs) {
|
7
6
|
const commandGraph = (0, create_command_graph_1.createCommandGraph)(projectGraph, projects.map((project) => project.name), nxArgs);
|
@@ -13,6 +12,22 @@ function getSortedProjects(commandGraph, sortedProjects = []) {
|
|
13
12
|
return sortedProjects;
|
14
13
|
}
|
15
14
|
sortedProjects.push(...roots);
|
16
|
-
const newGraph =
|
15
|
+
const newGraph = removeIdsFromGraph(commandGraph, roots, commandGraph.dependencies);
|
17
16
|
return getSortedProjects(newGraph, sortedProjects);
|
18
17
|
}
|
18
|
+
function removeIdsFromGraph(graph, ids, mapWithIds) {
|
19
|
+
const filteredMapWithIds = {};
|
20
|
+
const dependencies = {};
|
21
|
+
const removedSet = new Set(ids);
|
22
|
+
for (let id of Object.keys(mapWithIds)) {
|
23
|
+
if (!removedSet.has(id)) {
|
24
|
+
filteredMapWithIds[id] = mapWithIds[id];
|
25
|
+
dependencies[id] = graph.dependencies[id].filter((depId) => !removedSet.has(depId));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return {
|
29
|
+
mapWithIds: filteredMapWithIds,
|
30
|
+
dependencies: dependencies,
|
31
|
+
roots: Object.keys(dependencies).filter((k) => dependencies[k].length === 0),
|
32
|
+
};
|
33
|
+
}
|
@@ -84,6 +84,10 @@ export interface Task {
|
|
84
84
|
* Determines if a given task should be parallelizable.
|
85
85
|
*/
|
86
86
|
parallelism: boolean;
|
87
|
+
/**
|
88
|
+
* This denotes if the task runs continuously
|
89
|
+
*/
|
90
|
+
continuous?: boolean;
|
87
91
|
}
|
88
92
|
/**
|
89
93
|
* Graph of Tasks to be executed
|
@@ -101,4 +105,5 @@ export interface TaskGraph {
|
|
101
105
|
* Map of Task IDs to IDs of tasks which the task depends on
|
102
106
|
*/
|
103
107
|
dependencies: Record<string, string[]>;
|
108
|
+
continuousDependencies: Record<string, string[]>;
|
104
109
|
}
|
@@ -238,6 +238,10 @@ export interface TargetConfiguration<T = any> {
|
|
238
238
|
* Default is true
|
239
239
|
*/
|
240
240
|
parallelism?: boolean;
|
241
|
+
/**
|
242
|
+
* Whether this target runs continuously
|
243
|
+
*/
|
244
|
+
continuous?: boolean;
|
241
245
|
/**
|
242
246
|
* List of generators to run before the target to ensure the workspace
|
243
247
|
* is up to date.
|
@@ -1,23 +1,25 @@
|
|
1
1
|
import { ExecutorContext } from '../../config/misc-interfaces';
|
2
|
+
import { ParallelRunningTasks, SeriallyRunningTasks } from './running-tasks';
|
2
3
|
export declare const LARGE_BUFFER: number;
|
3
4
|
export type Json = {
|
4
5
|
[k: string]: any;
|
5
6
|
};
|
7
|
+
export interface RunCommandsCommandOptions {
|
8
|
+
command: string;
|
9
|
+
forwardAllArgs?: boolean;
|
10
|
+
/**
|
11
|
+
* description was added to allow users to document their commands inline,
|
12
|
+
* it is not intended to be used as part of the execution of the command.
|
13
|
+
*/
|
14
|
+
description?: string;
|
15
|
+
prefix?: string;
|
16
|
+
prefixColor?: string;
|
17
|
+
color?: string;
|
18
|
+
bgColor?: string;
|
19
|
+
}
|
6
20
|
export interface RunCommandsOptions extends Json {
|
7
21
|
command?: string | string[];
|
8
|
-
commands?:
|
9
|
-
command: string;
|
10
|
-
forwardAllArgs?: boolean;
|
11
|
-
/**
|
12
|
-
* description was added to allow users to document their commands inline,
|
13
|
-
* it is not intended to be used as part of the execution of the command.
|
14
|
-
*/
|
15
|
-
description?: string;
|
16
|
-
prefix?: string;
|
17
|
-
prefixColor?: string;
|
18
|
-
color?: string;
|
19
|
-
bgColor?: string;
|
20
|
-
} | string)[];
|
22
|
+
commands?: Array<RunCommandsCommandOptions | string>;
|
21
23
|
color?: boolean;
|
22
24
|
parallel?: boolean;
|
23
25
|
readyWhen?: string | string[];
|
@@ -55,4 +57,5 @@ export default function (options: RunCommandsOptions, context: ExecutorContext):
|
|
55
57
|
success: boolean;
|
56
58
|
terminalOutput: string;
|
57
59
|
}>;
|
60
|
+
export declare function runCommands(options: RunCommandsOptions, context: ExecutorContext): Promise<ParallelRunningTasks | SeriallyRunningTasks>;
|
58
61
|
export declare function interpolateArgsIntoCommand(command: string, opts: Pick<NormalizedRunCommandsOptions, 'args' | 'parsedArgs' | '__unparsed__' | 'unknownOptions' | 'unparsedCommandArgs'>, forwardAllArgs: boolean): string;
|
@@ -2,25 +2,13 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.LARGE_BUFFER = void 0;
|
4
4
|
exports.default = default_1;
|
5
|
+
exports.runCommands = runCommands;
|
5
6
|
exports.interpolateArgsIntoCommand = interpolateArgsIntoCommand;
|
6
|
-
const child_process_1 = require("child_process");
|
7
|
-
const path = require("path");
|
8
7
|
const yargsParser = require("yargs-parser");
|
9
|
-
const npm_run_path_1 = require("npm-run-path");
|
10
|
-
const chalk = require("chalk");
|
11
8
|
const pseudo_terminal_1 = require("../../tasks-runner/pseudo-terminal");
|
12
9
|
const exit_codes_1 = require("../../utils/exit-codes");
|
13
|
-
const
|
10
|
+
const running_tasks_1 = require("./running-tasks");
|
14
11
|
exports.LARGE_BUFFER = 1024 * 1000000;
|
15
|
-
let pseudoTerminal;
|
16
|
-
const childProcesses = new Set();
|
17
|
-
function loadEnvVarsFile(path, env = {}) {
|
18
|
-
(0, task_env_1.unloadDotEnvFile)(path, env);
|
19
|
-
const result = (0, task_env_1.loadAndExpandDotEnvFile)(path, env);
|
20
|
-
if (result.error) {
|
21
|
-
throw result.error;
|
22
|
-
}
|
23
|
-
}
|
24
12
|
const propKeys = [
|
25
13
|
'command',
|
26
14
|
'commands',
|
@@ -41,7 +29,14 @@ const propKeys = [
|
|
41
29
|
'tty',
|
42
30
|
];
|
43
31
|
async function default_1(options, context) {
|
44
|
-
|
32
|
+
const task = await runCommands(options, context);
|
33
|
+
const results = await task.getResults();
|
34
|
+
return {
|
35
|
+
...results,
|
36
|
+
success: results.code === 0,
|
37
|
+
};
|
38
|
+
}
|
39
|
+
async function runCommands(options, context) {
|
45
40
|
const normalized = normalizeOptions(options);
|
46
41
|
if (normalized.readyWhenStatus.length && !normalized.parallel) {
|
47
42
|
throw new Error('ERROR: Bad executor config for run-commands - "readyWhen" can only be used when "parallel=true".');
|
@@ -50,11 +45,15 @@ async function default_1(options, context) {
|
|
50
45
|
!options.parallel) {
|
51
46
|
throw new Error('ERROR: Bad executor config for run-commands - "prefix", "prefixColor", "color" and "bgColor" can only be set when "parallel=true".');
|
52
47
|
}
|
48
|
+
const pseudoTerminal = !options.parallel && pseudo_terminal_1.PseudoTerminal.isSupported()
|
49
|
+
? (0, pseudo_terminal_1.getPseudoTerminal)()
|
50
|
+
: null;
|
53
51
|
try {
|
54
|
-
const
|
55
|
-
?
|
56
|
-
:
|
57
|
-
|
52
|
+
const runningTask = options.parallel
|
53
|
+
? new running_tasks_1.ParallelRunningTasks(normalized, context)
|
54
|
+
: new running_tasks_1.SeriallyRunningTasks(normalized, context, pseudoTerminal);
|
55
|
+
registerProcessListener(runningTask, pseudoTerminal);
|
56
|
+
return runningTask;
|
58
57
|
}
|
59
58
|
catch (e) {
|
60
59
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
@@ -63,52 +62,6 @@ async function default_1(options, context) {
|
|
63
62
|
throw new Error(`ERROR: Something went wrong in run-commands - ${e.message}`);
|
64
63
|
}
|
65
64
|
}
|
66
|
-
async function runInParallel(options, context) {
|
67
|
-
const procs = options.commands.map((c) => createProcess(null, c, options.readyWhenStatus, options.color, calculateCwd(options.cwd, context), options.env ?? {}, true, options.usePty, options.streamOutput, options.tty, options.envFile).then((result) => ({
|
68
|
-
result,
|
69
|
-
command: c.command,
|
70
|
-
})));
|
71
|
-
let terminalOutput = '';
|
72
|
-
if (options.readyWhenStatus.length) {
|
73
|
-
const r = await Promise.race(procs);
|
74
|
-
terminalOutput += r.result.terminalOutput;
|
75
|
-
if (!r.result.success) {
|
76
|
-
const output = `Warning: command "${r.command}" exited with non-zero status code`;
|
77
|
-
terminalOutput += output;
|
78
|
-
if (options.streamOutput) {
|
79
|
-
process.stderr.write(output);
|
80
|
-
}
|
81
|
-
return { success: false, terminalOutput };
|
82
|
-
}
|
83
|
-
else {
|
84
|
-
return { success: true, terminalOutput };
|
85
|
-
}
|
86
|
-
}
|
87
|
-
else {
|
88
|
-
const r = await Promise.all(procs);
|
89
|
-
terminalOutput += r.map((f) => f.result.terminalOutput).join('');
|
90
|
-
const failed = r.filter((v) => !v.result.success);
|
91
|
-
if (failed.length > 0) {
|
92
|
-
const output = failed
|
93
|
-
.map((f) => `Warning: command "${f.command}" exited with non-zero status code`)
|
94
|
-
.join('\r\n');
|
95
|
-
terminalOutput += output;
|
96
|
-
if (options.streamOutput) {
|
97
|
-
process.stderr.write(output);
|
98
|
-
}
|
99
|
-
return {
|
100
|
-
success: false,
|
101
|
-
terminalOutput,
|
102
|
-
};
|
103
|
-
}
|
104
|
-
else {
|
105
|
-
return {
|
106
|
-
success: true,
|
107
|
-
terminalOutput,
|
108
|
-
};
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
112
65
|
function normalizeOptions(options) {
|
113
66
|
if (options.readyWhen && typeof options.readyWhen === 'string') {
|
114
67
|
options.readyWhenStatus = [
|
@@ -156,167 +109,6 @@ function normalizeOptions(options) {
|
|
156
109
|
});
|
157
110
|
return options;
|
158
111
|
}
|
159
|
-
async function runSerially(options, context) {
|
160
|
-
pseudoTerminal ??= pseudo_terminal_1.PseudoTerminal.isSupported() ? (0, pseudo_terminal_1.getPseudoTerminal)() : null;
|
161
|
-
let terminalOutput = '';
|
162
|
-
for (const c of options.commands) {
|
163
|
-
const result = await createProcess(pseudoTerminal, c, [], options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, false, options.usePty, options.streamOutput, options.tty, options.envFile);
|
164
|
-
terminalOutput += result.terminalOutput;
|
165
|
-
if (!result.success) {
|
166
|
-
const output = `Warning: command "${c.command}" exited with non-zero status code`;
|
167
|
-
result.terminalOutput += output;
|
168
|
-
if (options.streamOutput) {
|
169
|
-
process.stderr.write(output);
|
170
|
-
}
|
171
|
-
return { success: false, terminalOutput };
|
172
|
-
}
|
173
|
-
}
|
174
|
-
return { success: true, terminalOutput };
|
175
|
-
}
|
176
|
-
async function createProcess(pseudoTerminal, commandConfig, readyWhenStatus = [], color, cwd, env, isParallel, usePty = true, streamOutput = true, tty, envFile) {
|
177
|
-
env = processEnv(color, cwd, env, envFile);
|
178
|
-
// The rust runCommand is always a tty, so it will not look nice in parallel and if we need prefixes
|
179
|
-
// currently does not work properly in windows
|
180
|
-
if (pseudoTerminal &&
|
181
|
-
process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
|
182
|
-
!commandConfig.prefix &&
|
183
|
-
readyWhenStatus.length === 0 &&
|
184
|
-
!isParallel &&
|
185
|
-
usePty) {
|
186
|
-
let terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
|
187
|
-
if (streamOutput) {
|
188
|
-
process.stdout.write(terminalOutput);
|
189
|
-
}
|
190
|
-
const cp = pseudoTerminal.runCommand(commandConfig.command, {
|
191
|
-
cwd,
|
192
|
-
jsEnv: env,
|
193
|
-
quiet: !streamOutput,
|
194
|
-
tty,
|
195
|
-
});
|
196
|
-
childProcesses.add(cp);
|
197
|
-
return new Promise((res) => {
|
198
|
-
cp.onOutput((output) => {
|
199
|
-
terminalOutput += output;
|
200
|
-
});
|
201
|
-
cp.onExit((code) => {
|
202
|
-
if (code >= 128) {
|
203
|
-
process.exit(code);
|
204
|
-
}
|
205
|
-
else {
|
206
|
-
res({ success: code === 0, terminalOutput });
|
207
|
-
}
|
208
|
-
});
|
209
|
-
});
|
210
|
-
}
|
211
|
-
return nodeProcess(commandConfig, cwd, env, readyWhenStatus, streamOutput);
|
212
|
-
}
|
213
|
-
function nodeProcess(commandConfig, cwd, env, readyWhenStatus, streamOutput = true) {
|
214
|
-
let terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
|
215
|
-
if (streamOutput) {
|
216
|
-
process.stdout.write(terminalOutput);
|
217
|
-
}
|
218
|
-
return new Promise((res) => {
|
219
|
-
const childProcess = (0, child_process_1.exec)(commandConfig.command, {
|
220
|
-
maxBuffer: exports.LARGE_BUFFER,
|
221
|
-
env,
|
222
|
-
cwd,
|
223
|
-
windowsHide: false,
|
224
|
-
});
|
225
|
-
childProcesses.add(childProcess);
|
226
|
-
childProcess.stdout.on('data', (data) => {
|
227
|
-
const output = addColorAndPrefix(data, commandConfig);
|
228
|
-
terminalOutput += output;
|
229
|
-
if (streamOutput) {
|
230
|
-
process.stdout.write(output);
|
231
|
-
}
|
232
|
-
if (readyWhenStatus.length && isReady(readyWhenStatus, data.toString())) {
|
233
|
-
res({ success: true, terminalOutput });
|
234
|
-
}
|
235
|
-
});
|
236
|
-
childProcess.stderr.on('data', (err) => {
|
237
|
-
const output = addColorAndPrefix(err, commandConfig);
|
238
|
-
terminalOutput += output;
|
239
|
-
if (streamOutput) {
|
240
|
-
process.stderr.write(output);
|
241
|
-
}
|
242
|
-
if (readyWhenStatus.length && isReady(readyWhenStatus, err.toString())) {
|
243
|
-
res({ success: true, terminalOutput });
|
244
|
-
}
|
245
|
-
});
|
246
|
-
childProcess.on('error', (err) => {
|
247
|
-
const ouptput = addColorAndPrefix(err.toString(), commandConfig);
|
248
|
-
terminalOutput += ouptput;
|
249
|
-
if (streamOutput) {
|
250
|
-
process.stderr.write(ouptput);
|
251
|
-
}
|
252
|
-
res({ success: false, terminalOutput });
|
253
|
-
});
|
254
|
-
childProcess.on('exit', (code) => {
|
255
|
-
childProcesses.delete(childProcess);
|
256
|
-
if (!readyWhenStatus.length || isReady(readyWhenStatus)) {
|
257
|
-
res({ success: code === 0, terminalOutput });
|
258
|
-
}
|
259
|
-
});
|
260
|
-
});
|
261
|
-
}
|
262
|
-
function addColorAndPrefix(out, config) {
|
263
|
-
if (config.prefix) {
|
264
|
-
out = out
|
265
|
-
.split('\n')
|
266
|
-
.map((l) => {
|
267
|
-
let prefixText = config.prefix;
|
268
|
-
if (config.prefixColor && chalk[config.prefixColor]) {
|
269
|
-
prefixText = chalk[config.prefixColor](prefixText);
|
270
|
-
}
|
271
|
-
prefixText = chalk.bold(prefixText);
|
272
|
-
return l.trim().length > 0 ? `${prefixText} ${l}` : l;
|
273
|
-
})
|
274
|
-
.join('\n');
|
275
|
-
}
|
276
|
-
if (config.color && chalk[config.color]) {
|
277
|
-
out = chalk[config.color](out);
|
278
|
-
}
|
279
|
-
if (config.bgColor && chalk[config.bgColor]) {
|
280
|
-
out = chalk[config.bgColor](out);
|
281
|
-
}
|
282
|
-
return out;
|
283
|
-
}
|
284
|
-
function calculateCwd(cwd, context) {
|
285
|
-
if (!cwd)
|
286
|
-
return context.root;
|
287
|
-
if (path.isAbsolute(cwd))
|
288
|
-
return cwd;
|
289
|
-
return path.join(context.root, cwd);
|
290
|
-
}
|
291
|
-
/**
|
292
|
-
* Env variables are processed in the following order:
|
293
|
-
* - env option from executor options
|
294
|
-
* - env file from envFile option if provided
|
295
|
-
* - local env variables
|
296
|
-
*/
|
297
|
-
function processEnv(color, cwd, envOptionFromExecutor, envFile) {
|
298
|
-
let localEnv = (0, npm_run_path_1.env)({ cwd: cwd ?? process.cwd() });
|
299
|
-
localEnv = {
|
300
|
-
...process.env,
|
301
|
-
...localEnv,
|
302
|
-
};
|
303
|
-
if (process.env.NX_LOAD_DOT_ENV_FILES !== 'false' && envFile) {
|
304
|
-
loadEnvVarsFile(envFile, localEnv);
|
305
|
-
}
|
306
|
-
let res = {
|
307
|
-
...localEnv,
|
308
|
-
...envOptionFromExecutor,
|
309
|
-
};
|
310
|
-
// need to override PATH to make sure we are using the local node_modules
|
311
|
-
if (localEnv.PATH)
|
312
|
-
res.PATH = localEnv.PATH; // UNIX-like
|
313
|
-
if (localEnv.Path)
|
314
|
-
res.Path = localEnv.Path; // Windows
|
315
|
-
if (color) {
|
316
|
-
res.FORCE_COLOR = `${color}`;
|
317
|
-
}
|
318
|
-
return res;
|
319
|
-
}
|
320
112
|
function interpolateArgsIntoCommand(command, opts, forwardAllArgs) {
|
321
113
|
if (command.indexOf('{args.') > -1) {
|
322
114
|
const regex = /{args\.([^}]+)}/g;
|
@@ -404,7 +196,7 @@ function filterPropKeysFromUnParsedOptions(__unparsed__, parseArgs = {}) {
|
|
404
196
|
return parsedOptions;
|
405
197
|
}
|
406
198
|
let registered = false;
|
407
|
-
function registerProcessListener() {
|
199
|
+
function registerProcessListener(runningTask, pseudoTerminal) {
|
408
200
|
if (registered) {
|
409
201
|
return;
|
410
202
|
}
|
@@ -415,44 +207,24 @@ function registerProcessListener() {
|
|
415
207
|
if (pseudoTerminal) {
|
416
208
|
pseudoTerminal.sendMessageToChildren(message);
|
417
209
|
}
|
418
|
-
|
419
|
-
if ('connected' in p && p.connected) {
|
420
|
-
p.send(message);
|
421
|
-
}
|
422
|
-
});
|
210
|
+
runningTask.send(message);
|
423
211
|
});
|
424
212
|
// Terminate any task processes on exit
|
425
213
|
process.on('exit', () => {
|
426
|
-
|
427
|
-
if ('connected' in p ? p.connected : p.isAlive) {
|
428
|
-
p.kill();
|
429
|
-
}
|
430
|
-
});
|
214
|
+
runningTask.kill();
|
431
215
|
});
|
432
216
|
process.on('SIGINT', () => {
|
433
|
-
|
434
|
-
if ('connected' in p ? p.connected : p.isAlive) {
|
435
|
-
p.kill('SIGTERM');
|
436
|
-
}
|
437
|
-
});
|
217
|
+
runningTask.kill('SIGTERM');
|
438
218
|
// we exit here because we don't need to write anything to cache.
|
439
219
|
process.exit((0, exit_codes_1.signalToCode)('SIGINT'));
|
440
220
|
});
|
441
221
|
process.on('SIGTERM', () => {
|
442
|
-
|
443
|
-
if ('connected' in p ? p.connected : p.isAlive) {
|
444
|
-
p.kill('SIGTERM');
|
445
|
-
}
|
446
|
-
});
|
222
|
+
runningTask.kill('SIGTERM');
|
447
223
|
// no exit here because we expect child processes to terminate which
|
448
224
|
// will store results to the cache and will terminate this process
|
449
225
|
});
|
450
226
|
process.on('SIGHUP', () => {
|
451
|
-
|
452
|
-
if ('connected' in p ? p.connected : p.isAlive) {
|
453
|
-
p.kill('SIGTERM');
|
454
|
-
}
|
455
|
-
});
|
227
|
+
runningTask.kill('SIGTERM');
|
456
228
|
// no exit here because we expect child processes to terminate which
|
457
229
|
// will store results to the cache and will terminate this process
|
458
230
|
});
|
@@ -474,14 +246,3 @@ function wrapArgIntoQuotesIfNeeded(arg) {
|
|
474
246
|
return arg;
|
475
247
|
}
|
476
248
|
}
|
477
|
-
function isReady(readyWhenStatus = [], data) {
|
478
|
-
if (data) {
|
479
|
-
for (const readyWhenElement of readyWhenStatus) {
|
480
|
-
if (data.toString().indexOf(readyWhenElement.stringToMatch) > -1) {
|
481
|
-
readyWhenElement.found = true;
|
482
|
-
break;
|
483
|
-
}
|
484
|
-
}
|
485
|
-
}
|
486
|
-
return readyWhenStatus.every((readyWhenElement) => readyWhenElement.found);
|
487
|
-
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { Serializable } from 'child_process';
|
2
|
+
import { RunningTask } from '../../tasks-runner/running-tasks/running-task';
|
3
|
+
import { ExecutorContext } from '../../config/misc-interfaces';
|
4
|
+
import { NormalizedRunCommandsOptions } from './run-commands.impl';
|
5
|
+
import { PseudoTerminal } from '../../tasks-runner/pseudo-terminal';
|
6
|
+
export declare class ParallelRunningTasks implements RunningTask {
|
7
|
+
private readonly childProcesses;
|
8
|
+
private readyWhenStatus;
|
9
|
+
private readonly streamOutput;
|
10
|
+
private exitCallbacks;
|
11
|
+
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext);
|
12
|
+
getResults(): Promise<{
|
13
|
+
code: number;
|
14
|
+
terminalOutput: string;
|
15
|
+
}>;
|
16
|
+
onExit(cb: (code: number, terminalOutput: string) => void): void;
|
17
|
+
send(message: Serializable): void;
|
18
|
+
kill(signal?: NodeJS.Signals | number): Promise<void>;
|
19
|
+
private run;
|
20
|
+
}
|
21
|
+
export declare class SeriallyRunningTasks implements RunningTask {
|
22
|
+
private pseudoTerminal?;
|
23
|
+
private terminalOutput;
|
24
|
+
private currentProcess;
|
25
|
+
private exitCallbacks;
|
26
|
+
private code;
|
27
|
+
private error;
|
28
|
+
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext, pseudoTerminal?: PseudoTerminal);
|
29
|
+
getResults(): Promise<{
|
30
|
+
code: number;
|
31
|
+
terminalOutput: string;
|
32
|
+
}>;
|
33
|
+
onExit(cb: (code: number, terminalOutput: string) => void): void;
|
34
|
+
send(message: Serializable): void;
|
35
|
+
kill(signal?: NodeJS.Signals | number): void | Promise<void>;
|
36
|
+
private run;
|
37
|
+
private createProcess;
|
38
|
+
}
|