@@ -10,7 +10,7 @@ import treeKill from 'tree-kill';
10
10
interface ExecOptions {
11
11
silent ?: boolean ;
12
12
waitForMatch ?: RegExp ;
13
- env ?: { [ varname : string ] : string } ;
13
+ env ?: NodeJS . ProcessEnv ;
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 } ) ;
@@ -216,19 +222,14 @@ export function silentExec(cmd: string, ...args: string[]) {
216
222
return _exec ( { silent : true } , cmd , args ) ;
217
223
}
218
224
219
- export function execWithEnv (
220
- cmd : string ,
221
- args : string [ ] ,
222
- env : { [ varname : string ] : string } ,
223
- stdin ?: string ,
224
- ) {
225
+ export function execWithEnv ( cmd : string , args : string [ ] , env : NodeJS . ProcessEnv , stdin ?: string ) {
225
226
return _exec ( { env, stdin } , cmd , args ) ;
226
227
}
227
228
228
229
export async function execAndCaptureError (
229
230
cmd : string ,
230
231
args : string [ ] ,
231
- env ?: { [ varname : string ] : string } ,
232
+ env ?: NodeJS . ProcessEnv ,
232
233
stdin ?: string ,
233
234
) : Promise < Error > {
234
235
try {
@@ -243,7 +244,7 @@ export function execAndWaitForOutputToMatch(
243
244
cmd : string ,
244
245
args : string [ ] ,
245
246
match : RegExp ,
246
- env ?: { [ varName : string ] : string } ,
247
+ env ?: NodeJS . ProcessEnv ,
247
248
) {
248
249
if ( cmd === 'ng' && args [ 0 ] === 'serve' ) {
249
250
// Accept matches up to 20 times after the initial match.
0 commit comments