diff options
author | Rebecca Turner <me@re-becca.org> | 2016-03-08 22:44:45 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-05-04 02:12:51 +0300 |
commit | 91fc24f2763c2e0591093099ffc866c735f27fde (patch) | |
tree | 512d51e66fc92eea10ace0ec4124981dd2e0bf1f /lib/explore.js | |
parent | 8fccda8587209659c469ab55c608b0e2d7533530 (diff) |
explore: Fix running sub-commands on windows
Credit: @iarna
PR-URL: https://github.com/npm/npm/pull/11444
Reviewed-By: @zkat
Reviewed-By: @iarna
Reviewed-By: @othiym23
Diffstat (limited to 'lib/explore.js')
-rw-r--r-- | lib/explore.js | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/explore.js b/lib/explore.js index 105ff84cc..05b5220d5 100644 --- a/lib/explore.js +++ b/lib/explore.js @@ -9,15 +9,30 @@ var npm = require('./npm.js') var spawn = require('./utils/spawn') var path = require('path') var fs = require('graceful-fs') +var isWindowsShell = require('./utils/is-windows-shell.js') +var escapeExecPath = require('./utils/escape-exec-path.js') +var escapeArg = require('./utils/escape-arg.js') function explore (args, cb) { if (args.length < 1 || !args[0]) return cb(explore.usage) var p = args.shift() - args = args.join(' ').trim() - if (args) args = ['-c', args] - else args = [] var cwd = path.resolve(npm.dir, p) + var opts = {cwd: cwd, stdio: 'inherit'} + + var shellArgs = [] + if (args) { + if (isWindowsShell) { + var execCmd = escapeExecPath(args.shift()) + var execArgs = [execCmd].concat(args.map(escapeArg)) + opts.windowsVerbatimArguments = true + shellArgs = ['/d', '/s', '/c'].concat(execArgs) + } else { + shellArgs.unshift('-c') + shellArgs = ['-c', args.map(escapeArg).join(' ').trim()] + } + } + var sh = npm.config.get('shell') fs.stat(cwd, function (er, s) { if (er || !s.isDirectory()) { @@ -26,17 +41,17 @@ function explore (args, cb) { )) } - if (!args.length) { + if (!shellArgs.length) { console.log( '\nExploring ' + cwd + '\n' + "Type 'exit' or ^D when finished\n" ) } - var shell = spawn(sh, args, { cwd: cwd, stdio: 'inherit' }) + var shell = spawn(sh, shellArgs, opts) shell.on('close', function (er) { // only fail if non-interactive. - if (!args.length) return cb() + if (!shellArgs.length) return cb() cb(er) }) }) |