Skip to content

Commit 9d5ace9

Browse files
fix(enhanced): add runtime safety checks with warning logs
- Add typeof check for oldStartup function in EmbedFederationRuntimeModule - Log warning when oldStartup is not a function - Add typeof check for __webpack_require__.x in StartupHelpers - Log warning when __webpack_require__.x is not a function These defensive checks prevent runtime errors when expected functions don't exist in certain build configurations. The warnings help developers debug issues. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 52b123f commit 9d5ace9

File tree

3 files changed

+295
-2
lines changed

3 files changed

+295
-2
lines changed

INCREMENTAL_PR_PLAN_REVISED.md

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
# Revised Incremental PR Plan for packages/enhanced Changes
2+
3+
## Overview
4+
Based on a detailed diff analysis, this document provides a more accurate breakdown of changes into focused, incremental PRs. Each PR represents a distinct feature, fix, or refactor that can be merged independently.
5+
6+
## Updated PR Sequence
7+
8+
### PR 1: Runtime Safety Fixes
9+
**Size**: Tiny (~2 files)
10+
**Risk**: Low
11+
**Type**: Fix
12+
**Feature**: Add defensive checks to prevent runtime errors
13+
14+
**Files to include**:
15+
- `src/lib/container/runtime/EmbedFederationRuntimeModule.ts` (add `typeof oldStartup === 'function'` check)
16+
- `src/lib/startup/StartupHelpers.ts` (add `typeof __webpack_require__.x === "function"` check)
17+
18+
**Why first**: These are independent safety fixes that improve stability without any dependencies.
19+
20+
---
21+
22+
### PR 2: Hook Renaming and Cleanup
23+
**Size**: Small (~6 files)
24+
**Risk**: Medium (potential breaking change)
25+
**Type**: Refactor
26+
**Feature**: Rename container hooks for clarity and consistency
27+
28+
**Files to include**:
29+
- `src/lib/container/ContainerPlugin.ts` (rename hooks, add `addRemoteDependency`)
30+
- `src/lib/container/runtime/FederationRuntimePlugin.ts`
31+
- `src/lib/container/runtime/FederationModulesPlugin.ts`
32+
- `src/lib/container/runtime/EmbedFederationRuntimePlugin.ts`
33+
- `src/lib/container/RemoteModule.ts` (use new hook)
34+
35+
**Changes**:
36+
- `addContainerEntryModule``addContainerEntryDependency`
37+
- `addFederationRuntimeModule``addFederationRuntimeDependency`
38+
- Add new `addRemoteDependency` hook
39+
40+
**Implementation with backward compatibility**:
41+
```javascript
42+
compiler.hooks.addContainerEntryDependency = new SyncHook([...]);
43+
compiler.hooks.addContainerEntryModule = compiler.hooks.addContainerEntryDependency; // deprecated
44+
```
45+
46+
---
47+
48+
### PR 3: Enhanced HoistContainerReferencesPlugin
49+
**Size**: Medium (~3 files)
50+
**Risk**: Medium
51+
**Type**: Feature/Fix
52+
**Feature**: Improve module hoisting for runtime chunks
53+
54+
**Files to include**:
55+
- `src/lib/container/HoistContainerReferencesPlugin.ts` (complete rewrite)
56+
- `test/compiler-unit/container/HoistContainerReferencesPlugin.test.ts` (new tests)
57+
- Related test fixtures
58+
59+
**Depends on**: PR 2 (needs renamed hooks)
60+
61+
**Key improvements**:
62+
- Separate handling for container, federation, and remote dependencies
63+
- Better support for `runtimeChunk: 'single'` configuration
64+
- Proper remote module hoisting
65+
66+
---
67+
68+
### PR 4: Basic Share Filtering - Include/Exclude by Version
69+
**Size**: Medium (~12 files)
70+
**Risk**: Low
71+
**Type**: Feature
72+
**Feature**: Filter shared modules by version constraints
73+
74+
**Files to include**:
75+
- `src/lib/sharing/utils.ts` (add `testRequestFilters`, `addSingletonFilterWarning`)
76+
- `src/lib/sharing/ConsumeSharedPlugin.ts` (add version-based filtering)
77+
- `src/lib/sharing/ProvideSharedPlugin.ts` (add version-based filtering)
78+
- `src/schemas/sharing/ConsumeSharedPlugin.json` (add include/exclude schema)
79+
- `src/schemas/sharing/ConsumeSharedPlugin.ts`
80+
- `src/schemas/sharing/ConsumeSharedPlugin.check.ts`
81+
- `src/schemas/sharing/ProvideSharedPlugin.json`
82+
- `src/schemas/sharing/ProvideSharedPlugin.ts`
83+
- `src/schemas/sharing/ProvideSharedPlugin.check.ts`
84+
- `test/unit/sharing/utils-filtering.test.ts` (new)
85+
- `test/configCases/sharing/share-multiple-versions-include/*` (new)
86+
- `test/configCases/sharing/share-multiple-versions-exclude/*` (new)
87+
88+
**API**:
89+
```javascript
90+
shared: {
91+
react: {
92+
include: { version: "^18.0.0" },
93+
exclude: { version: "17.x" }
94+
}
95+
}
96+
```
97+
98+
---
99+
100+
### PR 5: Request Pattern Filtering
101+
**Size**: Small (~8 files)
102+
**Risk**: Low
103+
**Type**: Feature
104+
**Feature**: Filter shared modules by request patterns
105+
106+
**Files to include**:
107+
- `src/lib/sharing/ConsumeSharedPlugin.ts` (add request pattern support)
108+
- `src/lib/sharing/ProvideSharedPlugin.ts` (add request pattern support)
109+
- Update schemas for request patterns
110+
- `test/configCases/sharing/prefix-share-filter/*` (new)
111+
- Related unit tests
112+
113+
**Depends on**: PR 4 (builds on filtering infrastructure)
114+
115+
**API**:
116+
```javascript
117+
shared: {
118+
"@scope/*": {
119+
include: { request: /^@scope\/[^\/]+$/ }
120+
}
121+
}
122+
```
123+
124+
---
125+
126+
### PR 6: Fallback Version Support
127+
**Size**: Small (~6 files)
128+
**Risk**: Low
129+
**Type**: Feature
130+
**Feature**: Add fallback version checking for filters
131+
132+
**Files to include**:
133+
- `src/lib/sharing/ConsumeSharedPlugin.ts` (add fallbackVersion logic)
134+
- `src/lib/sharing/ProvideSharedPlugin.ts` (add fallbackVersion logic)
135+
- Schema updates for fallbackVersion
136+
- Unit tests for fallback version
137+
- Integration tests
138+
139+
**Depends on**: PR 4
140+
141+
**API**:
142+
```javascript
143+
shared: {
144+
react: {
145+
include: {
146+
version: "^18.0.0",
147+
fallbackVersion: "^17.0.0"
148+
}
149+
}
150+
}
151+
```
152+
153+
---
154+
155+
### PR 7: nodeModulesReconstructedLookup Feature
156+
**Size**: Medium (~10 files)
157+
**Risk**: Low
158+
**Type**: Feature
159+
**Feature**: Enable path reconstruction for node_modules resolution
160+
161+
**Files to include**:
162+
- `src/lib/sharing/utils.ts` (add `extractPathAfterNodeModules`)
163+
- `src/lib/sharing/ConsumeSharedPlugin.ts` (add two-stage lookup)
164+
- `src/lib/sharing/ProvideSharedPlugin.ts` (add two-stage lookup)
165+
- Schema updates for nodeModulesReconstructedLookup
166+
- `test/configCases/sharing/share-deep-module/*` (new)
167+
- Related unit tests
168+
169+
**Depends on**: PR 4 (uses filtering infrastructure)
170+
171+
---
172+
173+
### PR 8: SharePlugin - Unified API
174+
**Size**: Medium (~8 files)
175+
**Risk**: Low
176+
**Type**: Feature
177+
**Feature**: New SharePlugin that combines consume and provide
178+
179+
**Files to include**:
180+
- `src/lib/sharing/SharePlugin.ts` (add schema validation)
181+
- `src/index.ts` (export SharePlugin)
182+
- `src/schemas/sharing/SharePlugin.json` (new)
183+
- `src/schemas/sharing/SharePlugin.ts` (new)
184+
- `src/schemas/sharing/SharePlugin.check.ts` (new)
185+
- `test/unit/sharing/SharePlugin.test.ts`
186+
- `test/compiler-unit/sharing/SharePlugin.test.ts` (new)
187+
188+
**Depends on**: PR 4-7 (passes through all filtering options)
189+
190+
---
191+
192+
### PR 9: Enhanced Layer Support
193+
**Size**: Small (~6 files)
194+
**Risk**: Low
195+
**Type**: Feature/Fix
196+
**Feature**: Improve layer handling and issuerLayer fallback
197+
198+
**Files to include**:
199+
- `src/lib/sharing/ConsumeSharedModule.ts` (layer parameter)
200+
- `src/lib/sharing/ConsumeSharedFallbackDependency.ts` (layer support)
201+
- `src/lib/sharing/resolveMatchedConfigs.ts` (issuerLayer priority)
202+
- `src/lib/sharing/utils.ts` (createLookupKeyForSharing)
203+
- Layer-specific tests
204+
- Unit tests for issuerLayer fallback (PR #3893)
205+
206+
---
207+
208+
### PR 10: Module Exports and API Surface
209+
**Size**: Tiny (~3 files)
210+
**Risk**: Low
211+
**Type**: Feature
212+
**Feature**: Export internal modules for advanced usage
213+
214+
**Files to include**:
215+
- `src/index.ts` (add ConsumeSharedModule, ProvideSharedModule exports)
216+
- Declaration file updates
217+
- Documentation
218+
219+
---
220+
221+
### PR 11: Comprehensive Test Suite
222+
**Size**: Large (test-only)
223+
**Risk**: None
224+
**Type**: Test
225+
**Feature**: Additional test coverage and edge cases
226+
227+
**Files to include**:
228+
- Remaining test files not included in feature PRs
229+
- `test/helpers/webpack.ts`
230+
- Additional unit test coverage
231+
- Edge case tests
232+
233+
**Depends on**: All feature PRs
234+
235+
---
236+
237+
### PR 12: Package Updates and Cleanup
238+
**Size**: Small
239+
**Risk**: Low
240+
**Type**: Chore
241+
**Feature**: Update dependencies and final cleanup
242+
243+
**Files to include**:
244+
- `package.json`
245+
- `pnpm-lock.yaml`
246+
- `.cursorrules` (editor configuration file)
247+
- `src/scripts/compile-schema.js` (if needed)
248+
249+
## Key Insights from Analysis
250+
251+
1. **Runtime Safety Fixes** are completely independent and should go first
252+
2. **Hook Renaming** is a prerequisite for the hoisting improvements
253+
3. **Share Filtering** can be broken into smaller pieces:
254+
- Version filtering (core functionality)
255+
- Request pattern filtering (builds on version)
256+
- Fallback version support (enhancement)
257+
- nodeModulesReconstructedLookup (separate feature)
258+
4. **Layer Support** improvements are somewhat independent but share some utilities
259+
5. **Test files** are well-organized and can be included with their respective features
260+
261+
## Dependency Graph
262+
263+
```
264+
PR 1 (Runtime Fixes) ──────────────────> (Independent)
265+
266+
PR 2 (Hook Renaming) ──────────────────> PR 3 (Hoisting)
267+
268+
PR 4 (Version Filter) ──┬──> PR 5 (Request Filter)
269+
├──> PR 6 (Fallback Version)
270+
└──> PR 7 (nodeModules Lookup) ──> PR 8 (SharePlugin)
271+
272+
PR 9 (Layer Support) ──────────────────> (Semi-independent)
273+
274+
PR 10 (Exports) ───────────────────────> (Independent)
275+
276+
All Feature PRs ───────────────────────> PR 11 (Tests) ──> PR 12 (Cleanup)
277+
```
278+
279+
## Benefits of This Revised Plan
280+
281+
1. **Clearer Separation**: Each PR has a distinct purpose
282+
2. **Reduced Risk**: Smaller, focused changes are easier to review and test
283+
3. **Flexibility**: Some PRs can be developed in parallel
284+
4. **Progressive Enhancement**: Each filtering feature builds on the previous
285+
5. **Early Wins**: Runtime fixes and hook renaming can be merged quickly

packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimeModule.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ class EmbedFederationRuntimeModule extends RuntimeModule {
7171
` hasRun = true;`,
7272
` ${initRuntimeModuleGetter};`,
7373
`}`,
74-
`return oldStartup();`,
74+
`if (typeof oldStartup === 'function') {`,
75+
` return oldStartup();`,
76+
`} else {`,
77+
` console.warn('[Module Federation] oldStartup is not a function, skipping startup execution');`,
78+
`}`,
7579
],
7680
)};`,
7781
]);

packages/enhanced/src/lib/startup/StartupHelpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export const generateEntryStartup = (
4949
'',
5050
'\n',
5151
'var promises = [];',
52-
'__webpack_require__.x();',
52+
'if (typeof __webpack_require__.x === "function") {',
53+
' __webpack_require__.x();',
54+
'} else {',
55+
' console.warn("[Module Federation] __webpack_require__.x is not a function, skipping startup extension");',
56+
'}',
5357
];
5458

5559
const treeRuntimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);

0 commit comments

Comments
 (0)