11import { spawn , SpawnOptions } from 'node:child_process' ;
22import * as child_process from 'node:child_process' ;
3- import { concat , defer , EMPTY , from , lastValueFrom , catchError , repeat } from 'rxjs' ;
43import { getGlobalVariable , getGlobalVariablesEnv } from './env' ;
54import treeKill from 'tree-kill' ;
65import { delimiter , join , resolve } from 'node:path' ;
@@ -310,7 +309,7 @@ export async function execAndCaptureError(
310309 }
311310}
312311
313- export function execAndWaitForOutputToMatch (
312+ export async function execAndWaitForOutputToMatch (
314313 cmd : string ,
315314 args : string [ ] ,
316315 match : RegExp ,
@@ -322,15 +321,19 @@ export function execAndWaitForOutputToMatch(
322321 // happened just before the build (e.g. `git clean`).
323322 // This seems to be due to host file system differences, see
324323 // https://nodejs.org/docs/latest/api/fs.html#fs_caveats
325- return lastValueFrom (
326- concat (
327- from ( _exec ( { waitForMatch : match , env } , cmd , args ) ) ,
328- defer ( ( ) => waitForAnyProcessOutputToMatch ( match , 2500 ) ) . pipe (
329- repeat ( 20 ) ,
330- catchError ( ( ) => EMPTY ) ,
331- ) ,
332- ) ,
333- ) ;
324+ const maxRetries = 20 ;
325+ let lastResult = await _exec ( { waitForMatch : match , env } , cmd , args ) ;
326+
327+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
328+ try {
329+ lastResult = await waitForAnyProcessOutputToMatch ( match , 2500 ) ;
330+ } catch {
331+ // If we timeout (no new match found), we assume the process is stable.
332+ break ;
333+ }
334+ }
335+
336+ return lastResult ;
334337 } else {
335338 return _exec ( { waitForMatch : match , env } , cmd , args ) ;
336339 }
0 commit comments