@@ -15,7 +15,7 @@ function isNullOrUndefined(val) {
15
15
return val === null || val === undefined ;
16
16
}
17
17
18
- function commandNotFound ( execaResult ) {
18
+ function isCommandNotFound ( execaResult ) {
19
19
if ( process . platform === 'win32' ) {
20
20
var str = 'is not recognized as an internal or external command' ;
21
21
return execaResult . code && execaResult . stderr . includes ( str ) ;
@@ -28,6 +28,16 @@ function commandNotFound(execaResult) {
28
28
}
29
29
}
30
30
31
+ function isExecaInternalError ( result ) {
32
+ if ( typeof result . stdout !== 'string' ) return true ;
33
+ if ( typeof result . stderr !== 'string' ) return true ;
34
+ if ( typeof result . code !== 'number' ) return true ;
35
+ if ( result . code === 0 && result . failed ) return true ;
36
+ // Otherwise assume this executed correctly. The command may still have exited
37
+ // with non-zero status, but that's not due to anything execa did.
38
+ return false ;
39
+ }
40
+
31
41
//@
32
42
//@ ### cmd(arg1[, arg2, ...] [, options])
33
43
//@
@@ -110,26 +120,24 @@ function _cmd(options, command, commandArgs, userOptions) {
110
120
var stdout ;
111
121
var stderr ;
112
122
var code ;
113
- if ( commandNotFound ( result ) ) {
123
+ if ( isCommandNotFound ( result ) ) {
114
124
// This can happen if `command` is not an executable binary, or possibly
115
125
// under other conditions.
116
126
stdout = '' ;
117
127
stderr = "'" + command + "': command not found" ;
118
128
code = COMMAND_NOT_FOUND_ERROR_CODE ;
119
- } else if ( typeof result . stdout === 'string' &&
120
- typeof result . stderr === 'string' &&
121
- typeof result . code === 'number' ) {
122
- // Normal exit: execa was able to execute `command` and get a return value.
123
- stdout = result . stdout . toString ( ) ;
124
- stderr = result . stderr . toString ( ) ;
125
- code = result .code ;
126
- } else {
129
+ } else if ( isExecaInternalError ( result ) ) {
127
130
// Catch-all: execa tried to run `command` but it encountered some error
128
131
// (ex. maxBuffer, timeout).
129
132
stdout = result . stdout || '' ;
130
133
stderr = result . stderr ||
131
134
`'${ command } ' encountered an error during execution` ;
132
- code = result . code > 0 ? result . code : 1 ;
135
+ code = typeof result . code === 'number' && result . code > 0 ? result . code : 1 ;
136
+ } else {
137
+ // Normal exit: execa was able to execute `command` and get a return value.
138
+ stdout = result . stdout . toString ( ) ;
139
+ stderr = result . stderr . toString ( ) ;
140
+ code = result . code ;
133
141
}
134
142
135
143
// Pass `continue: true` so we can specify a value for stdout.
0 commit comments