Skip to content

Commit b0fa725

Browse files
fix: disable live bindings for CommonJS in runtime-tools and add enhanced test cases
1 parent 2ae8451 commit b0fa725

File tree

115 files changed

+895
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+895
-0
lines changed

.cursor/mcp.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mcpServers": {
3+
"nx-mcp": {
4+
"url": "http://localhost:9394/sse"
5+
}
6+
}
7+
}

.cursor/rules/01-project-overview.mdc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Module Federation Project Overview
7+
8+
This repository contains Module Federation 2.0, an advanced system for sharing code and resources across JavaScript applications. The project is primarily defined in [package.json](mdc:package.json) and uses a monorepo structure.
9+
10+
## Core Concepts
11+
12+
- **Module Federation Runtime**: Advanced runtime system for module sharing
13+
- **Plugin System**: Extensible architecture with runtime plugins
14+
- **Manifest System**: Enhanced module manifest handling
15+
- **Type Support**: Dynamic type hinting capabilities
16+
- **Developer Tools**: Including Chrome DevTools integration
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Development Workflow
7+
8+
## Build and Development
9+
10+
The project uses several key tools and processes:
11+
12+
- **Package Management**: Node.js package management with npm/yarn
13+
- **Build System**: Webpack-based build system in [webpack/](mdc:webpack)
14+
- **Testing**: Jest testing framework configured in [jest.config.ts](mdc:jest.config.ts)
15+
- **Code Quality**:
16+
- ESLint for linting: [.eslintrc.json](mdc:.eslintrc.json)
17+
- Prettier for formatting: [.prettierrc](mdc:.prettierrc)
18+
19+
## Directory Structure
20+
21+
- `apps/`: Application implementations
22+
- `packages/`: Shared packages and core modules
23+
- `docs/`: Documentation files
24+
- `scripts/`: Build and utility scripts
25+
- `tools/`: Development tools and utilities
26+
27+
## Version Control
28+
29+
- Uses Git for version control
30+
- Changesets for version management
31+
- Husky for Git hooks in [.husky/](mdc:.husky)
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Code Organization and Structure
7+
8+
## Monorepo Structure
9+
10+
This project follows a monorepo architecture with two main code directories:
11+
12+
1. **Apps Directory** ([apps/](mdc:apps))
13+
- Contains complete applications
14+
- Each app is a standalone implementation
15+
- Apps can consume shared packages
16+
17+
2. **Packages Directory** ([packages/](mdc:packages))
18+
- Contains shared libraries and modules
19+
- Core Module Federation functionality
20+
- Reusable utilities and components
21+
22+
## Configuration
23+
24+
- TypeScript configuration in [tsconfig.base.json](mdc:tsconfig.base.json)
25+
- Build configuration in [webpack/](mdc:webpack)
26+
- Package management in [package.json](mdc:package.json)
27+
28+
## Documentation
29+
30+
- Main documentation in [docs/](mdc:docs)
31+
- API documentation and guides
32+
- Contributing guidelines in [CONTRIBUTING.md](mdc:CONTRIBUTING.md)
33+
34+
## Build Output
35+
36+
- Build artifacts go to [dist/](mdc:dist)
37+
- Temporary files in [tmp/](mdc:tmp)
38+
- Build logs and output in [build_output_main/](mdc:build_output_main)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Webpack Bundler Runtime Package
7+
8+
## Overview
9+
10+
The `@module-federation/webpack-bundler-runtime` package provides the runtime implementation for Module Federation in webpack/rspack environments. Located in [packages/webpack-bundler-runtime](mdc:packages/webpack-bundler-runtime), it handles runtime extraction and integration.
11+
12+
## Package Structure
13+
14+
- **Source Code**: Main implementation in [src/](mdc:packages/webpack-bundler-runtime/src/)
15+
- **Tests**: Test files in [__tests__/](mdc:packages/webpack-bundler-runtime/__tests__/)
16+
- **Configuration**:
17+
- [rollup.config.cjs](mdc:packages/webpack-bundler-runtime/rollup.config.cjs): Build configuration
18+
- [tsconfig.json](mdc:packages/webpack-bundler-runtime/tsconfig.json): TypeScript settings
19+
- [.swcrc](mdc:packages/webpack-bundler-runtime/.swcrc): SWC compiler config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Webpack Bundler Runtime Implementation
7+
8+
## Source Code Structure
9+
10+
The implementation is organized into several key modules in [src/](mdc:packages/webpack-bundler-runtime/src/):
11+
12+
### Core Modules
13+
14+
- [index.ts](mdc:packages/webpack-bundler-runtime/src/index.ts): Main entry point and exports
15+
- [types.ts](mdc:packages/webpack-bundler-runtime/src/types.ts): TypeScript type definitions
16+
- [constant.ts](mdc:packages/webpack-bundler-runtime/src/constant.ts): Shared constants
17+
18+
### Container Management
19+
20+
- [container.ts](mdc:packages/webpack-bundler-runtime/src/container.ts): Core container implementation
21+
- [initContainerEntry.ts](mdc:packages/webpack-bundler-runtime/src/initContainerEntry.ts): Container entry initialization
22+
- [remotes.ts](mdc:packages/webpack-bundler-runtime/src/remotes.ts): Remote modules handling
23+
24+
### Sharing System
25+
26+
- [initializeSharing.ts](mdc:packages/webpack-bundler-runtime/src/initializeSharing.ts): Share scope initialization
27+
- [attachShareScopeMap.ts](mdc:packages/webpack-bundler-runtime/src/attachShareScopeMap.ts): Share scope mapping
28+
- [consumes.ts](mdc:packages/webpack-bundler-runtime/src/consumes.ts): Consumed modules management
29+
- [installInitialConsumes.ts](mdc:packages/webpack-bundler-runtime/src/installInitialConsumes.ts): Initial module consumption
30+
31+
## Implementation Guidelines
32+
33+
When working with this codebase:
34+
35+
1. **Type Safety**
36+
- All new code must be fully typed
37+
- Types are defined in [types.ts](mdc:packages/webpack-bundler-runtime/src/types.ts)
38+
39+
2. **Module Organization**
40+
- Keep related functionality grouped
41+
- Follow existing file naming conventions
42+
- Maintain clear separation of concerns
43+
44+
3. **Runtime Integration**
45+
- Code must be compatible with webpack/rspack
46+
- Follow Module Federation specifications
47+
- Consider both CJS and ESM environments

