Skip to content

Commit 56b882a

Browse files
committed
chore: stdin can bite me
1 parent 3879df7 commit 56b882a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/lib/commands/read-stdin.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ const fstat = promisify(fstat_);
88
export async function readStdin(stdinStream: typeof process.stdin = process.stdin) {
99
// The best showcase of what this does: https://stackoverflow.com/a/59024214
1010
const pipedIn = await fstat(0)
11-
.then((stat) => stat.isFIFO())
11+
.then((stat) => {
12+
// isFIFO -> `node a | node b`
13+
// isFile -> `node a < file`
14+
return stat.isFIFO() || stat.isFile();
15+
})
1216
.catch(() => false);
1317

14-
// The isTTY params says if TTY is connected to the process, if so the stdout is
15-
// synchronous and the stdout steam is empty.
16-
// See https://nodejs.org/docs/latest-v12.x/api/process.html#process_a_note_on_process_i_o
17-
if (stdinStream.isTTY || (stdinStream.readableEnded && !pipedIn)) {
18+
// The isTTY params will be true if there is no piping into stdin
19+
// pipedIn is set if someone either runs `node a | node b`, or `node a < file`
20+
// if that is the case, isTTY will be undefined (???)
21+
// readableEnded is a catch all for when the stream is closed
22+
if (stdinStream.isTTY || (!pipedIn && (stdinStream.isTTY === undefined || stdinStream.readableEnded))) {
1823
return;
1924
}
2025

21-
// This is required for some reason when piping from a previous oclif run
22-
stdinStream.resume();
23-
2426
const bufferChunks: Buffer[] = [];
2527

2628
stdinStream.on('data', (chunk) => {

0 commit comments

Comments
 (0)