Skip to content

Commit 839915c

Browse files
authored
Merge pull request webpack#5501 from webpack/bugfix/hash-watch-warnings-errors
Warnings and Errors contribute to hash
2 parents 0925a9d + 93af585 commit 839915c

11 files changed

Lines changed: 43 additions & 2 deletions

File tree

lib/Compilation.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,17 @@ class Compilation extends Tapable {
11201120
for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
11211121
chunks[indexChunk].sortItems();
11221122
}
1123+
1124+
const byMessage = (a, b) => {
1125+
const ma = `${a.message}`;
1126+
const mb = `${b.message}`;
1127+
if(ma < mb) return -1;
1128+
if(mb < ma) return 1;
1129+
return 0;
1130+
};
1131+
1132+
this.errors.sort(byMessage);
1133+
this.warnings.sort(byMessage);
11231134
}
11241135

11251136
summarizeDependencies() {
@@ -1188,6 +1199,12 @@ class Compilation extends Tapable {
11881199
this.children.forEach(function(child) {
11891200
hash.update(child.hash);
11901201
});
1202+
this.warnings.forEach(function(warning) {
1203+
hash.update(`${warning.message}`);
1204+
});
1205+
this.errors.forEach(function(error) {
1206+
hash.update(`${error.message}`);
1207+
});
11911208
// clone needed as sort below is inplace mutation
11921209
const chunks = this.chunks.slice();
11931210
/**

test/statsCases/module-trace-disabled-in-error/expected.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Hash: 6e950f2e83663cb6e9a6
21
Time: Xms
32
Asset Size Chunks Chunk Names
43
main.js 2.65 kB 0 [emitted] main
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
entry: "./index",
33
stats: {
4+
hash: false,
45
moduleTrace: false
56
}
67
};

test/statsCases/module-trace-enabled-in-error/expected.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Hash: 6e950f2e83663cb6e9a6
21
Time: Xms
32
Asset Size Chunks Chunk Names
43
main.js 2.65 kB 0 [emitted] main
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
entry: "./index",
33
stats: {
4+
hash: false,
45
moduleTrace: true
56
}
67
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warning1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require("./warning-loader!./changing-file");
2+
3+
it("should detect a change on warnings change", function() {
4+
switch(WATCH_STEP) {
5+
case "0":
6+
STATE.hash = STATS_JSON.hash;
7+
break;
8+
case "1":
9+
STATS_JSON.hash.should.be.not.eql(STATE.hash);
10+
break;
11+
}
12+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function(source) {
2+
this.emitWarning(new Error(source.trim()));
3+
return "";
4+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[/Warning1/]
3+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
New Warning

0 commit comments

Comments
 (0)