fix(mf): resolve version from parent package for secondary entry points#13636
fix(mf): resolve version from parent package for secondary entry points#13636davidfestal wants to merge 4 commits intoweb-infra-dev:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b9bd904f2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR fixes Module Federation sharing in ProvideSharedPlugin for packages that use “secondary entry points” (subpath exports) whose nearest package.json lacks a version, by falling back to the parent package’s version (e.g. @mui/material/styles → @mui/material).
Changes:
- Add parent-package version lookup for secondary entry points when
versionis missing in the nearestpackage.json. - Update
ProvideSharedPluginto use the parent version instead of warning/failing when the relationship is validated. - Add a new sharing config case
share-plugin-secondary-entry-pointto cover a scoped package with a versionless secondary entry point.
Reviewed changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_plugin_mf/src/sharing/provide_shared_plugin.rs | Adds parent package.json traversal + version fallback when a secondary entry point has no version. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/rspack.config.js | New config case enabling sharing for @scope/pkg and @scope/pkg/styles. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/index.js | New runtime test importing the root and secondary entry point. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/node_modules/@scope/pkg/package.json | Fixture parent package with name + version. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/node_modules/@scope/pkg/index.js | Fixture root entry implementation. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/node_modules/@scope/pkg/styles/package.json | Fixture secondary entry point without version. |
| tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/node_modules/@scope/pkg/styles/index.js | Fixture secondary entry implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/index.js
Show resolved
Hide resolved
2dc9c6c to
f08c013
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/configCases/sharing/share-plugin-secondary-entry-point/rspack.config.js
Outdated
Show resolved
Hide resolved
d268b1a to
3ec7587
Compare
Merging this PR will degrade performance by 1.21%
Performance Changes
Comparing Footnotes
|
When a secondary entry point (e.g. `@mui/material/styles`) has its own `package.json` without a `version` field, ProvideSharedPlugin now walks up the directory tree to find the parent package's version instead of emitting a warning. This matches the behavior expected for packages that use the secondary entry point pattern (MUI, Emotion, Apollo Client, etc). The fix validates the relationship by checking that the shared key exactly equals `<parent_name>/<relative_path>` and stops at the `node_modules` boundary. Fixes: webpack/webpack#15864 Ref: webpack/webpack#13457 Made-with: Cursor Signed-off-by: David Festal <dfestal@redhat.com>
3ec7587 to
9c14987
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
ProvideSharedPluginto resolve the version from a parent package when a secondary entry point'spackage.jsonhas noversionfield (e.g.@mui/material/styles,@emotion/react/jsx-runtime)find_parent_package_versionmethod that walks up the directory tree from the description file, bounded bynode_modules, and validates the relationship by checking the shared key matches<parent_name>/<relative_path>share-plugin-secondary-entry-pointcovering scoped packages with secondary entry pointsFixes #13635
Context
When sharing secondary entry points like
@mui/material/styles, the nearestpackage.jsonis atnode_modules/@mui/material/styles/package.jsonwhich has noversion. The version lives in the parentnode_modules/@mui/material/package.json. Before this fix,ProvideSharedPluginemitted a warning and failed to provide the shared module with a version.This complements #8388 (which addressed
ConsumeSharedPluginfor monorepo hoisting) by fixing the same class of problem inProvideSharedPlugin.Upstream references:
Test plan
configCases/sharing/share-plugin-secondary-entry-pointtest with a scoped package (@scope/pkg) that has a secondary entry point (styles/) whosepackage.jsonhas no versionversionin their ownpackage.json)Made with Cursor