Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect concatenation when module runtime are merged #11861

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}
}
}
};