Skip to content

Commit 45e7f7a

Browse files
authored
Merge pull request webpack#6878 from rchaser53/fix-options-loader-error
emit correct path when using loader in options
2 parents a8d70e7 + 65aa1c0 commit 45e7f7a

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎lib/Stats.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ class Stats {
5353
});
5454
}
5555

56+
formatFilePath(filePath) {
57+
const OPTIONS_REGEXP = /^(\s|\S)*!/;
58+
return filePath.includes("!")
59+
? `${filePath.replace(OPTIONS_REGEXP, "")} (${filePath})\n`
60+
: `${filePath}\n`;
61+
}
62+
5663
hasWarnings() {
5764
return (
5865
this.compilation.warnings.length > 0 ||
@@ -266,7 +273,9 @@ class Stats {
266273
e.module.readableIdentifier &&
267274
typeof e.module.readableIdentifier === "function"
268275
) {
269-
text += `${e.module.readableIdentifier(requestShortener)}\n`;
276+
text += this.formatFilePath(
277+
e.module.readableIdentifier(requestShortener)
278+
);
270279
}
271280
text += e.message;
272281
if (showErrorDetails && e.details) text += `\n${e.details}`;

‎test/Stats.unittest.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ const packageJson = require("../package.json");
99
describe(
1010
"Stats",
1111
() => {
12+
describe("formatFilePath", () => {
13+
it("emit the file path and request", () => {
14+
const mockStats = new Stats({
15+
children: [],
16+
errors: ["firstError"],
17+
hash: "1234",
18+
compiler: {
19+
context: ""
20+
}
21+
});
22+
const inputPath =
23+
"./node_modules/ts-loader!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/app.vue";
24+
const expectPath = `./src/app.vue (${inputPath})\n`;
25+
26+
mockStats.formatFilePath(inputPath).should.be.exactly(expectPath);
27+
});
28+
});
29+
1230
describe("Error Handling", () => {
1331
describe("does have", () => {
1432
it("hasErrors", () => {

0 commit comments

Comments
 (0)