.cursor/rules/06-sdk-package.mdc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# Module Federation SDK Package
8+
9+
## Overview
10+
11+
The `@module-federation/sdk` package provides essential utilities and tools for implementing Module Federation. Located in [packages/sdk](mdc:packages/sdk), it offers core functionality for module handling, environment detection, and debugging.
12+
13+
## Key Features
14+
15+
- Module name parsing and encoding
16+
- Filename generation for exposed/shared modules
17+
- Environment detection utilities
18+
- Debugging and logging tools
19+
- Manifest snapshot generation
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Module Federation SDK Implementation
7+
8+
## Source Code Structure
9+
10+
The implementation is organized into several key modules in [src/](mdc:packages/sdk/src/):
11+
12+
### Core Modules
13+
14+
- [index.ts](mdc:packages/sdk/src/index.ts): Main entry point and exports
15+
- [constant.ts](mdc:packages/sdk/src/constant.ts): Shared constants
16+
- [utils.ts](mdc:packages/sdk/src/utils.ts): Common utility functions
17+
18+
### Environment Handling
19+
20+
- [env.ts](mdc:packages/sdk/src/env.ts): Environment detection utilities
21+
- [node.ts](mdc:packages/sdk/src/node.ts): Node.js specific functionality
22+
- [dom.ts](mdc:packages/sdk/src/dom.ts): Browser/DOM specific functionality
23+
24+
### Module Management
25+
26+
- [normalize-webpack-path.ts](mdc:packages/sdk/src/normalize-webpack-path.ts): Webpack path normalization
27+
- [normalizeOptions.ts](mdc:packages/sdk/src/normalizeOptions.ts): Options normalization
28+
- [generateSnapshotFromManifest.ts](mdc:packages/sdk/src/generateSnapshotFromManifest.ts): Manifest snapshot generation
29+
30+
### Debugging
31+
32+
- [logger.ts](mdc:packages/sdk/src/logger.ts): Logging and debugging utilities
33+
34+
## Implementation Guidelines
35+
36+
When working with this codebase:
37+
38+
1. **Code Organization**
39+
- Keep platform-specific code in appropriate files (node.ts/dom.ts)
40+
- Use types directory for type definitions
41+
- Follow modular design patterns
42+
43+
2. **API Design**
44+
- Maintain consistent function signatures
45+
- Document all public APIs
46+
- Follow TypeScript best practices
47+
48+
3. **Cross-Platform Support**
49+
- Handle both Node.js and browser environments
50+
- Use appropriate environment checks
51+
- Consider bundler compatibility
52+
53+
4. **Testing**
54+
- Write comprehensive tests
55+
- Cover both Node.js and browser scenarios
56+
- Test error cases and edge conditions
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Module Federation Runtime Core Package
7+
8+
## Overview
9+
10+
The `@module-federation/runtime-core` package provides the core runtime implementation for Module Federation. Located in [packages/runtime-core](mdc:packages/runtime-core), it handles dependency sharing, module loading, and runtime plugin system.
11+
12+
## Key Features
13+
14+
- Dependency sharing and optimization
15+
- Selective module loading
16+
- Extensible plugin system
17+
- Runtime module federation
18+
- Global state management
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Module Federation Runtime Core Implementation
7+
8+
## Source Code Structure
9+
10+
The implementation is organized into several key modules in [src/](mdc:packages/runtime-core/src/):
11+
12+
### Core Runtime
13+
14+
- [core.ts](mdc:packages/runtime-core/src/core.ts): Core runtime implementation
15+
- [global.ts](mdc:packages/runtime-core/src/global.ts): Global state management
16+
- [index.ts](mdc:packages/runtime-core/src/index.ts): Public API exports
17+
- [helpers.ts](mdc:packages/runtime-core/src/helpers.ts): Utility functions
18+
19+
### Module System
20+
21+
- [module/](mdc:packages/runtime-core/src/module/): Module management
22+
- [remote/](mdc:packages/runtime-core/src/remote/): Remote module handling
23+
- [shared/](mdc:packages/runtime-core/src/shared/): Shared module system
24+
25+
### Plugin System
26+
27+
- [plugins/](mdc:packages/runtime-core/src/plugins/): Plugin architecture
28+
- [type/](mdc:packages/runtime-core/src/type/): Type definitions
29+
- [utils/](mdc:packages/runtime-core/src/utils/): Utility functions
30+
31+
## Implementation Guidelines
32+
33+
When working with this codebase:
34+
35+
1. **Core Runtime**
36+
- Maintain backward compatibility
37+
- Handle global state carefully
38+
- Follow error handling patterns
39+
- Document runtime behaviors
40+
41+
2. **Module Management**
42+
- Implement proper module loading
43+
- Handle circular dependencies
44+
- Manage module lifecycle
45+
- Support hot reloading
46+
47+
3. **Plugin System**
48+
- Follow plugin interface
49+
- Maintain extensibility
50+
- Document plugin hooks
51+
- Handle plugin errors
52+
53+
4. **Testing Requirements**
54+
- Test core runtime features
55+
- Cover plugin scenarios
56+
- Test module loading
57+
- Verify error handling
58+
59+
## Architecture Principles
60+
61+
1. **Modularity**
62+
- Keep components isolated
63+
- Use clear interfaces
64+
- Follow single responsibility
65+
66+
2. **Performance**
67+
- Optimize module loading
68+
- Minimize runtime overhead
69+
- Efficient dependency sharing
70+
71+
3. **Reliability**
72+
- Handle edge cases
73+
- Proper error recovery
74+
- Maintain stability

