Skip to content

Commit 0823f18

Browse files
committed
fix(windows): properly handle quoted args in event
Fixes: #1823 This mirrors the command parsing from run.js into the separate parser for launching event driven shells.
1 parent b52fc89 commit 0823f18

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lib/spawn.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const utils = require('./utils');
23
const merge = utils.merge;
34
const bus = utils.bus;
@@ -10,26 +11,43 @@ module.exports = function spawnCommand(command, config, eventArgs) {
1011
stdio = ['pipe', process.stdout, process.stderr];
1112
}
1213

14+
const env = merge(process.env, { FILENAME: eventArgs[0] });
15+
1316
var sh = 'sh';
1417
var shFlag = '-c';
18+
var spawnOptions = {
19+
env: merge(config.options.execOptions.env, env),
20+
stdio: stdio,
21+
};
1522

16-
if (utils.isWindows) {
17-
sh = 'cmd';
18-
shFlag = '/c';
23+
if (!Array.isArray(command)) {
24+
command = [command];
1925
}
2026

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+
}
2135

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;
2447
}
2548

2649
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);
3351

3452
if (config.required) {
3553
var emit = {

0 commit comments

Comments
 (0)