Skip to content

Commit

Permalink
Merge pull request #5501 from webpack/bugfix/hash-watch-warnings-errors
Browse files Browse the repository at this point in the history
Warnings and Errors contribute to hash
  • Loading branch information
sokra committed Aug 11, 2017
2 parents 0925a9d + 93af585 commit 839915c
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/Compilation.js
Expand Up @@ -1120,6 +1120,17 @@ class Compilation extends Tapable {
for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
chunks[indexChunk].sortItems();
}

const byMessage = (a, b) => {
const ma = `${a.message}`;
const mb = `${b.message}`;
if(ma < mb) return -1;
if(mb < ma) return 1;
return 0;
};

this.errors.sort(byMessage);
this.warnings.sort(byMessage);
}

summarizeDependencies() {
Expand Down Expand Up @@ -1188,6 +1199,12 @@ class Compilation extends Tapable {
this.children.forEach(function(child) {
hash.update(child.hash);
});
this.warnings.forEach(function(warning) {
hash.update(`${warning.message}`);
});
this.errors.forEach(function(error) {
hash.update(`${error.message}`);
});
// clone needed as sort below is inplace mutation
const chunks = this.chunks.slice();
/**
Expand Down
@@ -1,4 +1,3 @@
Hash: 6e950f2e83663cb6e9a6
Time: Xms
Asset Size Chunks Chunk Names
main.js 2.65 kB 0 [emitted] main
Expand Down
@@ -1,6 +1,7 @@
module.exports = {
entry: "./index",
stats: {
hash: false,
moduleTrace: false
}
};
1 change: 0 additions & 1 deletion test/statsCases/module-trace-enabled-in-error/expected.txt
@@ -1,4 +1,3 @@
Hash: 6e950f2e83663cb6e9a6
Time: Xms
Asset Size Chunks Chunk Names
main.js 2.65 kB 0 [emitted] main
Expand Down
@@ -1,6 +1,7 @@
module.exports = {
entry: "./index",
stats: {
hash: false,
moduleTrace: true
}
};
@@ -0,0 +1 @@
Warning1
12 changes: 12 additions & 0 deletions test/watchCases/warnings/warnings-contribute-to-hash/0/index.js
@@ -0,0 +1,12 @@
require("./warning-loader!./changing-file");

it("should detect a change on warnings change", function() {
switch(WATCH_STEP) {
case "0":
STATE.hash = STATS_JSON.hash;
break;
case "1":
STATS_JSON.hash.should.be.not.eql(STATE.hash);
break;
}
});
@@ -0,0 +1,4 @@
module.exports = function(source) {
this.emitWarning(new Error(source.trim()));
return "";
};
@@ -0,0 +1,3 @@
module.exports = [
[/Warning1/]
];
@@ -0,0 +1 @@
New Warning
@@ -0,0 +1,3 @@
module.exports = [
[/New Warning/]
];

0 comments on commit 839915c

Please sign in to comment.