Skip to content

Commit

Permalink
fix(bindings/cli): Skip empty stdin in non tty environments (#6714)
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimetodie committed Jan 5, 2023
1 parent 918a01b commit 0076418
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions bindings/swc_cli/src/commands/compile.rs
@@ -1,6 +1,6 @@
use std::{
fs::{self, File},
io::{self, BufRead, Write},
io::{self, Read, Write},
path::{Path, PathBuf},
sync::Arc,
};
Expand Down Expand Up @@ -245,14 +245,14 @@ fn collect_stdin_input() -> Option<String> {
return None;
}

Some(
io::stdin()
.lock()
.lines()
.map(|line| line.expect("Not able to read stdin"))
.collect::<Vec<String>>()
.join("\n"),
)
let mut buffer = String::new();
let result = io::stdin().lock().read_to_string(&mut buffer);

if result.is_ok() && !buffer.is_empty() {
Some(buffer)
} else {
None
}
}

struct InputContext {
Expand Down

0 comments on commit 0076418

Please sign in to comment.