From 065f362839597d9b979f4c0a52875b764b0d1075 Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Mon, 25 Sep 2017 09:42:23 +0530 Subject: [PATCH] fix(findBin): Add separator before npm args (#297) --- src/findBin.js | 2 +- src/runScript.js | 4 +--- test/findBin.spec.js | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/findBin.js b/src/findBin.js index 684d7b4b2..bce2d3067 100644 --- a/src/findBin.js +++ b/src/findBin.js @@ -4,7 +4,7 @@ const npmWhich = require('npm-which')(process.cwd()) module.exports = function findBin(cmd, scripts, options) { const npmArgs = (bin, args) => - ['run', options && options.verbose ? undefined : '--silent', bin] + ['run', options && options.verbose ? undefined : '--silent', bin, '--'] // args could be undefined but we filter that out. .concat(args) .filter(arg => arg !== undefined) diff --git a/src/runScript.js b/src/runScript.js index e19aba304..f4738607c 100644 --- a/src/runScript.js +++ b/src/runScript.js @@ -24,8 +24,6 @@ module.exports = function runScript(commands, pathsToLint, scripts, config) { try { const res = findBin(linter, scripts, config) - const separatorArgs = /npm(\.exe)?$/i.test(res.bin) ? ['--'] : [] - // Only use gitDir as CWD if we are using the git binary // e.g `npm` should run tasks in the actual CWD const execaOptions = @@ -33,7 +31,7 @@ module.exports = function runScript(commands, pathsToLint, scripts, config) { const errors = [] const mapper = pathsChunk => { - const args = res.args.concat(separatorArgs, pathsChunk) + const args = res.args.concat(pathsChunk) return ( execa(res.bin, args, Object.assign({}, execaOptions)) diff --git a/test/findBin.spec.js b/test/findBin.spec.js index 9ec5ef7a7..5ea8246c9 100644 --- a/test/findBin.spec.js +++ b/test/findBin.spec.js @@ -8,25 +8,25 @@ describe('findBin', () => { it('should favor `npm run` command if exists in both package.json and .bin/', () => { const { bin, args } = findBin('my-linter', { 'my-linter': 'my-linter' }) expect(bin).toEqual('npm') - expect(args).toEqual(['run', '--silent', 'my-linter']) + expect(args).toEqual(['run', '--silent', 'my-linter', '--']) }) it('should return npm run command without --silent in verbose mode', () => { const { bin, args } = findBin('eslint', { eslint: 'eslint' }, { verbose: true }) expect(bin).toEqual('npm') - expect(args).toEqual(['run', 'eslint']) + expect(args).toEqual(['run', 'eslint', '--']) }) it('should resolve cmd defined in scripts with args', () => { const { bin, args } = findBin('kcd-scripts format', { 'kcd-scripts': 'node index.js' }) expect(bin).toEqual('npm') - expect(args).toEqual(['run', '--silent', 'kcd-scripts', 'format']) + expect(args).toEqual(['run', '--silent', 'kcd-scripts', '--', 'format']) }) it('should resolve cmd defined in scripts with space in name', () => { const { bin, args } = findBin('my cmd', { 'my cmd': 'echo deal-with-it' }) expect(bin).toEqual('npm') - expect(args).toEqual(['run', '--silent', 'my cmd']) + expect(args).toEqual(['run', '--silent', 'my cmd', '--']) }) it('should return path to bin if there is no `script` with name in package.json', () => {