Skip to content

Commit

Permalink
fix(core): group command exit listeners to avoid warning (#22892)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Apr 18, 2024
1 parent 4d6cd36 commit e2cee00
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import {
getPseudoTerminal,
PseudoTerminal,
} from '../../tasks-runner/pseudo-terminal';
import { output } from '../../utils/output';

export const LARGE_BUFFER = 1024 * 1000000;

const exitListeners: Set<() => void> = new Set();

function processExitListener() {
for (const listener of exitListeners) {
listener();
}
}

process.on('exit', processExitListener);
process.on('SIGTERM', processExitListener);
process.on('SIGINT', processExitListener);
process.on('SIGQUIT', processExitListener);

async function loadEnvVars(path?: string) {
if (path) {
const result = (await import('dotenv')).config({ path });
Expand Down Expand Up @@ -363,13 +375,10 @@ function nodeProcess(
/**
* Ensure the child process is killed when the parent exits
*/
const processExitListener = (signal?: number | NodeJS.Signals) =>
const childProcessKiller = (signal?: number | NodeJS.Signals) =>
childProcess.kill(signal);

process.on('exit', processExitListener);
process.on('SIGTERM', processExitListener);
process.on('SIGINT', processExitListener);
process.on('SIGQUIT', processExitListener);
exitListeners.add(childProcessKiller);

childProcess.stdout.on('data', (data) => {
const output = addColorAndPrefix(data, commandConfig);
Expand Down Expand Up @@ -400,6 +409,7 @@ function nodeProcess(
res({ success: false, terminalOutput });
});
childProcess.on('exit', (code) => {
exitListeners.delete(childProcessKiller);
if (!readyWhen) {
res({ success: code === 0, terminalOutput });
}
Expand Down

0 comments on commit e2cee00

Please sign in to comment.