Skip to content

Commit

Permalink
chore: polish CSS HMR logs and correct the case
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Oct 10, 2024
1 parent 27188f2 commit abfdf12
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -274,17 +274,17 @@ 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();

return;
}

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,24 @@ 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);
function update() {
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function isUrlRequest(url: string): boolean {

function cssReload(moduleId: string, options: Record<string, any>) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");

return noop;
}
Expand All @@ -226,7 +226,7 @@ function cssReload(moduleId: string, options: Record<string, any>) {
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();

Expand All @@ -235,9 +235,9 @@ function cssReload(moduleId: string, options: Record<string, any>) {

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();
}
Expand Down
22 changes: 11 additions & 11 deletions tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\" href=\\"#href\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"stylesheet\\" href=\\"http://dev.com/dist/main.css\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"stylesheet\\" href=\\"chrome-extension://main.css\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\" href=\\"data:;base64,=\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
exports[`HMR should works 1`] = `"[HMR] css reload %s"`;
exports[`HMR should works 1`] = `"[HMR] CSS reload %s"`;
exports[`HMR should works 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
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`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ 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);
function update() {
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();
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/plugin-test/css-extract/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ 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);
function update() {
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();
}
}
Expand Down

0 comments on commit abfdf12

Please sign in to comment.