Skip to content

Commit

Permalink
Merge pull request #12396 from webpack/bugfix/transitive-roots
Browse files Browse the repository at this point in the history
compute chunk roots correctly when using transitive connections
  • Loading branch information
sokra committed Jan 11, 2021
2 parents a064b0f + 916bf69 commit a25173a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
18 changes: 14 additions & 4 deletions lib/ChunkGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"use strict";

const util = require("util");
const ModuleGraphConnection = require("./ModuleGraphConnection");
const SortableSet = require("./util/SortableSet");
const {
compareModulesById,
Expand Down Expand Up @@ -272,10 +273,19 @@ class ChunkGraph {
findGraphRoots(set, module => {
/** @type {Set<Module>} */
const set = new Set();
for (const connection of moduleGraph.getOutgoingConnections(module)) {
if (!connection.module) continue;
set.add(connection.module);
}
const addDependencies = module => {
for (const connection of moduleGraph.getOutgoingConnections(module)) {
if (!connection.module) continue;
const activeState = connection.getActiveState(undefined);
if (activeState === false) continue;
if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) {
addDependencies(connection.module);
continue;
}
set.add(connection.module);
}
};
addDependencies(module);
return set;
})
).sort(compareModulesByIdentifier);
Expand Down
11 changes: 8 additions & 3 deletions lib/ids/IdHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ const shortenLongString = (string, delimiter) => {
* @returns {string} short module name
*/
const getShortModuleName = (module, context, associatedObjectForCache) => {
return avoidNumber(
module.libIdent({ context, associatedObjectForCache }) || ""
);
const libIdent = module.libIdent({ context, associatedObjectForCache });
if (libIdent) return avoidNumber(libIdent);
const nameForCondition = module.nameForCondition();
if (nameForCondition)
return avoidNumber(
makePathsRelative(context, nameForCondition, associatedObjectForCache)
);
return "";
};
exports.getShortModuleName = getShortModuleName;

Expand Down
2 changes: 2 additions & 0 deletions test/configCases/plugins/mini-css-extract-plugin/chunk.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import "./chunk.css";

export default 42;
28 changes: 26 additions & 2 deletions test/configCases/plugins/mini-css-extract-plugin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
entry: {
a: "./a",
b: "./b",
c: "./c.css"
c: "./c.css",
x: "./x" // also imports chunk but with different exports
},
output: {
filename: "[name].js"
Expand All @@ -18,9 +19,32 @@ module.exports = {
}
]
},
optimization: {
chunkIds: "named"
},
target: "web",
node: {
__dirname: false
},
plugins: [new MCEP()]
plugins: [
new MCEP(),
compiler => {
compiler.hooks.done.tap("Test", stats => {
const chunkIds = stats
.toJson({ all: false, chunks: true, ids: true })
.chunks.map(c => c.id)
.sort();
expect(chunkIds).toEqual([
"a",
"b",
"c",
"chunk_js-_43b60",
"chunk_js-_43b61",
"chunk_js-_43b62",
"d_css",
"x"
]);
});
}
]
};
1 change: 1 addition & 0 deletions test/configCases/plugins/mini-css-extract-plugin/x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import(/* webpackExports: [] */ "./chunk");

0 comments on commit a25173a

Please sign in to comment.