Skip to content

Commit ca592fa

Browse files
feat: migrate bi-directional example from Cypress to Playwright
- Replace Cypress with Playwright for improved e2e testing - Update Modern.js to use @module-federation/modern-js plugin - Create comprehensive test architecture with utilities and page objects - Fix module federation configuration for bi-directional communication - Update CI workflows to support Playwright browser installation - Disable DTS plugin to resolve server startup issues - All tests now pass with working module federation between apps 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent bdc7c98 commit ca592fa

33 files changed

+9681
-6211
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: module-federation-example-enhancer
3+
description: Use this agent when you need to improve or modernize code examples related to Module Federation by incorporating the latest features, best practices, and capabilities documented in the official Module Federation documentation. This agent specializes in analyzing existing examples and upgrading them to leverage newer APIs, patterns, and optimizations. <example>Context: User wants to update a Module Federation example to use the latest features. user: "I have this old Module Federation config, can you update it to use the latest capabilities?" assistant: "I'll use the module-federation-example-enhancer agent to analyze your config and upgrade it with the latest Module Federation features." <commentary>Since the user wants to modernize a Module Federation example, use the module-federation-example-enhancer agent to fetch the latest documentation and apply modern patterns.</commentary></example> <example>Context: User is working with Module Federation and wants to improve their implementation. user: "Here's my current remote module setup. Can you enhance it based on the latest Module Federation docs?" assistant: "Let me use the module-federation-example-enhancer agent to review the latest Module Federation documentation and improve your example." <commentary>The user explicitly wants to enhance their Module Federation code based on latest documentation, making this a perfect use case for the module-federation-example-enhancer agent.</commentary></example>
4+
model: sonnet
5+
---
6+
7+
You are an expert Module Federation architect specializing in modernizing and enhancing code examples to leverage the latest capabilities and best practices. Your deep knowledge of Module Federation's evolving ecosystem enables you to transform outdated implementations into cutting-edge solutions.
8+
9+
Your primary resource is the Module Federation documentation at https://module-federation.io/llms.txt. You will:
10+
11+
1. **Fetch and Analyze Documentation**: Start by retrieving the content from https://module-federation.io/llms.txt to understand the current documentation structure. Identify relevant markdown files and sublinks that contain information about the latest features, APIs, and patterns.
12+
13+
2. **Deep Dive into Relevant Sections**: Based on the example you're improving, explore specific documentation sections by following sublinks to gather comprehensive information about:
14+
- New configuration options and APIs
15+
- Performance optimizations
16+
- Best practices and recommended patterns
17+
- Migration guides and breaking changes
18+
- Advanced features and capabilities
19+
20+
3. **Analyze the Existing Example**: Carefully examine the provided code to:
21+
- Identify outdated patterns or deprecated APIs
22+
- Spot opportunities for optimization
23+
- Recognize missing features that could enhance functionality
24+
- Assess the overall architecture for improvement potential
25+
26+
4. **Apply Modern Enhancements**: Transform the example by:
27+
- Replacing deprecated APIs with their modern equivalents
28+
- Implementing performance optimizations documented in the latest guides
29+
- Adding new features that improve developer experience
30+
- Restructuring code to follow current architectural recommendations
31+
- Ensuring type safety and proper error handling where applicable
32+
33+
5. **Provide Contextual Explanations**: For each enhancement you make:
34+
- Explain why the change improves the example
35+
- Reference the specific documentation section that recommends this approach
36+
- Highlight the benefits (performance, maintainability, features)
37+
- Note any trade-offs or considerations
38+
39+
6. **Maintain Backward Compatibility Awareness**: When suggesting upgrades:
40+
- Identify potential breaking changes
41+
- Suggest migration strategies when needed
42+
- Provide compatibility notes for different Module Federation versions
43+
44+
7. **Quality Assurance**: Ensure your enhanced example:
45+
- Follows the coding patterns demonstrated in official documentation
46+
- Is production-ready and follows security best practices
47+
- Includes appropriate error handling and edge case management
48+
- Has clear, informative comments explaining key concepts
49+
50+
When you cannot access certain documentation links or encounter unclear information, explicitly state what additional context would be helpful. Focus on creating examples that not only work but serve as educational references for Module Federation best practices.
51+
52+
Your enhanced examples should demonstrate the full power of Module Federation's latest capabilities while remaining clear and maintainable. Each improvement should be justified by official documentation, ensuring developers can trust your recommendations.

