@@ -20,25 +20,31 @@ function handleArgs(command, args, options) {
20
20
args = parsed . args ;
21
21
options = parsed . options ;
22
22
23
- options = Object . assign ( {
23
+ options = {
24
24
maxBuffer : TEN_MEGABYTES ,
25
25
buffer : true ,
26
26
stripFinalNewline : true ,
27
27
preferLocal : true ,
28
28
localDir : options . cwd || process . cwd ( ) ,
29
29
encoding : 'utf8' ,
30
30
reject : true ,
31
- cleanup : true
32
- } , options , {
31
+ cleanup : true ,
32
+ ... options ,
33
33
windowsHide : true
34
- } ) ;
34
+ } ;
35
35
36
36
if ( options . extendEnv !== false ) {
37
- options . env = Object . assign ( { } , process . env , options . env ) ;
37
+ options . env = {
38
+ ...process . env ,
39
+ ...options . env
40
+ } ;
38
41
}
39
42
40
43
if ( options . preferLocal ) {
41
- options . env = npmRunPath . env ( Object . assign ( { } , options , { cwd : options . localDir } ) ) ;
44
+ options . env = npmRunPath . env ( {
45
+ ...options ,
46
+ cwd : options . localDir
47
+ } ) ;
42
48
}
43
49
44
50
// TODO: Remove in the next major release
@@ -82,7 +88,7 @@ function handleOutput(options, value) {
82
88
}
83
89
84
90
function handleShell ( fn , command , options ) {
85
- return fn ( command , Object . assign ( { } , options , { shell : true } ) ) ;
91
+ return fn ( command , { ... options , shell : true } ) ;
86
92
}
87
93
88
94
function getStream ( process , stream , { encoding, buffer, maxBuffer} ) {
@@ -257,14 +263,15 @@ module.exports = (command, args, options) => {
257
263
}
258
264
}
259
265
266
+ // TODO: Use native "finally" syntax when targeting Node.js 10
260
267
const handlePromise = ( ) => pFinally ( Promise . all ( [
261
268
processDone ,
262
269
getStream ( spawned , 'stdout' , { encoding, buffer, maxBuffer} ) ,
263
270
getStream ( spawned , 'stderr' , { encoding, buffer, maxBuffer} )
264
- ] ) . then ( arr => {
265
- const result = arr [ 0 ] ;
266
- result . stdout = arr [ 1 ] ;
267
- result . stderr = arr [ 2 ] ;
271
+ ] ) . then ( results => { // eslint-disable-line promise/prefer-await-to-then
272
+ const result = results [ 0 ] ;
273
+ result . stdout = results [ 1 ] ;
274
+ result . stderr = results [ 2 ] ;
268
275
269
276
if ( result . error || result . code !== 0 || result . signal !== null ) {
270
277
const error = makeError ( result , {
@@ -301,21 +308,29 @@ module.exports = (command, args, options) => {
301
308
302
309
handleInput ( spawned , parsed . options . input ) ;
303
310
304
- spawned . then = ( onfulfilled , onrejected ) => handlePromise ( ) . then ( onfulfilled , onrejected ) ;
305
- spawned . catch = onrejected => handlePromise ( ) . catch ( onrejected ) ;
306
- // eslint-disable-next-line no-use-extend-native/no-use-extend-native
311
+ // eslint-disable-next-line promise/prefer-await-to-then
312
+ spawned . then = ( onFulfilled , onRejected ) => handlePromise ( ) . then ( onFulfilled , onRejected ) ;
313
+ spawned . catch = onRejected => handlePromise ( ) . catch ( onRejected ) ;
314
+
315
+ // TOOD: Remove the `if`-guard when targeting Node.js 10
307
316
if ( Promise . prototype . finally ) {
308
- spawned . finally = onfinally => handlePromise ( ) . finally ( onfinally ) ;
317
+ spawned . finally = onFinally => handlePromise ( ) . finally ( onFinally ) ;
309
318
}
310
319
311
320
return spawned ;
312
321
} ;
313
322
314
323
// TODO: set `stderr: 'ignore'` when that option is implemented
315
- module . exports . stdout = ( ...args ) => module . exports ( ...args ) . then ( x => x . stdout ) ;
324
+ module . exports . stdout = async ( ...args ) => {
325
+ const { stdout} = await module . exports ( ...args ) ;
326
+ return stdout ;
327
+ } ;
316
328
317
329
// TODO: set `stdout: 'ignore'` when that option is implemented
318
- module . exports . stderr = ( ...args ) => module . exports ( ...args ) . then ( x => x . stderr ) ;
330
+ module . exports . stderr = async ( ...args ) => {
331
+ const { stderr} = await module . exports ( ...args ) ;
332
+ return stderr ;
333
+ } ;
319
334
320
335
module . exports . shell = ( command , options ) => handleShell ( module . exports , command , options ) ;
321
336
0 commit comments