Skip to content

Commit 9723c1b

Browse files
authored
fix(diagnostic): dim gutter style for better visual hierarchy (#12341)
* fix(diagnostic): dim gutter style for better visual hierarchy * fix: style
1 parent 7c3506a commit 9723c1b

File tree

16 files changed

+300
-254
lines changed

16 files changed

+300
-254
lines changed

Cargo.lock

Lines changed: 37 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ linked_hash_set = { version = "0.1.5", default-features = false }
6161
md4 = { version = "0.10.2", default-features = false }
6262
memchr = { version = "2.7.5", default-features = false }
6363
micromegas-perfetto = { version = "0.9.0", default-features = false }
64-
miette = { version = "7.5.0", default-features = false }
64+
miette = { version = "7.6.0", default-features = false }
6565
mimalloc = { version = "0.2.4", package = "mimalloc-rspack", default-features = false }
6666
mime_guess = { version = "2.0.5", default-features = false, features = ["rev-mappings"] }
6767
notify = { version = "8.2.0", default-features = false }
6868
num-bigint = { version = "0.4.6", default-features = false }
6969
once_cell = { version = "1.20.2", default-features = false }
7070
oneshot = { version = "0.1.8", default-features = false, features = ["std", "async"] }
71-
owo-colors = { version = "4.0.0", default-features = false }
71+
owo-colors = { version = "4.0.0", default-features = false, features = ["supports-colors"] }
7272
parcel_sourcemap = { version = "2.1.1", default-features = false }
7373
paste = { version = "1.0.15", default-features = false }
7474
path-clean = { version = "1.0.1", default-features = false }

crates/rspack_core/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use itertools::Itertools;
2-
use rspack_error::{Diagnostic, Error, Label};
2+
use rspack_error::{Diagnostic, Error, Label, dim};
33

44
use crate::{BoxLoader, DependencyRange};
55

@@ -48,7 +48,7 @@ impl From<ModuleBuildError> for Error {
4848
let source = value.error;
4949

5050
let message = if let Some(from) = value.from {
51-
format!("Module build failed (from {from}):")
51+
format!("Module build failed {}:", dim(format!("(from {from})")))
5252
} else {
5353
"Module build failed:".to_string()
5454
};

crates/rspack_error/src/colors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use owo_colors::{OwoColorize, Stream};
2+
3+
/**
4+
* Dim the text if the stream supports color.
5+
*/
6+
pub fn dim(text: impl std::fmt::Display) -> String {
7+
text
8+
.if_supports_color(Stream::Stdout, |text| text.dimmed())
9+
.to_string()
10+
}

crates/rspack_error/src/displayer/renderer/graphical.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use miette::{
1313
use owo_colors::{OwoColorize, Style};
1414
use unicode_width::UnicodeWidthChar;
1515

16+
use crate::colors::dim;
17+
1618
/**
1719
A [`ReportHandler`] that displays a given [`Report`](crate::Report) in a
1820
quasi-graphical way, using terminal colors, unicode drawing characters, and
@@ -212,7 +214,7 @@ impl GraphicalReportHandler {
212214
};
213215

214216
let initial_indent = format!(" {} ", severity_icon.style(severity_style));
215-
let rest_indent = format!(" {} ", self.theme.characters.vbar.style(severity_style));
217+
let rest_indent = format!(" {} ", dim(self.theme.characters.vbar));
216218
let width = self.termwidth.saturating_sub(2);
217219
let opts = textwrap::Options::new(width)
218220
.initial_indent(&initial_indent)
@@ -237,21 +239,19 @@ impl GraphicalReportHandler {
237239
} else {
238240
self.theme.characters.lbot
239241
};
240-
let initial_indent = format!(
242+
let initial_indent = dim(format!(
241243
" {}{}{} ",
242244
char, self.theme.characters.hbar, self.theme.characters.rarrow
243-
)
244-
.style(severity_style)
245+
))
245246
.to_string();
246-
let rest_indent = format!(
247+
let rest_indent = dim(format!(
247248
" {} ",
248249
if is_last {
249250
' '
250251
} else {
251252
self.theme.characters.vbar
252253
}
253-
)
254-
.style(severity_style)
254+
))
255255
.to_string();
256256
let opts = textwrap::Options::new(width)
257257
.initial_indent(&initial_indent)

crates/rspack_error/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod batch_error;
2+
mod colors;
23
mod convert;
34
mod diagnosable;
45
mod diagnostic;
@@ -9,6 +10,7 @@ mod macros;
910

1011
pub use self::{
1112
batch_error::BatchErrors,
13+
colors::dim,
1214
convert::{
1315
AnyhowResultToRspackResultExt, SerdeResultToRspackResultExt, ToStringResultToRspackResultExt,
1416
},

deny.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ skip = [
246246
{ crate = "foldhash", reason = "external dependency" },
247247
{ crate = "wasmparser", reason = "external dependency"},
248248
{ crate = "windows_i686_gnullvm", reason = "external dependency"},
249+
{ crate = "hermit-abi", reason = "external dependency"},
250+
{ crate = "supports-color", reason = "external dependency"},
249251

250252
{ crate = "zerocopy", reason = "external dependency"},
251253
{ crate = "linux-raw-sys", reason = "external dependency"},

tests/rspack-test/errorCases/error-case-sensitive.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ module.exports = isCaseInsensitiveFilesystem
1818
},
1919
async check(diagnostics) {
2020
expect(diagnostics).toMatchInlineSnapshot(`
21-
Object {
22-
"errors": Array [],
23-
"warnings": Array [
24-
Object {
25-
"code": "Sensitive Modules Warn",
26-
"message": " ⚠ There are multiple modules with names that only differ in casing. │ - <TEST_ROOT>/fixtures/errors/FILE.js │ - used by <TEST_ROOT>/fixtures/errors/case-sensitive.js │ - <TEST_ROOT>/fixtures/errors/file.js │ - used by <TEST_ROOT>/fixtures/errors/case-sensitive.js │ ",
27-
"moduleTrace": Array [],
28-
"stack": undefined,
29-
},
30-
],
31-
}
32-
`);
21+
Object {
22+
"errors": Array [],
23+
"warnings": Array [
24+
Object {
25+
"code": "Sensitive Modules Warn",
26+
"message": " ⚠ There are multiple modules with names that only differ in casing. │ - <TEST_ROOT>/fixtures/errors/FILE.js │ - used by <TEST_ROOT>/fixtures/errors/case-sensitive.js │ - <TEST_ROOT>/fixtures/errors/file.js │ - used by <TEST_ROOT>/fixtures/errors/case-sensitive.js │ ",
27+
"moduleTrace": Array [],
28+
"stack": undefined,
29+
},
30+
],
31+
}
32+
`);
3333
}
3434
}
3535
: {

tests/rspack-test/errorCases/error-library.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module.exports = {
1111
},
1212
async check(diagnostics) {
1313
expect(diagnostics).toMatchInlineSnapshot(`
14-
Object {
15-
"errors": Array [
16-
Object {
17-
"code": "GenericFailure",
18-
"message": " × caused by plugins in Compilation.hooks.additionalChunkRuntimeRequirements ╰─▶ × Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'. ",
19-
"stack": "Error: × caused by plugins in Compilation.hooks.additionalChunkRuntimeRequirements ╰─▶ × Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'. ",
20-
},
21-
],
22-
"warnings": Array [],
23-
}
24-
`);
14+
Object {
15+
"errors": Array [
16+
Object {
17+
"code": "GenericFailure",
18+
"message": " × caused by plugins in Compilation.hooks.additionalChunkRuntimeRequirements ╰─▶ × Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'. ",
19+
"stack": "Error: × caused by plugins in Compilation.hooks.additionalChunkRuntimeRequirements ╰─▶ × Library name must be a string or string array. Common configuration options that specific library names are 'output.library[.name]', 'entry.xyz.library[.name]', 'ModuleFederationPlugin.name' and 'ModuleFederationPlugin.library[.name]'. ",
20+
},
21+
],
22+
"warnings": Array [],
23+
}
24+
`);
2525
}
2626
};

0 commit comments

Comments
 (0)