Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit 314e5eb

Browse files
authored
fix(windows): escape spawn args because windows is picky (#87)
Fixes: #84
1 parent 0f50a4d commit 314e5eb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ function installPackages (specs, prefix, opts) {
219219
const args = buildArgs(specs, prefix, opts)
220220
return findNodeScript(opts.npm, {isLocal: true}).then(npmPath => {
221221
if (npmPath) {
222-
args.unshift(opts.npm)
222+
args.unshift(
223+
process.platform === 'win32'
224+
? child.escapeArg(opts.npm)
225+
: opts.npm
226+
)
223227
return process.argv[0]
224228
} else {
225229
return opts.npm

test/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const test = require('tap').test
99

1010
const main = require('../index.js')
1111

12-
const NPX_PATH = path.resolve(__dirname, 'util', 'npx-bin.js')
12+
let NPX_PATH = path.resolve(__dirname, 'util', 'npx-bin.js')
1313
let NPM_PATH = path.resolve(__dirname, '..', 'node_modules', 'npm', 'bin', 'npm-cli.js')
1414

1515
test('npx --shell-auto-fallback', t => {
1616
return child.spawn('node', [
17-
NPX_PATH, '--shell-auto-fallback', 'zsh'
17+
child.escapeArg(NPX_PATH), '--shell-auto-fallback', 'zsh'
1818
], {stdio: 'pipe'}).then(res => {
1919
t.equal(res.code, 0, 'command succeeded')
2020
t.match(
@@ -25,7 +25,7 @@ test('npx --shell-auto-fallback', t => {
2525

2626
test('npx no command', t => {
2727
return child.spawn('node', [
28-
NPX_PATH
28+
child.escapeArg(NPX_PATH)
2929
], {stdio: 'pipe'}).then(res => {
3030
throw new Error('Should not have succeeded')
3131
}, err => {
@@ -43,7 +43,7 @@ test('npx existing subcommand', {
4343
skip: process.platform === 'win32' && 'Windows fail this test when run via nyc, but not when run directly'
4444
}, t => {
4545
return child.spawn('node', [
46-
NPX_PATH, 'which', 'npm'
46+
child.escapeArg(NPX_PATH), 'which', 'npm'
4747
], {stdio: 'pipe'}).then(res => {
4848
t.notOk(res.stderr, 'no stderr output')
4949
t.ok(res.stdout.trim(), 'got output from command')

0 commit comments

Comments
 (0)