@@ -108,8 +108,8 @@ function startInspector() {
108108/**
109109 * Wait for the dev server to be ready
110110 */
111- async function waitForServerReady ( { process, textMatch, name } ) {
112- if ( ! process ) return
111+ async function waitForServerReady ( { process : childProcess , textMatch, name } ) {
112+ if ( ! childProcess ) return
113113
114114 return new Promise ( ( resolve , reject ) => {
115115 const timeout = setTimeout ( ( ) => {
@@ -121,18 +121,21 @@ async function waitForServerReady({ process, textMatch, name }) {
121121 const str = data . toString ( )
122122 if ( str . includes ( textMatch ) ) {
123123 clearTimeout ( timeout )
124+ // Remove the listeners after finding the match
125+ childProcess . stdout . removeListener ( 'data' , searchForMatch )
126+ childProcess . stderr . removeListener ( 'data' , searchForMatch )
124127 resolve ( )
125128 }
126129 }
127- process . stdout . on ( 'data' , searchForMatch )
128- process . stderr . on ( 'data' , searchForMatch )
130+ childProcess . stdout . on ( 'data' , searchForMatch )
131+ childProcess . stderr . on ( 'data' , searchForMatch )
129132
130- process . on ( 'error' , ( err ) => {
133+ childProcess . on ( 'error' , ( err ) => {
131134 clearTimeout ( timeout )
132135 reject ( err )
133136 } )
134137
135- process . on ( 'exit' , ( code ) => {
138+ childProcess . on ( 'exit' , ( code ) => {
136139 if ( code !== 0 ) {
137140 clearTimeout ( timeout )
138141 reject ( new Error ( `${ name } exited with code ${ code } ` ) )
@@ -141,15 +144,15 @@ async function waitForServerReady({ process, textMatch, name }) {
141144 } )
142145}
143146
144- function pipeOutputToConsole ( { process, name, color } ) {
145- if ( ! process ) return
147+ function pipeOutputToConsole ( { process : childProcess , name, color } ) {
148+ if ( ! childProcess ) return
146149
147- process . stdout . on ( 'data' , ( data ) => {
150+ childProcess . stdout . on ( 'data' , ( data ) => {
148151 const str = data . toString ( )
149152 process . stdout . write ( styleText ( color , `${ name } ` ) + str )
150153 } )
151154
152- process . stderr . on ( 'data' , ( data ) => {
155+ childProcess . stderr . on ( 'data' , ( data ) => {
153156 const str = data . toString ( )
154157 process . stderr . write ( styleText ( color , `${ name } ` ) + str )
155158 } )
@@ -285,7 +288,7 @@ function startProxyServer(server) {
285288/**
286289 * Setup graceful shutdown
287290 */
288- function setupGracefulShutdown ( server , proxy ) {
291+ function setupGracefulShutdown ( ) {
289292 const closeListeners = closeWithGrace (
290293 { delay : 500 } ,
291294 async function ( { signal, err } ) {
@@ -316,6 +319,9 @@ async function main() {
316319 startProxyServer ( server )
317320 setupGracefulShutdown ( server , proxy )
318321 } catch ( error ) {
322+ devServerProcess ?. kill ( )
323+ inspectorProcess ?. kill ( )
324+
319325 console . error ( 'Failed to start servers:' , error . message )
320326 process . exit ( 1 )
321327 }
0 commit comments