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

Proposed fix to module federation to stop ignoring the singleton flag when requiredVersion is false #14884

Merged
merged 2 commits into from Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions lib/sharing/ConsumeSharedModule.js
Expand Up @@ -210,6 +210,10 @@ class ConsumeSharedModule extends Module {
}
args.push(stringifyHoley(requiredVersion));
fn += "VersionCheck";
} else {
if (singleton) {
fn += "Singleton";
}
}
if (fallbackCode) {
fn += "Fallback";
Expand Down
21 changes: 21 additions & 0 deletions lib/sharing/ConsumeSharedRuntimeModule.js
Expand Up @@ -108,6 +108,13 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
`return "Unsatisfied version " + version + " from " + (version && scope[key][version].from) + " of shared singleton module " + key + " (required " + rangeToString(requiredVersion) + ")"`
]
)};`,
`var getSingleton = ${runtimeTemplate.basicFunction(
"scope, scopeName, key, requiredVersion",
[
"var version = findSingletonVersionKey(scope, key);",
"return get(scope[key][version]);"
]
)};`,
`var getSingletonVersion = ${runtimeTemplate.basicFunction(
"scope, scopeName, key, requiredVersion",
[
Expand Down Expand Up @@ -202,6 +209,13 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
"return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));"
]
)});`,
`var loadSingleton = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(
"scopeName, scope, key",
[
"ensureExistence(scopeName, key);",
"return getSingleton(scope, scopeName, key);"
]
)});`,
`var loadSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(
"scopeName, scope, key, version",
[
Expand Down Expand Up @@ -230,6 +244,13 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
"return get(findValidVersion(scope, key, version) || warnInvalidVersion(scope, scopeName, key, version) || findVersion(scope, key));"
]
)});`,
`var loadSingletonFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(
"scopeName, scope, key, fallback",
[
`if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,
"return getSingletonVersion(scope, scopeName, key);"
]
)});`,
`var loadSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(
"scopeName, scope, key, version, fallback",
[
Expand Down