1
1
/* eslint camelcase: "off" */
2
- const isWindows = require ( './is-windows.js' )
3
2
const setPATH = require ( './set-path.js' )
4
3
const { resolve } = require ( 'path' )
5
- const which = require ( 'which' )
6
4
const npm_config_node_gyp = require . resolve ( 'node-gyp/bin/node-gyp.js' )
7
- const escape = require ( './escape.js' )
8
5
9
6
const makeSpawnArgs = options => {
10
7
const {
11
8
event,
12
9
path,
13
- scriptShell = isWindows ? process . env . ComSpec || 'cmd' : 'sh' ,
10
+ scriptShell = true ,
14
11
binPaths,
15
12
env = { } ,
16
13
stdio,
@@ -29,55 +26,15 @@ const makeSpawnArgs = options => {
29
26
npm_config_node_gyp,
30
27
} )
31
28
32
- let doubleEscape = false
33
- const isCmd = / (?: ^ | \\ ) c m d (?: \. e x e ) ? $ / i. test ( scriptShell )
34
- if ( isCmd ) {
35
- let initialCmd = ''
36
- let insideQuotes = false
37
- for ( let i = 0 ; i < cmd . length ; ++ i ) {
38
- const char = cmd . charAt ( i )
39
- if ( char === ' ' && ! insideQuotes ) {
40
- break
41
- }
42
-
43
- initialCmd += char
44
- if ( char === '"' || char === "'" ) {
45
- insideQuotes = ! insideQuotes
46
- }
47
- }
48
-
49
- let pathToInitial
50
- try {
51
- pathToInitial = which . sync ( initialCmd , {
52
- path : spawnEnv . path ,
53
- pathext : spawnEnv . pathext ,
54
- } ) . toLowerCase ( )
55
- } catch ( err ) {
56
- pathToInitial = initialCmd . toLowerCase ( )
57
- }
58
-
59
- doubleEscape = pathToInitial . endsWith ( '.cmd' ) || pathToInitial . endsWith ( '.bat' )
60
- }
61
-
62
- let script = cmd
63
- for ( const arg of args ) {
64
- script += isCmd
65
- ? ` ${ escape . cmd ( arg , doubleEscape ) } `
66
- : ` ${ escape . sh ( arg ) } `
67
- }
68
- const spawnArgs = isCmd
69
- ? [ '/d' , '/s' , '/c' , script ]
70
- : [ '-c' , '--' , script ]
71
-
72
29
const spawnOpts = {
73
30
env : spawnEnv ,
74
31
stdioString,
75
32
stdio,
76
33
cwd : path ,
77
- ... ( isCmd ? { windowsVerbatimArguments : true } : { } ) ,
34
+ shell : scriptShell ,
78
35
}
79
36
80
- return [ scriptShell , spawnArgs , spawnOpts ]
37
+ return [ cmd , args , spawnOpts ]
81
38
}
82
39
83
40
module . exports = makeSpawnArgs
0 commit comments