Skip to content

Commit b0069f1

Browse files
authored
refactor: remove js stats warning (#10900)
1 parent 33732df commit b0069f1

File tree

11 files changed

+19
-98
lines changed

11 files changed

+19
-98
lines changed

crates/node_binding/binding.d.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,11 @@ export interface JsStatsCompilation {
12911291
hash?: string
12921292
modules?: Array<JsStatsModule>
12931293
namedChunkGroups?: Array<JsStatsChunkGroup>
1294-
warnings: Array<JsStatsWarning>
1294+
warnings: Array<JsStatsError>
12951295
}
12961296

12971297
export interface JsStatsError {
1298+
name?: string
12981299
moduleDescriptor?: JsModuleDescriptor
12991300
message: string
13001301
chunkName?: string
@@ -1433,21 +1434,6 @@ export interface JsStatsSize {
14331434
size: number
14341435
}
14351436

1436-
export interface JsStatsWarning {
1437-
moduleDescriptor?: JsModuleDescriptor
1438-
name?: string
1439-
message: string
1440-
chunkName?: string
1441-
code?: string
1442-
chunkEntry?: boolean
1443-
chunkInitial?: boolean
1444-
file?: string
1445-
chunkId?: string
1446-
details?: string
1447-
stack?: string
1448-
moduleTrace: Array<JsStatsModuleTrace>
1449-
}
1450-
14511437
export interface JsTap {
14521438
function: any
14531439
stage: number

crates/rspack_binding_api/src/stats.rs

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl<'a> From<JsModuleDescriptor<'a>> for JsModuleDescriptorWrapper<'a> {
137137

138138
#[napi(object, object_from_js = false)]
139139
pub struct JsStatsError<'a> {
140+
pub name: Option<String>,
140141
#[napi(ts_type = "JsModuleDescriptor")]
141142
pub module_descriptor: Option<JsModuleDescriptorWrapper<'a>>,
142143
pub message: String,
@@ -155,6 +156,7 @@ pub struct JsStatsError<'a> {
155156
impl<'a> From<rspack_core::StatsError<'a>> for JsStatsError<'a> {
156157
fn from(stats: rspack_core::StatsError<'a>) -> Self {
157158
Self {
159+
name: stats.name,
158160
module_descriptor: stats.module_identifier.map(|identifier| {
159161
JsModuleDescriptor {
160162
identifier: identifier.into(),
@@ -182,53 +184,6 @@ impl<'a> From<rspack_core::StatsError<'a>> for JsStatsError<'a> {
182184
}
183185
}
184186

185-
#[napi(object, object_from_js = false)]
186-
pub struct JsStatsWarning<'a> {
187-
#[napi(ts_type = "JsModuleDescriptor")]
188-
pub module_descriptor: Option<JsModuleDescriptorWrapper<'a>>,
189-
pub name: Option<String>,
190-
pub message: String,
191-
pub chunk_name: Option<&'a str>,
192-
pub code: Option<String>,
193-
pub chunk_entry: Option<bool>,
194-
pub chunk_initial: Option<bool>,
195-
pub file: Option<&'a str>,
196-
pub chunk_id: Option<&'a str>,
197-
pub details: Option<String>,
198-
pub stack: Option<String>,
199-
pub module_trace: Vec<JsStatsModuleTrace<'a>>,
200-
}
201-
202-
impl<'a> From<rspack_core::StatsWarning<'a>> for JsStatsWarning<'a> {
203-
fn from(stats: rspack_core::StatsWarning<'a>) -> Self {
204-
Self {
205-
module_descriptor: stats.module_identifier.map(|identifier| {
206-
JsModuleDescriptor {
207-
identifier: identifier.into(),
208-
name: CowStrWrapper::new(stats.module_name.unwrap_or_default()),
209-
id: stats.module_id.map(|s| to_js_module_id(&s)),
210-
}
211-
.into()
212-
}),
213-
name: stats.name,
214-
message: stats.message,
215-
file: stats.file.map(|f| f.as_str()),
216-
code: stats.code,
217-
chunk_name: stats.chunk_name,
218-
chunk_entry: stats.chunk_entry,
219-
chunk_initial: stats.chunk_initial,
220-
chunk_id: stats.chunk_id,
221-
details: stats.details,
222-
stack: stats.stack,
223-
module_trace: stats
224-
.module_trace
225-
.into_iter()
226-
.map(Into::into)
227-
.collect::<Vec<_>>(),
228-
}
229-
}
230-
}
231-
232187
#[napi(object, object_from_js = false)]
233188
pub struct JsStatsModuleTrace<'a> {
234189
pub origin: JsStatsModuleTraceModule<'a>,
@@ -1078,7 +1033,7 @@ pub struct JsStatsCompilation<'a> {
10781033
#[napi(ts_type = "Array<JsStatsModule>")]
10791034
pub modules: Option<napi_value>,
10801035
pub named_chunk_groups: Option<Vec<JsStatsChunkGroup<'a>>>,
1081-
#[napi(ts_type = "Array<JsStatsWarning>")]
1036+
#[napi(ts_type = "Array<JsStatsError>")]
10821037
pub warnings: napi_value,
10831038
}
10841039

@@ -1250,7 +1205,7 @@ impl JsStats {
12501205
self.inner.get_warnings(|warnings| {
12511206
let val = warnings
12521207
.into_iter()
1253-
.map(JsStatsWarning::from)
1208+
.map(JsStatsError::from)
12541209
.collect::<Vec<_>>();
12551210
unsafe { ToNapiValue::to_napi_value(env.raw(), val) }
12561211
})

crates/rspack_core/src/stats/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ impl Stats<'_> {
649649
);
650650
let code = d.code().map(|code| code.to_string());
651651
StatsError {
652+
name: d.code().map(|c| c.to_string()),
652653
message: diagnostic_displayer
653654
.emit_diagnostic(d)
654655
.expect("should print diagnostics"),
@@ -676,7 +677,7 @@ impl Stats<'_> {
676677
f(errors)
677678
}
678679

679-
pub fn get_warnings<T>(&self, f: impl Fn(Vec<StatsWarning>) -> T) -> T {
680+
pub fn get_warnings<T>(&self, f: impl Fn(Vec<StatsError>) -> T) -> T {
680681
let mut diagnostic_displayer = DiagnosticDisplayer::new(self.compilation.options.stats.colors);
681682

682683
let module_graph = self.compilation.get_module_graph();
@@ -710,7 +711,7 @@ impl Stats<'_> {
710711

711712
let code = d.code().map(|code| code.to_string());
712713

713-
StatsWarning {
714+
StatsError {
714715
name: d.code().map(|c| c.to_string()),
715716
message: diagnostic_displayer
716717
.emit_diagnostic(d)

crates/rspack_core/src/stats/struct.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@ pub struct ExtendedStatsOptions {
3939

4040
#[derive(Debug)]
4141
pub struct StatsError<'a> {
42-
pub message: String,
43-
pub code: Option<String>,
44-
pub module_identifier: Option<ModuleIdentifier>,
45-
pub module_name: Option<Cow<'a, str>>,
46-
pub module_id: Option<ModuleId>,
47-
pub loc: Option<String>,
48-
pub file: Option<&'a Utf8Path>,
49-
50-
pub chunk_name: Option<&'a str>,
51-
pub chunk_entry: Option<bool>,
52-
pub chunk_initial: Option<bool>,
53-
pub chunk_id: Option<&'a str>,
54-
pub details: Option<String>,
55-
pub stack: Option<String>,
56-
pub module_trace: Vec<StatsModuleTrace<'a>>,
57-
}
58-
59-
#[derive(Debug)]
60-
pub struct StatsWarning<'a> {
6142
pub name: Option<String>,
6243
pub message: String,
6344
pub code: Option<String>,

packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ Rspack compiled successfully
470470
`;
471471
472472
exports[`statsOutput statsOutput/try-require-module should print correct stats for 1`] = `
473-
WARNING in ./index.js
473+
WARNING in ./index.js 2:12-31
474474
⚠ Module not found: Can't resolve './missing-module' in '<TEST_TOOLS_ROOT>/tests/statsOutputCases/try-require-module'
475475
╭─[2:4]
476476
1 │ try {

packages/rspack-test-tools/tests/diagnosticsCases/factorize/missing-module/raw-warning.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Array [
22
Object {
3+
loc: 4:16-35,
34
moduleIdentifier: <TEST_TOOLS_ROOT>/tests/diagnosticsCases/factorize/missing-module/index.js,
45
moduleName: ./index.js,
56
},

packages/rspack-test-tools/tests/diagnosticsCases/factorize/missing-module/stats.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
WARNING in ./index.js
1+
WARNING in ./index.js 4:16-35
22
⚠ Module not found: Can't resolve './missing-module' in '<TEST_TOOLS_ROOT>/tests/diagnosticsCases/factorize/missing-module'
33
╭─[4:8]
44
2 │ let errored = false;

packages/rspack/etc/core.api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import type { JsRuntimeModule } from '@rspack/binding';
5959
import type { JsStats } from '@rspack/binding';
6060
import type { JsStatsCompilation } from '@rspack/binding';
6161
import type { JsStatsError } from '@rspack/binding';
62-
import type { JsStatsWarning } from '@rspack/binding';
6362
import * as liteTapable from '@rspack/lite-tapable';
6463
import { Logger } from './logging/Logger';
6564
import { Module } from '@rspack/binding';
@@ -3923,7 +3922,7 @@ type KnownStatsFactoryContext = {
39233922
makePathsRelative?: ((arg0: string) => string) | undefined;
39243923
compilation?: Compilation | undefined;
39253924
cachedGetErrors?: ((arg0: Compilation) => JsStatsError[]) | undefined;
3926-
cachedGetWarnings?: ((arg0: Compilation) => JsStatsWarning[]) | undefined;
3925+
cachedGetWarnings?: ((arg0: Compilation) => JsStatsError[]) | undefined;
39273926
getStatsCompilation: (compilation: Compilation) => JsStatsCompilation;
39283927
getInner: (compilation: Compilation) => JsStats;
39293928
};

packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import type {
1313
JsOriginRecord,
1414
JsStatsAssetInfo,
1515
JsStatsError,
16-
JsStatsModule,
17-
JsStatsWarning
16+
JsStatsModule
1817
} from "@rspack/binding";
1918
import type { Chunk } from "../Chunk";
2019
import type { NormalizedStatsOptions } from "../Compilation";
@@ -609,7 +608,7 @@ const EXTRACT_ERROR: Record<
609608
string,
610609
(
611610
object: StatsError,
612-
error: JsStatsError | JsStatsWarning,
611+
error: JsStatsError,
613612
context: KnownStatsFactoryContext,
614613
options: StatsOptions,
615614
factory: StatsFactory

packages/rspack/src/stats/StatsFactory.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import type {
1111
JsStats,
1212
JsStatsCompilation,
13-
JsStatsError,
14-
JsStatsWarning
13+
JsStatsError
1514
} from "@rspack/binding";
1615
import { HookMap, SyncBailHook, SyncWaterfallHook } from "@rspack/lite-tapable";
1716

@@ -28,7 +27,7 @@ export type KnownStatsFactoryContext = {
2827
// compilationAuxiliaryFileToChunks?: Map<string, Chunk[]> | undefined;
2928
// runtime?: RuntimeSpec | undefined;
3029
cachedGetErrors?: ((arg0: Compilation) => JsStatsError[]) | undefined;
31-
cachedGetWarnings?: ((arg0: Compilation) => JsStatsWarning[]) | undefined;
30+
cachedGetWarnings?: ((arg0: Compilation) => JsStatsError[]) | undefined;
3231
getStatsCompilation: (compilation: Compilation) => JsStatsCompilation;
3332
getInner: (compilation: Compilation) => JsStats;
3433
};

0 commit comments

Comments
 (0)