diff --git a/bindings/swc_cli/src/commands/compile.rs b/bindings/swc_cli/src/commands/compile.rs index 84d19b49bfc..8f7b95d7d70 100644 --- a/bindings/swc_cli/src/commands/compile.rs +++ b/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, }; @@ -245,14 +245,14 @@ fn collect_stdin_input() -> Option { return None; } - Some( - io::stdin() - .lock() - .lines() - .map(|line| line.expect("Not able to read stdin")) - .collect::>() - .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 {