From abfdf1207d8faaa06c6398c5d0facd6e178d052a Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 10 Oct 2024 18:58:14 +0800 Subject: [PATCH] chore: polish CSS HMR logs and correct the case --- .../hmr/expected/main.js | 8 +++---- .../css/recovery/__snapshots__/web/2.snap.txt | 8 +++---- .../css-extract/hmr/hotModuleReplacement.ts | 8 +++---- .../__snapshots__/HMR.test.js.snap | 22 +++++++++---------- .../cases/hmr-locals/expected/main.js | 8 +++---- .../css-extract/cases/hmr/expected/main.js | 8 +++---- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/rspack_plugin_css/webpack_css_cases_to_be_migrated/hmr/expected/main.js b/crates/rspack_plugin_css/webpack_css_cases_to_be_migrated/hmr/expected/main.js index 229a3eb642e..f3e46eabb8d 100644 --- a/crates/rspack_plugin_css/webpack_css_cases_to_be_migrated/hmr/expected/main.js +++ b/crates/rspack_plugin_css/webpack_css_cases_to_be_migrated/hmr/expected/main.js @@ -262,7 +262,7 @@ function isUrlRequest(url) { */ module.exports = function (moduleId, options) { if (noDocument) { - console.log("no window.document found, will not HMR CSS"); + console.log("[HMR] No `window.document` found, CSS HMR disabled"); return noop; } @@ -274,7 +274,7 @@ module.exports = function (moduleId, options) { const reloaded = reloadStyle(src); if (options.locals) { - console.log("[HMR] Detected local css modules. Reload all css"); + console.log("[HMR] Detected local CSS Modules. Reload all CSS"); reloadAll(); @@ -282,9 +282,9 @@ module.exports = function (moduleId, options) { } if (reloaded) { - console.log("[HMR] css reload %s", src.join(" ")); + console.log("[HMR] CSS reload %s", src.join(" ")); } else { - console.log("[HMR] Reload all css"); + console.log("[HMR] Reload all CSS"); reloadAll(); } diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt index aaef75e617b..d3cca618942 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt @@ -193,7 +193,7 @@ function isUrlRequest(url) { } function cssReload(moduleId, options) { if (noDocument) { - console.log("no window.document found, will not HMR CSS"); + console.log("[HMR] No `window.document` found, CSS HMR disabled"); return noop; } const getScriptSrc = getCurrentScriptUrl(moduleId); @@ -201,16 +201,16 @@ function cssReload(moduleId, options) { const src = getScriptSrc(options.filename); const reloaded = reloadStyle(src); if (options.locals) { - console.log("[HMR] Detected local css modules. Reload all css"); + console.log("[HMR] Detected local CSS Modules. Reload all CSS"); reloadAll(); return; } if (reloaded) { // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser - console.log("[HMR] css reload %s", src && src.join(" ")); + console.log("[HMR] CSS reload %s", src && src.join(" ")); } else { - console.log("[HMR] Reload all css"); + console.log("[HMR] Reload all CSS"); reloadAll(); } } diff --git a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts index 6f2e9593db4..9f2741ebc98 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts @@ -214,7 +214,7 @@ function isUrlRequest(url: string): boolean { function cssReload(moduleId: string, options: Record) { if (noDocument) { - console.log("no window.document found, will not HMR CSS"); + console.log("[HMR] No `window.document` found, CSS HMR disabled"); return noop; } @@ -226,7 +226,7 @@ function cssReload(moduleId: string, options: Record) { const reloaded = reloadStyle(src); if (options.locals) { - console.log("[HMR] Detected local css modules. Reload all css"); + console.log("[HMR] Detected local CSS Modules. Reload all CSS"); reloadAll(); @@ -235,9 +235,9 @@ function cssReload(moduleId: string, options: Record) { if (reloaded) { // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser - console.log("[HMR] css reload %s", src && src.join(" ")); + console.log("[HMR] CSS reload %s", src && src.join(" ")); } else { - console.log("[HMR] Reload all css"); + console.log("[HMR] Reload all CSS"); reloadAll(); } diff --git a/tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap b/tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap index ba874297103..386bfe84873 100644 --- a/tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap +++ b/tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap @@ -52,47 +52,47 @@ exports[`HMR hotLoader works for non-locals 1`] = ` " `; -exports[`HMR should handle error event 1`] = `"[HMR] css reload %s"`; +exports[`HMR should handle error event 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should handle error event 2`] = `""`; -exports[`HMR should reloads with # link href 1`] = `"[HMR] css reload %s"`; +exports[`HMR should reloads with # link href 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should reloads with # link href 2`] = `""`; -exports[`HMR should reloads with absolute remove url 1`] = `"[HMR] css reload %s"`; +exports[`HMR should reloads with absolute remove url 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should reloads with absolute remove url 2`] = `""`; -exports[`HMR should reloads with browser extension protocol 1`] = `"[HMR] css reload %s"`; +exports[`HMR should reloads with browser extension protocol 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should reloads with browser extension protocol 2`] = `""`; -exports[`HMR should reloads with link without href 1`] = `"[HMR] css reload %s"`; +exports[`HMR should reloads with link without href 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should reloads with link without href 2`] = `""`; -exports[`HMR should reloads with locals 1`] = `"[HMR] Detected local css modules. Reload all css"`; +exports[`HMR should reloads with locals 1`] = `"[HMR] Detected local CSS Modules. Reload all CSS"`; exports[`HMR should reloads with locals 2`] = `""`; -exports[`HMR should reloads with non http/https link href 1`] = `"[HMR] css reload %s"`; +exports[`HMR should reloads with non http/https link href 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should reloads with non http/https link href 2`] = `""`; -exports[`HMR should reloads with non-file script in the end of page 1`] = `"[HMR] Reload all css"`; +exports[`HMR should reloads with non-file script in the end of page 1`] = `"[HMR] Reload all CSS"`; exports[`HMR should reloads with non-file script in the end of page 2`] = `""`; -exports[`HMR should work reload all css 1`] = `"[HMR] Reload all css"`; +exports[`HMR should work reload all css 1`] = `"[HMR] Reload all CSS"`; exports[`HMR should work reload all css 2`] = `""`; -exports[`HMR should works 1`] = `"[HMR] css reload %s"`; +exports[`HMR should works 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should works 2`] = `""`; -exports[`HMR should works with multiple updates 1`] = `"[HMR] css reload %s"`; +exports[`HMR should works with multiple updates 1`] = `"[HMR] CSS reload %s"`; exports[`HMR should works with multiple updates 2`] = `""`; diff --git a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js index d23ec3a18e8..9f464dd815a 100644 --- a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js @@ -160,7 +160,7 @@ function isUrlRequest(url) { } function cssReload(moduleId, options) { if (noDocument) { - console.log("no window.document found, will not HMR CSS"); + console.log("[HMR] No `window.document` found, CSS HMR disabled"); return noop; } const getScriptSrc = getCurrentScriptUrl(moduleId); @@ -168,16 +168,16 @@ function cssReload(moduleId, options) { const src = getScriptSrc(options.filename); const reloaded = reloadStyle(src); if (options.locals) { - console.log("[HMR] Detected local css modules. Reload all css"); + console.log("[HMR] Detected local CSS Modules. Reload all CSS"); reloadAll(); return; } if (reloaded) { // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser - console.log("[HMR] css reload %s", src && src.join(" ")); + console.log("[HMR] CSS reload %s", src && src.join(" ")); } else { - console.log("[HMR] Reload all css"); + console.log("[HMR] Reload all CSS"); reloadAll(); } } diff --git a/tests/plugin-test/css-extract/cases/hmr/expected/main.js b/tests/plugin-test/css-extract/cases/hmr/expected/main.js index f6f326c83d4..d39d0aad558 100644 --- a/tests/plugin-test/css-extract/cases/hmr/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr/expected/main.js @@ -160,7 +160,7 @@ function isUrlRequest(url) { } function cssReload(moduleId, options) { if (noDocument) { - console.log("no window.document found, will not HMR CSS"); + console.log("[HMR] No `window.document` found, CSS HMR disabled"); return noop; } const getScriptSrc = getCurrentScriptUrl(moduleId); @@ -168,16 +168,16 @@ function cssReload(moduleId, options) { const src = getScriptSrc(options.filename); const reloaded = reloadStyle(src); if (options.locals) { - console.log("[HMR] Detected local css modules. Reload all css"); + console.log("[HMR] Detected local CSS Modules. Reload all CSS"); reloadAll(); return; } if (reloaded) { // biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser - console.log("[HMR] css reload %s", src && src.join(" ")); + console.log("[HMR] CSS reload %s", src && src.join(" ")); } else { - console.log("[HMR] Reload all css"); + console.log("[HMR] Reload all CSS"); reloadAll(); } }