diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a598484ea..130b863ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ #### :bug: Bug fix - Fix rewatch swallowing parse warnings (%todo). https://github.com/rescript-lang/rescript/pull/8135 -- Rewatch: log errors to `stderr`. https://github.com/rescript-lang/rescript/pull/8147 +- Rewatch: log errors and warnings to `stderr`. https://github.com/rescript-lang/rescript/pull/8147 https://github.com/rescript-lang/rescript/pull/8148 #### :memo: Documentation diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index 13d272cf8a..0bd5419b0f 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -306,7 +306,7 @@ pub fn incremental_build( } } if helpers::contains_ascii_characters(&parse_warnings) { - println!("{}", &parse_warnings); + eprintln!("{}", &parse_warnings); } mark_modules_with_expired_deps_dirty(build_state); @@ -371,7 +371,7 @@ pub fn incremental_build( } } if helpers::contains_ascii_characters(&compile_warnings) { - println!("{}", &compile_warnings); + eprintln!("{}", &compile_warnings); } if initial_build { log_config_warnings(build_state); @@ -400,7 +400,7 @@ pub fn incremental_build( } if helpers::contains_ascii_characters(&compile_warnings) { - println!("{}", &compile_warnings); + eprintln!("{}", &compile_warnings); } if initial_build { log_config_warnings(build_state); @@ -451,21 +451,21 @@ fn log_deprecated_config_field(package_name: &str, field_name: &str, new_field_n "The field '{field_name}' found in the package config of '{package_name}' is deprecated and will be removed in a future version.\n\ Use '{new_field_name}' instead." ); - println!("\n{}", style(warning).yellow()); + eprintln!("\n{}", style(warning).yellow()); } fn log_unsupported_config_field(package_name: &str, field_name: &str) { let warning = format!( "The field '{field_name}' found in the package config of '{package_name}' is not supported by ReScript 12's new build system." ); - println!("\n{}", style(warning).yellow()); + eprintln!("\n{}", style(warning).yellow()); } fn log_unknown_config_field(package_name: &str, field_name: &str) { let warning = format!( "Unknown field '{field_name}' found in the package config of '{package_name}'. This option will be ignored." ); - println!("\n{}", style(warning).yellow()); + eprintln!("\n{}", style(warning).yellow()); } // write build.ninja files in the packages after a non-incremental build diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index f6451a5e88..65b1ff5b64 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -165,10 +165,9 @@ impl log::Log for SplitLogger { } fn log(&self, record: &log::Record) { - if record.level() == log::Level::Error { - self.stderr.log(record); - } else { - self.stdout.log(record); + match record.level() { + log::Level::Error | log::Level::Warn => self.stderr.log(record), + _ => self.stdout.log(record), } } diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index 2d8fbe4733..bd0e9f9473 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -8,7 +8,7 @@ const o1 = await execBuild(); // biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI color codes from output const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, ""); -const first_message = stripAnsi(o1.stdout) +const first_message = stripAnsi(o1.stderr) .split("\n") .map(s => s.trim()) .find(s => s === "Warning number 110");