@@ -8,10 +8,22 @@ import {
8
8
getPseudoTerminal ,
9
9
PseudoTerminal ,
10
10
} from '../../tasks-runner/pseudo-terminal' ;
11
- import { output } from '../../utils/output' ;
12
11
13
12
export const LARGE_BUFFER = 1024 * 1000000 ;
14
13
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
+
15
27
async function loadEnvVars ( path ?: string ) {
16
28
if ( path ) {
17
29
const result = ( await import ( 'dotenv' ) ) . config ( { path } ) ;
@@ -363,13 +375,10 @@ function nodeProcess(
363
375
/**
364
376
* Ensure the child process is killed when the parent exits
365
377
*/
366
- const processExitListener = ( signal ?: number | NodeJS . Signals ) =>
378
+ const childProcessKiller = ( signal ?: number | NodeJS . Signals ) =>
367
379
childProcess . kill ( signal ) ;
368
380
369
- process . on ( 'exit' , processExitListener ) ;
370
- process . on ( 'SIGTERM' , processExitListener ) ;
371
- process . on ( 'SIGINT' , processExitListener ) ;
372
- process . on ( 'SIGQUIT' , processExitListener ) ;
381
+ exitListeners . add ( childProcessKiller ) ;
373
382
374
383
childProcess . stdout . on ( 'data' , ( data ) => {
375
384
const output = addColorAndPrefix ( data , commandConfig ) ;
@@ -400,6 +409,7 @@ function nodeProcess(
400
409
res ( { success : false , terminalOutput } ) ;
401
410
} ) ;
402
411
childProcess . on ( 'exit' , ( code ) => {
412
+ exitListeners . delete ( childProcessKiller ) ;
403
413
if ( ! readyWhen ) {
404
414
res ( { success : code === 0 , terminalOutput } ) ;
405
415
}
0 commit comments