1
+ const path = require ( 'path' ) ;
1
2
const utils = require ( './utils' ) ;
2
3
const merge = utils . merge ;
3
4
const bus = utils . bus ;
@@ -10,26 +11,43 @@ module.exports = function spawnCommand(command, config, eventArgs) {
10
11
stdio = [ 'pipe' , process . stdout , process . stderr ] ;
11
12
}
12
13
14
+ const env = merge ( process . env , { FILENAME : eventArgs [ 0 ] } ) ;
15
+
13
16
var sh = 'sh' ;
14
17
var shFlag = '-c' ;
18
+ var spawnOptions = {
19
+ env : merge ( config . options . execOptions . env , env ) ,
20
+ stdio : stdio ,
21
+ } ;
15
22
16
- if ( utils . isWindows ) {
17
- sh = 'cmd' ;
18
- shFlag = '/c' ;
23
+ if ( ! Array . isArray ( command ) ) {
24
+ command = [ command ] ;
19
25
}
20
26
27
+ if ( utils . isWindows ) {
28
+ // if the exec includes a forward slash, reverse it for windows compat
29
+ // but *only* apply to the first command, and none of the arguments.
30
+ // ref #1251 and #1236
31
+ command = command . map ( executable => {
32
+ if ( executable . indexOf ( '/' ) === - 1 ) {
33
+ return executable ;
34
+ }
21
35
22
- if ( ! Array . isArray ( command ) ) {
23
- command = [ command ] ;
36
+ return executable . split ( ' ' ) . map ( ( e , i ) => {
37
+ if ( i === 0 ) {
38
+ return path . normalize ( e ) ;
39
+ }
40
+ return e ;
41
+ } ) . join ( ' ' ) ;
42
+ } ) ;
43
+ // taken from npm's cli: https://git.io/vNFD4
44
+ sh = process . env . comspec || 'cmd' ;
45
+ shFlag = '/d /s /c' ;
46
+ spawnOptions . windowsVerbatimArguments = true ;
24
47
}
25
48
26
49
const args = command . join ( ' ' ) ;
27
-
28
- const env = merge ( process . env , { FILENAME : eventArgs [ 0 ] } ) ;
29
- const child = spawn ( sh , [ shFlag , args ] , {
30
- env : merge ( config . options . execOptions . env , env ) ,
31
- stdio : stdio ,
32
- } ) ;
50
+ const child = spawn ( sh , [ shFlag , args ] , spawnOptions ) ;
33
51
34
52
if ( config . required ) {
35
53
var emit = {
0 commit comments