Skip to content

Commit 1792d23

Browse files
authored
Rewatch: log warnings to stderr, too (#8148)
* Rewatch, log warnings to stderr, too * fix test * CHANGELOG
1 parent d04afe6 commit 1792d23

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#### :bug: Bug fix
2525

2626
- Fix rewatch swallowing parse warnings (%todo). https://github.com/rescript-lang/rescript/pull/8135
27-
- Rewatch: log errors to `stderr`. https://github.com/rescript-lang/rescript/pull/8147
27+
- Rewatch: log errors and warnings to `stderr`. https://github.com/rescript-lang/rescript/pull/8147 https://github.com/rescript-lang/rescript/pull/8148
2828

2929
#### :memo: Documentation
3030

rewatch/src/build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn incremental_build(
306306
}
307307
}
308308
if helpers::contains_ascii_characters(&parse_warnings) {
309-
println!("{}", &parse_warnings);
309+
eprintln!("{}", &parse_warnings);
310310
}
311311

312312
mark_modules_with_expired_deps_dirty(build_state);
@@ -371,7 +371,7 @@ pub fn incremental_build(
371371
}
372372
}
373373
if helpers::contains_ascii_characters(&compile_warnings) {
374-
println!("{}", &compile_warnings);
374+
eprintln!("{}", &compile_warnings);
375375
}
376376
if initial_build {
377377
log_config_warnings(build_state);
@@ -400,7 +400,7 @@ pub fn incremental_build(
400400
}
401401

402402
if helpers::contains_ascii_characters(&compile_warnings) {
403-
println!("{}", &compile_warnings);
403+
eprintln!("{}", &compile_warnings);
404404
}
405405
if initial_build {
406406
log_config_warnings(build_state);
@@ -451,21 +451,21 @@ fn log_deprecated_config_field(package_name: &str, field_name: &str, new_field_n
451451
"The field '{field_name}' found in the package config of '{package_name}' is deprecated and will be removed in a future version.\n\
452452
Use '{new_field_name}' instead."
453453
);
454-
println!("\n{}", style(warning).yellow());
454+
eprintln!("\n{}", style(warning).yellow());
455455
}
456456

457457
fn log_unsupported_config_field(package_name: &str, field_name: &str) {
458458
let warning = format!(
459459
"The field '{field_name}' found in the package config of '{package_name}' is not supported by ReScript 12's new build system."
460460
);
461-
println!("\n{}", style(warning).yellow());
461+
eprintln!("\n{}", style(warning).yellow());
462462
}
463463

464464
fn log_unknown_config_field(package_name: &str, field_name: &str) {
465465
let warning = format!(
466466
"Unknown field '{field_name}' found in the package config of '{package_name}'. This option will be ignored."
467467
);
468-
println!("\n{}", style(warning).yellow());
468+
eprintln!("\n{}", style(warning).yellow());
469469
}
470470

471471
// write build.ninja files in the packages after a non-incremental build

rewatch/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ impl log::Log for SplitLogger {
165165
}
166166

167167
fn log(&self, record: &log::Record) {
168-
if record.level() == log::Level::Error {
169-
self.stderr.log(record);
170-
} else {
171-
self.stdout.log(record);
168+
match record.level() {
169+
log::Level::Error | log::Level::Warn => self.stderr.log(record),
170+
_ => self.stdout.log(record),
172171
}
173172
}
174173

tests/build_tests/build_warn_as_error/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const o1 = await execBuild();
88
// biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI color codes from output
99
const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, "");
1010

11-
const first_message = stripAnsi(o1.stdout)
11+
const first_message = stripAnsi(o1.stderr)
1212
.split("\n")
1313
.map(s => s.trim())
1414
.find(s => s === "Warning number 110");

0 commit comments

Comments
 (0)