Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12132 from jakenorthey/feature/prioritize-eager-s…
…hared-modules
- Loading branch information
Showing
9 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
if (Math.random() < 0) { | ||
require("common"); | ||
require("uncommon"); | ||
} | ||
|
||
it("should overwrite non-eager shared module with eager shared module", async () => { | ||
__webpack_require__.S = { | ||
eagerOverrideNonEager: { | ||
common: { | ||
"1.0.0": { | ||
eager: undefined, // any falsy value | ||
from: "dashboard" | ||
} | ||
} | ||
} | ||
}; | ||
await __webpack_init_sharing__("eagerOverrideNonEager"); | ||
expect( | ||
Object.keys(__webpack_share_scopes__["eagerOverrideNonEager"]) | ||
).toContain("common"); | ||
const commonModule = __webpack_share_scopes__.eagerOverrideNonEager.common; | ||
expect(Object.keys(commonModule)).toContain("1.0.0"); | ||
expect(commonModule["1.0.0"].eager).toBe(true); | ||
}); | ||
it("should not overwrite already shared eager module with non-eager module", async () => { | ||
__webpack_require__.S = { | ||
nonEagerDontOverrideEager: { | ||
uncommon: { | ||
"2.0.0": { | ||
eager: 1, // any truthy value | ||
from: "aaa" | ||
} | ||
} | ||
} | ||
}; | ||
await __webpack_init_sharing__("nonEagerDontOverrideEager"); | ||
expect( | ||
Object.keys(__webpack_share_scopes__["nonEagerDontOverrideEager"]) | ||
).toContain("uncommon"); | ||
const uncommonModule = | ||
__webpack_share_scopes__.nonEagerDontOverrideEager.uncommon; | ||
expect(Object.keys(uncommonModule)).toContain("2.0.0"); | ||
expect(uncommonModule["2.0.0"].eager).toBe(1); | ||
}); | ||
it("should prefer shared non-eager module from newer container", async () => { | ||
__webpack_require__.S = { | ||
newerNonEager: { | ||
uncommon: { | ||
"2.0.0": { | ||
from: "appshell-1.0" | ||
} | ||
} | ||
} | ||
}; | ||
await __webpack_init_sharing__("newerNonEager"); | ||
const uncommonModule = __webpack_share_scopes__.newerNonEager.uncommon; | ||
expect(Object.keys(uncommonModule)).toContain("2.0.0"); | ||
expect(uncommonModule["2.0.0"].from).toBe("appshell-2.0"); | ||
}); | ||
it("should prefer shared eager module from newer container", async () => { | ||
__webpack_require__.S = { | ||
newerEager: { | ||
common: { | ||
"1.0.0": { | ||
from: "appshell-1.0", | ||
eager: true | ||
} | ||
} | ||
} | ||
}; | ||
await __webpack_init_sharing__("newerEager"); | ||
const commonModule = __webpack_share_scopes__.newerEager.common; | ||
expect(Object.keys(commonModule)).toContain("1.0.0"); | ||
expect(commonModule["1.0.0"].from).toBe("appshell-2.0"); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/configCases/sharing/provide-eager-module/node_modules/common/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/configCases/sharing/provide-eager-module/node_modules/common/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/configCases/sharing/provide-eager-module/node_modules/uncommon/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/configCases/sharing/provide-eager-module/node_modules/uncommon/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"common": "*", | ||
"uncommon": "*" | ||
}, | ||
"name": "appshell-2.0" | ||
} |
43 changes: 43 additions & 0 deletions
43
test/configCases/sharing/provide-eager-module/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// eslint-disable-next-line node/no-unpublished-require | ||
const { ProvideSharedPlugin } = require("../../../../").sharing; | ||
|
||
/** @type {import("../../../../types").Configuration} */ | ||
module.exports = { | ||
mode: "development", | ||
plugins: [ | ||
new ProvideSharedPlugin({ | ||
shareScope: "eagerOverrideNonEager", | ||
provides: { | ||
common: { | ||
shareKey: "common", | ||
eager: true | ||
} | ||
} | ||
}), | ||
new ProvideSharedPlugin({ | ||
shareScope: "nonEagerDontOverrideEager", | ||
provides: { | ||
uncommon: { | ||
shareKey: "uncommon" | ||
} | ||
} | ||
}), | ||
new ProvideSharedPlugin({ | ||
shareScope: "newerNonEager", | ||
provides: { | ||
uncommon: { | ||
shareKey: "uncommon" | ||
} | ||
} | ||
}), | ||
new ProvideSharedPlugin({ | ||
shareScope: "newerEager", | ||
provides: { | ||
common: { | ||
shareKey: "common", | ||
eager: true | ||
} | ||
} | ||
}) | ||
] | ||
}; |