diff --git a/.changeset/ai-happy-lion.md b/.changeset/ai-happy-lion.md new file mode 100644 index 00000000000..934f0fc514e --- /dev/null +++ b/.changeset/ai-happy-lion.md @@ -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. diff --git a/.changeset/ai-noisy-wolf.md b/.changeset/ai-noisy-wolf.md index 0b45c838db0..7910fa530dc 100644 --- a/.changeset/ai-noisy-wolf.md +++ b/.changeset/ai-noisy-wolf.md @@ -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. -``` \ No newline at end of file diff --git a/.cursor/mcp.json b/.cursor/mcp.json new file mode 100644 index 00000000000..fdb72efd240 --- /dev/null +++ b/.cursor/mcp.json @@ -0,0 +1,7 @@ +{ + "mcpServers": { + "nx-mcp": { + "url": "http://localhost:9394/sse" + } + } +} diff --git a/.cursor/rules/01-project-overview.mdc b/.cursor/rules/01-project-overview.mdc new file mode 100644 index 00000000000..3f2890c4eac --- /dev/null +++ b/.cursor/rules/01-project-overview.mdc @@ -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 diff --git a/.cursor/rules/02-development-workflow.mdc b/.cursor/rules/02-development-workflow.mdc new file mode 100644 index 00000000000..2cbb3afb392 --- /dev/null +++ b/.cursor/rules/02-development-workflow.mdc @@ -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) diff --git a/.cursor/rules/03-code-organization.mdc b/.cursor/rules/03-code-organization.mdc new file mode 100644 index 00000000000..2d919d02d44 --- /dev/null +++ b/.cursor/rules/03-code-organization.mdc @@ -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) diff --git a/.cursor/rules/04-webpack-bundler-runtime.mdc b/.cursor/rules/04-webpack-bundler-runtime.mdc new file mode 100644 index 00000000000..7d98c978889 --- /dev/null +++ b/.cursor/rules/04-webpack-bundler-runtime.mdc @@ -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 diff --git a/.cursor/rules/05-webpack-bundler-runtime-implementation.mdc b/.cursor/rules/05-webpack-bundler-runtime-implementation.mdc new file mode 100644 index 00000000000..701f01e6961 --- /dev/null +++ b/.cursor/rules/05-webpack-bundler-runtime-implementation.mdc @@ -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 diff --git a/.cursor/rules/06-sdk-package.mdc b/.cursor/rules/06-sdk-package.mdc new file mode 100644 index 00000000000..51dcf9ab5f6 --- /dev/null +++ b/.cursor/rules/06-sdk-package.mdc @@ -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 diff --git a/.cursor/rules/07-sdk-implementation.mdc b/.cursor/rules/07-sdk-implementation.mdc new file mode 100644 index 00000000000..cba6fb8e419 --- /dev/null +++ b/.cursor/rules/07-sdk-implementation.mdc @@ -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 diff --git a/.cursor/rules/08-runtime-core-package.mdc b/.cursor/rules/08-runtime-core-package.mdc new file mode 100644 index 00000000000..d0e85abe4b9 --- /dev/null +++ b/.cursor/rules/08-runtime-core-package.mdc @@ -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 diff --git a/.cursor/rules/09-runtime-core-implementation.mdc b/.cursor/rules/09-runtime-core-implementation.mdc new file mode 100644 index 00000000000..09cd6d35aa1 --- /dev/null +++ b/.cursor/rules/09-runtime-core-implementation.mdc @@ -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 diff --git a/.cursor/rules/10-runtime-package.mdc b/.cursor/rules/10-runtime-package.mdc new file mode 100644 index 00000000000..da1b9f9c414 --- /dev/null +++ b/.cursor/rules/10-runtime-package.mdc @@ -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) diff --git a/.cursor/rules/11-runtime-implementation.mdc b/.cursor/rules/11-runtime-implementation.mdc new file mode 100644 index 00000000000..337d4b63270 --- /dev/null +++ b/.cursor/rules/11-runtime-implementation.mdc @@ -0,0 +1,93 @@ +--- +description: +globs: +alwaysApply: true +--- +# Module Federation Runtime Implementation + +## Source Code Structure + +The implementation is organized into several key modules in [src/](mdc:packages/runtime/src/): + +### Core Modules + +- [index.ts](mdc:packages/runtime/src/index.ts): Main entry point and public API +- [core.ts](mdc:packages/runtime/src/core.ts): Core runtime exports +- [types.ts](mdc:packages/runtime/src/types.ts): Type definitions + +### Utility Modules + +- [helpers.ts](mdc:packages/runtime/src/helpers.ts): Helper functions +- [utils.ts](mdc:packages/runtime/src/utils.ts): Utility functions + +## Implementation Guidelines + +When working with this codebase: + +1. **API Design** + - Keep APIs simple and intuitive + - Maintain backward compatibility + - Document all public interfaces + - Follow TypeScript best practices + +2. **Runtime Integration** + - Use runtime-core for core functionality + - Extend core features appropriately + - Maintain plugin compatibility + - Consider performance implications + +3. **Error Handling** + - Use error-codes package + - Provide helpful error messages + - Handle edge cases gracefully + - Maintain error consistency + +4. **Testing Requirements** + - Test public APIs thoroughly + - Verify runtime integration + - Test error scenarios + - Cover edge cases + +## Usage Patterns + +1. **Module Loading** +```typescript +import { loadModule } from '@module-federation/runtime'; +await loadModule('remote/module'); +``` + +2. **Plugin Integration** +```typescript +import { registerPlugin } from '@module-federation/runtime'; +registerPlugin('name', plugin); +``` + +3. **Error Handling** +```typescript +import { handleError } from '@module-federation/runtime'; +try { + // runtime operations +} catch (error) { + handleError(error); +} +``` + +## Best Practices + +1. **Performance** + - Use selective loading + - Share dependencies efficiently + - Minimize runtime overhead + - Optimize plugin usage + +2. **Maintainability** + - Follow consistent patterns + - Document complex logic + - Keep code modular + - Use type safety + +3. **Compatibility** + - Support multiple environments + - Handle version differences + - Maintain plugin compatibility + - Consider bundler support diff --git a/.cursor/rules/12-manifest-package.mdc b/.cursor/rules/12-manifest-package.mdc new file mode 100644 index 00000000000..025d96c1c6f --- /dev/null +++ b/.cursor/rules/12-manifest-package.mdc @@ -0,0 +1,66 @@ +--- +description: +globs: +alwaysApply: true +--- + +# Module Federation Manifest Package + +## Overview + +The `@module-federation/manifest` package provides manifest and stats functionality for Module Federation projects. Located in [packages/manifest](mdc:packages/manifest), it handles module exposure configuration and stats collection for webpack/rspack projects. + +## Key Features + +- Module exposure management +- Stats collection and processing +- Webpack/Rspack integration +- Container management +- Type generation support + +## Package Structure + +- **Source Code**: Main implementation in [src/](mdc:packages/manifest/src/) +- **Tests**: Test suite in [__tests__/](mdc:packages/manifest/__tests__/) +- **Configuration**: + - [rollup.config.js](mdc:packages/manifest/rollup.config.js): Build setup + - [tsconfig.json](mdc:packages/manifest/tsconfig.json): TypeScript config + - [jest.config.js](mdc:packages/manifest/jest.config.js): Test configuration + +## Build System + +The package uses: +- Rollup for bundling (CJS and ESM outputs) +- TypeScript for type safety +- Jest for testing +- Standard JS module format + +## Core Dependencies + +- `@module-federation/sdk`: Core utilities +- `@module-federation/dts-plugin`: Type generation +- `@module-federation/managers`: Container management + +## Usage Example + +```javascript +import { StatsPlugin } from '@module-federation/manifest'; + +// Configure stats plugin +new StatsPlugin(mfOptions, { + pluginVersion: pkg.version, + bundler: 'webpack' +}).apply(compiler); + +// Container management +import { ContainerManager } from '@module-federation/managers'; +const containerManager = new ContainerManager(); +containerManager.init(options); +options.exposes = containerManager.containerPluginExposesOptions; +``` + +## Documentation + +For more details, see: +- [README.md](mdc:packages/manifest/README.md): Package documentation +- Module Federation documentation diff --git a/.cursor/rules/13-manifest-implementation.mdc b/.cursor/rules/13-manifest-implementation.mdc new file mode 100644 index 00000000000..0746bd84f87 --- /dev/null +++ b/.cursor/rules/13-manifest-implementation.mdc @@ -0,0 +1,16 @@ +--- +description: +globs: +alwaysApply: true +--- +# Module Federation Manifest Implementation + +## Source Code Structure + +The implementation is organized into several key modules in [src/](mdc:packages/manifest/src/): + +### Core Components + +- [index.ts](mdc:packages/manifest/src/index.ts): Main entry point +- [StatsPlugin.ts](mdc:packages/manifest/src/StatsPlugin.ts): Webpack/Rspack plugin +- [types.ts](mdc:packages/manifest/src/types.ts): Type definitions diff --git a/.cursor/rules/14-enhanced-package.mdc b/.cursor/rules/14-enhanced-package.mdc new file mode 100644 index 00000000000..eee75b40b12 --- /dev/null +++ b/.cursor/rules/14-enhanced-package.mdc @@ -0,0 +1,82 @@ +--- +description: +globs: +alwaysApply: true +--- + +# Module Federation Enhanced Package + +## Overview + +The `@module-federation/enhanced` package provides advanced features and plugins for Module Federation. Located in [packages/enhanced](mdc:packages/enhanced), it offers a comprehensive set of tools for module federation, including webpack/rspack plugins, runtime enhancements, and CLI utilities. + +## Key Components + +### Core Plugins +- ModuleFederationPlugin +- ContainerPlugin +- ContainerReferencePlugin +- SharePlugin +- ConsumeSharedPlugin +- ProvideSharedPlugin +- FederationRuntimePlugin +- AsyncBoundaryPlugin +- HoistContainerReferencesPlugin + +### CLI Tools +- Type generation utilities +- Remote type fetching +- Configuration management + +## Package Structure + +- **Source Code**: Core implementation in [src/](mdc:packages/enhanced/src/) + - [lib/](mdc:packages/enhanced/src/lib/): Core functionality + - [runtime/](mdc:packages/enhanced/src/runtime/): Runtime components + - [schemas/](mdc:packages/enhanced/src/schemas/): JSON schemas + - [types/](mdc:packages/enhanced/src/types/): TypeScript definitions + - [wrapper/](mdc:packages/enhanced/src/wrapper/): Plugin wrappers + +- **CLI Tools**: Command-line utilities in [bin/](mdc:packages/enhanced/bin/) +- **Tests**: Test suite in [test/](mdc:packages/enhanced/test/) +- **Configuration**: + - [tsconfig.json](mdc:packages/enhanced/tsconfig.json): TypeScript settings + - [jest.config.ts](mdc:packages/enhanced/jest.config.ts): Test configuration + - [.swcrc](mdc:packages/enhanced/.swcrc): SWC compiler config + +## Core Dependencies + +### Runtime Dependencies +- `@module-federation/runtime-tools`: Runtime utilities +- `@module-federation/sdk`: Core SDK +- `@module-federation/managers`: Container management + +### Build Dependencies +- `@module-federation/dts-plugin`: Type generation +- `@module-federation/manifest`: Manifest handling +- `@module-federation/rspack`: Rspack integration + +## Configuration Options + +### ModuleFederationPlugin Options +- `name`: Container name +- `exposes`: Module exposure configuration +- `remotes`: Remote module configuration +- `shared`: Dependency sharing settings +- `runtimePlugins`: Additional runtime plugins + +### CLI Options +```bash +mf dts [options] + --root # Project root directory + --output # DTS output directory + --fetch # Fetch remote types + --generate # Generate types + --config # Configuration file +``` + +## Documentation + +For detailed documentation, see: +- [README.md](mdc:packages/enhanced/README.md): Package documentation +- [Module Federation Guide](https://module-federation.io/guide/basic/webpack.html) diff --git a/.cursor/rules/15-enhanced-implementation.mdc b/.cursor/rules/15-enhanced-implementation.mdc new file mode 100644 index 00000000000..ef0e4cadd15 --- /dev/null +++ b/.cursor/rules/15-enhanced-implementation.mdc @@ -0,0 +1,19 @@ +--- +description: +globs: +alwaysApply: true +--- +# Module Federation Enhanced Implementation + +## Source Code Structure + +The implementation is organized into several key directories in [src/](mdc:packages/enhanced/src/): + +### Core Files + +- [index.ts](mdc:packages/enhanced/src/index.ts): Main entry point and exports +- [webpack.ts](mdc:packages/enhanced/src/webpack.ts): Webpack integration +- [rspack.ts](mdc:packages/enhanced/src/rspack.ts): Rspack integration +- [runtime.ts](mdc:packages/enhanced/src/runtime.ts): Runtime exports +- [prefetch.ts](mdc:packages/enhanced/src/prefetch.ts): Prefetching functionality +- [utils.ts](mdc:packages/enhanced/src/utils.ts): Shared utilities diff --git a/changeset-gen.js b/changeset-gen.js index 5250896aa7b..8060db0bda6 100755 --- a/changeset-gen.js +++ b/changeset-gen.js @@ -87,8 +87,8 @@ Only return the changeset, nothing else.`; return response.choices[0].message.content .trim() - .replace('```markdown', '') - .replace('```', '') + .replace(/```markdown/g, '') + .replace(/```/g, '') .replace(/\n?/g, '') .replace(/<\/?[^>]+(>|$)/g, '') // Remove all HTML tags .trim(); diff --git a/package.json b/package.json index 10f9154706e..6f89e87d813 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "prepare": "husky install", "changeset": "changeset", "build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'", - "changegen": "./changeset-gen.js --path ./packages/enhanced --staged &&./changeset-gen.js --path ./packages/cli --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged", + "changegen": "./changeset-gen.js --path ./packages/enhanced --staged &&./changeset-gen.js --path ./packages/cli --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged && ./changeset-gen.js --path ./packages/sdk --staged", "commitgen:staged": "./commit-gen.js --path ./packages --staged", "commitgen:main": "./commit-gen.js --path ./packages", "changeset:status": "changeset status", diff --git a/packages/sdk/__tests__/dom.spec.ts b/packages/sdk/__tests__/dom.spec.ts index 729991f75e8..26247111eaf 100644 --- a/packages/sdk/__tests__/dom.spec.ts +++ b/packages/sdk/__tests__/dom.spec.ts @@ -283,4 +283,25 @@ describe('createLink', () => { expect(link).toBe(customLink); }); + + it('should not create a duplicate link when existing link has no rel and attrs.rel is undefined (https://github.com/module-federation/core/issues/3705)', () => { + // Simulate an existing link with no rel attribute + const url = 'https://example.com/stylesheet.css'; + const existingLink = document.createElement('link'); + existingLink.setAttribute('href', url); + // Note: no rel attribute set + document.head.appendChild(existingLink); + + // Now call createLink with matching url and no rel in attrs + const cb = jest.fn(); + const { link, needAttach } = createLink({ + url, + cb, + attrs: { as: 'style' }, // rel is omitted, so info.attrs['rel'] is undefined + }); + + // Should reuse the existing link, not create a new one + expect(link).toBe(existingLink); + expect(needAttach).toBe(false); + }); }); diff --git a/packages/sdk/src/dom.ts b/packages/sdk/src/dom.ts index 5c478b13068..d8fafc3b1f7 100644 --- a/packages/sdk/src/dom.ts +++ b/packages/sdk/src/dom.ts @@ -156,10 +156,11 @@ export function createLink(info: { const l = links[i]; const linkHref = l.getAttribute('href'); const linkRel = l.getAttribute('rel'); + // Use == to treat null and undefined as equivalent (see https://github.com/module-federation/core/issues/3705) if ( linkHref && isStaticResourcesEqual(linkHref, info.url) && - linkRel === info.attrs['rel'] + linkRel == info.attrs['rel'] ) { link = l; needAttach = false;