Skip to content

Commit e4023f6

Browse files
committed
fix: ignore stdin of spawned commands
1 parent 46f2c43 commit e4023f6

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

.changeset/dirty-eagles-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lint-staged': patch
3+
---
4+
5+
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.

lib/execGit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const execGit = async (cmd, options = {}) => {
1919
...options,
2020
all: true,
2121
cwd: options.cwd || process.cwd(),
22+
stdin: 'ignore',
2223
})
2324
return stdout
2425
} catch ({ all }) {

lib/resolveTaskFn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export const resolveTaskFn = ({
152152
preferLocal: true,
153153
reject: false,
154154
shell,
155+
stdin: 'ignore',
155156
}
156157

157158
debugLog('execaOptions:', execaOptions)

test/unit/execGit.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('execGit', () => {
2121
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
2222
all: true,
2323
cwd,
24+
stdin: 'ignore',
2425
})
2526
})
2627

@@ -30,6 +31,7 @@ describe('execGit', () => {
3031
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
3132
all: true,
3233
cwd,
34+
stdin: 'ignore',
3335
})
3436
})
3537
})

test/unit/makeCmdTasks.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe('makeCmdTasks', () => {
4949
preferLocal: true,
5050
reject: false,
5151
shell: false,
52+
stdin: 'ignore',
5253
})
5354
taskPromise = linter2.task()
5455
expect(taskPromise).toBeInstanceOf(Promise)
@@ -59,6 +60,7 @@ describe('makeCmdTasks', () => {
5960
preferLocal: true,
6061
reject: false,
6162
shell: false,
63+
stdin: 'ignore',
6264
})
6365
})
6466

test/unit/resolveTaskFn.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('resolveTaskFn', () => {
4040
preferLocal: true,
4141
reject: false,
4242
shell: false,
43+
stdin: 'ignore',
4344
})
4445
})
4546

@@ -58,6 +59,7 @@ describe('resolveTaskFn', () => {
5859
preferLocal: true,
5960
reject: false,
6061
shell: false,
62+
stdin: 'ignore',
6163
})
6264
})
6365

@@ -77,6 +79,7 @@ describe('resolveTaskFn', () => {
7779
preferLocal: true,
7880
reject: false,
7981
shell: true,
82+
stdin: 'ignore',
8083
})
8184
})
8285

@@ -95,6 +98,7 @@ describe('resolveTaskFn', () => {
9598
preferLocal: true,
9699
reject: false,
97100
shell: true,
101+
stdin: 'ignore',
98102
})
99103
})
100104

@@ -113,6 +117,7 @@ describe('resolveTaskFn', () => {
113117
preferLocal: true,
114118
reject: false,
115119
shell: '/bin/bash',
120+
stdin: 'ignore',
116121
})
117122
})
118123

@@ -131,6 +136,7 @@ describe('resolveTaskFn', () => {
131136
preferLocal: true,
132137
reject: false,
133138
shell: false,
139+
stdin: 'ignore',
134140
})
135141
})
136142

@@ -145,6 +151,7 @@ describe('resolveTaskFn', () => {
145151
preferLocal: true,
146152
reject: false,
147153
shell: false,
154+
stdin: 'ignore',
148155
})
149156
})
150157

test/unit/resolveTaskFn.unmocked.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('resolveTaskFn', () => {
1717
const context = getInitialState()
1818

1919
const taskFn = resolveTaskFn({
20-
command: 'node',
20+
command: 'node -e "setTimeout(() => void 0, 10000)"',
2121
isFn: true,
2222
})
2323
const taskPromise = taskFn(context)
@@ -31,6 +31,8 @@ describe('resolveTaskFn', () => {
3131
await expect(task2Promise).rejects.toThrowErrorMatchingInlineSnapshot(
3232
`"node -e "process.exit(1)" [FAILED]"`
3333
)
34-
await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(`"node [KILLED]"`)
34+
await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(
35+
`"node -e "setTimeout(() => void 0, 10000)" [KILLED]"`
36+
)
3537
})
3638
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy