Skip to content

Commit

Permalink
fix: optimize debug message formatting, #1065 (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus authored Jun 20, 2022
1 parent cb98ad5 commit 49a578a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,20 @@ module.exports = {
};
```

## How to enable `@debug` output

Defaults, the output of `@debug` messages is disabled.
To enable it, add to **webpack.config.js** following:

```js
module.exports = {
stats: {
loggingDebug: ["sass-loader"],
},
// ...
};
```

## Examples

### Extracts CSS into separate files
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ async function getSassOptions(
const logger = loaderContext.getLogger("sass-loader");
const formatSpan = (span) =>
`${span.url || "-"}:${span.start.line}:${span.start.column}: `;
const formatDebugSpan = (span) =>
`[debug:${span.start.line}:${span.start.column}] `;

options.logger = {
debug(message, loggerOptions) {
let builtMessage = "";

if (loggerOptions.span) {
builtMessage = formatSpan(loggerOptions.span);
builtMessage = formatDebugSpan(loggerOptions.span);
}

builtMessage += message;
Expand Down
16 changes: 8 additions & 8 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2833,7 +2833,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2861,7 +2861,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2889,7 +2889,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2917,7 +2917,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2945,7 +2945,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -2973,7 +2973,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -3001,7 +3001,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down
48 changes: 24 additions & 24 deletions test/__snapshots__/warnRuleAsWarning.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -41,7 +41,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -69,7 +69,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -97,7 +97,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -149,7 +149,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -177,7 +177,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -205,7 +205,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -233,7 +233,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -261,7 +261,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -289,7 +289,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -317,7 +317,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -345,7 +345,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -397,7 +397,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -425,7 +425,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -453,7 +453,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -481,7 +481,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -509,7 +509,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -541,7 +541,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -573,7 +573,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -605,7 +605,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -661,7 +661,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -693,7 +693,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -725,7 +725,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/sass/logging.sass:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down Expand Up @@ -757,7 +757,7 @@ Array [
Array [
Object {
"args": Array [
"file:///<cwd>/scss/logging.scss:0:0: My debug message",
"[debug:0:0] My debug message",
],
"type": "debug",
},
Expand Down

0 comments on commit 49a578a

Please sign in to comment.