Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2016-03-08 22:44:45 +0300
committerRebecca Turner <me@re-becca.org>2016-05-04 02:12:51 +0300
commit91fc24f2763c2e0591093099ffc866c735f27fde (patch)
tree512d51e66fc92eea10ace0ec4124981dd2e0bf1f /lib/explore.js
parent8fccda8587209659c469ab55c608b0e2d7533530 (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.js27
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)
})
})