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

feat: show which singleton loaded version #14782

Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions lib/sharing/ConsumeSharedRuntimeModule.js
Expand Up @@ -103,17 +103,17 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
]
)};`,
`var getInvalidSingletonVersionMessage = ${runtimeTemplate.basicFunction(
"key, version, requiredVersion",
"scope, key, version, requiredVersion",
[
`return "Unsatisfied version " + version + " of shared singleton module " + key + " (required " + rangeToString(requiredVersion) + ")"`
`return "Unsatisfied version " + version + " from " + (version && scope[key][version].from) + " of shared singleton module " + key + " (required " + rangeToString(requiredVersion) + ")"`
]
)};`,
`var getSingletonVersion = ${runtimeTemplate.basicFunction(
"scope, scopeName, key, requiredVersion",
[
"var version = findSingletonVersionKey(scope, key);",
"if (!satisfy(requiredVersion, version)) " +
'typeof console !== "undefined" && console.warn && console.warn(getInvalidSingletonVersionMessage(key, version, requiredVersion));',
'typeof console !== "undefined" && console.warn && console.warn(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));',
"return get(scope[key][version]);"
]
)};`,
Expand All @@ -122,7 +122,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
[
"var version = findSingletonVersionKey(scope, key);",
"if (!satisfy(requiredVersion, version)) " +
"throw new Error(getInvalidSingletonVersionMessage(key, version, requiredVersion));",
"throw new Error(getInvalidSingletonVersionMessage(scope, key, version, requiredVersion));",
"return get(scope[key][version]);"
]
)};`,
Expand Down
5 changes: 3 additions & 2 deletions test/configCases/sharing/consume-module/index.js
Expand Up @@ -193,7 +193,8 @@ it("should handle version matching correctly in strict and singleton mode", asyn
},
singleton: {
"1.1.1": {
get: () => () => "shared singleton"
get: () => () => "shared singleton",
from: 'container-a'
}
}
};
Expand Down Expand Up @@ -230,7 +231,7 @@ it("should handle version matching correctly in strict and singleton mode", asyn
const result = await import("singleton");
expect(result.default).toBe("shared singleton");
expectWarning(
/Unsatisfied version 1\.1\.1 of shared singleton module singleton \(required =1\.1\.0\)/
/Unsatisfied version 1\.1\.1 from container-a of shared singleton module singleton \(required =1\.1\.0\)/
);
}
});