Skip to content

Commit

Permalink
fix(findBin): Add separator before npm args (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas committed Sep 25, 2017
1 parent 1dc3bd6 commit 065f362
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/findBin.js
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/runScript.js
Expand Up @@ -24,16 +24,14 @@ 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 =
/git(\.exe)?$/i.test(res.bin) && config && gitDir ? { cwd: gitDir } : {}

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))
Expand Down
8 changes: 4 additions & 4 deletions test/findBin.spec.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 065f362

Please sign in to comment.