@@ -6,9 +6,9 @@ const execa = require("execa");
66const logTransformer = require ( "strong-log-transformer" ) ;
77
88// bookkeeping for spawned processes
9- let children = 0 ;
9+ const children = new Set ( ) ;
1010
11- // when streaming children are spawned, use this color for prefix
11+ // when streaming processes are spawned, use this color for prefix
1212const colorWheel = [ "cyan" , "magenta" , "blue" , "yellow" , "green" , "red" ] ;
1313const NUM_COLORS = colorWheel . length ;
1414
@@ -54,9 +54,9 @@ function spawnStreaming(command, args, opts, prefix) {
5454 }
5555
5656 // Avoid "Possible EventEmitter memory leak detected" warning due to piped stdio
57- if ( children > process . stdout . listenerCount ( "close" ) ) {
58- process . stdout . setMaxListeners ( children ) ;
59- process . stderr . setMaxListeners ( children ) ;
57+ if ( children . size > process . stdout . listenerCount ( "close" ) ) {
58+ process . stdout . setMaxListeners ( children . size ) ;
59+ process . stderr . setMaxListeners ( children . size ) ;
6060 }
6161
6262 spawned . stdout . pipe ( logTransformer ( stdoutOpts ) ) . pipe ( process . stdout ) ;
@@ -66,7 +66,7 @@ function spawnStreaming(command, args, opts, prefix) {
6666}
6767
6868function getChildProcessCount ( ) {
69- return children ;
69+ return children . size ;
7070}
7171
7272function getExitCode ( result ) {
@@ -86,11 +86,9 @@ function getExitCode(result) {
8686}
8787
8888function spawnProcess ( command , args , opts ) {
89- children += 1 ;
90-
9189 const child = execa ( command , args , opts ) ;
9290 const drain = ( code , signal ) => {
93- children -= 1 ;
91+ children . delete ( child ) ;
9492
9593 // don't run repeatedly if this is the error event
9694 if ( signal === undefined ) {
@@ -105,6 +103,8 @@ function spawnProcess(command, args, opts) {
105103 child . pkg = opts . pkg ;
106104 }
107105
106+ children . add ( child ) ;
107+
108108 return child ;
109109}
110110
0 commit comments