Skip to content
Browse files

npm-run: fix commands with whitespaces on windows

Fixes #4403
  • Loading branch information...
1 parent 10a2867 commit 80282edb6c2a91d60d3c87c67dc00cae7415b126 @robertkowalski robertkowalski committed with domenic Jan 3, 2014
View
17 lib/utils/lifecycle.js
@@ -185,14 +185,6 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
process.nextTick(dequeue)
}
- var sh = "sh"
- var shFlag = "-c"
-
- if (process.platform === "win32") {
- sh = "cmd"
- shFlag = "/c"
- }
-
var conf = { cwd: wd
, env: env
, stdio: [ 0, 1, 2 ]
@@ -203,6 +195,15 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
conf.gid = gid ^ 0
}
+ var sh = "sh"
+ var shFlag = "-c"
+
+ if (process.platform === "win32") {
+ sh = "cmd"
+ shFlag = "/c"
+ conf.windowsVerbatimArguments = true
+ }
+
var proc = spawn(sh, [shFlag, cmd], conf)
proc.on("close", function (code, signal) {
if (signal) {
View
71 test/tap/scripts-whitespace-windows.js
@@ -0,0 +1,71 @@
+var test = require('tap').test
+var path = require('path')
+var npm = path.resolve(__dirname, '../../cli.js')
+var pkg = __dirname + '/scripts-whitespace-windows'
+var tmp = pkg + '/tmp'
+var cache = pkg + '/cache'
+var modules = pkg + '/node_modules'
+var dep = pkg + '/dep'
+
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var node = process.execPath
+var spawn = require('child_process').spawn
+
+test('setup', function (t) {
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
+ rimraf.sync(modules)
+
+ var env = {
+ npm_config_cache: cache,
+ npm_config_tmp: tmp,
+ npm_config_prefix: pkg,
+ npm_config_global: 'false'
+ }
+
+ var child = spawn(node, [npm, 'i', dep], {
+ cwd: pkg,
+ env: env
+ })
+
+ child.stdout.setEncoding('utf8')
+ child.stderr.on('data', function(chunk) {
+ throw new Error('got stderr data: ' + JSON.stringify('' + chunk))
+ })
+ child.on('close', function () {
+ t.end()
+ })
+})
+
+test('test', function (t) {
+
+ var child = spawn(node, [npm, 'run', 'foo'], {
+ cwd: pkg,
+ env: process.env
+ })
+
+ child.stdout.setEncoding('utf8')
+ child.stderr.on('data', function(chunk) {
+ throw new Error('got stderr data: ' + JSON.stringify('' + chunk))
+ })
+ child.stdout.on('data', ondata)
+ child.on('close', onend)
+ var c = ''
+ function ondata (chunk) {
+ c += chunk
+ }
+ function onend () {
+ c = c.trim()
+
+ t.ok(/npm-test-fine/.test(c))
+ t.end()
+ }
+})
+
+test('cleanup', function (t) {
+ rimraf.sync(cache)
+ rimraf.sync(tmp)
+ rimraf.sync(modules)
+ t.end()
+})
View
1 test/tap/scripts-whitespace-windows/README.md
@@ -0,0 +1 @@
+# Hi
View
1 test/tap/scripts-whitespace-windows/dep/README.md
@@ -0,0 +1 @@
+# Hi!
View
4 test/tap/scripts-whitespace-windows/dep/bin/foo
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+
+if (process.argv.length === 8)
+ console.log('npm-test-fine')
View
6 test/tap/scripts-whitespace-windows/dep/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "scripts-whitespace-windows-dep",
+ "version": "0.0.1",
+ "bin": [ "bin/foo" ],
+ "repository": "git://github.com/robertkowalski/bogusfixture"
+}
View
11 test/tap/scripts-whitespace-windows/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "scripts-whitespace-windows",
+ "scripts": {
+ "foo": "foo --title \"Analysis of\" --recurse -d report src"
+ },
+ "description": "a test",
+ "repository": "git://github.com/robertkowalski/bogus",
+ "dependencies": {
+ "scripts-whitespace-windows-dep": "0.0.1"
+ }
+}

0 comments on commit 80282ed

Please sign in to comment.
Something went wrong with that request. Please try again.