Skip to content

fix(sdk): issue where duplicate links were created when existing #3707

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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/ai-happy-lion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@module-federation/sdk": patch
---

Fix issue where `createLink` incorrectly created duplicate links when existing links lacked a `rel` attribute.

- Added a test case to verify `createLink` does not duplicate links when existing ones have no `rel`.
- Modified `createLink` logic to treat `null` and `undefined` as equivalent for `rel` attribute.
- Ensures consistent behavior even when `rel` attribute is missing.
1 change: 0 additions & 1 deletion .changeset/ai-noisy-wolf.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Improve dynamic module import for `readConfig` function to use file URL format.
- Added `pathToFileURL` import from 'url' module.
- Updated the dynamic import statement for `mfConfig` to use `pathToFileURL(preBundlePath).href`.
- Ensures compatibility and correctness in environments where file paths require URL format.
```
7 changes: 7 additions & 0 deletions .cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mcpServers": {
"nx-mcp": {
"url": "http://localhost:9394/sse"
}
}
}
16 changes: 16 additions & 0 deletions .cursor/rules/01-project-overview.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
description:
globs:
alwaysApply: true
---
# Module Federation Project Overview

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.

## Core Concepts

- **Module Federation Runtime**: Advanced runtime system for module sharing
- **Plugin System**: Extensible architecture with runtime plugins
- **Manifest System**: Enhanced module manifest handling
- **Type Support**: Dynamic type hinting capabilities
- **Developer Tools**: Including Chrome DevTools integration
31 changes: 31 additions & 0 deletions .cursor/rules/02-development-workflow.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
description:
globs:
alwaysApply: true
---
# Development Workflow

## Build and Development

The project uses several key tools and processes:

- **Package Management**: Node.js package management with npm/yarn
- **Build System**: Webpack-based build system in [webpack/](mdc:webpack)
- **Testing**: Jest testing framework configured in [jest.config.ts](mdc:jest.config.ts)
- **Code Quality**:
- ESLint for linting: [.eslintrc.json](mdc:.eslintrc.json)
- Prettier for formatting: [.prettierrc](mdc:.prettierrc)

## Directory Structure

- `apps/`: Application implementations
- `packages/`: Shared packages and core modules
- `docs/`: Documentation files
- `scripts/`: Build and utility scripts
- `tools/`: Development tools and utilities

## Version Control

- Uses Git for version control
- Changesets for version management
- Husky for Git hooks in [.husky/](mdc:.husky)
38 changes: 38 additions & 0 deletions .cursor/rules/03-code-organization.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
description:
globs:
alwaysApply: true
---
# Code Organization and Structure

## Monorepo Structure

This project follows a monorepo architecture with two main code directories:

1. **Apps Directory** ([apps/](mdc:apps))
- Contains complete applications
- Each app is a standalone implementation
- Apps can consume shared packages

2. **Packages Directory** ([packages/](mdc:packages))
- Contains shared libraries and modules
- Core Module Federation functionality
- Reusable utilities and components

## Configuration

- TypeScript configuration in [tsconfig.base.json](mdc:tsconfig.base.json)
- Build configuration in [webpack/](mdc:webpack)
- Package management in [package.json](mdc:package.json)

## Documentation

- Main documentation in [docs/](mdc:docs)
- API documentation and guides
- Contributing guidelines in [CONTRIBUTING.md](mdc:CONTRIBUTING.md)

## Build Output

- Build artifacts go to [dist/](mdc:dist)
- Temporary files in [tmp/](mdc:tmp)
- Build logs and output in [build_output_main/](mdc:build_output_main)
19 changes: 19 additions & 0 deletions .cursor/rules/04-webpack-bundler-runtime.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
description:
globs:
alwaysApply: true
---
# Webpack Bundler Runtime Package

## Overview

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.

## Package Structure

- **Source Code**: Main implementation in [src/](mdc:packages/webpack-bundler-runtime/src/)
- **Tests**: Test files in [__tests__/](mdc:packages/webpack-bundler-runtime/__tests__/)
- **Configuration**:
- [rollup.config.cjs](mdc:packages/webpack-bundler-runtime/rollup.config.cjs): Build configuration
- [tsconfig.json](mdc:packages/webpack-bundler-runtime/tsconfig.json): TypeScript settings
- [.swcrc](mdc:packages/webpack-bundler-runtime/.swcrc): SWC compiler config
47 changes: 47 additions & 0 deletions .cursor/rules/05-webpack-bundler-runtime-implementation.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
description:
globs:
alwaysApply: true
---
# Webpack Bundler Runtime Implementation

## Source Code Structure

The implementation is organized into several key modules in [src/](mdc:packages/webpack-bundler-runtime/src/):

### Core Modules

- [index.ts](mdc:packages/webpack-bundler-runtime/src/index.ts): Main entry point and exports
- [types.ts](mdc:packages/webpack-bundler-runtime/src/types.ts): TypeScript type definitions
- [constant.ts](mdc:packages/webpack-bundler-runtime/src/constant.ts): Shared constants

### Container Management

- [container.ts](mdc:packages/webpack-bundler-runtime/src/container.ts): Core container implementation
- [initContainerEntry.ts](mdc:packages/webpack-bundler-runtime/src/initContainerEntry.ts): Container entry initialization
- [remotes.ts](mdc:packages/webpack-bundler-runtime/src/remotes.ts): Remote modules handling

### Sharing System

- [initializeSharing.ts](mdc:packages/webpack-bundler-runtime/src/initializeSharing.ts): Share scope initialization
- [attachShareScopeMap.ts](mdc:packages/webpack-bundler-runtime/src/attachShareScopeMap.ts): Share scope mapping
- [consumes.ts](mdc:packages/webpack-bundler-runtime/src/consumes.ts): Consumed modules management
- [installInitialConsumes.ts](mdc:packages/webpack-bundler-runtime/src/installInitialConsumes.ts): Initial module consumption

## Implementation Guidelines

When working with this codebase:

1. **Type Safety**
- All new code must be fully typed
- Types are defined in [types.ts](mdc:packages/webpack-bundler-runtime/src/types.ts)

2. **Module Organization**
- Keep related functionality grouped
- Follow existing file naming conventions
- Maintain clear separation of concerns

3. **Runtime Integration**
- Code must be compatible with webpack/rspack
- Follow Module Federation specifications
- Consider both CJS and ESM environments
19 changes: 19 additions & 0 deletions .cursor/rules/06-sdk-package.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
description:
globs:
alwaysApply: true
---

# Module Federation SDK Package

## Overview

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.

## Key Features

- Module name parsing and encoding
- Filename generation for exposed/shared modules
- Environment detection utilities
- Debugging and logging tools
- Manifest snapshot generation
56 changes: 56 additions & 0 deletions .cursor/rules/07-sdk-implementation.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
description:
globs:
alwaysApply: true
---
# Module Federation SDK Implementation

## Source Code Structure

The implementation is organized into several key modules in [src/](mdc:packages/sdk/src/):

### Core Modules

- [index.ts](mdc:packages/sdk/src/index.ts): Main entry point and exports
- [constant.ts](mdc:packages/sdk/src/constant.ts): Shared constants
- [utils.ts](mdc:packages/sdk/src/utils.ts): Common utility functions

### Environment Handling

- [env.ts](mdc:packages/sdk/src/env.ts): Environment detection utilities
- [node.ts](mdc:packages/sdk/src/node.ts): Node.js specific functionality
- [dom.ts](mdc:packages/sdk/src/dom.ts): Browser/DOM specific functionality

### Module Management

- [normalize-webpack-path.ts](mdc:packages/sdk/src/normalize-webpack-path.ts): Webpack path normalization
- [normalizeOptions.ts](mdc:packages/sdk/src/normalizeOptions.ts): Options normalization
- [generateSnapshotFromManifest.ts](mdc:packages/sdk/src/generateSnapshotFromManifest.ts): Manifest snapshot generation

### Debugging

- [logger.ts](mdc:packages/sdk/src/logger.ts): Logging and debugging utilities

## Implementation Guidelines

When working with this codebase:

1. **Code Organization**
- Keep platform-specific code in appropriate files (node.ts/dom.ts)
- Use types directory for type definitions
- Follow modular design patterns

2. **API Design**
- Maintain consistent function signatures
- Document all public APIs
- Follow TypeScript best practices

3. **Cross-Platform Support**
- Handle both Node.js and browser environments
- Use appropriate environment checks
- Consider bundler compatibility

4. **Testing**
- Write comprehensive tests
- Cover both Node.js and browser scenarios
- Test error cases and edge conditions
18 changes: 18 additions & 0 deletions .cursor/rules/08-runtime-core-package.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
description:
globs:
alwaysApply: true
---
# Module Federation Runtime Core Package

## Overview

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.

## Key Features

- Dependency sharing and optimization
- Selective module loading
- Extensible plugin system
- Runtime module federation
- Global state management
74 changes: 74 additions & 0 deletions .cursor/rules/09-runtime-core-implementation.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
description:
globs:
alwaysApply: true
---
# Module Federation Runtime Core Implementation

## Source Code Structure

The implementation is organized into several key modules in [src/](mdc:packages/runtime-core/src/):

### Core Runtime

- [core.ts](mdc:packages/runtime-core/src/core.ts): Core runtime implementation
- [global.ts](mdc:packages/runtime-core/src/global.ts): Global state management
- [index.ts](mdc:packages/runtime-core/src/index.ts): Public API exports
- [helpers.ts](mdc:packages/runtime-core/src/helpers.ts): Utility functions

### Module System

- [module/](mdc:packages/runtime-core/src/module/): Module management
- [remote/](mdc:packages/runtime-core/src/remote/): Remote module handling
- [shared/](mdc:packages/runtime-core/src/shared/): Shared module system

### Plugin System

- [plugins/](mdc:packages/runtime-core/src/plugins/): Plugin architecture
- [type/](mdc:packages/runtime-core/src/type/): Type definitions
- [utils/](mdc:packages/runtime-core/src/utils/): Utility functions

## Implementation Guidelines

When working with this codebase:

1. **Core Runtime**
- Maintain backward compatibility
- Handle global state carefully
- Follow error handling patterns
- Document runtime behaviors

2. **Module Management**
- Implement proper module loading
- Handle circular dependencies
- Manage module lifecycle
- Support hot reloading

3. **Plugin System**
- Follow plugin interface
- Maintain extensibility
- Document plugin hooks
- Handle plugin errors

4. **Testing Requirements**
- Test core runtime features
- Cover plugin scenarios
- Test module loading
- Verify error handling

## Architecture Principles

1. **Modularity**
- Keep components isolated
- Use clear interfaces
- Follow single responsibility

2. **Performance**
- Optimize module loading
- Minimize runtime overhead
- Efficient dependency sharing

3. **Reliability**
- Handle edge cases
- Proper error recovery
- Maintain stability
47 changes: 47 additions & 0 deletions .cursor/rules/10-runtime-package.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
description:
globs:
alwaysApply: true
---
# Module Federation Runtime Package

## Overview

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.

## Key Features

- Smart dependency sharing
- Selective module loading
- Plugin system integration
- Performance optimization
- Runtime extension support

## Package Structure

- **Source Code**: Main implementation in [src/](mdc:packages/runtime/src/)
- **Tests**: Test suite in [__tests__/](mdc:packages/runtime/__tests__/)
- **Configuration**:
- [rollup.config.cjs](mdc:packages/runtime/rollup.config.cjs): Build setup
- [tsconfig.json](mdc:packages/runtime/tsconfig.json): TypeScript config
- [vitest.config.ts](mdc:packages/runtime/vitest.config.ts): Test configuration

## Build System

The package uses:
- Rollup for bundling (CJS and ESM outputs)
- TypeScript for type safety
- Vitest for testing
- SWC for fast compilation

## Core Dependencies

- `@module-federation/runtime-core`: Core runtime functionality
- `@module-federation/sdk`: Utility functions
- `@module-federation/error-codes`: Error handling

## Documentation

Detailed documentation available at:
- [README.md](mdc:packages/runtime/README.md): Package overview
- [Module Federation Runtime Guide](https://module-federation.io/guide/basic/runtime.html)
Loading
Loading