Skip to content

Commit

Permalink
fix: ignore stdin of spawned commands
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jan 30, 2024
1 parent 46f2c43 commit e4023f6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-eagles-decide.md
@@ -0,0 +1,5 @@
---
'lint-staged': patch
---

Ignore stdin of spawned commands so that they don't get stuck waiting. Until now, _lint-staged_ has used the default settings to spawn linter commands. This means the `stdin` of the spawned commands has accepted input, and essentially gotten stuck waiting. Now the `stdin` is ignored and commands will no longer get stuck. If you relied on this behavior, please open a new issue and describe how; the behavior has not been intended.
1 change: 1 addition & 0 deletions lib/execGit.js
Expand Up @@ -19,6 +19,7 @@ export const execGit = async (cmd, options = {}) => {
...options,
all: true,
cwd: options.cwd || process.cwd(),
stdin: 'ignore',
})
return stdout
} catch ({ all }) {
Expand Down
1 change: 1 addition & 0 deletions lib/resolveTaskFn.js
Expand Up @@ -152,6 +152,7 @@ export const resolveTaskFn = ({
preferLocal: true,
reject: false,
shell,
stdin: 'ignore',
}

debugLog('execaOptions:', execaOptions)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/execGit.spec.js
Expand Up @@ -21,6 +21,7 @@ describe('execGit', () => {
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
all: true,
cwd,
stdin: 'ignore',
})
})

Expand All @@ -30,6 +31,7 @@ describe('execGit', () => {
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
all: true,
cwd,
stdin: 'ignore',
})
})
})
2 changes: 2 additions & 0 deletions test/unit/makeCmdTasks.spec.js
Expand Up @@ -49,6 +49,7 @@ describe('makeCmdTasks', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
taskPromise = linter2.task()
expect(taskPromise).toBeInstanceOf(Promise)
Expand All @@ -59,6 +60,7 @@ describe('makeCmdTasks', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
})

Expand Down
7 changes: 7 additions & 0 deletions test/unit/resolveTaskFn.spec.js
Expand Up @@ -40,6 +40,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
})

Expand All @@ -58,6 +59,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
})

Expand All @@ -77,6 +79,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: true,
stdin: 'ignore',
})
})

Expand All @@ -95,6 +98,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: true,
stdin: 'ignore',
})
})

Expand All @@ -113,6 +117,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: '/bin/bash',
stdin: 'ignore',
})
})

Expand All @@ -131,6 +136,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
})

Expand All @@ -145,6 +151,7 @@ describe('resolveTaskFn', () => {
preferLocal: true,
reject: false,
shell: false,
stdin: 'ignore',
})
})

Expand Down
6 changes: 4 additions & 2 deletions test/unit/resolveTaskFn.unmocked.spec.js
Expand Up @@ -17,7 +17,7 @@ describe('resolveTaskFn', () => {
const context = getInitialState()

const taskFn = resolveTaskFn({
command: 'node',
command: 'node -e "setTimeout(() => void 0, 10000)"',
isFn: true,
})
const taskPromise = taskFn(context)
Expand All @@ -31,6 +31,8 @@ describe('resolveTaskFn', () => {
await expect(task2Promise).rejects.toThrowErrorMatchingInlineSnapshot(
`"node -e "process.exit(1)" [FAILED]"`
)
await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(`"node [KILLED]"`)
await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(
`"node -e "setTimeout(() => void 0, 10000)" [KILLED]"`
)
})
})

0 comments on commit e4023f6

Please sign in to comment.