Skip to content

Commit cce6a94

Browse files
refactor: rename container hooks for clarity and consistency
Co-authored-by: zackary.l.jackson <zackary.l.jackson@gmail.com>
2 parents 1825b9d + 22eaadc commit cce6a94

File tree

10 files changed

+60
-17
lines changed

10 files changed

+60
-17
lines changed

.changeset/hook-renaming-cleanup.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@module-federation/enhanced": patch
3+
"@module-federation/nextjs-mf": patch
4+
---
5+
6+
refactor: rename container hooks for clarity and consistency
7+
8+
- Renamed `addContainerEntryModule` to `addContainerEntryDependency`
9+
- Renamed `addFederationRuntimeModule` to `addFederationRuntimeDependency`
10+
- Added new `addRemoteDependency` hook for remote module tracking
11+
- Updated all hook usages across the codebase to use new names
12+
- This is an internal refactoring with no breaking changes to external APIs

INCREMENTAL_PR_PLAN_REVISED.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Based on a detailed diff analysis, this document provides a more accurate breakd
2121

2222
### PR 2: Hook Renaming and Cleanup
2323
**Size**: Small (~6 files)
24-
**Risk**: Medium (potential breaking change)
24+
**Risk**: Low (internal refactoring only - all usages updated)
2525
**Type**: Refactor
2626
**Feature**: Rename container hooks for clarity and consistency
2727

@@ -31,18 +31,22 @@ Based on a detailed diff analysis, this document provides a more accurate breakd
3131
- `src/lib/container/runtime/FederationModulesPlugin.ts`
3232
- `src/lib/container/runtime/EmbedFederationRuntimePlugin.ts`
3333
- `src/lib/container/RemoteModule.ts` (use new hook)
34+
- Any other files that reference these hooks
3435

3536
**Changes**:
3637
- `addContainerEntryModule``addContainerEntryDependency`
3738
- `addFederationRuntimeModule``addFederationRuntimeDependency`
3839
- Add new `addRemoteDependency` hook
3940

40-
**Implementation with backward compatibility**:
41+
**Implementation**:
4142
```javascript
43+
// Direct rename - all usages updated in same PR
4244
compiler.hooks.addContainerEntryDependency = new SyncHook([...]);
43-
compiler.hooks.addContainerEntryModule = compiler.hooks.addContainerEntryDependency; // deprecated
45+
compiler.hooks.addFederationRuntimeDependency = new SyncHook([...]);
46+
compiler.hooks.addRemoteDependency = new SyncHook([...]);
4447
```
4548

49+
**Note**: This is NOT a breaking change because all hook usages within the codebase are updated in the same PR.
4650
---
4751

4852
### PR 3: Enhanced HoistContainerReferencesPlugin
@@ -282,4 +286,8 @@ All Feature PRs ─────────────────────
282286
2. **Reduced Risk**: Smaller, focused changes are easier to review and test
283287
3. **Flexibility**: Some PRs can be developed in parallel
284288
4. **Progressive Enhancement**: Each filtering feature builds on the previous
285-
5. **Early Wins**: Runtime fixes and hook renaming can be merged quickly
289+
<<<<<<< HEAD
290+
5. **Early Wins**: Runtime fixes and hook renaming can be merged quickly
291+
=======
292+
5. **Early Wins**: Runtime fixes and hook renaming can be merged quickly
293+
>>>>>>> origin/refactor/hook-renaming-cleanup-v2

