From 00764188195c63af1e5a8e34ce29dcf650b20f04 Mon Sep 17 00:00:00 2001 From: realtimetodie Date: Thu, 5 Jan 2023 06:15:36 +0100 Subject: [PATCH] fix(bindings/cli): Skip empty stdin in non tty environments (#6714) --- bindings/swc_cli/src/commands/compile.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bindings/swc_cli/src/commands/compile.rs b/bindings/swc_cli/src/commands/compile.rs index 84d19b49bfc3..8f7b95d7d70d 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 {