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

fix: ignore stdin of spawned commands #1387

Merged
merged 2 commits into from Jan 31, 2024
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
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.
2 changes: 1 addition & 1 deletion .github/workflows/install.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/push.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
node-version: 20
# Install node_modules
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand All @@ -52,7 +52,7 @@ jobs:
with:
node-version: 20
# Install node_modules
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand All @@ -72,7 +72,7 @@ jobs:
with:
node-version: 20
# Install node_modules
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
# Install node_modules
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-node_modules
with:
path: node_modules
Expand Down
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]"`
)
})
})