Skip to content

Commit 6ab9ae3

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): group command exit listeners to avoid warning (#22892)
(cherry picked from commit e2cee00)
1 parent b633c04 commit 6ab9ae3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ import {
88
getPseudoTerminal,
99
PseudoTerminal,
1010
} from '../../tasks-runner/pseudo-terminal';
11-
import { output } from '../../utils/output';
1211

1312
export const LARGE_BUFFER = 1024 * 1000000;
1413

14+
const exitListeners: Set<() => void> = new Set();
15+
16+
function processExitListener() {
17+
for (const listener of exitListeners) {
18+
listener();
19+
}
20+
}
21+
22+
process.on('exit', processExitListener);
23+
process.on('SIGTERM', processExitListener);
24+
process.on('SIGINT', processExitListener);
25+
process.on('SIGQUIT', processExitListener);
26+
1527
async function loadEnvVars(path?: string) {
1628
if (path) {
1729
const result = (await import('dotenv')).config({ path });
@@ -363,13 +375,10 @@ function nodeProcess(
363375
/**
364376
* Ensure the child process is killed when the parent exits
365377
*/
366-
const processExitListener = (signal?: number | NodeJS.Signals) =>
378+
const childProcessKiller = (signal?: number | NodeJS.Signals) =>
367379
childProcess.kill(signal);
368380

369-
process.on('exit', processExitListener);
370-
process.on('SIGTERM', processExitListener);
371-
process.on('SIGINT', processExitListener);
372-
process.on('SIGQUIT', processExitListener);
381+
exitListeners.add(childProcessKiller);
373382

374383
childProcess.stdout.on('data', (data) => {
375384
const output = addColorAndPrefix(data, commandConfig);
@@ -400,6 +409,7 @@ function nodeProcess(
400409
res({ success: false, terminalOutput });
401410
});
402411
childProcess.on('exit', (code) => {
412+
exitListeners.delete(childProcessKiller);
403413
if (!readyWhen) {
404414
res({ success: code === 0, terminalOutput });
405415
}

0 commit comments

Comments
 (0)