Skip to content

Commit 6b72b93

Browse files
committedFeb 19, 2016
fix(args): fixes passing arguments with space, fixes #21
1 parent 3fa0e7b commit 6b72b93

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed
 

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@
4444
},
4545
"homepage": "https://github.com/bahmutov/npm-quick-run#readme",
4646
"dependencies": {
47+
"bluebird": "3.3.1",
48+
"cross-spawn-async": "2.1.8",
4749
"debug": "2.2.0",
4850
"findup": "0.1.5",
4951
"json-package": "1.1.2",
50-
"npm-utils": "1.5.0",
5152
"simple-bin-help": "1.6.0"
5253
},
5354
"config": {

‎src/quick-run.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const debug = require('debug')('quick')
22
const findScripts = require('json-package').find
3-
const runNpmCommand = require('npm-utils').test
43
const join = require('path').join
54
const findup = require('findup')
65
const printNames = require('json-package').printNames
6+
const run = require('./run')
77

88
function printAllScripts (pkg) {
99
printNames('Available scripts are',
@@ -76,14 +76,11 @@ function runPrefix (prefix) {
7676
process.exit(-1)
7777
}
7878

79-
var cmd = 'npm run ' + candidates[0]
80-
var extraArguments = process.argv.slice(3)
81-
if (extraArguments.length) {
82-
cmd += ' -- ' + extraArguments.join(' ')
83-
}
84-
debug('formed command "%s"', cmd)
79+
debug('all arguments', process.argv)
80+
var extraArguments = ['run', candidates[0], '--'].concat(process.argv.slice(3))
81+
debug('formed command: npm', extraArguments)
8582

86-
runNpmCommand(cmd, npmErrorLoggers)
83+
run('npm', extraArguments)
8784
.catch(function (result) {
8885
process.exit(result.code)
8986
})

‎src/run.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var spawn = require('cross-spawn-async')
2+
var Promise = require('bluebird')
3+
4+
function runner (app, parts) {
5+
return new Promise(function (resolve, reject) {
6+
var npm = spawn(app, parts, { stdio: 'inherit' })
7+
var testErrors = ''
8+
9+
npm.on('error', function (err) {
10+
console.error(err)
11+
testErrors += err.toString()
12+
})
13+
14+
npm.on('exit', function (code) {
15+
if (code) {
16+
reject({
17+
code: code,
18+
errors: testErrors
19+
})
20+
return
21+
}
22+
resolve()
23+
})
24+
})
25+
}
26+
27+
module.exports = runner

0 commit comments

Comments
 (0)