fix(module-federation): normalize workspace protocol versions in requiredVersion #33733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current Behavior
When using pnpm with workspace protocol (
workspace:*,workspace:^, etc.), module federation setsrequiredVersionto the raw protocol string (e.g.,workspace:*) instead of resolving it to the actual semver version from the library's package.json.This causes issues like:
requiredVersion: "workspace:*"which is not a valid semverExample of the broken output:
{ "version": "*", "singleton": true, "requiredVersion": "^*" }Expected Behavior
When a workspace protocol version is detected, it should be resolved to the actual version from the library's package.json:
{ "version": "2.0.0", "singleton": true, "requiredVersion": "2.0.0" }Changes Made
Added helper functions in
share.ts:isWorkspaceProtocolVersion()- Detects workspace protocol versions (workspace:*,workspace:^,*,file:)normalizeWorkspaceProtocolVersion()- Resolves protocol versions to actual semver by looking up the library's package.jsonApplied normalization in
shareWorkspaceLibraries():getDependencyVersionFromPackageJson, normalize it if it's a workspace protocolworkspaceLibrariesAsDepsloop by using the helper function (removed duplicated logic)Updated
getNpmPackageSharedConfig():Added comprehensive tests (13 new tests):
shareWorkspaceLibrariesgetNpmPackageSharedConfighandling workspace protocol versionsRelated Issue(s)
Fixes #31397
Merge Dependencies
This PR has no dependencies and can be merged independently.
Must be merged BEFORE: #33734