Skip to content

Commit

Permalink
Merge pull request #11861 from webpack/bugfix/11856
Browse files Browse the repository at this point in the history
fix incorrect concatenation when module runtime are merged
  • Loading branch information
sokra committed Oct 28, 2020
2 parents b792749 + 9874390 commit 103a052
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/optimize/ModuleConcatenationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ModuleConcatenationPlugin {
const filteredRuntime = filterRuntime(chunkRuntime, r =>
exportsInfo.isModuleUsed(r)
);
const runtime =
const activeRuntime =
filteredRuntime === true
? chunkRuntime
: filteredRuntime === false
Expand All @@ -235,7 +235,7 @@ class ModuleConcatenationPlugin {
// create a configuration with the root
const currentConfiguration = new ConcatConfiguration(
currentRoot,
runtime
activeRuntime
);

// cache failures to add modules
Expand All @@ -249,7 +249,7 @@ class ModuleConcatenationPlugin {
for (const imp of this._getImports(
compilation,
currentRoot,
runtime
activeRuntime
)) {
candidates.add(imp);
}
Expand All @@ -263,7 +263,8 @@ class ModuleConcatenationPlugin {
compilation,
currentConfiguration,
imp,
runtime,
chunkRuntime,
activeRuntime,
possibleInners,
impCandidates,
failureCache,
Expand Down Expand Up @@ -498,7 +499,8 @@ class ModuleConcatenationPlugin {
* @param {Compilation} compilation webpack compilation
* @param {ConcatConfiguration} config concat configuration (will be modified when added)
* @param {Module} module the module to be added
* @param {RuntimeSpec} runtime the runtime scope
* @param {RuntimeSpec} runtime the runtime scope of the generated code
* @param {RuntimeSpec} activeRuntime the runtime scope of the root module
* @param {Set<Module>} possibleModules modules that are candidates
* @param {Set<Module>} candidates list of potential candidates (will be added to)
* @param {Map<Module, Module | function(RequestShortener): string>} failureCache cache for problematic modules to be more performant
Expand All @@ -510,6 +512,7 @@ class ModuleConcatenationPlugin {
config,
module,
runtime,
activeRuntime,
possibleModules,
candidates,
failureCache,
Expand Down Expand Up @@ -732,6 +735,7 @@ class ModuleConcatenationPlugin {
config,
originModule,
runtime,
activeRuntime,
possibleModules,
candidates,
failureCache,
Expand Down
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856.2/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from "./shared-c";

it("should have to correct value", () => {
expect(value).toBe(42);
});
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856.2/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from "./b2";

it("should have to correct value", () => {
expect(value).toBe(42);
});
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856.2/b2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./shared-e";
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856.2/shared-c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./shared-d";
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856.2/shared-d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./shared-e";
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856.2/shared-e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 42;
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856.2/test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle: function (i, options) {
return ["shared.js", "a.js", "b.js"];
}
};
26 changes: 26 additions & 0 deletions test/configCases/graph/issue-11856.2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
entry: {
a: "./a",
b: "./b"
},
target: "web",
output: {
filename: "[name].js",
library: { type: "commonjs-module" }
},
optimization: {
usedExports: true,
concatenateModules: true,
splitChunks: {
cacheGroups: {
forceMerge: {
test: /shared/,
enforce: true,
name: "shared",
chunks: "all"
}
}
}
}
};
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from "./shared-c";

it("should have to correct value", () => {
expect(value).toBe(42);
});
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from "./shared-d";

it("should have to correct value", () => {
expect(value).toBe(42);
});
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856/shared-c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./shared-d";
1 change: 1 addition & 0 deletions test/configCases/graph/issue-11856/shared-d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 42;
5 changes: 5 additions & 0 deletions test/configCases/graph/issue-11856/test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
findBundle: function (i, options) {
return ["shared.js", "a.js", "b.js"];
}
};
26 changes: 26 additions & 0 deletions test/configCases/graph/issue-11856/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
entry: {
a: "./a",
b: "./b"
},
target: "web",
output: {
filename: "[name].js",
library: { type: "commonjs-module" }
},
optimization: {
usedExports: true,
concatenateModules: true,
splitChunks: {
cacheGroups: {
forceMerge: {
test: /shared/,
enforce: true,
name: "shared",
chunks: "all"
}
}
}
}
};

0 comments on commit 103a052

Please sign in to comment.