diff --git a/README.md b/README.md index 449828b0a..59dee6c92 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Options: tasks serially (default: true) -q, --quiet disable lint-staged’s own console output (default: false) -r, --relative pass relative filepaths to tasks (default: false) - -x, --shell skip parsing of tasks for better shell support (default: + -x, --shell skip parsing of tasks for better shell support (default: false) -v, --verbose show task output even when tasks succeed; by default only failed output is shown (default: false) @@ -90,7 +90,7 @@ Options: - **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit. - **`--quiet`**: Supress all CLI output, except from tasks. - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`. -- **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option. +- **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option. To use a specific shell, use a path like `--shell "/bin/bash"`. - **`--verbose`**: Show task output even when tasks succeed. By default only failed output is shown. ## Configuration diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 28c3a692b..0b1724c17 100755 --- a/bin/lint-staged.js +++ b/bin/lint-staged.js @@ -42,7 +42,7 @@ cmdline ) .option('-q, --quiet', 'disable lint-staged’s own console output', false) .option('-r, --relative', 'pass relative filepaths to tasks', false) - .option('-x, --shell', 'skip parsing of tasks for better shell support', false) + .option('-x, --shell ', 'skip parsing of tasks for better shell support', false) .option( '-v, --verbose', 'show task output even when tasks succeed; by default only failed output is shown', @@ -85,7 +85,7 @@ const options = { stash: !!cmdlineOptions.stash, // commander inverts `no-` flags to `!x` quiet: !!cmdlineOptions.quiet, relative: !!cmdlineOptions.relative, - shell: !!cmdlineOptions.shell, + shell: cmdlineOptions.shell /* Either a boolean or a string pointing to the shell */, verbose: !!cmdlineOptions.verbose, } diff --git a/test/resolveTaskFn.spec.js b/test/resolveTaskFn.spec.js index 82b077655..3a98a9384 100644 --- a/test/resolveTaskFn.spec.js +++ b/test/resolveTaskFn.spec.js @@ -79,6 +79,23 @@ describe('resolveTaskFn', () => { }) }) + it('should work with path to custom shell', async () => { + expect.assertions(2) + const taskFn = resolveTaskFn({ + ...defaultOpts, + shell: '/bin/bash', + command: 'node --arg=true ./myscript.js', + }) + + await taskFn() + expect(execa).toHaveBeenCalledTimes(1) + expect(execa).lastCalledWith('node --arg=true ./myscript.js test.js', { + preferLocal: true, + reject: false, + shell: '/bin/bash', + }) + }) + it('should pass `gitDir` as `cwd` to `execa()` gitDir !== process.cwd for git commands', async () => { expect.assertions(2) const taskFn = resolveTaskFn({