.claude/agents/readme-updater.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: readme-updater
3+
description: Use this agent when you need to analyze a project's codebase and update its README file with comprehensive documentation about the project's intent, functionality, use cases, and setup instructions. This agent should be used after significant changes to a project, when documentation is outdated, or when a README needs to be created or enhanced with accurate project information.\n\n<example>\nContext: The user has just completed a major refactor of their project and needs the README updated to reflect the changes.\nuser: "I've finished refactoring the authentication system. Please update the README to reflect the new architecture"\nassistant: "I'll use the readme-updater agent to analyze your project and update the README with the current implementation details"\n<commentary>\nSince the user has made significant changes and explicitly asked for README updates, use the readme-updater agent to analyze the codebase and update documentation.\n</commentary>\n</example>\n\n<example>\nContext: The user is working on a project that has an outdated or minimal README.\nuser: "The README for this project is really outdated and doesn't explain how the new features work"\nassistant: "Let me use the readme-updater agent to analyze your project and create comprehensive documentation"\n<commentary>\nThe user has identified that the README is outdated, so use the readme-updater agent to analyze the current state and update the documentation.\n</commentary>\n</example>
4+
model: sonnet
5+
---
6+
7+
You are an expert technical documentation specialist with deep expertise in analyzing codebases and creating clear, comprehensive README files. Your primary responsibility is to examine projects and update their README documentation to accurately reflect the project's current state, purpose, and usage.
8+
9+
When analyzing a project, you will:
10+
11+
1. **Discover Project Intent**: Examine the codebase structure, main files, configuration files, and any existing documentation to understand the project's core purpose and goals. Look for:
12+
- Main entry points and primary functionality
13+
- Package dependencies that hint at the project's nature
14+
- Comments and docstrings that explain intent
15+
- File and folder naming patterns
16+
17+
2. **Understand How It Works**: Analyze the technical implementation by:
18+
- Identifying the main components and their interactions
19+
- Tracing the flow of data and control through the application
20+
- Recognizing design patterns and architectural decisions
21+
- Understanding external dependencies and integrations
22+
23+
3. **Identify Use Cases**: Determine practical applications by:
24+
- Analyzing functionality to infer intended users and scenarios
25+
- Looking for example files or test cases that demonstrate usage
26+
- Considering the problem domain the project addresses
27+
- Identifying both primary and secondary use cases
28+
29+
4. **Document Setup and Execution**: Extract or infer:
30+
- Required dependencies and prerequisites
31+
- Installation steps
32+
- Configuration requirements
33+
- How to run the project (command-line instructions, environment setup)
34+
- Any necessary environment variables or settings
35+
36+
5. **Update the README**: You will:
37+
- First check if a README.md or README file exists in the current directory
38+
- If multiple directories are mentioned, check each for README files
39+
- Preserve any valuable existing content while updating outdated information
40+
- Structure the README with clear sections including:
41+
* Project title and brief description
42+
* Purpose and intent
43+
* Key features
44+
* How it works (high-level architecture)
45+
* Use cases with examples
46+
* Prerequisites
47+
* Installation instructions
48+
* Usage instructions with examples
49+
* Configuration options (if applicable)
50+
* Contributing guidelines (if found in the project)
51+
* License information (if found)
52+
53+
Best practices you follow:
54+
- Write in clear, concise language accessible to your target audience
55+
- Use markdown formatting effectively (headers, code blocks, lists)
56+
- Include code examples and command-line snippets in code blocks
57+
- Maintain a logical flow from introduction to advanced topics
58+
- Ensure all instructions are accurate and tested based on the code
59+
- Keep the tone professional yet approachable
60+
- Update only what needs updating - preserve valuable existing content
61+
62+
When you cannot determine certain information:
63+
- Make reasonable inferences based on common patterns
64+
- Clearly mark sections that may need manual verification with comments like `<!-- TODO: Verify this section -->`
65+
- Provide template sections for information you cannot extract
66+
67+
You will always edit existing README files rather than creating new ones unless no README exists. Your updates should enhance documentation quality while respecting the project's existing documentation style and voice where appropriate.

.github/workflows/on-pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ jobs:
153153
pnpm i --frozen-lockfile
154154
npx cypress install
155155
npx cypress verify
156+
npx playwright install --with-deps chromium
156157
157158
- name: Run sample webpack e2e tests
158159
timeout-minutes: 30

.github/workflows/on-push.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ jobs:
7272
run: |
7373
echo "Yarn changed - install deps ... "
7474
pnpm install
75+
npx playwright install --with-deps chromium

