Compare commits

...

1 Commits

Author SHA1 Message Date
FrozenPandaz b708623fab fix(core): ensure that run-commands processes are cleaned up 2025-05-16 15:33:22 -04:00
2 changed files with 15 additions and 10 deletions
@@ -1,6 +1,5 @@
import * as yargsParser from 'yargs-parser';
import { ExecutorContext } from '../../config/misc-interfaces';
import { isTuiEnabled } from '../../tasks-runner/is-tui-enabled';
import { PseudoTerminal } from '../../tasks-runner/pseudo-terminal';
import {
ParallelRunningTasks,
@@ -129,14 +128,12 @@ export async function runCommands(
!normalized.commands[0].prefix &&
normalized.usePty;
const tuiEnabled = isTuiEnabled();
try {
const runningTask = isSingleCommandAndCanUsePseudoTerminal
? await runSingleCommandWithPseudoTerminal(normalized, context)
: options.parallel
? new ParallelRunningTasks(normalized, context)
: new SeriallyRunningTasks(normalized, context, tuiEnabled);
: new SeriallyRunningTasks(normalized, context);
return runningTask;
} catch (e) {
if (process.env.NX_VERBOSE_LOGGING === 'true') {
@@ -21,6 +21,13 @@ import {
RunCommandsCommandOptions,
} from './run-commands.impl';
const cleanupFns: Array<() => void> = [];
process.on('exit', () => {
for (const fn of cleanupFns) {
fn();
}
});
export class ParallelRunningTasks implements RunningTask {
private readonly childProcesses: RunningNodeProcess[];
private readyWhenStatus: { stringToMatch: string; found: boolean }[];
@@ -175,11 +182,7 @@ export class SeriallyRunningTasks implements RunningTask {
private error: any;
private outputCallbacks: Array<(terminalOutput: string) => void> = [];
constructor(
options: NormalizedRunCommandsOptions,
context: ExecutorContext,
private readonly tuiEnabled: boolean
) {
constructor(options: NormalizedRunCommandsOptions, context: ExecutorContext) {
this.run(options, context)
.catch((e) => {
this.error = e;
@@ -333,6 +336,7 @@ class RunningNodeProcess implements RunningTask {
cwd,
windowsHide: false,
});
cleanupFns.push(() => this.kill());
this.addListeners(commandConfig, streamOutput);
}
@@ -472,12 +476,16 @@ async function createProcessWithPseudoTty(
tty: boolean,
envFile?: string
) {
return pseudoTerminal.runCommand(commandConfig.command, {
const pseudoTtyProcess = pseudoTerminal.runCommand(commandConfig.command, {
cwd,
jsEnv: processEnv(color, cwd, env, envFile),
quiet: !streamOutput,
tty,
});
cleanupFns.push(() => pseudoTtyProcess.kill());
return pseudoTtyProcess;
}
function addColorAndPrefix(out: string, config: RunCommandsCommandOptions) {