Skip to content

Commit 72211ab

Browse files
refactor: always register finishModules hook
1 parent 78f91a0 commit 72211ab

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -869,47 +869,44 @@ class ConsumeSharedPlugin {
869869
);
870870

871871
// Add finishModules hook to copy buildMeta/buildInfo from fallback modules *after* webpack's export analysis
872-
// Guard for test environments where hooks may be lightly stubbed
873-
if (compilation.hooks?.finishModules?.tapAsync) {
874-
compilation.hooks.finishModules.tapAsync(
875-
{
876-
name: PLUGIN_NAME,
877-
stage: 10, // Run after FlagDependencyExportsPlugin (default stage 0)
878-
},
879-
(modules, callback) => {
880-
for (const module of modules) {
881-
// Only process ConsumeSharedModule instances with fallback dependencies
882-
if (
883-
!(module instanceof ConsumeSharedModule) ||
884-
!module.options.import
885-
) {
886-
continue;
887-
}
872+
compilation.hooks.finishModules.tapAsync(
873+
{
874+
name: PLUGIN_NAME,
875+
stage: 10, // Run after FlagDependencyExportsPlugin (default stage 0)
876+
},
877+
(modules, callback) => {
878+
for (const module of modules) {
879+
// Only process ConsumeSharedModule instances with fallback dependencies
880+
if (
881+
!(module instanceof ConsumeSharedModule) ||
882+
!module.options.import
883+
) {
884+
continue;
885+
}
888886

889-
let dependency;
890-
if (module.options.eager) {
891-
dependency = module.dependencies[0];
892-
} else {
893-
dependency = module.blocks[0]?.dependencies[0];
894-
}
887+
let dependency;
888+
if (module.options.eager) {
889+
dependency = module.dependencies[0];
890+
} else {
891+
dependency = module.blocks[0]?.dependencies[0];
892+
}
895893

896-
if (dependency) {
897-
const fallbackModule =
898-
compilation.moduleGraph.getModule(dependency);
899-
if (
900-
fallbackModule &&
901-
fallbackModule.buildMeta &&
902-
fallbackModule.buildInfo
903-
) {
904-
module.buildMeta = { ...fallbackModule.buildMeta };
905-
module.buildInfo = { ...fallbackModule.buildInfo };
906-
}
894+
if (dependency) {
895+
const fallbackModule =
896+
compilation.moduleGraph.getModule(dependency);
897+
if (
898+
fallbackModule &&
899+
fallbackModule.buildMeta &&
900+
fallbackModule.buildInfo
901+
) {
902+
module.buildMeta = { ...fallbackModule.buildMeta };
903+
module.buildInfo = { ...fallbackModule.buildInfo };
907904
}
908905
}
909-
callback();
910-
},
911-
);
912-
}
906+
}
907+
callback();
908+
},
909+
);
913910

914911
compilation.hooks.additionalTreeRuntimeRequirements.tap(
915912
PLUGIN_NAME,

0 commit comments

Comments
 (0)