Skip to content

Commit

Permalink
Merge pull request #6300 from nename0/fix-6243
Browse files Browse the repository at this point in the history
Fix #6243: TemplatedPathPlugin: Don't include initial chunks in chunkhash computation
  • Loading branch information
sokra committed Jan 22, 2018
2 parents 80ed1c4 + 1895b76 commit 33f518b
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/TemplatedPathPlugin.js
Expand Up @@ -105,9 +105,9 @@ class TemplatedPathPlugin {
const outputOptions = this.outputOptions;
const chunkFilename = outputOptions.chunkFilename || outputOptions.filename;
if(REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).hash));
hash.update(JSON.stringify(chunk.getChunkMaps(false, true).hash));
if(REGEXP_NAME_FOR_TEST.test(chunkFilename))
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).name));
hash.update(JSON.stringify(chunk.getChunkMaps(false, true).name));
});
});
}
Expand Down
14 changes: 11 additions & 3 deletions test/WatchTestCases.test.js
Expand Up @@ -155,6 +155,10 @@ describe("WatchTestCases", () => {
return test;
}

const globalContext = {
console: console
};

function _require(currentDirectory, module) {
if(Array.isArray(module) || /^\.\.?\//.test(module)) {
let fn;
Expand All @@ -170,11 +174,15 @@ describe("WatchTestCases", () => {
p = path.join(currentDirectory, module);
content = fs.readFileSync(p, "utf-8");
}
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})", p);
if(options.target === "web" || options.target === "webworker") {
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, window) {" + content + "\n})", globalContext, p);
} else {
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE) {" + content + "\n})", p);
}
const m = {
exports: {}
};
fn.call(m.exports, _require.bind(null, path.dirname(p)), m, m.exports, path.dirname(p), p, _it, run.name, jsonStats, state);
fn.call(m.exports, _require.bind(null, path.dirname(p)), m, m.exports, path.dirname(p), p, _it, run.name, jsonStats, state, globalContext);
return module.exports;
} else if(testConfig.modules && module in testConfig.modules) {
return testConfig.modules[module];
Expand All @@ -188,7 +196,7 @@ describe("WatchTestCases", () => {
} catch(e) {}

if(testConfig.noTests) return process.nextTick(done);
_require(outputDirectory, "./bundle.js");
_require(outputDirectory, testConfig.bundlePath || "./bundle.js");

if(exportedTests < 1) return done(new Error("No tests exported by test case"));
runIdx++;
Expand Down
1 change: 1 addition & 0 deletions test/watchCases/runtime/dynamic-import/0/dynamic.js
@@ -0,0 +1 @@
module.exports = "Normal";
28 changes: 28 additions & 0 deletions test/watchCases/runtime/dynamic-import/0/index.js
@@ -0,0 +1,28 @@
it("should change chunkhash of main chunk", function () {
const mainChunk = STATS_JSON.chunks.find((chunk) => chunk.names.indexOf("main") !== -1);
(!mainChunk).should.be.false("Main chunk not found");
switch (WATCH_STEP) {
case "0":
STATE.hash = mainChunk.hash;
break;
case "1":
mainChunk.hash.should.be.not.eql(STATE.hash);
break;
}
});

it("should load additional chunk", function (done) {
const step = WATCH_STEP;
import(/* webpackChunkName: "dynamic" */ './dynamic')
.then((dynamic) => {
switch (step) {
case "0":
dynamic.should.be.eql("Normal");
break;
case "1":
dynamic.should.be.eql("Changed");
break;
}
done();
});
});
1 change: 1 addition & 0 deletions test/watchCases/runtime/dynamic-import/1/dynamic.js
@@ -0,0 +1 @@
module.exports = "Changed";
5 changes: 5 additions & 0 deletions test/watchCases/runtime/dynamic-import/webpack.config.js
@@ -0,0 +1,5 @@
module.exports = {
output: {
chunkFilename: "[name].[chunkhash].js"
}
};
@@ -0,0 +1 @@
module.exports = "Normal";
44 changes: 44 additions & 0 deletions test/watchCases/runtime/static-import/0/index.js
@@ -0,0 +1,44 @@
require("should");

import * as both from './dynamic-and-static'
import * as staticModule from './static'

it("should not change chunkhash of manifest chunk", function () {
const manifestChunk = STATS_JSON.chunks.find((chunk) => chunk.names.indexOf("manifest") !== -1);
(!manifestChunk).should.be.false("Main chunk not found");
switch (WATCH_STEP) {
case "0":
STATE.hash = manifestChunk.hash;
staticModule.should.be.eql("Normal");
both.should.be.eql("Normal");
break;
case "1":
manifestChunk.hash.should.be.eql(STATE.hash);
staticModule.should.be.eql("Changed");
both.should.be.eql("Normal");
break;
case "2":
manifestChunk.hash.should.be.eql(STATE.hash);
staticModule.should.be.eql("Changed");
both.should.be.eql("Changed");
break;
}
});

it("should load additional chunk", function (done) {
const step = WATCH_STEP;
import(/* webpackChunkName: "dynamic-and-static" */ './dynamic-and-static')
.then((dynamic) => {
switch (step) {
case "0":
case "1":
dynamic.should.be.eql("Normal");
break;
case "2":
dynamic.should.be.eql("Changed");
break;
}
done();
})
.catch(done);;
});
1 change: 1 addition & 0 deletions test/watchCases/runtime/static-import/0/static.js
@@ -0,0 +1 @@
module.exports = "Normal";
1 change: 1 addition & 0 deletions test/watchCases/runtime/static-import/1/static.js
@@ -0,0 +1 @@
module.exports = "Changed";
@@ -0,0 +1 @@
module.exports = "Changed";
6 changes: 6 additions & 0 deletions test/watchCases/runtime/static-import/test.config.js
@@ -0,0 +1,6 @@
module.exports = {
bundlePath: [
"./manifest.bundle.js",
"./main.bundle.js"
]
}
14 changes: 14 additions & 0 deletions test/watchCases/runtime/static-import/webpack.config.js
@@ -0,0 +1,14 @@
var CommonsChunkPlugin = require("../../../../lib/optimize/CommonsChunkPlugin");
module.exports = {
output: {
filename: "[name].bundle.js",
chunkFilename: "[name].[chunkhash].js"
},
target: "web",
plugins: [
new CommonsChunkPlugin({
name: ["manifest"],
minChunks: Infinity
})
]
};

0 comments on commit 33f518b

Please sign in to comment.