@@ -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
cwd ?: string ;
16
16
}
@@ -61,7 +61,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
61
61
}
62
62
63
63
const childProcess = child_process . spawn ( cmd , args , spawnOptions ) ;
64
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
64
+ // @ts -ignore
65
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
65
66
stdout += data . toString ( 'utf-8' ) ;
66
67
if ( options . silent ) {
67
68
return ;
@@ -72,7 +73,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
72
73
. filter ( ( line ) => line !== '' )
73
74
. forEach ( ( line ) => console . log ( ' ' + line ) ) ;
74
75
} ) ;
75
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
76
+ // @ts -ignore
77
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
76
78
stderr += data . toString ( 'utf-8' ) ;
77
79
if ( options . silent ) {
78
80
return ;
@@ -118,13 +120,15 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
118
120
119
121
if ( options . waitForMatch ) {
120
122
const match = options . waitForMatch ;
121
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
123
+ // @ts -ignore
124
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
122
125
if ( data . toString ( ) . match ( match ) ) {
123
126
resolve ( { stdout, stderr } ) ;
124
127
matched = true ;
125
128
}
126
129
} ) ;
127
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
130
+ // @ts -ignore
131
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
128
132
if ( data . toString ( ) . match ( match ) ) {
129
133
resolve ( { stdout, stderr } ) ;
130
134
matched = true ;
@@ -134,16 +138,16 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
134
138
135
139
// Provide input to stdin if given.
136
140
if ( options . stdin ) {
137
- childProcess . stdin . write ( options . stdin ) ;
138
- childProcess . stdin . end ( ) ;
141
+ childProcess . stdin ! . write ( options . stdin ) ;
142
+ childProcess . stdin ! . end ( ) ;
139
143
}
140
144
} ) ;
141
145
}
142
146
143
147
export function extractNpmEnv ( ) {
144
148
return Object . keys ( process . env )
145
149
. filter ( ( v ) => NPM_CONFIG_RE . test ( v ) )
146
- . reduce (
150
+ . reduce < NodeJS . ProcessEnv > (
147
151
( vars , n ) => {
148
152
vars [ n ] = process . env [ n ] ;
149
153
return vars ;
@@ -171,13 +175,15 @@ export function waitForAnyProcessOutputToMatch(
171
175
new Promise ( ( resolve ) => {
172
176
let stdout = '' ;
173
177
let stderr = '' ;
174
- childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
178
+ // @ts -ignore
179
+ childProcess . stdout ! . on ( 'data' , ( data : Buffer ) => {
175
180
stdout += data . toString ( ) ;
176
181
if ( data . toString ( ) . match ( match ) ) {
177
182
resolve ( { stdout, stderr } ) ;
178
183
}
179
184
} ) ;
180
- childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
185
+ // @ts -ignore
186
+ childProcess . stderr ! . on ( 'data' , ( data : Buffer ) => {
181
187
stderr += data . toString ( ) ;
182
188
if ( data . toString ( ) . match ( match ) ) {
183
189
resolve ( { stdout, stderr } ) ;
@@ -205,7 +211,7 @@ export function silentExec(cmd: string, ...args: string[]) {
205
211
export function execWithEnv (
206
212
cmd : string ,
207
213
args : string [ ] ,
208
- env : { [ varname : string ] : string } ,
214
+ env : { [ varname : string ] : string | undefined } ,
209
215
stdin ?: string ,
210
216
) {
211
217
return _exec ( { env, stdin } , cmd , args ) ;
@@ -214,7 +220,7 @@ export function execWithEnv(
214
220
export async function execAndCaptureError (
215
221
cmd : string ,
216
222
args : string [ ] ,
217
- env ?: { [ varname : string ] : string } ,
223
+ env ?: { [ varname : string ] : string | undefined } ,
218
224
stdin ?: string ,
219
225
) : Promise < Error > {
220
226
try {
@@ -229,7 +235,7 @@ export function execAndWaitForOutputToMatch(
229
235
cmd : string ,
230
236
args : string [ ] ,
231
237
match : RegExp ,
232
- env ?: { [ varName : string ] : string } ,
238
+ env ?: { [ varName : string ] : string | undefined } ,
233
239
) {
234
240
if ( cmd === 'ng' && args [ 0 ] === 'serve' ) {
235
241
// Accept matches up to 20 times after the initial match.
0 commit comments