@@ -31,15 +31,16 @@ export class Executer {
31
31
}
32
32
33
33
async _execute ( command : string , name : string , args : string [ ] , logger : Logger ) {
34
+
34
35
if ( this . child ) {
35
36
await this . closeChild ( ) ;
36
37
}
37
-
38
38
const child = execaCommand ( [ command , ...args ] . join ( ' ' ) , {
39
39
cwd : process . cwd ( ) ,
40
40
stdio : 'pipe' ,
41
41
} ) ;
42
42
43
+
43
44
child . stdout ?. on ( 'data' , ( data ) => logger . debug ( trimEndLF ( data . toString ( ) ) ) ) ;
44
45
45
46
child . stderr ?. on ( 'data' , ( err ) => logger . error ( err ) ) ;
@@ -49,17 +50,37 @@ export class Executer {
49
50
process . on ( 'beforeExit' , this . closeChild ) ;
50
51
process . on ( 'exit' , this . closeChild ) ;
51
52
52
- child . on ( 'exit' , ( code ) => {
53
+ child . once ( 'exit' , ( code ) => {
53
54
this . logger . info ( `"${ name } " PID ${ child . pid } ${ ! code ? 'done' : `exit ${ code } ` } ` ) ;
54
55
this . child = undefined ;
55
56
} ) ;
56
57
}
57
58
58
59
async closeChild ( ) {
59
- while ( this . child && ! this . child . killed ) {
60
- this . child . kill ( ) ;
61
- await delay ( 50 ) ;
60
+ if ( ! this . child ) {
61
+ return ;
62
+ }
63
+
64
+ const child = this . child ;
65
+
66
+ const exitPromise = new Promise < void > ( ( resolve ) => {
67
+ child . once ( 'exit' , ( ) => {
68
+ resolve ( ) ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ try {
73
+ await this . terminateChild ( child ) ;
74
+ await exitPromise ;
75
+ } finally {
76
+ this . child = undefined ;
77
+ }
78
+ }
79
+
80
+ private async terminateChild ( child : ExecaChildProcess ) {
81
+ while ( child && ! child . killed ) {
82
+ child . kill ( ) ;
83
+ await delay ( 30 ) ;
62
84
}
63
- this . child = undefined ;
64
85
}
65
86
}
0 commit comments