Skip to content

Commit 0f607ba

Browse files
committed
Fix child_process event order for different node versions
1 parent a9697fe commit 0f607ba

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

server/src/linter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ export default class Linter {
7373
const proc = spawn(executablePath, [...args, '-'], { cwd: this.cwd })
7474
proc.on('error', reject)
7575
proc.on('close', resolve)
76-
proc.on('spawn', () => {
77-
proc.stdin.write(document.getText())
78-
proc.stdin.end()
79-
})
8076
proc.stdout.on('data', data => (out += data))
8177
proc.stderr.on('data', data => (err += data))
78+
proc.stdin.on('error', () => {
79+
// XXX: Ignore STDIN errors in case the process ends too quickly, before we try to
80+
// write. If we write after the process ends without this, we get an uncatchable EPIPE.
81+
// This is solved in Node >= 15.1 by the "on('spawn', ...)" event, but we need to
82+
// support earlier versions.
83+
})
84+
proc.stdin.end(document.getText())
8285
})
8386

8487
// XXX: do we care about exit code? 0 means "ok", 1 possibly means "errors",

0 commit comments

Comments
 (0)