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.
Files changed (31) hide show
  1. package/package.json +11 -12
  2. package/src/command-line/graph/graph.js +0 -2
  3. package/src/commands-runner/get-command-projects.js +2 -17
  4. package/src/config/task-graph.d.ts +0 -5
  5. package/src/config/workspace-json-project-json.d.ts +0 -4
  6. package/src/executors/run-commands/run-commands.impl.d.ts +13 -16
  7. package/src/executors/run-commands/run-commands.impl.js +263 -24
  8. package/src/native/index.d.ts +0 -1
  9. package/src/native/nx.wasm32-wasi.wasm +0 -0
  10. package/src/tasks-runner/create-task-graph.d.ts +0 -3
  11. package/src/tasks-runner/create-task-graph.js +5 -36
  12. package/src/tasks-runner/forked-process-task-runner.d.ts +12 -6
  13. package/src/tasks-runner/forked-process-task-runner.js +263 -110
  14. package/src/tasks-runner/init-tasks-runner.js +0 -4
  15. package/src/tasks-runner/pseudo-terminal.d.ts +1 -7
  16. package/src/tasks-runner/pseudo-terminal.js +12 -26
  17. package/src/tasks-runner/task-orchestrator.d.ts +1 -7
  18. package/src/tasks-runner/task-orchestrator.js +82 -137
  19. package/src/tasks-runner/tasks-schedule.js +1 -5
  20. package/src/tasks-runner/utils.d.ts +8 -0
  21. package/src/tasks-runner/utils.js +4 -12
  22. package/src/executors/run-commands/running-tasks.d.ts +0 -38
  23. package/src/executors/run-commands/running-tasks.js +0 -349
  24. package/src/tasks-runner/running-tasks/batch-process.d.ts +0 -14
  25. package/src/tasks-runner/running-tasks/batch-process.js +0 -70
  26. package/src/tasks-runner/running-tasks/node-child-process.d.ts +0 -36
  27. package/src/tasks-runner/running-tasks/node-child-process.js +0 -184
  28. package/src/tasks-runner/running-tasks/noop-child-process.d.ts +0 -15
  29. package/src/tasks-runner/running-tasks/noop-child-process.js +0 -19
  30. package/src/tasks-runner/running-tasks/running-task.d.ts +0 -8
  31. package/src/tasks-runner/running-tasks/running-task.js +0 -6
