Skip to content

feat(enhanced): implement layer-aware module sharing with comprehensive test coverage (PR9) #3915

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ScriptedAlchemy
Copy link
Member

@ScriptedAlchemy ScriptedAlchemy commented Jul 15, 2025

Summary

This PR implements enhanced layer support for module sharing in Module Federation, enabling layer-aware module resolution with proper fallback mechanisms. It also includes comprehensive test coverage for both ConsumeSharedPlugin and ProvideSharedPlugin.

Key Features

🎯 Layer-Aware Module Sharing

  • Added issuerLayer parameter support throughout ConsumeSharedPlugin and related modules
  • Implemented issuerLayer fallback pattern that tries layer-specific resolution first, then falls back to non-layered resolution
  • Added createLookupKeyForSharing utility to generate layer-aware lookup keys (e.g., (client)react, (server)express)
  • Support for layer-specific module sharing configuration with proper precedence rules

🧪 Comprehensive Test Coverage

  • ConsumeSharedPlugin: Added 70+ tests covering all critical business logic including:

    • Multi-stage module resolution with layer support
    • Import resolution logic with error handling
    • RequiredVersion resolution and package extraction
    • Include/exclude version filtering with fallback support
    • Singleton warning generation for version filters
  • ProvideSharedPlugin: Added 73 tests covering:

    • shouldProvideSharedModule method with semver validation
    • provideSharedModule with version resolution and request filtering
    • Module matching and multi-stage resolution logic
    • Warning generation rules (only for version filters with singleton)

🔧 Additional Improvements

  • Fixed infinite recursion in node module imports with circular dependencies
  • Added request pattern filtering tests with extractPathAfterNodeModules utility
  • Fixed rsbuild-plugin build dependencies configuration
  • Improved test infrastructure stability and CI reliability

Implementation Details

The layer support follows a consistent fallback pattern across all resolution stages:

const match = 
  unresolvedConsumes.get(createLookupKeyForSharing(request, contextInfo.issuerLayer)) ||
  unresolvedConsumes.get(createLookupKeyForSharing(request, undefined));

This enables scenarios like:

  • Client-specific React version: (client)react
  • Server-specific Express version: (server)express
  • Automatic fallback to shared version when no layer-specific config exists

Testing

  • Unit tests validate issuerLayer fallback behavior and utility functions
  • Integration tests cover layer-specific module sharing scenarios
  • Performance tests ensure efficient handling of large-scale configurations
  • All tests pass with improved assertions for CI stability

Breaking Changes

None - all changes are backward compatible with existing configurations.

Related Issues

Completes PR9 implementation as defined in the incremental PR plan for enhanced layer support.

Copy link

changeset-bot bot commented Jul 15, 2025

🦋 Changeset detected

Latest commit: 80a7180

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@module-federation/enhanced Patch
@module-federation/node Patch
@module-federation/sdk Patch
@module-federation/modern-js Patch
@module-federation/nextjs-mf Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rspress-plugin Patch
@module-federation/storybook-addon Patch
@module-federation/modernjsapp Patch
@module-federation/devtools Patch
@module-federation/cli Patch
@module-federation/data-prefetch Patch
@module-federation/dts-plugin Patch
@module-federation/esbuild Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/retry-plugin Patch
@module-federation/rspack Patch
@module-federation/runtime-core Patch
@module-federation/runtime Patch
@module-federation/utilities Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
remote5 Patch
website-new Patch
@module-federation/runtime-tools Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-shared Patch
@module-federation/error-codes Patch
create-module-federation Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ScriptedAlchemy added a commit that referenced this pull request Aug 3, 2025
- Remove accidentally added vite git submodule from repository
- Add changeset for PR #3915 (Enhanced Layer Support)
  - Documents issuerLayer fallback logic implementation
  - Minor version bump for new feature
- Add changeset for PR #3969 (Comprehensive Test Coverage)
  - Documents 73 tests for ProvideSharedPlugin
  - Documents 70+ tests for ConsumeSharedPlugin
  - Patch version bumps for test additions

These changesets ensure proper version bumping and changelog
generation for the incremental PR features and test coverage.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ScriptedAlchemy ScriptedAlchemy changed the title PR9: Enhanced Layer Support feat(enhanced): implement layer-aware module sharing with comprehensive test coverage Aug 4, 2025
@ScriptedAlchemy ScriptedAlchemy changed the title feat(enhanced): implement layer-aware module sharing with comprehensive test coverage feat(enhanced): implement layer-aware module sharing with comprehensive test coverage (PR9) Aug 6, 2025
Copy link
Member Author

ScriptedAlchemy commented Aug 8, 2025

Base automatically changed from pr8-unified-api to main August 11, 2025 22:28
Copy link

netlify bot commented Aug 11, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 80a7180
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/689ad984597f410008668ecb
😎 Deploy Preview https://deploy-preview-3915--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

ScriptedAlchemy and others added 5 commits August 11, 2025 16:00
- Add silent: true and verbose: false to Jest config to reduce console noise
- Remove incomplete consume-shared-with-alias test directory that was missing webpack.config.js
- This improves test readability while maintaining all functional test coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Remove all HTML, CSS, and JS coverage report files that were accidentally committed.
These files are auto-generated and should not be tracked in version control.
@@ -0,0 +1,378 @@
# Enhanced Module Federation - Unit Tests

This directory contains comprehensive unit tests for the Enhanced Module Federation package. Tests are organized by functional area and component, providing extensive coverage for core Module Federation features.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this

Apply suggested changes
Apply suggested changes
@@ -0,0 +1,14 @@
---
"@module-federation/enhanced": minor
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a patch and update it based on the actual changes in the pr (if any) otherwise delete

Apply suggested changes
- Add apply method tests for plugin registration logic and hook setup
- Achieve test coverage parity with ProvideSharedPlugin (70+ tests each)

This addresses the requirement for "immense test coverage for consume share plugin and provide share plugin to cover all its very complex logic" and ensures comprehensive testing of multi-stage module resolution, layer matching, version filtering, and error handling.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

ScriptedAlchemy and others added 2 commits August 11, 2025 22:31
- Update ModuleNotFoundError mock to return an instance with proper structure
- Add validation for error object structure in test assertions
- Ensures tests correctly verify error handling in resolveMatchedConfigs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove extra wrapper function that was breaking the mock
- Ensure mock returns constructor function directly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant