Skip to content

Commit

Permalink
fix: Skip '--' argument for non-npm commands (#196)
Browse files Browse the repository at this point in the history
Closes #195

BREAKING CHANGE: 

This might affect existing setups which depend on the `--` argument.
  • Loading branch information
avaly authored and okonet committed Jun 18, 2017
1 parent 48fbe20 commit ad26566
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/runScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function runScript(commands, pathsToLint, packageJson, options)
try {
const res = findBin(linter, packageJson, options)

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 =
Expand All @@ -35,7 +38,7 @@ module.exports = function runScript(commands, pathsToLint, packageJson, options)

const errors = []
const mapper = (pathsChunk) => {
const args = res.args.concat(['--'], pathsChunk)
const args = res.args.concat(separatorArgs, pathsChunk)

return execa(res.bin, args, Object.assign({}, execaOptions))
/* If we don't catch, pMap will terminate on first rejection */
Expand Down Expand Up @@ -67,4 +70,3 @@ ${ errStderr }`)
}
}))
}

3 changes: 1 addition & 2 deletions test/runScript-mock-findBin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ describe.only('runScript with absolute paths', () => {
await taskPromise
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0][0]).toMatch('/usr/local/bin/git')
expect(mockFn.mock.calls[0][1]).toEqual(['add', '--', 'test.js'])
expect(mockFn.mock.calls[0][1]).toEqual(['add', 'test.js'])
expect(mockFn.mock.calls[0][2]).toEqual({ cwd: '../' })
})
})

9 changes: 4 additions & 5 deletions test/runScript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ describe('runScript', () => {
await taskPromise
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0][0]).toContain('node')
expect(mockFn.mock.calls[0][1]).toEqual(['--arg=true', './myscript.js', '--', 'test.js'])
expect(mockFn.mock.calls[0][1]).toEqual(['--arg=true', './myscript.js', 'test.js'])

taskPromise = res[1].task()
expect(taskPromise).toBeAPromise()
await taskPromise
expect(mockFn.mock.calls.length).toEqual(2)
expect(mockFn.mock.calls[1][0]).toContain('git')
expect(mockFn.mock.calls[1][1]).toEqual(['add', '--', 'test.js'])
expect(mockFn.mock.calls[1][1]).toEqual(['add', 'test.js'])
})

it('should pass cwd to execa if gitDir option is set for non-npm tasks', async () => {
Expand All @@ -135,7 +135,7 @@ describe('runScript', () => {
await taskPromise
expect(mockFn.mock.calls.length).toEqual(2)
expect(mockFn.mock.calls[1][0]).toMatch(/git$/)
expect(mockFn.mock.calls[1][1]).toEqual(['add', '--', 'test.js'])
expect(mockFn.mock.calls[1][1]).toEqual(['add', 'test.js'])
expect(mockFn.mock.calls[1][2]).toEqual({ cwd: '../' })
})

Expand All @@ -151,7 +151,7 @@ describe('runScript', () => {
await taskPromise
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0]).toEqual(
['jest', ['--', 'test.js'], {}]
['jest', ['test.js'], {}]
)
})

Expand Down Expand Up @@ -204,4 +204,3 @@ ${ linteErr.stderr }`)
}
})
})

0 comments on commit ad26566

Please sign in to comment.