@@ -10,7 +10,7 @@ const treeKill = require('tree-kill');
10
10
interface ExecOptions {
11
11
silent ?: boolean ;
12
12
waitForMatch ?: RegExp ;
13
- env ?: { [ varname : string ] : string } ;
13
+ env ?: { [ varname : string ] : string | undefined } ;
14
14
stdin ?: string ;
15
15
}
16
16
@@ -58,7 +58,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
58
58
}
59
59
60
60
const childProcess = child_process . spawn ( cmd , args , spawnOptions ) ;
61
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
61
+ // @ts -ignore
62
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
62
63
stdout += data . toString ( 'utf-8' ) ;
63
64
if ( options . silent ) {
64
65
return ;
@@ -69,7 +70,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
69
70
. filter ( ( line ) => line !== '' )
70
71
. forEach ( ( line ) => console . log ( ' ' + line ) ) ;
71
72
} ) ;
72
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
73
+ // @ts -ignore
74
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
73
75
stderr += data . toString ( 'utf-8' ) ;
74
76
if ( options . silent ) {
75
77
return ;
@@ -109,19 +111,21 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
109
111
) ;
110
112
} ) ;
111
113
childProcess . on ( 'error' , ( error ) => {
112
- err . message += `${ error } ...\n\nSTDOUT:\n${ stdout } \n\nSTDERR:\n${ stderr } \n` ;
113
- reject ( err ) ;
114
+ error . message += `${ error } ...\n\nSTDOUT:\n${ stdout } \n\nSTDERR:\n${ stderr } \n` ;
115
+ reject ( error ) ;
114
116
} ) ;
115
117
116
118
if ( options . waitForMatch ) {
117
119
const match = options . waitForMatch ;
118
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
120
+ // @ts -ignore
121
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
119
122
if ( data . toString ( ) . match ( match ) ) {
120
123
resolve ( { stdout, stderr } ) ;
121
124
matched = true ;
122
125
}
123
126
} ) ;
124
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
127
+ // @ts -ignore
128
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
125
129
if ( data . toString ( ) . match ( match ) ) {
126
130
resolve ( { stdout, stderr } ) ;
127
131
matched = true ;
@@ -131,8 +135,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
131
135
132
136
// Provide input to stdin if given.
133
137
if ( options . stdin ) {
134
- childProcess . stdin . write ( options . stdin ) ;
135
- childProcess . stdin . end ( ) ;
138
+ childProcess . stdin ! . write ( options . stdin ) ;
139
+ childProcess . stdin ! . end ( ) ;
136
140
}
137
141
} ) ;
138
142
}
@@ -154,13 +158,15 @@ export function waitForAnyProcessOutputToMatch(
154
158
new Promise ( ( resolve ) => {
155
159
let stdout = '' ;
156
160
let stderr = '' ;
157
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
161
+ // @ts -ignore
162
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
158
163
stdout += data . toString ( ) ;
159
164
if ( data . toString ( ) . match ( match ) ) {
160
165
resolve ( { stdout, stderr } ) ;
161
166
}
162
167
} ) ;
163
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
168
+ // @ts -ignore
169
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
164
170
stderr += data . toString ( ) ;
165
171
if ( data . toString ( ) . match ( match ) ) {
166
172
resolve ( { stdout, stderr } ) ;
@@ -188,7 +194,7 @@ export function silentExec(cmd: string, ...args: string[]) {
188
194
export function execWithEnv (
189
195
cmd : string ,
190
196
args : string [ ] ,
191
- env : { [ varname : string ] : string } ,
197
+ env : { [ varname : string ] : string | undefined } ,
192
198
stdin ?: string ,
193
199
) {
194
200
return _exec ( { env, stdin } , cmd , args ) ;
@@ -197,7 +203,7 @@ export function execWithEnv(
197
203
export async function execAndCaptureError (
198
204
cmd : string ,
199
205
args : string [ ] ,
200
- env ?: { [ varname : string ] : string } ,
206
+ env ?: { [ varname : string ] : string | undefined } ,
201
207
stdin ?: string ,
202
208
) : Promise < Error > {
203
209
try {
0 commit comments