Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
fix(windows): escape spawn args because windows is picky (#87)
Browse files Browse the repository at this point in the history
Fixes: #84
  • Loading branch information
zkat authored Jul 17, 2017
1 parent 0f50a4d commit 314e5eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ function installPackages (specs, prefix, opts) {
const args = buildArgs(specs, prefix, opts)
return findNodeScript(opts.npm, {isLocal: true}).then(npmPath => {
if (npmPath) {
args.unshift(opts.npm)
args.unshift(
process.platform === 'win32'
? child.escapeArg(opts.npm)
: opts.npm
)
return process.argv[0]
} else {
return opts.npm
Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const test = require('tap').test

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

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

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

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

0 comments on commit 314e5eb

Please sign in to comment.