@@ -13,19 +13,20 @@ const NUM_COLORS = colorWheel.length;
13
13
14
14
function exec ( command , args , opts ) {
15
15
const options = Object . assign ( { stdio : "pipe" } , opts ) ;
16
+ const spawned = spawnProcess ( command , args , options ) ;
16
17
17
- return _spawn ( command , args , options ) ;
18
+ return wrapError ( spawned ) ;
18
19
}
19
20
20
21
function execSync ( command , args , opts ) {
21
22
return execa . sync ( command , args , opts ) . stdout ;
22
23
}
23
24
24
25
function spawn ( command , args , opts ) {
25
- const options = Object . assign ( { } , opts ) ;
26
- options . stdio = "inherit" ;
26
+ const options = Object . assign ( { } , opts , { stdio : "inherit" } ) ;
27
+ const spawned = spawnProcess ( command , args , options ) ;
27
28
28
- return _spawn ( command , args , options ) ;
29
+ return wrapError ( spawned ) ;
29
30
}
30
31
31
32
// istanbul ignore next
@@ -35,7 +36,7 @@ function spawnStreaming(command, args, opts, prefix) {
35
36
36
37
const colorName = colorWheel [ children % NUM_COLORS ] ;
37
38
const color = chalk [ colorName ] ;
38
- const spawned = _spawn ( command , args , options ) ;
39
+ const spawned = spawnProcess ( command , args , options ) ;
39
40
40
41
const stdoutOpts = { } ;
41
42
const stderrOpts = { } ; // mergeMultiline causes escaped newlines :P
@@ -54,15 +55,14 @@ function spawnStreaming(command, args, opts, prefix) {
54
55
spawned . stdout . pipe ( logTransformer ( stdoutOpts ) ) . pipe ( process . stdout ) ;
55
56
spawned . stderr . pipe ( logTransformer ( stderrOpts ) ) . pipe ( process . stderr ) ;
56
57
57
- return spawned ;
58
+ return wrapError ( spawned ) ;
58
59
}
59
60
60
61
function getChildProcessCount ( ) {
61
62
return children ;
62
63
}
63
64
64
- // eslint-disable-next-line no-underscore-dangle
65
- function _spawn ( command , args , opts ) {
65
+ function spawnProcess ( command , args , opts ) {
66
66
children += 1 ;
67
67
68
68
const child = execa ( command , args , opts ) ;
@@ -78,9 +78,29 @@ function _spawn(command, args, opts) {
78
78
child . once ( "exit" , drain ) ;
79
79
child . once ( "error" , drain ) ;
80
80
81
+ if ( opts . pkg ) {
82
+ child . pkg = opts . pkg ;
83
+ }
84
+
81
85
return child ;
82
86
}
83
87
88
+ function wrapError ( spawned ) {
89
+ if ( spawned . pkg ) {
90
+ return spawned . catch ( err => {
91
+ // istanbul ignore else
92
+ if ( err . code ) {
93
+ // log non-lerna error cleanly
94
+ err . pkg = spawned . pkg ;
95
+ }
96
+
97
+ throw err ;
98
+ } ) ;
99
+ }
100
+
101
+ return spawned ;
102
+ }
103
+
84
104
exports . exec = exec ;
85
105
exports . execSync = execSync ;
86
106
exports . spawn = spawn ;
0 commit comments