From 61bccf66b17dfdc8b15d0a9a21b3a86928fa054c Mon Sep 17 00:00:00 2001 From: Daniil Suvorov Date: Tue, 23 Jul 2024 19:25:39 +0300 Subject: [PATCH 1/2] fix(deps): rm atty atty is unmaintained - see GHSA-g98v-hv3f-hcfr --- Cargo.lock | 2 -- Cargo.toml | 1 - crates/swc_cli_impl/Cargo.toml | 1 - crates/swc_cli_impl/src/commands/compile.rs | 7 ++++--- crates/swc_common/Cargo.toml | 3 +-- crates/swc_common/src/errors/emitter.rs | 8 +++++--- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6758f310c869..3b7aa70aac60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3906,7 +3906,6 @@ dependencies = [ "anyhow", "assert_cmd", "assert_fs", - "atty", "clap 3.2.25", "glob", "path-absolutize", @@ -3931,7 +3930,6 @@ dependencies = [ "anyhow", "arbitrary", "ast_node", - "atty", "better_scoped_tls", "bytecheck", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 09aabf0ea386..611c15cc4d54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ resolver = "2" arrayvec = "0.7.4" assert_cmd = "2.0.12" assert_fs = "1.0.13" - atty = "0.2.14" auto_impl = "1.2.0" backtrace = "0.3.61" base64 = "0.21.0" diff --git a/crates/swc_cli_impl/Cargo.toml b/crates/swc_cli_impl/Cargo.toml index 529c9ab69f31..c3f1eb52ba2f 100644 --- a/crates/swc_cli_impl/Cargo.toml +++ b/crates/swc_cli_impl/Cargo.toml @@ -25,7 +25,6 @@ plugin = [ [dependencies] anyhow = { workspace = true } -atty = { workspace = true } clap = { version = "3.2.25", features = ["derive", "wrap_help"] } glob = { workspace = true } path-absolutize = { workspace = true, features = ["once_cell_cache"] } diff --git a/crates/swc_cli_impl/src/commands/compile.rs b/crates/swc_cli_impl/src/commands/compile.rs index f58f42e65f9a..5abbc50b6e5a 100644 --- a/crates/swc_cli_impl/src/commands/compile.rs +++ b/crates/swc_cli_impl/src/commands/compile.rs @@ -1,6 +1,6 @@ use std::{ fs::{self, File}, - io::{self, Read, Write}, + io::{self, IsTerminal, Read, Write}, path::{Component, Path, PathBuf}, sync::Arc, }; @@ -261,12 +261,13 @@ fn emit_output( } fn collect_stdin_input() -> Option { - if atty::is(atty::Stream::Stdin) { + let stdin = io::stdin(); + if stdin.is_terminal() { return None; } let mut buffer = String::new(); - let result = io::stdin().lock().read_to_string(&mut buffer); + let result = stdin.lock().read_to_string(&mut buffer); if result.is_ok() && !buffer.is_empty() { Some(buffer) diff --git a/crates/swc_common/Cargo.toml b/crates/swc_common/Cargo.toml index f77723e1a2ad..cd9effb84891 100644 --- a/crates/swc_common/Cargo.toml +++ b/crates/swc_common/Cargo.toml @@ -31,7 +31,7 @@ plugin-rt = ["__plugin_rt", "plugin-base"] plugin_transform_schema_v1 = [] plugin_transform_schema_vtest = [] -tty-emitter = ["atty", "termcolor"] +tty-emitter = ["termcolor"] __rkyv = [] rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "bytecheck"] @@ -40,7 +40,6 @@ rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "bytecheck"] ahash = { workspace = true, optional = true } anyhow = { workspace = true, optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true } -atty = { workspace = true, optional = true } # bytecheck version should be in sync with rkyv version. Do not bump individually. bytecheck = { workspace = true, optional = true } cfg-if = { workspace = true } diff --git a/crates/swc_common/src/errors/emitter.rs b/crates/swc_common/src/errors/emitter.rs index d5537f765d71..beabb6663dbe 100644 --- a/crates/swc_common/src/errors/emitter.rs +++ b/crates/swc_common/src/errors/emitter.rs @@ -12,7 +12,7 @@ use std::{ borrow::Cow, cmp::{min, Reverse}, collections::HashMap, - io::{self, prelude::*}, + io::{self, prelude::*, IsTerminal}, }; #[cfg(feature = "tty-emitter")] @@ -116,16 +116,18 @@ pub enum ColorConfig { impl ColorConfig { #[cfg(feature = "tty-emitter")] fn to_color_choice(self) -> ColorChoice { + let stderr = io::stderr(); + match self { ColorConfig::Always => { - if atty::is(atty::Stream::Stderr) { + if stderr.is_terminal() { ColorChoice::Always } else { ColorChoice::AlwaysAnsi } } ColorConfig::Never => ColorChoice::Never, - ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto, + ColorConfig::Auto if stderr.is_terminal() => ColorChoice::Auto, ColorConfig::Auto => ColorChoice::Never, } } From 1ccb35cc07b4c7a2ed470d450dbb7fe59940d7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 24 Jul 2024 09:28:18 +0900 Subject: [PATCH 2/2] Create shaggy-rats-knock.md --- .changeset/shaggy-rats-knock.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/shaggy-rats-knock.md diff --git a/.changeset/shaggy-rats-knock.md b/.changeset/shaggy-rats-knock.md new file mode 100644 index 000000000000..4bdc37f4c14d --- /dev/null +++ b/.changeset/shaggy-rats-knock.md @@ -0,0 +1,6 @@ +--- +swc_cli_impl: patch +swc_common: patch +--- + +fix(deps): rm atty