Skip to content

Commit a87b61f

Browse files
uncleyoTheLarkInn
authored andcommitted
Include child compilation hash into parent hash computation (webpack#3744)
Without it, child compilations like those added by "extract-text-webpack-plugin" are not included in stats hash and aren't properly displayed on change.
1 parent efc576c commit a87b61f

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

lib/Compilation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,9 @@ class Compilation extends Tapable {
961961
this.mainTemplate.updateHash(hash);
962962
this.chunkTemplate.updateHash(hash);
963963
this.moduleTemplate.updateHash(hash);
964+
this.children.forEach(function(child) {
965+
hash.update(child.hash);
966+
});
964967
let chunk;
965968
const chunks = this.chunks.slice();
966969
chunks.sort((a, b) => {

test/WatchTestCases.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ describe("WatchTestCases", function() {
103103
} else {
104104
applyConfig(options)
105105
}
106+
107+
var state = {};
106108
var runIdx = 0;
107109
var run = runs[runIdx];
108110
var lastHash = "";
@@ -148,11 +150,11 @@ describe("WatchTestCases", function() {
148150
var p = path.join(currentDirectory, module);
149151
content = fs.readFileSync(p, "utf-8");
150152
}
151-
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON) {" + content + "\n})", p);
153+
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})", p);
152154
var module = {
153155
exports: {}
154156
};
155-
fn.call(module.exports, _require.bind(null, path.dirname(p)), module, module.exports, path.dirname(p), p, _it, run.name, jsonStats);
157+
fn.call(module.exports, _require.bind(null, path.dirname(p)), module, module.exports, path.dirname(p), p, _it, run.name, jsonStats, state);
156158
return module.exports;
157159
} else if(testConfig.modules && module in testConfig.modules) {
158160
return testConfig.modules[module];

test/statsCases/separate-css-bundle/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Hash: 9ff2cfa8882f273c8c6d9ff2cfa8882f273c8c6d
1+
Hash: 961cb0ccbdd4410998cff853996e18b417486bde
22
Child
3-
Hash: 9ff2cfa8882f273c8c6d
3+
Hash: 961cb0ccbdd4410998cf
44
Time: Xms
55
Asset Size Chunks Chunk Names
66
f49aa1e6c5ada5da859b.js 2.65 kB 0 [emitted] main
@@ -13,7 +13,7 @@ Child
1313
[0] (webpack)/~/css-loader/lib/css-base.js 1.46 kB {0} [built]
1414
[1] (webpack)/~/css-loader!(webpack)/test/statsCases/separate-css-bundle/a/file.css 192 bytes {0} [built]
1515
Child
16-
Hash: 9ff2cfa8882f273c8c6d
16+
Hash: f853996e18b417486bde
1717
Time: Xms
1818
Asset Size Chunks Chunk Names
1919
f49aa1e6c5ada5da859b.js 2.65 kB 0 [emitted] main
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "./style.css"
2+
3+
it("should handle css changes", function() {
4+
switch(WATCH_STEP) {
5+
case "0":
6+
STATE.first = STATS_JSON.hash;
7+
break;
8+
case "1":
9+
STATS_JSON.hash.should.not.be.eql(STATE.first, "stats hash should have changed, but didn't");
10+
break;
11+
}
12+
});

test/watchCases/plugins/extract-text-plugin/0/style.css

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.x {
2+
background: red;
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
2+
3+
module.exports = {
4+
module: {
5+
loaders: [
6+
{
7+
test: /\.css$/,
8+
loader: ExtractTextPlugin.extract({
9+
loader: "css-loader"
10+
})
11+
}
12+
]
13+
},
14+
plugins: [
15+
new ExtractTextPlugin({
16+
filename: "[name].css"
17+
})
18+
]
19+
};

0 commit comments

Comments
 (0)