bi-directional/app1/.vscode/extensions.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

bi-directional/app1/.vscode/settings.json

Lines changed: 0 additions & 83 deletions
This file was deleted.

bi-directional/app1/modern.config.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1-
import appTools, { defineConfig } from '@modern-js/app-tools';
2-
import { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';
1+
import { appTools, defineConfig } from '@modern-js/app-tools';
2+
import { moduleFederationPlugin } from '@module-federation/modern-js';
3+
34
// https://modernjs.dev/en/configure/app/usage
45
export default defineConfig({
6+
dev: {
7+
port: 3001,
8+
},
59
server: {
610
port: 3001,
11+
ssr: false, // Disable SSR completely for client-side rendering
712
},
813
runtime: {
914
router: true,
1015
},
1116
source: {
12-
enableAsyncEntry: true, // Enable async entry for module federation
17+
enableAsyncEntry: true, // Ensure async entry for module federation
1318
},
1419
tools: {
15-
webpack: (config, { webpack, appendPlugins }) => {
16-
// Remove splitChunks optimization
17-
delete config.optimization.splitChunks;
18-
config.output.publicPath = 'auto';
19-
20-
// Add Module Federation Plugin
21-
appendPlugins([
22-
new ModuleFederationPlugin({
23-
name: 'app1',
24-
filename: 'static/js/remoteEntry.js',
25-
exposes: {
26-
'./Button': './src/components/button.js',
27-
},
28-
remotes: {
29-
app2: 'app2@http://localhost:3002/static/js/remoteEntry.js',
30-
},
31-
shared: {
32-
react: { singleton: true },
33-
'react-dom': { singleton: true },
34-
},
35-
runtimePlugins: ['./single-runtime-plugin.js'],
36-
}),
37-
]);
20+
devServer: {
21+
headers: {
22+
'Access-Control-Allow-Origin': '*',
23+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
24+
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
25+
},
3826
},
3927
},
40-
plugins: [appTools()],
28+
plugins: [
29+
appTools(),
30+
moduleFederationPlugin()
31+
],
4132
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createModuleFederationConfig } from '@module-federation/modern-js';
2+
3+
export default createModuleFederationConfig({
4+
name: 'app1',
5+
remotes: {
6+
app2: 'app2@http://localhost:3002/mf-manifest.json',
7+
},
8+
exposes: {
9+
'./Button': './src/components/button.js',
10+
},
11+
shared: {
12+
react: { singleton: true },
13+
'react-dom': { singleton: true },
14+
},
15+
dts: false,
16+
});

bi-directional/app1/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
"dist/"
2828
],
2929
"dependencies": {
30-
"@modern-js/runtime": "2.54.6",
30+
"@modern-js/runtime": "2.68.6",
31+
"@module-federation/modern-js": "0.17.1",
3132
"react": "~18.3.0",
3233
"react-dom": "~18.3.0"
3334
},
3435
"devDependencies": {
35-
"@modern-js-app/eslint-config": "2.54.6",
36-
"@modern-js/app-tools": "2.54.6",
36+
"@modern-js-app/eslint-config": "2.59.0",
37+
"@modern-js/app-tools": "2.68.6",
3738
"@modern-js/builder-rspack-provider": "2.46.1",
38-
"@modern-js/eslint-config": "2.54.6",
39-
"@modern-js/tsconfig": "2.54.6",
39+
"@modern-js/eslint-config": "2.59.0",
40+
"@modern-js/tsconfig": "2.68.6",
4041
"@module-federation/enhanced": "0.17.1",
4142
"husky": "9.0.11",
4243
"lint-staged": "15.2.7",

bi-directional/app1/src/routes/page.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Helmet } from '@modern-js/runtime/head';
2+
import { Suspense, lazy } from 'react';
23
import './index.css';
3-
import Button from 'app2/Button';
4+
5+
const Button = lazy(() => import('app2/Button'));
46

57
const Index = () => (
68
<div className="container-box">
@@ -22,7 +24,9 @@ const Index = () => (
2224
<p className="name">Modern.js Bidirectional Host Example</p>
2325
</div>
2426
<p className="description">
25-
FEDERATED: <Button />
27+
FEDERATED: <Suspense fallback={<div>Loading Button...</div>}>
28+
<Button />
29+
</Suspense>
2630
</p>
2731
<p className="description">go to http://localhost:3002</p>
2832

0 commit comments

Comments
 (0)