@@ -9,37 +9,36 @@ module.exports = function run(commands, options, callback) {
99 let results = [ ] ;
1010 const queue = new Queue ( options . concurrency || Infinity ) ;
1111
12- for ( let index = 0 ; index < commands . length ; index ++ ) {
13- ( ( index ) => {
14- queue . defer ( ( cb ) => {
15- const command = commands [ index ] ;
16- const match = commands [ index ] . match ( bracketsRegEx ) ;
17- const argv = match ? parse ( match [ 1 ] ) : parse ( command ) ;
18- const args = argv . slice ( 1 ) ;
12+ commands . forEach ( ( _command , index ) => {
13+ queue . defer ( ( cb ) => {
14+ const command = commands [ index ] ;
15+ const match = commands [ index ] . match ( bracketsRegEx ) ;
16+ const argv = match ? parse ( match [ 1 ] ) : parse ( command ) ;
17+ const args = argv . slice ( 1 ) ;
1918
20- ! options . header || options . header ( command ) ;
21- spawn ( argv [ 0 ] , args , spawnOptions , ( err , result ) => {
22- if ( err && err . message . indexOf ( 'ExperimentalWarning' ) >= 0 ) {
23- res = err ;
24- err = null ;
25- }
19+ ! options . header || options . header ( command ) ;
20+ spawn ( argv [ 0 ] , args , spawnOptions , ( err , result ) => {
21+ if ( err && err . message . indexOf ( 'ExperimentalWarning' ) >= 0 ) {
22+ res = err ;
23+ err = null ;
24+ }
2625
27- // suppress error
28- if ( err && match ) {
29- result = err ;
30- err = null ;
31- }
26+ // suppress error
27+ if ( err && match ) {
28+ result = err ;
29+ err = null ;
30+ }
3231
33- results . push ( { index, command : argv [ 0 ] , args, error : err , result } ) ;
34- if ( err && options . concurrency === 1 ) return cb ( err ) ; // break early
35- cb ( ) ;
36- } ) ;
32+ results . push ( { index, command : argv [ 0 ] , args, error : err , result } ) ;
33+ if ( err && options . concurrency === 1 ) return cb ( err ) ; // break early
34+ cb ( ) ;
3735 } ) ;
38- } ) ( index ) ;
39- }
36+ } ) ;
37+ } ) ;
4038
41- queue . await ( ( ) => {
39+ queue . await ( ( err ) => {
4240 results = results . sort ( ( a , b ) => a . index - b . index ) ;
43- callback ( null , results ) ;
41+ if ( err ) err . results = results ;
42+ err ? callback ( err ) : callback ( null , results ) ;
4443 } ) ;
4544} ;
0 commit comments