Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Skip '--' argument for non-npm commands #196

Merged
merged 1 commit into from
Jun 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }`)
}
})
})