Skip to content

Commit fd11334

Browse files
caioaaoAgentEnder
andauthoredMar 17, 2023
fix(core): combine serial and parallel execution + forward sigint to child process (#13885)
Co-authored-by: AgentEnder <craigorycoppola@gmail.com>
1 parent 616f0f0 commit fd11334

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed
 

‎e2e/nx-misc/src/extras.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ describe('Extra Nx Misc Tests', () => {
200200
runCLI(`run ${mylib}:error`);
201201
fail('Should error if process errors');
202202
} catch (e) {
203-
expect(e.stdout.toString()).toContain(
204-
'Something went wrong in run-commands - Command failed: exit 1'
203+
expect(e.stderr.toString()).toContain(
204+
'command "exit 1" exited with non-zero status code'
205205
);
206206
}
207207
});

‎packages/nx/src/executors/run-commands/run-commands.impl.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec, execSync } from 'child_process';
1+
import { exec } from 'child_process';
22
import * as path from 'path';
33
import * as yargsParser from 'yargs-parser';
44
import { env as appendLocalEnv } from 'npm-run-path';
@@ -176,12 +176,20 @@ async function runSerially(
176176
context: ExecutorContext
177177
) {
178178
for (const c of options.commands) {
179-
createSyncProcess(
180-
c.command,
179+
const success = await createProcess(
180+
c,
181+
undefined,
181182
options.color,
182183
calculateCwd(options.cwd, context)
183184
);
185+
if (!success) {
186+
process.stderr.write(
187+
`Warning: run-commands command "${c.command}" exited with non-zero status code`
188+
);
189+
return false;
190+
}
184191
}
192+
185193
return true;
186194
}
187195

@@ -205,9 +213,14 @@ function createProcess(
205213
/**
206214
* Ensure the child process is killed when the parent exits
207215
*/
208-
const processExitListener = () => childProcess.kill();
216+
const processExitListener = (signal?: number | NodeJS.Signals) => () =>
217+
childProcess.kill(signal);
218+
209219
process.on('exit', processExitListener);
210220
process.on('SIGTERM', processExitListener);
221+
process.on('SIGINT', processExitListener);
222+
process.on('SIGQUIT', processExitListener);
223+
211224
childProcess.stdout.on('data', (data) => {
212225
process.stdout.write(addColorAndPrefix(data, commandConfig));
213226
if (readyWhen && data.toString().indexOf(readyWhen) > -1) {
@@ -253,15 +266,6 @@ function addColorAndPrefix(
253266
return out;
254267
}
255268

256-
function createSyncProcess(command: string, color: boolean, cwd: string) {
257-
execSync(command, {
258-
env: processEnv(color),
259-
stdio: ['inherit', 'inherit', 'inherit'],
260-
maxBuffer: LARGE_BUFFER,
261-
cwd,
262-
});
263-
}
264-
265269
function calculateCwd(
266270
cwd: string | undefined,
267271
context: ExecutorContext

0 commit comments

Comments
 (0)