core
core copied to clipboard
feat(enhanced): support shared module layers
Description
This pull request enhances the module sharing functionality in the enhanced package by implementing comprehensive layer support and improving schema validation. The changes focus on the compiler mechanics for module layers, with runtime updates planned for a future PR.
https://github.com/module-federation/core/issues/3153
Key Changes
-
Schema Validation Enhancements
- Added TypeScript-based validation for
ConsumeSharedPluginschema - Enhanced
ProvideSharedPluginschema with layer support - Added new properties for layer configuration:
layer: { description: 'Layer for the shared module.', type: 'string', minLength: 1 }, issuerLayer: { description: 'Layer in which the issuer should be.', type: 'string', minLength: 1 }
- Added TypeScript-based validation for
-
Module Resolution Improvements
- Enhanced request key creation with layer support
- Updated module resolution logic to handle layer-specific requests
- Improved handling of relative, absolute, and module requests
- Added support for composite keys in module resolution
-
Share Configuration Updates
- Added layer support to
normalizeConsumeShareOptions - Enhanced share scope management with layer awareness
- Updated module matching logic to consider layer context
- Improved type definitions for shared module configurations
- Added layer support to
Example Configuration
new SharePlugin({
shareScope: ['rsc','default'],
shared: {
react: {
singleton: true,
},
'explicit-layer-react': {
request: 'react/index2',
import: 'react/index2',
shareKey: 'react',
singleton: true,
issuerLayer: 'differing-layer',
layer: 'explicit-layer',
}
}
})
Technical Implementation Details
- [
utils.ts]: Enhanced module resolution with layer support - [
ConsumeSharedPlugin.check.ts]: Added comprehensive schema validation - [
ProviderSharedPlugin.ts]: Updated schema with layer properties - Added support for composite keys in module resolution
- Improved error handling for module resolution failures
Note
This PR focuses on the compiler mechanics for module layers. Runtime module aspects will be updated in a subsequent PR.
Types of changes
- [ ] Docs change / refactoring / dependency upgrade
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
Checklist
- [x] I have added tests to cover my changes
- [x] All new and existing tests passed
- [ ] I have updated the documentation