Skip to content

Commit

Permalink
feat: allow a path to be supplied to the --shell option (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jul 20, 2021
1 parent 7734156 commit efc5304
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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 <path> 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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/lint-staged.js
Expand Up @@ -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 <path>', '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',
Expand Down Expand Up @@ -85,7 +85,7 @@ const options = {
stash: !!cmdlineOptions.stash, // commander inverts `no-<x>` 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,
}

Expand Down
17 changes: 17 additions & 0 deletions test/resolveTaskFn.spec.js
Expand Up @@ -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({
Expand Down

0 comments on commit efc5304

Please sign in to comment.