Skip to content

feat(enhanced): add include/exclude filtering support for shared modules #3904

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 17 commits into
base: feat/enhanced-hoist-container-refs
Choose a base branch
from

Conversation

ScriptedAlchemy
Copy link
Member

Summary

Implements basic share filtering functionality for ConsumeSharedPlugin and ProvideSharedPlugin, allowing fine-grained control over which shared modules are consumed or provided based on version requirements and request patterns.

Part of incremental PR plan - Step 4: Basic Share Filtering

Features Added

  • Version Filtering: Include/exclude shared modules based on semver version requirements
  • Request Filtering: Include/exclude shared modules based on request patterns (string/RegExp)
  • Singleton Warnings: Automatic warnings when filtering singleton modules
  • Comprehensive Testing: Unit tests and config test cases for all filtering scenarios

Technical Implementation

  • Enhanced ConsumeSharedPlugin with version and request filtering logic
  • Enhanced ProvideSharedPlugin with version and request filtering logic
  • Added testRequestFilters utility for request pattern matching
  • Added addSingletonFilterWarning utility for singleton filter warnings
  • Updated JSON schemas and TypeScript declarations
  • Generated new schema validation files

Test Plan

  • Unit tests for filtering utilities (11 test cases)
  • Config test cases for consume filtering scenarios
  • Config test cases for provide filtering scenarios
  • All existing sharing tests continue to pass
  • Schema generation successful

🤖 Generated with Claude Code

- Add testRequestFilters and addSingletonFilterWarning utilities
- Update ConsumeSharedPlugin with version and request filtering
- Update ProvideSharedPlugin with version and request filtering
- Update schemas to include include/exclude filter properties
- Add comprehensive unit tests for filtering functionality
- Add config test cases for consume and provide filtering

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

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

changeset-bot bot commented Jul 12, 2025

🦋 Changeset detected

Latest commit: a1e7b2c

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 Major
@module-federation/modern-js Major
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Major
@module-federation/rspress-plugin Major
@module-federation/storybook-addon Major
@module-federation/modernjsapp Patch
remote5 Patch
website-new Patch
@module-federation/runtime Major
@module-federation/rspack Major
@module-federation/webpack-bundler-runtime Major
@module-federation/sdk Major
@module-federation/runtime-tools Major
@module-federation/managers Major
@module-federation/manifest Major
@module-federation/dts-plugin Major
@module-federation/third-party-dts-extractor Major
@module-federation/devtools Major
@module-federation/bridge-react Major
@module-federation/bridge-vue3 Major
@module-federation/bridge-shared Major
@module-federation/bridge-react-webpack-plugin Major
@module-federation/retry-plugin Major
@module-federation/data-prefetch Major
@module-federation/error-codes Major
@module-federation/inject-external-runtime-core-plugin Major
@module-federation/runtime-core Major
create-module-federation Major
@module-federation/cli Major
@module-federation/esbuild Patch
@module-federation/utilities 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

Copy link

netlify bot commented Jul 12, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 9bab6fb
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6875aa77862a5100081b5bad
😎 Deploy Preview https://deploy-preview-3904--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 8 commits July 12, 2025 16:50
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixes TypeScript error TS2742 where inferred type could not be named
without portable React types reference.

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed main entry path in project.json to correct location
- Added extends to tsconfig.json to inherit base configuration
- Added dependsOn configuration for proper build dependencies

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

Co-Authored-By: Claude <noreply@anthropic.com>
- add include/exclude properties to share plugin schema
- update share plugin to pass through include/exclude filters to underlying plugins
- generate updated typescript definitions and validation schemas
- support version and request filtering for both include and exclude
- part of pr4: basic share filtering - include/exclude by version
…ugin and ConsumeSharedPlugin

- Add include/exclude version filtering support to ProvideSharedPlugin
- Add include/exclude version filtering support to ConsumeSharedPlugin
- Implement proper filtering logic that prevents filtered modules from being shared
- Add type definitions for IncludeExcludeOptions interface
- Update provide-filters integration test with proper share scope initialization
- Fix unit test mock compilation to extend actual Compilation class
- All tests passing (7/7 provide-filters tests, 13/13 unit tests)

This implements PR4 (Basic Share Filtering - Include/Exclude by Version) requirements
by allowing filtering of shared modules based on semantic version ranges.

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

Co-Authored-By: Claude <noreply@anthropic.com>
…hare-filter branch

This directory was accidentally created during development but doesn't exist
in the original share-filter branch and was causing compilation errors.

The provide-filters test is working correctly and all filtering functionality
is properly implemented for PR4 (Basic Share Filtering).
@ScriptedAlchemy ScriptedAlchemy force-pushed the feat/basic-share-filtering branch from 60e2ad7 to 9bab6fb Compare July 15, 2025 01:10
@ScriptedAlchemy ScriptedAlchemy changed the base branch from main to feat/enhanced-hoist-container-refs July 15, 2025 21:43
ScriptedAlchemy and others added 8 commits July 15, 2025 18:57
- Accept utilities and webpack dependencies in app package.json files
- Use tsconfig.lib.json for rsbuild-plugin project
- Accept incoming pnpm-lock.yaml changes

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Add import caching to SDK importNodeModule to prevent circular calls
- Add import caching to node runtime plugin importNodeModule
- Add ESM module caching to prevent loadModule recursion
- Use direct dynamic import in vm.Script fallback to avoid cycles
- Add regression test for maximum call stack exceeded scenario

Fixes RangeError: Maximum call stack size exceeded when NextJS apps
use Module Federation with both SDK and node runtime plugin importing
each other's modules through importModuleDynamically callbacks.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Now that import caching prevents infinite recursion, we can use the
proper importNodeModule function instead of the workaround in
vm.Script importModuleDynamically fallback.

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

Co-Authored-By: Claude <noreply@anthropic.com>
…dule directly

Remove vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER fallback since caching prevents recursion.

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

Co-Authored-By: Claude <noreply@anthropic.com>
…OADER

Prefer using vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER when available,
fallback to cached importNodeModule to prevent recursion.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Export the cache and clear it in beforeEach to ensure test isolation.
The caching mechanism was causing tests to reuse cached promises from
previous tests instead of running the intended mocked behavior.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Use direct export declaration instead of separate export statement
to match the pattern used by all other exports in the file.

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

Co-Authored-By: Claude <noreply@anthropic.com>
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