feat(mf): shareScope support array type#13107
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Module Federation/share configuration to accept shareScope as either a string or an array of strings (normalized to a single scope internally), and adds a new rspack-test config case to validate the behavior.
Changes:
- Add
ShareScope = string | string[]and propagate it through MF/sharing plugin option types. - Normalize array-form
shareScopevalues in JS/TS and in the Rust binding layer. - Add a new
remote-array-share-scopeconfigCase with host/remote setup to exercise array-formshareScope.
Reviewed changes
Copilot reviewed 15 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/test.config.js | Test harness config for selecting the output bundle. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/runtime-plugin.js | Runtime plugin used by the test to proxy remote entry loading locally. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/rspack.config.js | MF configuration for host + provider, including array-form shareScope. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib/package.json | Fixture package for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib/index.js | Fixture implementation for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib2/package.json | Fixture package for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib2/index.js | Fixture implementation for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib3/package.json | Fixture package for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib3/index.js | Fixture implementation for shared module in the test case. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js | Test assertions validating sharing behavior under the new config shape. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/Expose.js | Remote-exposed module used by the test to validate shared instances. |
| tests/rspack-test/configCases/container-1-5/remote-array-share-scope/App.js | Host-side module that mutates shared module state to validate sharing. |
| packages/rspack/src/sharing/SharePlugin.ts | Introduces ShareScope union type and a helper to normalize it. |
| packages/rspack/src/sharing/ProvideSharedPlugin.ts | Updates provide-side option types to accept ShareScope. |
| packages/rspack/src/sharing/ConsumeSharedPlugin.ts | Updates consume-side option types to accept `string |
| packages/rspack/src/sharing/CollectSharedEntryPlugin.ts | Updates option types to accept ShareScope. |
| packages/rspack/src/container/ModuleFederationPluginV1.ts | Updates MF v1 option typing to accept ShareScope. |
| packages/rspack/src/container/ModuleFederationPlugin.ts | Normalizes array-form shareScope when building runtime remoteInfos. |
| packages/rspack/src/container/ContainerReferencePlugin.ts | Updates reference plugin option typing to accept ShareScope. |
| packages/rspack/src/container/ContainerPlugin.ts | Updates container plugin option typing to accept ShareScope. |
| crates/rspack_binding_api/src/raw_options/raw_builtins/raw_mf.rs | Accepts share_scope as Either<String, Vec<String>> and normalizes to a single string. |
| crates/node_binding/napi-binding.d.ts | Updates TS binding surface to use RawShareScope for relevant fields. |
Comments suppressed due to low confidence (4)
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js:4
- The test name references tree-shaking/runtime-infer, but this case is about
shareScopeaccepting an array. Updating theit(...)description will make failures easier to diagnose and keep the suite searchable.
it('should load tree shaking shared via set "runtime-infer" mode', async () => {
const App = await import('./App.js');
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js:11
- This comment says
UiLib3should not be shared, but the expectations below assert0.1.5(which would only happen if the remote sees the host-mutated version). Please update or remove the comment to match the actual intended behavior.
// TheUiLib3 should not shared
expect(Expose.default()).toBe(`UiLib1: This is @scope-sc/ui-lib 0.1.3
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/rspack.config.js:10
outputis declared twice; the lateroutputobject overwrites the earlier one, soignoreBrowserWarnings: trueis currently a no-op. Merge these into a singleoutputblock so all settings apply.
entry: './index.js',
output: {
ignoreBrowserWarnings: true
},
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/runtime-plugin.js:13
entry.replace(...)will throw ifremoteInfo.entryis undefined (e.g. non-scriptexternals). Consider guarding onentrybeing a string and matching the expected prefix before doing the replacement/require, similar to other test runtime-plugins in this repo.
loadEntry: ({ remoteInfo }) => {
const { entry, entryGlobalName } = remoteInfo;
const relativePath = entry.replace('http://localhost:3001/', './');
globalThis[entryGlobalName] =
__non_webpack_require__(relativePath)[entryGlobalName];
return globalThis[entryGlobalName];
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 14.00KB from 48.99MB to 49.00MB (⬆️0.03%) |
Merging this PR will not alter performance
Comparing Footnotes
|
Deploying rspack with
|
| Latest commit: |
df2829a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8b8379ef.rspack-v2.pages.dev |
| Branch Preview URL: | https://feat-mf-share-array-scope.rspack-v2.pages.dev |
…enum introduce ShareScope enum to handle both single and multiple scope cases update all related structs and functions to use the new ShareScope type add helper methods for key generation and scope access
df2829a to
5ea29e6
Compare
Summary
Support array shareScope to satisfy multiple shareScope demands, like rsc or other advanced features.
Related doc: https://module-federation.io/guide/advanced/multiple-shared-scope.html
Related links
Checklist