.cursor/rules/10-runtime-package.mdc

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Module Federation Runtime Package
7+
8+
## Overview
9+
10+
The `@module-federation/runtime` package provides the main runtime interface for Module Federation. Located in [packages/runtime](mdc:packages/runtime), it builds on top of runtime-core to provide a user-friendly API for module federation features.
11+
12+
## Key Features
13+
14+
- Smart dependency sharing
15+
- Selective module loading
16+
- Plugin system integration
17+
- Performance optimization
18+
- Runtime extension support
19+
20+
## Package Structure
21+
22+
- **Source Code**: Main implementation in [src/](mdc:packages/runtime/src/)
23+
- **Tests**: Test suite in [__tests__/](mdc:packages/runtime/__tests__/)
24+
- **Configuration**:
25+
- [rollup.config.cjs](mdc:packages/runtime/rollup.config.cjs): Build setup
26+
- [tsconfig.json](mdc:packages/runtime/tsconfig.json): TypeScript config
27+
- [vitest.config.ts](mdc:packages/runtime/vitest.config.ts): Test configuration
28+
29+
## Build System
30+
31+
The package uses:
32+
- Rollup for bundling (CJS and ESM outputs)
33+
- TypeScript for type safety
34+
- Vitest for testing
35+
- SWC for fast compilation
36+
37+
## Core Dependencies
38+
39+
- `@module-federation/runtime-core`: Core runtime functionality
40+
- `@module-federation/sdk`: Utility functions
41+
- `@module-federation/error-codes`: Error handling
42+
43+
## Documentation
44+
45+
Detailed documentation available at:
46+
- [README.md](mdc:packages/runtime/README.md): Package overview
47+
- [Module Federation Runtime Guide](https://module-federation.io/guide/basic/runtime.html)

0 commit comments

Comments
 (0)