Skip to content

Commit

Permalink
Warnings and Errors contribute to hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 11, 2017
1 parent f7bcba7 commit 7905bf5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/Compilation.js
Expand Up @@ -1103,6 +1103,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 @@ -1171,6 +1182,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(warning) {
hash.update(`${warning.message}`);
});
// clone needed as sort below is inplace mutation
const chunks = this.chunks.slice();
/**
Expand Down
@@ -1,4 +1,4 @@
Hash: 6e950f2e83663cb6e9a6
Hash: 96df8294017a444709b1
Time: Xms
Asset Size Chunks Chunk Names
main.js 2.65 kB 0 [emitted] main
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/module-trace-enabled-in-error/expected.txt
@@ -1,4 +1,4 @@
Hash: 6e950f2e83663cb6e9a6
Hash: d59adee54681f1f3ab37
Time: Xms
Asset Size Chunks Chunk Names
main.js 2.65 kB 0 [emitted] main
Expand Down
@@ -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 7905bf5

Please sign in to comment.