From ef4686830bb5adc2b75ed7774ab7dc2bb590d830 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 11 Jan 2024 17:16:05 +0800 Subject: [PATCH] try --- crates/rspack_core/src/resolver/mod.rs | 4 ++-- crates/rspack_error/src/diagnostic.rs | 2 +- packages/rspack/tests/Errors.test.ts | 4 ++-- .../__snapshots__/StatsTestCases.test.ts.snap | 18 +++++++++--------- .../stats.err | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/rspack_core/src/resolver/mod.rs b/crates/rspack_core/src/resolver/mod.rs index 9bde78bb137..94b2212bc42 100644 --- a/crates/rspack_core/src/resolver/mod.rs +++ b/crates/rspack_core/src/resolver/mod.rs @@ -124,11 +124,11 @@ pub fn resolve_for_error_hints( return Some(format!("Did you mean '{}'? The request '{}' failed to resolve only because it was resolved as fully specified, -probably because the origin '{}' is strict EcmaScript Module, +probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\"type\": \"module\"'. The extension in the request is mandatory for it to be fully specified. -Add the extension to the request.", suggestion, args.specifier, args.issuer.unwrap_or_default())); +Add the extension to the request.", suggestion, args.specifier)); } Err(_) => return None, _ => {} diff --git a/crates/rspack_error/src/diagnostic.rs b/crates/rspack_error/src/diagnostic.rs index ac3277f6ee4..fea190f05cc 100644 --- a/crates/rspack_error/src/diagnostic.rs +++ b/crates/rspack_error/src/diagnostic.rs @@ -91,6 +91,7 @@ impl Diagnostic { impl Diagnostic { pub fn render_report(&self, colored: bool) -> crate::Result { + let mut buf = String::new(); let h = GraphicalReportHandler::new() .with_theme(if colored { GraphicalTheme::unicode() @@ -98,7 +99,6 @@ impl Diagnostic { GraphicalTheme::unicode_nocolor() }) .with_context_lines(2); - let mut buf = String::new(); h.render_report(&mut buf, self.as_ref()).into_diagnostic()?; Ok(buf) } diff --git a/packages/rspack/tests/Errors.test.ts b/packages/rspack/tests/Errors.test.ts index c7860d64d25..864c9ff84fa 100644 --- a/packages/rspack/tests/Errors.test.ts +++ b/packages/rspack/tests/Errors.test.ts @@ -146,8 +146,8 @@ it("should emit warnings for resolve failure in esm", async () => { Object { "errors": Array [ Object { - "formatted": " × Resolve error: Can't resolve './answer' in '/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin '/tests/fixtures/errors/resolve-fail-esm/index.js' is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", - "message": " × Resolve error: Can't resolve './answer' in '/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin '/tests/fixtures/errors/resolve-fail-esm/index.js' is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", + "formatted": " × Resolve error: Can't resolve './answer' in '/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", + "message": " × Resolve error: Can't resolve './answer' in '/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "moduleId": "./resolve-fail-esm/index.js", "moduleIdentifier": "javascript/esm|/tests/fixtures/errors/resolve-fail-esm/index.js", "moduleName": "./resolve-fail-esm/index.js", diff --git a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap index dbea104fd4e..6901edd57d9 100644 --- a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap +++ b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap @@ -829,7 +829,7 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` "hotModuleReplacement": false, }, "name": "bundle.js", - "size": 9038, + "size": 9108, "type": "asset", }, ], @@ -894,10 +894,10 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` "assets": [ { "name": "bundle.js", - "size": 9038, + "size": 9108, }, ], - "assetsSize": 9038, + "assetsSize": 9108, "chunks": [ "909", ], @@ -907,7 +907,7 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` "errors": [], "errorsCount": 0, "filteredModules": undefined, - "hash": "d938674585ad9aa214d9", + "hash": "5f9f75789352d7c6b706", "logging": {}, "modules": [ { @@ -1065,10 +1065,10 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` "assets": [ { "name": "bundle.js", - "size": 9038, + "size": 9108, }, ], - "assetsSize": 9038, + "assetsSize": 9108, "chunks": [ "909", ], @@ -1084,8 +1084,8 @@ exports[`StatsTestCases should print correct stats for hot+production 1`] = ` exports[`StatsTestCases should print correct stats for hot+production 2`] = ` "PublicPath: (none) -asset bundle.js 8.83 KiB {909} [emitted] (name: main) -Entrypoint main 8.83 KiB = bundle.js +asset bundle.js 8.89 KiB {909} [emitted] (name: main) +Entrypoint main 8.89 KiB = bundle.js chunk {909} bundle.js (main) [entry] ./index.js [10] {909} entry ./index.js @@ -1098,7 +1098,7 @@ webpack/runtime/hot_module_replacement {909} webpack/runtime/get_chunk_update_filename {909} webpack/runtime/get_main_filename/update manifest {909} -Rspack compiled successfully (d938674585ad9aa214d9)" +Rspack compiled successfully (5f9f75789352d7c6b706)" `; exports[`StatsTestCases should print correct stats for identifier-let-strict-mode 1`] = ` diff --git a/packages/rspack/tests/diagnostics/factorize/fully-specified-resolve-suggestions/stats.err b/packages/rspack/tests/diagnostics/factorize/fully-specified-resolve-suggestions/stats.err index 4d4570c56d6..1706b778f6a 100644 --- a/packages/rspack/tests/diagnostics/factorize/fully-specified-resolve-suggestions/stats.err +++ b/packages/rspack/tests/diagnostics/factorize/fully-specified-resolve-suggestions/stats.err @@ -7,7 +7,7 @@ ERROR in ./index.js help: Did you mean './foo.js'? The request './foo' failed to resolve only because it was resolved as fully specified, - probably because the origin '/tests/diagnostics/factorize/fully-specified-resolve-suggestions/index.js' is strict EcmaScript Module, + probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"'. The extension in the request is mandatory for it to be fully specified.