@@ -1,349 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SeriallyRunningTasks = exports.ParallelRunningTasks = void 0;
4
- const child_process_1 = require("child_process");
5
- const run_commands_impl_1 = require("./run-commands.impl");
6
- const path_1 = require("path");
7
- const chalk = require("chalk");
8
- const npm_run_path_1 = require("npm-run-path");
9
- const task_env_1 = require("../../tasks-runner/task-env");
10
- const treeKill = require("tree-kill");
11
- class ParallelRunningTasks {
12
- constructor(options, context) {
13
- this.exitCallbacks = [];
14
- this.childProcesses = options.commands.map((commandConfig) => new RunningNodeProcess(commandConfig, options.color, calculateCwd(options.cwd, context), options.env ?? {}, options.readyWhenStatus, options.streamOutput, options.envFile));
15
- this.readyWhenStatus = options.readyWhenStatus;
16
- this.streamOutput = options.streamOutput;
17
- this.run();
18
- }
19
- async getResults() {
20
- return new Promise((res) => {
21
- this.onExit((code, terminalOutput) => {
22
- res({ code, terminalOutput });
23
- });
24
- });
25
- }
26
- onExit(cb) {
27
- this.exitCallbacks.push(cb);
28
- }
29
- send(message) {
30
- for (const childProcess of this.childProcesses) {
31
- childProcess.send(message);
32
- }
33
- }
34
- async kill(signal) {
35
- await Promise.all(this.childProcesses.map(async (p) => {
36
- try {
37
- return p.kill();
38
- }
39
- catch (e) {
40
- console.error(`Unable to terminate "${p.command}"\nError:`, e);
41
- }
42
- }));
43
- }
44
- async run() {
45
- if (this.readyWhenStatus.length) {
46
- let { childProcess, result: { code, terminalOutput }, } = await Promise.race(this.childProcesses.map((childProcess) => new Promise((res) => {
47
- childProcess.onExit((code, terminalOutput) => {
48
- res({
49
- childProcess,
50
- result: { code, terminalOutput },
51
- });
52
- });
53
- })));
54
- if (code !== 0) {
55
- const output = `Warning: command "${childProcess.command}" exited with non-zero status code`;
56
- terminalOutput += output;
57
- if (this.streamOutput) {
58
- process.stderr.write(output);
59
- }
60
- }
61
- for (const cb of this.exitCallbacks) {
62
- cb(code, terminalOutput);
63
- }
64
- }
65
- else {
66
- const results = await Promise.all(this.childProcesses.map((childProcess) => childProcess.getResults().then((result) => ({
67
- childProcess,
68
- result,
69
- }))));
70
- let terminalOutput = results
71
- .map((r) => r.result.terminalOutput)
72
- .join('\r\n');
73
- const failed = results.filter((result) => result.result.code !== 0);
74
- if (failed.length > 0) {
75
- const output = failed
76
- .map((failedResult) => `Warning: command "${failedResult.childProcess.command}" exited with non-zero status code`)
77
- .join('\r\n');
78
- terminalOutput += output;
79
- if (this.streamOutput) {
80
- process.stderr.write(output);
81
- }
82
- for (const cb of this.exitCallbacks) {
83
- cb(1, terminalOutput);
84
- }
85
- }
86
- else {
87
- for (const cb of this.exitCallbacks) {
88
- cb(0, terminalOutput);
89
- }
90
- }
91
- }
92
- }
93
- }
94
- exports.ParallelRunningTasks = ParallelRunningTasks;
95
- class SeriallyRunningTasks {
96
- constructor(options, context, pseudoTerminal) {
97
- this.pseudoTerminal = pseudoTerminal;
98
- this.terminalOutput = '';
99
- this.currentProcess = null;
100
- this.exitCallbacks = [];
101
- this.code = 0;
102
- this.run(options, context)
103
- .catch((e) => {
104
- this.error = e;
105
- })
106
- .finally(() => {
107
- for (const cb of this.exitCallbacks) {
108
- cb(this.code, this.terminalOutput);
109
- }
110
- });
111
- }
112
- getResults() {
113
- return new Promise((res, rej) => {
114
- this.onExit((code) => {
115
- if (this.error) {
116
- rej(this.error);
117
- }
118
- else {
119
- res({ code, terminalOutput: this.terminalOutput });
120
- }
121
- });
122
- });
123
- }
124
- onExit(cb) {
125
- this.exitCallbacks.push(cb);
126
- }
127
- send(message) {
128
- throw new Error('Not implemented');
129
- }
130
- kill(signal) {
131
- return this.currentProcess.kill(signal);
132
- }
133
- async run(options, context) {
134
- for (const c of options.commands) {
135
- const childProcess = await this.createProcess(c, [], options.color, calculateCwd(options.cwd, context), options.processEnv ?? options.env ?? {}, false, options.usePty, options.streamOutput, options.tty, options.envFile);
136
- this.currentProcess = childProcess;
137
- let { code, terminalOutput } = await childProcess.getResults();
138
- this.terminalOutput += terminalOutput;
139
- this.code = code;
140
- if (code !== 0) {
141
- const output = `Warning: command "${c.command}" exited with non-zero status code`;
142
- terminalOutput += output;
143
- if (options.streamOutput) {
144
- process.stderr.write(output);
145
- }
146
- this.terminalOutput += terminalOutput;
147
- // Stop running commands
148
- break;
149
- }
150
- }
151
- }
152
- async createProcess(commandConfig, readyWhenStatus = [], color, cwd, env, isParallel, usePty = true, streamOutput = true, tty, envFile) {
153
- // The rust runCommand is always a tty, so it will not look nice in parallel and if we need prefixes
154
- // currently does not work properly in windows
155
- if (this.pseudoTerminal &&
156
- process.env.NX_NATIVE_COMMAND_RUNNER !== 'false' &&
157
- !commandConfig.prefix &&
158
- readyWhenStatus.length === 0 &&
159
- !isParallel &&
160
- usePty) {
161
- return createProcessWithPseudoTty(this.pseudoTerminal, commandConfig, color, cwd, env, streamOutput, tty, envFile);
162
- }
163
- return new RunningNodeProcess(commandConfig, color, cwd, env, readyWhenStatus, streamOutput, envFile);
164
- }
165
- }
166
- exports.SeriallyRunningTasks = SeriallyRunningTasks;
167
- class RunningNodeProcess {
168
- constructor(commandConfig, color, cwd, env, readyWhenStatus, streamOutput = true, envFile) {
169
- this.readyWhenStatus = readyWhenStatus;
170
- this.terminalOutput = '';
171
- this.exitCallbacks = [];
172
- env = processEnv(color, cwd, env, envFile);
173
- this.command = commandConfig.command;
174
- this.terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
175
- if (streamOutput) {
176
- process.stdout.write(this.terminalOutput);
177
- }
178
- this.childProcess = (0, child_process_1.exec)(commandConfig.command, {
179
- maxBuffer: run_commands_impl_1.LARGE_BUFFER,
180
- env,
181
- cwd,
182
- windowsHide: false,
183
- });
184
- this.addListeners(commandConfig, streamOutput);
185
- }
186
- getResults() {
187
- return new Promise((res) => {
188
- this.onExit((code, terminalOutput) => {
189
- res({ code, terminalOutput });
190
- });
191
- });
192
- }
193
- onExit(cb) {
194
- this.exitCallbacks.push(cb);
195
- }
196
- send(message) {
197
- this.childProcess.send(message);
198
- }
199
- kill(signal) {
200
- return new Promise((res, rej) => {
201
- treeKill(this.childProcess.pid, signal, (err) => {
202
- if (err) {
203
- rej(err);
204
- }
205
- else {
206
- res();
207
- }
208
- });
209
- });
210
- }
211
- addListeners(commandConfig, streamOutput) {
212
- this.childProcess.stdout.on('data', (data) => {
213
- const output = addColorAndPrefix(data, commandConfig);
214
- this.terminalOutput += output;
215
- if (streamOutput) {
216
- process.stdout.write(output);
217
- }
218
- if (this.readyWhenStatus.length &&
219
- isReady(this.readyWhenStatus, data.toString())) {
220
- for (const cb of this.exitCallbacks) {
221
- cb(0, this.terminalOutput);
222
- }
223
- }
224
- });
225
- this.childProcess.stderr.on('data', (err) => {
226
- const output = addColorAndPrefix(err, commandConfig);
227
- this.terminalOutput += output;
228
- if (streamOutput) {
229
- process.stderr.write(output);
230
- }
231
- if (this.readyWhenStatus.length &&
232
- isReady(this.readyWhenStatus, err.toString())) {
233
- for (const cb of this.exitCallbacks) {
234
- cb(1, this.terminalOutput);
235
- }
236
- }
237
- });
238
- this.childProcess.on('error', (err) => {
239
- const output = addColorAndPrefix(err.toString(), commandConfig);
240
- this.terminalOutput += output;
241
- if (streamOutput) {
242
- process.stderr.write(output);
243
- }
244
- for (const cb of this.exitCallbacks) {
245
- cb(1, this.terminalOutput);
246
- }
247
- });
248
- this.childProcess.on('exit', (code) => {
249
- if (!this.readyWhenStatus.length || isReady(this.readyWhenStatus)) {
250
- for (const cb of this.exitCallbacks) {
251
- cb(code, this.terminalOutput);
252
- }
253
- }
254
- });
255
- }
256
- }
257
- async function createProcessWithPseudoTty(pseudoTerminal, commandConfig, color, cwd, env, streamOutput = true, tty, envFile) {
258
- let terminalOutput = chalk.dim('> ') + commandConfig.command + '\r\n\r\n';
259
- if (streamOutput) {
260
- process.stdout.write(terminalOutput);
261
- }
262
- env = processEnv(color, cwd, env, envFile);
263
- const childProcess = pseudoTerminal.runCommand(commandConfig.command, {
264
- cwd,
265
- jsEnv: env,
266
- quiet: !streamOutput,
267
- tty,
268
- });
269
- childProcess.onOutput((output) => {
270
- terminalOutput += output;
271
- });
272
- return childProcess;
273
- }
274
- function addColorAndPrefix(out, config) {
275
- if (config.prefix) {
276
- out = out
277
- .split('\n')
278
- .map((l) => {
279
- let prefixText = config.prefix;
280
- if (config.prefixColor && chalk[config.prefixColor]) {
281
- prefixText = chalk[config.prefixColor](prefixText);
282
- }
283
- prefixText = chalk.bold(prefixText);
284
- return l.trim().length > 0 ? `${prefixText} ${l}` : l;
285
- })
286
- .join('\n');
287
- }
288
- if (config.color && chalk[config.color]) {
289
- out = chalk[config.color](out);
290
- }
291
- if (config.bgColor && chalk[config.bgColor]) {
292
- out = chalk[config.bgColor](out);
293
- }
294
- return out;
295
- }
296
- function calculateCwd(cwd, context) {
297
- if (!cwd)
298
- return context.root;
299
- if ((0, path_1.isAbsolute)(cwd))
300
- return cwd;
301
- return (0, path_1.join)(context.root, cwd);
302
- }
303
- /**
304
- * Env variables are processed in the following order:
305
- * - env option from executor options
306
- * - env file from envFile option if provided
307
- * - local env variables
308
- */
309
- function processEnv(color, cwd, envOptionFromExecutor, envFile) {
310
- let localEnv = (0, npm_run_path_1.env)({ cwd: cwd ?? process.cwd() });
311
- localEnv = {
312
- ...process.env,
313
- ...localEnv,
314
- };
315
- if (process.env.NX_LOAD_DOT_ENV_FILES !== 'false' && envFile) {
316
- loadEnvVarsFile(envFile, localEnv);
317
- }
318
- let res = {
319
- ...localEnv,
320
- ...envOptionFromExecutor,
321
- };
322
- // need to override PATH to make sure we are using the local node_modules
323
- if (localEnv.PATH)
324
- res.PATH = localEnv.PATH; // UNIX-like
325
- if (localEnv.Path)
326
- res.Path = localEnv.Path; // Windows
327
- if (color) {
328
- res.FORCE_COLOR = `${color}`;
329
- }
330
- return res;
331
- }
332
- function isReady(readyWhenStatus = [], data) {
333
- if (data) {
334
- for (const readyWhenElement of readyWhenStatus) {
335
- if (data.toString().indexOf(readyWhenElement.stringToMatch) > -1) {
336
- readyWhenElement.found = true;
337
- break;
338
- }
339
- }
340
- }
341
- return readyWhenStatus.every((readyWhenElement) => readyWhenElement.found);
342
- }
343
- function loadEnvVarsFile(path, env = {}) {
344
- (0, task_env_1.unloadDotEnvFile)(path, env);
345
- const result = (0, task_env_1.loadAndExpandDotEnvFile)(path, env);
346
- if (result.error) {
347
- throw result.error;
348
- }
349
- }
@@ -1,14 +0,0 @@
1
- import { BatchResults } from '../batch/batch-messages';
2
- import { ChildProcess, Serializable } from 'child_process';
3
- export declare class BatchProcess {
4
- private childProcess;
5
- private executorName;
6
- private exitCallbacks;
7
- private resultsCallbacks;
8
- constructor(childProcess: ChildProcess, executorName: string);
9
- onExit(cb: (code: number) => void): void;
10
- onResults(cb: (results: BatchResults) => void): void;
11
- getResults(): Promise<BatchResults>;
12
- send(message: Serializable): void;
13
- kill(signal?: NodeJS.Signals | number): void;
14
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BatchProcess = void 0;
4
- const batch_messages_1 = require("../batch/batch-messages");
5
- const exit_codes_1 = require("../../utils/exit-codes");
6
- class BatchProcess {
7
- constructor(childProcess, executorName) {
8
- this.childProcess = childProcess;
9
- this.executorName = executorName;
10
- this.exitCallbacks = [];
11
- this.resultsCallbacks = [];
12
- this.childProcess.on('message', (message) => {
13
- switch (message.type) {
14
- case batch_messages_1.BatchMessageType.CompleteBatchExecution: {
15
- for (const cb of this.resultsCallbacks) {
16
- cb(message.results);
17
- }
18
- break;
19
- }
20
- case batch_messages_1.BatchMessageType.RunTasks: {
21
- break;
22
- }
23
- default: {
24
- // Re-emit any non-batch messages from the task process
25
- if (process.send) {
26
- process.send(message);
27
- }
28
- }
29
- }
30
- });
31
- this.childProcess.once('exit', (code, signal) => {
32
- if (code === null)
33
- code = (0, exit_codes_1.signalToCode)(signal);
34
- for (const cb of this.exitCallbacks) {
35
- cb(code);
36
- }
37
- });
38
- }
39
- onExit(cb) {
40
- this.exitCallbacks.push(cb);
41
- }
42
- onResults(cb) {
43
- this.resultsCallbacks.push(cb);
44
- }
45
- async getResults() {
46
- return Promise.race([
47
- new Promise((_, rej) => {
48
- this.onExit((code) => {
49
- if (code !== 0) {
50
- rej(new Error(`"${this.executorName}" exited unexpectedly with code: ${code}`));
51
- }
52
- });
53
- }),
54
- new Promise((res) => {
55
- this.onResults(res);
56
- }),
57
- ]);
58
- }
59
- send(message) {
60
- if (this.childProcess.connected) {
61
- this.childProcess.send(message);
62
- }
63
- }
64
- kill(signal) {
65
- if (this.childProcess.connected) {
66
- this.childProcess.kill(signal);
67
- }
68
- }
69
- }
70
- exports.BatchProcess = BatchProcess;
@@ -1,36 +0,0 @@
1
- import { ChildProcess, Serializable } from 'child_process';
2
- import { RunningTask } from './running-task';
3
- export declare class NodeChildProcessWithNonDirectOutput implements RunningTask {
4
- private childProcess;
5
- private terminalOutput;
6
- private exitCallbacks;
7
- constructor(childProcess: ChildProcess, { streamOutput, prefix }: {
8
- streamOutput: boolean;
9
- prefix: string;
10
- });
11
- onExit(cb: (code: number, terminalOutput: string) => void): void;
12
- getResults(): Promise<{
13
- code: number;
14
- terminalOutput: string;
15
- }>;
16
- send(message: Serializable): void;
17
- kill(signal?: NodeJS.Signals | number): void;
18
- }
19
- export declare class NodeChildProcessWithDirectOutput implements RunningTask {
20
- private childProcess;
21
- private temporaryOutputPath;
22
- private terminalOutput;
23
- private exitCallbacks;
24
- private exited;
25
- private exitCode;
26
- constructor(childProcess: ChildProcess, temporaryOutputPath: string);
27
- send(message: Serializable): void;
28
- onExit(cb: (code: number, signal: NodeJS.Signals) => void): void;
29
- getResults(): Promise<{
30
- code: number;
31
- terminalOutput: string;
32
- }>;
33
- waitForExit(): Promise<void>;
34
- getTerminalOutput(): string;
35
- kill(signal?: NodeJS.Signals | number): void;
36
- }
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeChildProcessWithDirectOutput = exports.NodeChildProcessWithNonDirectOutput = void 0;
4
- const exit_codes_1 = require("../../utils/exit-codes");
5
- const stream_1 = require("stream");
6
- const chalk = require("chalk");
7
- const fs_1 = require("fs");
8
- class NodeChildProcessWithNonDirectOutput {
9
- constructor(childProcess, { streamOutput, prefix }) {
10
- this.childProcess = childProcess;
11
- this.terminalOutput = '';
12
- this.exitCallbacks = [];
13
- if (streamOutput) {
14
- if (process.env.NX_PREFIX_OUTPUT === 'true') {
15
- const color = getColor(prefix);
16
- const prefixText = `${prefix}:`;
17
- this.childProcess.stdout
18
- .pipe(logClearLineToPrefixTransformer(color.bold(prefixText) + ' '))
19
- .pipe(addPrefixTransformer(color.bold(prefixText)))
20
- .pipe(process.stdout);
21
- this.childProcess.stderr
22
- .pipe(logClearLineToPrefixTransformer(color(prefixText) + ' '))
23
- .pipe(addPrefixTransformer(color(prefixText)))
24
- .pipe(process.stderr);
25
- }
26
- else {
27
- this.childProcess.stdout
28
- .pipe(addPrefixTransformer())
29
- .pipe(process.stdout);
30
- this.childProcess.stderr
31
- .pipe(addPrefixTransformer())
32
- .pipe(process.stderr);
33
- }
34
- }
35
- this.childProcess.on('exit', (code, signal) => {
36
- if (code === null)
37
- code = (0, exit_codes_1.signalToCode)(signal);
38
- for (const cb of this.exitCallbacks) {
39
- cb(code, this.terminalOutput);
40
- }
41
- });
42
- // Re-emit any messages from the task process
43
- this.childProcess.on('message', (message) => {
44
- if (process.send) {
45
- process.send(message);
46
- }
47
- });
48
- this.childProcess.stdout.on('data', (chunk) => {
49
- this.terminalOutput += chunk.toString();
50
- });
51
- this.childProcess.stderr.on('data', (chunk) => {
52
- this.terminalOutput += chunk.toString();
53
- });
54
- }
55
- onExit(cb) {
56
- this.exitCallbacks.push(cb);
57
- }
58
- async getResults() {
59
- return new Promise((res) => {
60
- this.onExit((code, terminalOutput) => {
61
- res({ code, terminalOutput });
62
- });
63
- });
64
- }
65
- send(message) {
66
- if (this.childProcess.connected) {
67
- this.childProcess.send(message);
68
- }
69
- }
70
- kill(signal) {
71
- if (this.childProcess.connected) {
72
- this.childProcess.kill(signal);
73
- }
74
- }
75
- }
76
- exports.NodeChildProcessWithNonDirectOutput = NodeChildProcessWithNonDirectOutput;
77
- function addPrefixTransformer(prefix) {
78
- const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';
79
- return new stream_1.Transform({
80
- transform(chunk, _encoding, callback) {
81
- const list = chunk.toString().split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
82
- list
83
- .filter(Boolean)
84
- .forEach((m) => this.push(prefix ? prefix + ' ' + m + newLineSeparator : m + newLineSeparator));
85
- callback();
86
- },
87
- });
88
- }
89
- const colors = [
90
- chalk.green,
91
- chalk.greenBright,
92
- chalk.red,
93
- chalk.redBright,
94
- chalk.cyan,
95
- chalk.cyanBright,
96
- chalk.yellow,
97
- chalk.yellowBright,
98
- chalk.magenta,
99
- chalk.magentaBright,
100
- ];
101
- function getColor(projectName) {
102
- let code = 0;
103
- for (let i = 0; i < projectName.length; ++i) {
104
- code += projectName.charCodeAt(i);
105
- }
106
- const colorIndex = code % colors.length;
107
- return colors[colorIndex];
108
- }
109
- /**
110
- * Prevents terminal escape sequence from clearing line prefix.
111
- */
112
- function logClearLineToPrefixTransformer(prefix) {
113
- let prevChunk = null;
114
- return new stream_1.Transform({
115
- transform(chunk, _encoding, callback) {
116
- if (prevChunk && prevChunk.toString() === '\x1b[2K') {
117
- chunk = chunk.toString().replace(/\x1b\[1G/g, (m) => m + prefix);
118
- }
119
- this.push(chunk);
120
- prevChunk = chunk;
121
- callback();
122
- },
123
- });
124
- }
125
- class NodeChildProcessWithDirectOutput {
126
- constructor(childProcess, temporaryOutputPath) {
127
- this.childProcess = childProcess;
128
- this.temporaryOutputPath = temporaryOutputPath;
129
- this.exitCallbacks = [];
130
- this.exited = false;
131
- // Re-emit any messages from the task process
132
- this.childProcess.on('message', (message) => {
133
- if (process.send) {
134
- process.send(message);
135
- }
136
- });
137
- this.childProcess.on('exit', (code, signal) => {
138
- if (code === null)
139
- code = (0, exit_codes_1.signalToCode)(signal);
140
- this.exited = true;
141
- this.exitCode = code;
142
- for (const cb of this.exitCallbacks) {
143
- cb(code, signal);
144
- }
145
- });
146
- }
147
- send(message) {
148
- if (this.childProcess.connected) {
149
- this.childProcess.send(message);
150
- }
151
- }
152
- onExit(cb) {
153
- this.exitCallbacks.push(cb);
154
- }
155
- async getResults() {
156
- const terminalOutput = this.getTerminalOutput();
157
- if (this.exited) {
158
- return Promise.resolve({
159
- code: this.exitCode,
160
- terminalOutput,
161
- });
162
- }
163
- await this.waitForExit();
164
- return Promise.resolve({
165
- code: this.exitCode,
166
- terminalOutput,
167
- });
168
- }
169
- waitForExit() {
170
- return new Promise((res) => {
171
- this.onExit(() => res());
172
- });
173
- }
174
- getTerminalOutput() {
175
- this.terminalOutput ??= (0, fs_1.readFileSync)(this.temporaryOutputPath).toString();
176
- return this.terminalOutput;
177
- }
178
- kill(signal) {
179
- if (this.childProcess.connected) {
180
- this.childProcess.kill(signal);
181
- }
182
- }
183
- }
184
- exports.NodeChildProcessWithDirectOutput = NodeChildProcessWithDirectOutput;
@@ -1,15 +0,0 @@
1
- import { RunningTask } from './running-task';
2
- export declare class NoopChildProcess implements RunningTask {
3
- private results;
4
- constructor(results: {
5
- code: number;
6
- terminalOutput: string;
7
- });
8
- send(): void;
9
- getResults(): Promise<{
10
- code: number;
11
- terminalOutput: string;
12
- }>;
13
- kill(): void;
14
- onExit(cb: (code: number) => void): void;
15
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoopChildProcess = void 0;
4
- class NoopChildProcess {
5
- constructor(results) {
6
- this.results = results;
7
- }
8
- send() { }
9
- async getResults() {
10
- return this.results;
11
- }
12
- kill() {
13
- return;
14
- }
15
- onExit(cb) {
16
- cb(this.results.code);
17
- }
18
- }
19
- exports.NoopChildProcess = NoopChildProcess;
@@ -1,8 +0,0 @@
1
- export declare abstract class RunningTask {
2
- abstract getResults(): Promise<{
3
- code: number;
4
- terminalOutput: string;
5
- }>;
6
- abstract onExit(cb: (code: number) => void): void;
7
- abstract kill(signal?: NodeJS.Signals | number): Promise<void> | void;
8
- }