packages/enhanced/src/lib/container/ContainerPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class ContainerPlugin {
218218
},
219219
(error: WebpackError | null | undefined) => {
220220
if (error) return reject(error);
221-
hooks.addContainerEntryModule.call(dep);
221+
hooks.addContainerEntryDependency.call(dep);
222222
resolve(undefined);
223223
},
224224
);
@@ -233,7 +233,7 @@ class ContainerPlugin {
233233
if (err) {
234234
return reject(err);
235235
}
236-
hooks.addFederationRuntimeModule.call(
236+
hooks.addFederationRuntimeDependency.call(
237237
federationRuntimeDependency,
238238
);
239239
resolve(undefined);
@@ -291,7 +291,7 @@ class ContainerPlugin {
291291
{ name: undefined },
292292
(error: WebpackError | null | undefined) => {
293293
if (error) return callback(error);
294-
hooks.addContainerEntryModule.call(dep);
294+
hooks.addContainerEntryDependency.call(dep);
295295
callback();
296296
},
297297
);

packages/enhanced/src/lib/container/ContainerReferencePlugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import RemoteToExternalDependency from './RemoteToExternalDependency';
1515
import { parseOptions } from './options';
1616
import { containerReferencePlugin } from '@module-federation/sdk';
1717
import FederationRuntimePlugin from './runtime/FederationRuntimePlugin';
18+
import FederationModulesPlugin from './runtime/FederationModulesPlugin';
1819
import schema from '../../schemas/container/ContainerReferencePlugin';
1920
import checkOptions from '../../schemas/container/ContainerReferencePlugin.check';
2021

@@ -107,6 +108,8 @@ class ContainerReferencePlugin {
107108
new FallbackModuleFactory(),
108109
);
109110

111+
const hooks = FederationModulesPlugin.getCompilationHooks(compilation);
112+
110113
normalModuleFactory.hooks.factorize.tap(
111114
'ContainerReferencePlugin',
112115
//@ts-ignore
@@ -118,7 +121,7 @@ class ContainerReferencePlugin {
118121
(data.request.length === key.length ||
119122
data.request.charCodeAt(key.length) === slashCode)
120123
) {
121-
return new RemoteModule(
124+
const remoteModule = new RemoteModule(
122125
data.request,
123126
//@ts-ignore
124127
config.external.map((external: any, i: any) =>
@@ -132,6 +135,8 @@ class ContainerReferencePlugin {
132135
//@ts-ignore
133136
config.shareScope,
134137
);
138+
hooks.addRemoteDependency.call(remoteModule);
139+
return remoteModule;
135140
}
136141
}
137142
}

packages/enhanced/src/lib/container/HoistContainerReferencesPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export class HoistContainerReferences implements WebpackPluginInstance {
2828
const logger = compilation.getLogger(PLUGIN_NAME);
2929
const hooks = FederationModulesPlugin.getCompilationHooks(compilation);
3030
const containerEntryDependencies = new Set<Dependency>();
31-
hooks.addContainerEntryModule.tap(
31+
hooks.addContainerEntryDependency.tap(
3232
'HoistContainerReferences',
3333
(dep: ContainerEntryDependency) => {
3434
containerEntryDependencies.add(dep);
3535
},
3636
);
37-
hooks.addFederationRuntimeModule.tap(
37+
hooks.addFederationRuntimeDependency.tap(
3838
'HoistContainerReferences',
3939
(dep: FederationRuntimeDependency) => {
4040
containerEntryDependencies.add(dep);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class EmbedFederationRuntimePlugin {
124124
);
125125

126126
// Collect federation runtime dependencies.
127-
federationHooks.addFederationRuntimeModule.tap(
127+
federationHooks.addFederationRuntimeDependency.tap(
128128
PLUGIN_NAME,
129129
(dependency: FederationRuntimeDependency) => {
130130
containerEntrySet.add(dependency);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const PLUGIN_NAME = 'FederationModulesPlugin';
1616
/** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */
1717

1818
type CompilationHooks = {
19-
addContainerEntryModule: SyncHook<[ContainerEntryDependency], void>;
20-
addFederationRuntimeModule: SyncHook<[FederationRuntimeDependency], void>;
19+
addContainerEntryDependency: SyncHook<[ContainerEntryDependency], void>;
20+
addFederationRuntimeDependency: SyncHook<[FederationRuntimeDependency], void>;
21+
addRemoteDependency: SyncHook<[any], void>;
2122
};
2223

2324
class FederationModulesPlugin {
@@ -36,8 +37,9 @@ class FederationModulesPlugin {
3637
let hooks = compilationHooksMap.get(compilation);
3738
if (hooks === undefined) {
3839
hooks = {
39-
addContainerEntryModule: new SyncHook(['dependency']),
40-
addFederationRuntimeModule: new SyncHook(['module']),
40+
addContainerEntryDependency: new SyncHook(['dependency']),
41+
addFederationRuntimeDependency: new SyncHook(['dependency']),
42+
addRemoteDependency: new SyncHook(['dependency']),
4143
};
4244
compilationHooksMap.set(compilation, hooks);
4345
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ class FederationRuntimePlugin {
255255
if (err) {
256256
return callback(err);
257257
}
258-
hooks.addFederationRuntimeModule.call(federationRuntimeDependency);
258+
hooks.addFederationRuntimeDependency.call(
259+
federationRuntimeDependency,
260+
);
259261
callback();
260262
},
261263
);

packages/enhanced/test/unit/container/ContainerReferencePlugin.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ jest.mock('../../../src/lib/container/runtime/FederationRuntimePlugin', () => {
5858
return mockFederationRuntimePlugin;
5959
});
6060

61+
// Mock FederationModulesPlugin
62+
jest.mock('../../../src/lib/container/runtime/FederationModulesPlugin', () => {
63+
return {
64+
__esModule: true,
65+
default: {
66+
getCompilationHooks: jest.fn(() => ({
67+
addContainerEntryDependency: { tap: jest.fn() },
68+
addFederationRuntimeDependency: { tap: jest.fn() },
69+
addRemoteDependency: { tap: jest.fn() },
70+
})),
71+
},
72+
};
73+
});
74+
6175
// Mock FallbackModuleFactory
6276
jest.mock(
6377
'../../../src/lib/container/FallbackModuleFactory',

packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class InvertedContainerPlugin {
1212
(compilation: Compilation) => {
1313
const hooks = FederationModulesPlugin.getCompilationHooks(compilation);
1414
const containers = new Set();
15-
hooks.addContainerEntryModule.tap(
15+
hooks.addContainerEntryDependency.tap(
1616
'EmbeddedContainerPlugin',
1717
(dependency) => {
1818
if (dependency instanceof dependencies.ContainerEntryDependency) {

0 commit comments

Comments
 (0)