Skip to content

Commit

Permalink
record chunk ids for unnamed chunks in the entrypoint chunk group
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 24, 2020
1 parent b6f6f5d commit 6ee72bc
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
50 changes: 28 additions & 22 deletions lib/RecordIdsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,34 @@ class RecordIdsPlugin {
const sources = [];
for (const chunkGroup of chunk.groupsIterable) {
const index = chunkGroup.chunks.indexOf(chunk);
for (const origin of chunkGroup.origins) {
if (origin.module) {
if (origin.request) {
sources.push(
`${index} ${getModuleIdentifier(origin.module)} ${
origin.request
}`
);
} else if (typeof origin.loc === "string") {
sources.push(
`${index} ${getModuleIdentifier(origin.module)} ${origin.loc}`
);
} else if (
origin.loc &&
typeof origin.loc === "object" &&
"start" in origin.loc
) {
sources.push(
`${index} ${getModuleIdentifier(
origin.module
)} ${JSON.stringify(origin.loc.start)}`
);
if (chunkGroup.name) {
sources.push(`${index} ${chunkGroup.name}`);
} else {
for (const origin of chunkGroup.origins) {
if (origin.module) {
if (origin.request) {
sources.push(
`${index} ${getModuleIdentifier(origin.module)} ${
origin.request
}`
);
} else if (typeof origin.loc === "string") {
sources.push(
`${index} ${getModuleIdentifier(origin.module)} ${
origin.loc
}`
);
} else if (
origin.loc &&
typeof origin.loc === "object" &&
"start" in origin.loc
) {
sources.push(
`${index} ${getModuleIdentifier(
origin.module
)} ${JSON.stringify(origin.loc.start)}`
);
}
}
}
}
Expand Down
30 changes: 26 additions & 4 deletions test/HotTestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const describeCases = config => {
options.output.chunkFilename = "[name].chunk.[fullhash].js";
if (options.output.pathinfo === undefined)
options.output.pathinfo = true;
if (options.output.library === undefined)
options.output.library = { type: "commonjs2" };
if (!options.optimization) options.optimization = {};
if (!options.optimization.moduleIds)
options.optimization.moduleIds = "named";
Expand Down Expand Up @@ -229,11 +231,31 @@ const describeCases = config => {
}
} else return require(module);
}
_require("./bundle.js");
if (getNumberOfTests() < 1)
return done(new Error("No tests exported by test case"));
let promise = Promise.resolve();
const info = stats.toJson({ all: false, entrypoints: true });
if (config.target === "web") {
for (const file of info.entrypoints.main.assets)
_require(`./${file}`);
} else {
const assets = info.entrypoints.main.assets;
const result = _require(`./${assets[assets.length - 1]}`);
if (typeof result === "object" && "then" in result)
promise = promise.then(() => result);
}
promise.then(
() => {
if (getNumberOfTests() < 1)
return done(
new Error("No tests exported by test case")
);

done();
done();
},
err => {
console.log(err);
done(err);
}
);
});
},
20000
Expand Down
8 changes: 6 additions & 2 deletions test/__snapshots__/ConfigTestCases.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative
\\"byName\\": {
\\"main\\": 179
},
\\"bySource\\": {},
\\"bySource\\": {
\\"0 main\\": 179
},
\\"usedIds\\": [
179
]
Expand Down Expand Up @@ -47,7 +49,9 @@ exports[`ConfigTestCases records issue-7339 exported tests should write relative
\\"byName\\": {
\\"main\\": 179
},
\\"bySource\\": {},
\\"bySource\\": {
\\"0 main\\": 179
},
\\"usedIds\\": [
179
]
Expand Down
11 changes: 11 additions & 0 deletions test/hotCases/chunks/split-chunks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import vendor from "vendor";
module.hot.accept("vendor");
it("should hot update a splitted initial chunk", function (done) {
expect(vendor).toBe("1");
NEXT(
require("../../update")(done, true, () => {
expect(vendor).toBe("2");
done();
})
);
});
3 changes: 3 additions & 0 deletions test/hotCases/chunks/split-chunks/node_modules/vendor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/hotCases/chunks/split-chunks/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
output: {
filename: "[name].js"
},
optimization: {
chunkIds: "total-size",
splitChunks: {
chunks: "all",
minSize: 0
}
}
};

0 comments on commit 6ee72bc

Please sign in to comment.