@module-federation/enhanced 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +2375 -0
- package/dist/README.md +213 -0
- package/dist/rstestmigrate.md +140 -0
- package/dist/src/_virtual/_rolldown/runtime.js +47 -0
- package/dist/src/index.d.ts +22 -19
- package/dist/src/index.js +47 -43
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/Constants.d.ts +25 -29
- package/dist/src/lib/Constants.js +136 -116
- package/dist/src/lib/Constants.js.map +1 -1
- package/dist/src/lib/container/AsyncBoundaryPlugin.d.ts +20 -16
- package/dist/src/lib/container/AsyncBoundaryPlugin.js +137 -200
- package/dist/src/lib/container/AsyncBoundaryPlugin.js.map +1 -1
- package/dist/src/lib/container/ContainerEntryDependency.d.ts +28 -23
- package/dist/src/lib/container/ContainerEntryDependency.js +39 -39
- package/dist/src/lib/container/ContainerEntryDependency.js.map +1 -1
- package/dist/src/lib/container/ContainerEntryModule.d.ts +93 -84
- package/dist/src/lib/container/ContainerEntryModule.js +219 -234
- package/dist/src/lib/container/ContainerEntryModule.js.map +1 -1
- package/dist/src/lib/container/ContainerEntryModuleFactory.d.ts +15 -10
- package/dist/src/lib/container/ContainerEntryModuleFactory.js +21 -25
- package/dist/src/lib/container/ContainerEntryModuleFactory.js.map +1 -1
- package/dist/src/lib/container/ContainerExposedDependency.d.ts +29 -24
- package/dist/src/lib/container/ContainerExposedDependency.js +47 -47
- package/dist/src/lib/container/ContainerExposedDependency.js.map +1 -1
- package/dist/src/lib/container/ContainerPlugin.d.ts +12 -8
- package/dist/src/lib/container/ContainerPlugin.js +147 -211
- package/dist/src/lib/container/ContainerPlugin.js.map +1 -1
- package/dist/src/lib/container/ContainerReferencePlugin.d.ts +16 -12
- package/dist/src/lib/container/ContainerReferencePlugin.js +74 -102
- package/dist/src/lib/container/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/lib/container/FallbackDependency.d.ts +24 -19
- package/dist/src/lib/container/FallbackDependency.js +46 -44
- package/dist/src/lib/container/FallbackDependency.js.map +1 -1
- package/dist/src/lib/container/FallbackItemDependency.d.ts +13 -8
- package/dist/src/lib/container/FallbackItemDependency.js +24 -24
- package/dist/src/lib/container/FallbackItemDependency.js.map +1 -1
- package/dist/src/lib/container/FallbackModule.d.ts +82 -71
- package/dist/src/lib/container/FallbackModule.js +133 -145
- package/dist/src/lib/container/FallbackModule.js.map +1 -1
- package/dist/src/lib/container/FallbackModuleFactory.d.ts +15 -10
- package/dist/src/lib/container/FallbackModuleFactory.js +20 -24
- package/dist/src/lib/container/FallbackModuleFactory.js.map +1 -1
- package/dist/src/lib/container/HoistContainerReferencesPlugin.d.ts +11 -7
- package/dist/src/lib/container/HoistContainerReferencesPlugin.js +125 -188
- package/dist/src/lib/container/HoistContainerReferencesPlugin.js.map +1 -1
- package/dist/src/lib/container/ModuleFederationPlugin.d.ts +20 -16
- package/dist/src/lib/container/ModuleFederationPlugin.js +143 -181
- package/dist/src/lib/container/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/lib/container/RemoteModule.d.ts +79 -74
- package/dist/src/lib/container/RemoteModule.js +143 -153
- package/dist/src/lib/container/RemoteModule.js.map +1 -1
- package/dist/src/lib/container/RemoteRuntimeModule.d.ts +12 -7
- package/dist/src/lib/container/RemoteRuntimeModule.js +86 -132
- package/dist/src/lib/container/RemoteRuntimeModule.js.map +1 -1
- package/dist/src/lib/container/RemoteToExternalDependency.d.ts +13 -8
- package/dist/src/lib/container/RemoteToExternalDependency.js +25 -23
- package/dist/src/lib/container/RemoteToExternalDependency.js.map +1 -1
- package/dist/src/lib/container/constant.d.ts +3 -0
- package/dist/src/lib/container/constant.js +11 -14
- package/dist/src/lib/container/constant.js.map +1 -1
- package/dist/src/lib/container/options.d.ts +7 -3
- package/dist/src/lib/container/options.js +51 -69
- package/dist/src/lib/container/options.js.map +1 -1
- package/dist/src/lib/container/runtime/EmbedFederationRuntimeModule.d.ts +14 -9
- package/dist/src/lib/container/runtime/EmbedFederationRuntimeModule.js +56 -64
- package/dist/src/lib/container/runtime/EmbedFederationRuntimeModule.js.map +1 -1
- package/dist/src/lib/container/runtime/EmbedFederationRuntimePlugin.d.ts +23 -19
- package/dist/src/lib/container/runtime/EmbedFederationRuntimePlugin.js +71 -101
- package/dist/src/lib/container/runtime/EmbedFederationRuntimePlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationModulesPlugin.d.ts +20 -16
- package/dist/src/lib/container/runtime/FederationModulesPlugin.js +55 -47
- package/dist/src/lib/container/runtime/FederationModulesPlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimeDependency.d.ts +9 -4
- package/dist/src/lib/container/runtime/FederationRuntimeDependency.js +16 -12
- package/dist/src/lib/container/runtime/FederationRuntimeDependency.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimeModule.d.ts +16 -11
- package/dist/src/lib/container/runtime/FederationRuntimeModule.js +39 -46
- package/dist/src/lib/container/runtime/FederationRuntimeModule.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.d.ts +31 -20
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +265 -358
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/getFederationGlobal.d.ts +9 -4
- package/dist/src/lib/container/runtime/getFederationGlobal.js +43 -41
- package/dist/src/lib/container/runtime/getFederationGlobal.js.map +1 -1
- package/dist/src/lib/container/runtime/utils.d.ts +24 -13
- package/dist/src/lib/container/runtime/utils.js +83 -101
- package/dist/src/lib/container/runtime/utils.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedFallbackDependency.d.ts +15 -10
- package/dist/src/lib/sharing/ConsumeSharedFallbackDependency.js +27 -25
- package/dist/src/lib/sharing/ConsumeSharedFallbackDependency.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedModule.d.ts +77 -68
- package/dist/src/lib/sharing/ConsumeSharedModule.js +186 -214
- package/dist/src/lib/sharing/ConsumeSharedModule.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedPlugin.d.ts +13 -9
- package/dist/src/lib/sharing/ConsumeSharedPlugin.js +308 -475
- package/dist/src/lib/sharing/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.d.ts +16 -11
- package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js +107 -137
- package/dist/src/lib/sharing/ConsumeSharedRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/ProvideForSharedDependency.d.ts +14 -9
- package/dist/src/lib/sharing/ProvideForSharedDependency.js +25 -25
- package/dist/src/lib/sharing/ProvideForSharedDependency.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedDependency.d.ts +44 -39
- package/dist/src/lib/sharing/ProvideSharedDependency.js +72 -76
- package/dist/src/lib/sharing/ProvideSharedDependency.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedModule.d.ts +91 -82
- package/dist/src/lib/sharing/ProvideSharedModule.js +177 -184
- package/dist/src/lib/sharing/ProvideSharedModule.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedModuleFactory.d.ts +14 -9
- package/dist/src/lib/sharing/ProvideSharedModuleFactory.js +19 -25
- package/dist/src/lib/sharing/ProvideSharedModuleFactory.js.map +1 -1
- package/dist/src/lib/sharing/ProvideSharedPlugin.d.ts +27 -21
- package/dist/src/lib/sharing/ProvideSharedPlugin.js +341 -550
- package/dist/src/lib/sharing/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/SharePlugin.d.ts +53 -49
- package/dist/src/lib/sharing/SharePlugin.js +86 -100
- package/dist/src/lib/sharing/SharePlugin.js.map +1 -1
- package/dist/src/lib/sharing/ShareRuntimeModule.d.ts +12 -7
- package/dist/src/lib/sharing/ShareRuntimeModule.js +81 -103
- package/dist/src/lib/sharing/ShareRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/resolveMatchedConfigs.d.ts +11 -7
- package/dist/src/lib/sharing/resolveMatchedConfigs.js +58 -71
- package/dist/src/lib/sharing/resolveMatchedConfigs.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.d.ts +18 -14
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.js +74 -128
- package/dist/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.d.ts +39 -34
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js +234 -328
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.d.ts +16 -11
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.js +30 -28
- package/dist/src/lib/sharing/tree-shaking/IndependentSharedRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.d.ts +28 -24
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js +91 -95
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedContainerPlugin.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.d.ts +29 -24
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js +47 -43
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.d.ts +20 -15
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js +33 -29
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.d.ts +85 -77
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js +141 -153
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.d.ts +15 -10
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.js +20 -24
- package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModuleFactory.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.d.ts +21 -16
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.js +157 -231
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerPlugin.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.d.ts +14 -9
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.js +26 -27
- package/dist/src/lib/sharing/tree-shaking/SharedUsedExportsOptimizerRuntimeModule.js.map +1 -1
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.d.ts +18 -13
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.js +41 -49
- package/dist/src/lib/sharing/tree-shaking/TreeShakingSharedPlugin.js.map +1 -1
- package/dist/src/lib/sharing/utils.d.ts +27 -24
- package/dist/src/lib/sharing/utils.js +224 -367
- package/dist/src/lib/sharing/utils.js.map +1 -1
- package/dist/src/lib/startup/MfStartupChunkDependenciesPlugin.d.ts +11 -7
- package/dist/src/lib/startup/MfStartupChunkDependenciesPlugin.js +56 -75
- package/dist/src/lib/startup/MfStartupChunkDependenciesPlugin.js.map +1 -1
- package/dist/src/lib/startup/StartupHelpers.d.ts +11 -6
- package/dist/src/lib/startup/StartupHelpers.js +128 -178
- package/dist/src/lib/startup/StartupHelpers.js.map +1 -1
- package/dist/src/prefetch.d.ts +3 -2
- package/dist/src/prefetch.js +17 -8
- package/dist/src/rspack.d.ts +3 -2
- package/dist/src/rspack.js +35 -11
- package/dist/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +8 -4
- package/dist/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -16
- package/dist/src/runtime/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -1
- package/dist/src/runtime.d.ts +1 -1
- package/dist/src/runtime.js +11 -18
- package/dist/src/schemas/container/ContainerPlugin.check.d.ts +13 -5
- package/dist/src/schemas/container/ContainerPlugin.check.js +958 -1218
- package/dist/src/schemas/container/ContainerPlugin.check.js.map +1 -1
- package/dist/src/schemas/container/ContainerPlugin.d.ts +271 -268
- package/dist/src/schemas/container/ContainerPlugin.js +273 -361
- package/dist/src/schemas/container/ContainerPlugin.js.map +1 -1
- package/dist/src/schemas/container/ContainerReferencePlugin.check.d.ts +13 -5
- package/dist/src/schemas/container/ContainerReferencePlugin.check.js +335 -443
- package/dist/src/schemas/container/ContainerReferencePlugin.check.js.map +1 -1
- package/dist/src/schemas/container/ContainerReferencePlugin.d.ts +102 -99
- package/dist/src/schemas/container/ContainerReferencePlugin.js +122 -162
- package/dist/src/schemas/container/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/schemas/container/ExternalsType.check.d.ts +13 -5
- package/dist/src/schemas/container/ExternalsType.check.js +36 -62
- package/dist/src/schemas/container/ExternalsType.check.js.map +1 -1
- package/dist/src/schemas/container/ExternalsType.d.ts +5 -2
- package/dist/src/schemas/container/ExternalsType.js +8 -11
- package/dist/src/schemas/container/ExternalsType.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js +3001 -4812
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.d.ts +819 -814
- package/dist/src/schemas/container/ModuleFederationPlugin.js +780 -1053
- package/dist/src/schemas/container/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.check.d.ts +13 -5
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.check.js +568 -768
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.d.ts +197 -194
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.js +212 -238
- package/dist/src/schemas/sharing/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.d.ts +13 -5
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.js +598 -804
- package/dist/src/schemas/sharing/ProvideSharedPlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/ProvideSharedPlugin.d.ts +184 -181
- package/dist/src/schemas/sharing/ProvideSharedPlugin.js +196 -229
- package/dist/src/schemas/sharing/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/ProviderSharedPlugin.check.d.ts +12 -4
- package/dist/src/schemas/sharing/ProviderSharedPlugin.check.js +285 -482
- package/dist/src/schemas/sharing/ProviderSharedPlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/ProviderSharedPlugin.d.ts +103 -100
- package/dist/src/schemas/sharing/ProviderSharedPlugin.js +104 -126
- package/dist/src/schemas/sharing/ProviderSharedPlugin.js.map +1 -1
- package/dist/src/schemas/sharing/SharePlugin.check.d.ts +13 -5
- package/dist/src/schemas/sharing/SharePlugin.check.js +749 -965
- package/dist/src/schemas/sharing/SharePlugin.check.js.map +1 -1
- package/dist/src/schemas/sharing/SharePlugin.d.ts +245 -242
- package/dist/src/schemas/sharing/SharePlugin.js +256 -293
- package/dist/src/schemas/sharing/SharePlugin.js.map +1 -1
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +35 -26
- package/dist/src/utils.js.map +1 -1
- package/dist/src/webpack.d.ts +2 -2
- package/dist/src/webpack.js +6 -40
- package/dist/src/wrapper/AsyncBoundaryPlugin.d.ts +9 -4
- package/dist/src/wrapper/AsyncBoundaryPlugin.js +12 -11
- package/dist/src/wrapper/AsyncBoundaryPlugin.js.map +1 -1
- package/dist/src/wrapper/BaseWrapperPlugin.d.ts +18 -13
- package/dist/src/wrapper/BaseWrapperPlugin.js +39 -39
- package/dist/src/wrapper/BaseWrapperPlugin.js.map +1 -1
- package/dist/src/wrapper/ConsumeSharedPlugin.d.ts +10 -4
- package/dist/src/wrapper/ConsumeSharedPlugin.js +12 -11
- package/dist/src/wrapper/ConsumeSharedPlugin.js.map +1 -1
- package/dist/src/wrapper/ContainerPlugin.d.ts +9 -4
- package/dist/src/wrapper/ContainerPlugin.js +12 -11
- package/dist/src/wrapper/ContainerPlugin.js.map +1 -1
- package/dist/src/wrapper/ContainerReferencePlugin.d.ts +9 -4
- package/dist/src/wrapper/ContainerReferencePlugin.js +12 -11
- package/dist/src/wrapper/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/wrapper/FederationModulesPlugin.d.ts +18 -10
- package/dist/src/wrapper/FederationModulesPlugin.js +19 -19
- package/dist/src/wrapper/FederationModulesPlugin.js.map +1 -1
- package/dist/src/wrapper/FederationRuntimePlugin.d.ts +11 -6
- package/dist/src/wrapper/FederationRuntimePlugin.js +18 -17
- package/dist/src/wrapper/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/wrapper/HoistContainerReferencesPlugin.d.ts +8 -3
- package/dist/src/wrapper/HoistContainerReferencesPlugin.js +12 -11
- package/dist/src/wrapper/HoistContainerReferencesPlugin.js.map +1 -1
- package/dist/src/wrapper/ModuleFederationPlugin.d.ts +12 -7
- package/dist/src/wrapper/ModuleFederationPlugin.js +73 -99
- package/dist/src/wrapper/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/wrapper/ProvideSharedPlugin.d.ts +10 -4
- package/dist/src/wrapper/ProvideSharedPlugin.js +12 -11
- package/dist/src/wrapper/ProvideSharedPlugin.js.map +1 -1
- package/dist/src/wrapper/SharePlugin.d.ts +10 -4
- package/dist/src/wrapper/SharePlugin.js +12 -11
- package/dist/src/wrapper/SharePlugin.js.map +1 -1
- package/dist/src/wrapper/TreeShakingSharedPlugin.d.ts +9 -4
- package/dist/src/wrapper/TreeShakingSharedPlugin.js +12 -11
- package/dist/src/wrapper/TreeShakingSharedPlugin.js.map +1 -1
- package/package.json +23 -14
- package/dist/package.json +0 -110
- package/dist/src/declarations/plugins/container/AsyncDependenciesBlock.d.ts +0 -57
- package/dist/src/declarations/plugins/container/ModuleFactory.d.ts +0 -33
- package/dist/src/declarations/plugins/container/ObjectDeserializerContext.d.ts +0 -4
- package/dist/src/declarations/plugins/container/StaticExportsDependency.d.ts +0 -28
- package/dist/src/declarations/plugins/container/Template.d.ts +0 -198
- package/dist/src/declarations/plugins/container/WebpackError.d.ts +0 -33
- package/dist/src/declarations/plugins/sharing/ConsumeSharedModule.d.ts +0 -86
- package/dist/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts +0 -100
- package/dist/src/declarations/plugins/sharing/ProvideSharedPlugin.d.ts +0 -102
- package/dist/src/declarations/plugins/sharing/SharePlugin.d.ts +0 -116
- package/dist/src/lib/container/runtime/ChildCompilationRuntimePlugin.d.ts +0 -20
- package/dist/src/lib/container/runtime/ChildCompilationRuntimePlugin.js +0 -222
- package/dist/src/lib/container/runtime/ChildCompilationRuntimePlugin.js.map +0 -1
- package/dist/src/prefetch.js.map +0 -1
- package/dist/src/rspack.js.map +0 -1
- package/dist/src/runtime.js.map +0 -1
- package/dist/src/types/runtime.d.ts +0 -10
- package/dist/src/types/runtime.js +0 -3
- package/dist/src/types/runtime.js.map +0 -1
- package/dist/src/webpack.js.map +0 -1
|
@@ -1,363 +1,270 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (compiler.options.output?.module) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const library = compiler.options.output?.library;
|
|
42
|
-
if (library &&
|
|
43
|
-
typeof library === 'object' &&
|
|
44
|
-
!Array.isArray(library) &&
|
|
45
|
-
'type' in library) {
|
|
46
|
-
return library.type === 'module';
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
3
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./FederationModulesPlugin.js');
|
|
4
|
+
const require_lib_container_runtime_utils = require('./utils.js');
|
|
5
|
+
const require_lib_container_runtime_FederationRuntimeModule = require('./FederationRuntimeModule.js');
|
|
6
|
+
const require_lib_container_constant = require('../constant.js');
|
|
7
|
+
const require_lib_container_runtime_EmbedFederationRuntimePlugin = require('./EmbedFederationRuntimePlugin.js');
|
|
8
|
+
const require_lib_container_HoistContainerReferencesPlugin = require('../HoistContainerReferencesPlugin.js');
|
|
9
|
+
const require_lib_container_runtime_FederationRuntimeDependency = require('./FederationRuntimeDependency.js');
|
|
10
|
+
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
11
|
+
let path = require("path");
|
|
12
|
+
path = require_runtime.__toESM(path);
|
|
13
|
+
let fs = require("fs");
|
|
14
|
+
fs = require_runtime.__toESM(fs);
|
|
15
|
+
let _module_federation_data_prefetch_cli = require("@module-federation/data-prefetch/cli");
|
|
16
|
+
let btoa = require("btoa");
|
|
17
|
+
btoa = require_runtime.__toESM(btoa);
|
|
18
|
+
|
|
19
|
+
//#region src/lib/container/runtime/FederationRuntimePlugin.ts
|
|
20
|
+
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
21
|
+
const ModuleDependency = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/dependencies/ModuleDependency"));
|
|
22
|
+
const { RuntimeGlobals, Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
23
|
+
const { mkdirpSync } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/fs"));
|
|
24
|
+
function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
|
|
25
|
+
const candidates = [
|
|
26
|
+
spec.bundler,
|
|
27
|
+
spec.esm,
|
|
28
|
+
spec.cjs
|
|
29
|
+
];
|
|
30
|
+
const modulePaths = implementation ? [implementation] : void 0;
|
|
31
|
+
let lastError;
|
|
32
|
+
for (const candidate of candidates) try {
|
|
33
|
+
return modulePaths ? resolve(candidate, { paths: modulePaths }) : resolve(candidate);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
lastError = error;
|
|
36
|
+
}
|
|
37
|
+
throw lastError;
|
|
49
38
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
? [`${packageName}/dist/index.esm.js`, `${packageName}/dist/index.cjs.cjs`]
|
|
56
|
-
: [`${packageName}/dist/index.cjs.cjs`, `${packageName}/dist/index.esm.js`];
|
|
57
|
-
// Keep legacy dist entry names as fallbacks for mixed plugin/runtime versions.
|
|
58
|
-
// Resolve package root last to avoid accidentally selecting a CJS export when
|
|
59
|
-
// an explicit ESM fallback file exists in legacy runtime layouts.
|
|
60
|
-
return [...preferred, ...legacyFallback, packageName];
|
|
39
|
+
function resolveRuntimeEntryWithFallback(spec, implementation, resolve = require.resolve) {
|
|
40
|
+
if (implementation) try {
|
|
41
|
+
return resolveRuntimeEntry(spec, implementation, resolve);
|
|
42
|
+
} catch {}
|
|
43
|
+
return resolveRuntimeEntry(spec, void 0, resolve);
|
|
61
44
|
}
|
|
62
|
-
function resolveRuntimePaths(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
class FederationRuntimePlugin {
|
|
83
|
-
constructor(options) {
|
|
84
|
-
this.options = options ? { ...options } : undefined;
|
|
85
|
-
this.entryFilePath = '';
|
|
86
|
-
this.bundlerRuntimePath = BundlerRuntimePath;
|
|
87
|
-
this.runtimePath = RuntimePath;
|
|
88
|
-
this.runtimeToolsPath = RuntimeToolsPath;
|
|
89
|
-
this.federationRuntimeDependency = undefined; // Initialize as undefined
|
|
90
|
-
}
|
|
91
|
-
static getTemplate(compiler, options, bundlerRuntimePath) {
|
|
92
|
-
// internal runtime plugin
|
|
93
|
-
const runtimePlugins = options.runtimePlugins;
|
|
94
|
-
const normalizedBundlerRuntimePath = (0, utils_1.normalizeToPosixPath)(bundlerRuntimePath || BundlerRuntimePath);
|
|
95
|
-
let runtimePluginTemplates = '';
|
|
96
|
-
const runtimePluginCalls = [];
|
|
97
|
-
if (Array.isArray(runtimePlugins)) {
|
|
98
|
-
runtimePlugins.forEach((runtimePlugin, index) => {
|
|
99
|
-
if (!runtimePlugin) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const runtimePluginName = `plugin_${index}`;
|
|
103
|
-
const runtimePluginEntry = Array.isArray(runtimePlugin)
|
|
104
|
-
? runtimePlugin[0]
|
|
105
|
-
: runtimePlugin;
|
|
106
|
-
const runtimePluginPath = (0, utils_1.normalizeToPosixPath)(path_1.default.isAbsolute(runtimePluginEntry)
|
|
107
|
-
? runtimePluginEntry
|
|
108
|
-
: path_1.default.join(process.cwd(), runtimePluginEntry));
|
|
109
|
-
const paramsStr = Array.isArray(runtimePlugin) && runtimePlugin.length > 1
|
|
110
|
-
? JSON.stringify(runtimePlugin[1])
|
|
111
|
-
: 'undefined';
|
|
112
|
-
runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
|
|
113
|
-
runtimePluginCalls.push(`${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const embedRuntimeLines = Template.asString([
|
|
117
|
-
`if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,
|
|
118
|
-
Template.indent([
|
|
119
|
-
`var prevFederation = ${federationGlobal};`,
|
|
120
|
-
`${federationGlobal} = {}`,
|
|
121
|
-
`for(var key in federation){`,
|
|
122
|
-
Template.indent([`${federationGlobal}[key] = federation[key];`]),
|
|
123
|
-
'}',
|
|
124
|
-
`for(var key in prevFederation){`,
|
|
125
|
-
Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),
|
|
126
|
-
'}',
|
|
127
|
-
]),
|
|
128
|
-
'}',
|
|
129
|
-
]);
|
|
130
|
-
return Template.asString([
|
|
131
|
-
`import federation from '${normalizedBundlerRuntimePath}';`,
|
|
132
|
-
runtimePluginTemplates,
|
|
133
|
-
embedRuntimeLines,
|
|
134
|
-
`if(!${federationGlobal}.instance){`,
|
|
135
|
-
Template.indent([
|
|
136
|
-
runtimePluginCalls.length
|
|
137
|
-
? Template.asString([
|
|
138
|
-
`var pluginsToAdd = [`,
|
|
139
|
-
Template.indent(Template.indent(runtimePluginCalls.map((call) => `${call},`))),
|
|
140
|
-
`].filter(Boolean);`,
|
|
141
|
-
`${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,
|
|
142
|
-
`${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`,
|
|
143
|
-
])
|
|
144
|
-
: '',
|
|
145
|
-
// `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,
|
|
146
|
-
`${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,
|
|
147
|
-
`if(${federationGlobal}.attachShareScopeMap){`,
|
|
148
|
-
Template.indent([
|
|
149
|
-
`${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,
|
|
150
|
-
]),
|
|
151
|
-
'}',
|
|
152
|
-
`if(${federationGlobal}.installInitialConsumes){`,
|
|
153
|
-
Template.indent([`${federationGlobal}.installInitialConsumes()`]),
|
|
154
|
-
'}',
|
|
155
|
-
]),
|
|
156
|
-
cli_1.PrefetchPlugin.addRuntime(compiler, {
|
|
157
|
-
name: options.name,
|
|
158
|
-
}),
|
|
159
|
-
'}',
|
|
160
|
-
]);
|
|
161
|
-
}
|
|
162
|
-
getFilePath(compiler) {
|
|
163
|
-
if (!this.options) {
|
|
164
|
-
return '';
|
|
165
|
-
}
|
|
166
|
-
const existedFilePath = onceForCompilerEntryMap.get(compiler);
|
|
167
|
-
if (existedFilePath) {
|
|
168
|
-
return existedFilePath;
|
|
169
|
-
}
|
|
170
|
-
let entryFilePath = '';
|
|
171
|
-
if (!this.options?.virtualRuntimeEntry) {
|
|
172
|
-
const containerName = this.options.name;
|
|
173
|
-
const hash = (0, utils_1.createHash)(`${containerName} ${FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath)}`);
|
|
174
|
-
entryFilePath = path_1.default.join(constant_1.TEMP_DIR, `entry.${hash}.js`);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
entryFilePath = `data:text/javascript;charset=utf-8;base64,${(0, btoa_1.default)(FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath))}`;
|
|
178
|
-
}
|
|
179
|
-
onceForCompilerEntryMap.set(compiler, entryFilePath);
|
|
180
|
-
return entryFilePath;
|
|
181
|
-
}
|
|
182
|
-
ensureFile(compiler) {
|
|
183
|
-
if (!this.options) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
// skip virtual entry
|
|
187
|
-
if (this.options?.virtualRuntimeEntry) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const filePath = this.entryFilePath;
|
|
191
|
-
const outputFs = compiler
|
|
192
|
-
.outputFileSystem;
|
|
193
|
-
const fsLike = outputFs &&
|
|
194
|
-
typeof outputFs.readFileSync === 'function' &&
|
|
195
|
-
typeof outputFs.writeFileSync === 'function'
|
|
196
|
-
? outputFs
|
|
197
|
-
: fs_1.default;
|
|
198
|
-
try {
|
|
199
|
-
fsLike.readFileSync(filePath);
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
mkdirpSync(fsLike, constant_1.TEMP_DIR);
|
|
203
|
-
fsLike.writeFileSync(filePath, FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
getDependency(compiler) {
|
|
207
|
-
if (this.federationRuntimeDependency)
|
|
208
|
-
return this.federationRuntimeDependency;
|
|
209
|
-
this.ensureFile(compiler);
|
|
210
|
-
this.federationRuntimeDependency = new FederationRuntimeDependency_1.default(this.entryFilePath);
|
|
211
|
-
return this.federationRuntimeDependency;
|
|
212
|
-
}
|
|
213
|
-
prependEntry(compiler) {
|
|
214
|
-
if (!this.options?.virtualRuntimeEntry) {
|
|
215
|
-
this.ensureFile(compiler);
|
|
216
|
-
}
|
|
217
|
-
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
|
|
218
|
-
compilation.dependencyFactories.set(FederationRuntimeDependency_1.default, normalModuleFactory);
|
|
219
|
-
compilation.dependencyTemplates.set(FederationRuntimeDependency_1.default, new ModuleDependency.Template());
|
|
220
|
-
});
|
|
221
|
-
compiler.hooks.make.tapAsync(this.constructor.name, (compilation, callback) => {
|
|
222
|
-
const federationRuntimeDependency = this.getDependency(compiler);
|
|
223
|
-
const hooks = FederationModulesPlugin_1.default.getCompilationHooks(compilation);
|
|
224
|
-
compilation.addInclude(compiler.context, federationRuntimeDependency, { name: undefined }, (err, module) => {
|
|
225
|
-
if (err) {
|
|
226
|
-
return callback(err);
|
|
227
|
-
}
|
|
228
|
-
hooks.addFederationRuntimeDependency.call(federationRuntimeDependency);
|
|
229
|
-
callback();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
injectRuntime(compiler) {
|
|
234
|
-
if (!this.options || !this.options.name) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const name = this.options.name;
|
|
238
|
-
const initOptionsWithoutShared = (0, utils_1.normalizeRuntimeInitOptionsWithOutShared)(this.options);
|
|
239
|
-
const federationGlobal = (0, utils_1.getFederationGlobalScope)(RuntimeGlobals || {});
|
|
240
|
-
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
|
|
241
|
-
const handler = (chunk, runtimeRequirements) => {
|
|
242
|
-
if (runtimeRequirements.has(federationGlobal))
|
|
243
|
-
return;
|
|
244
|
-
runtimeRequirements.add(federationGlobal);
|
|
245
|
-
runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);
|
|
246
|
-
runtimeRequirements.add(RuntimeGlobals.moduleCache);
|
|
247
|
-
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
|
248
|
-
compilation.addRuntimeModule(chunk, new FederationRuntimeModule_1.default(runtimeRequirements, name, initOptionsWithoutShared));
|
|
249
|
-
};
|
|
250
|
-
compilation.hooks.additionalTreeRuntimeRequirements.tap(this.constructor.name, (chunk, runtimeRequirements) => {
|
|
251
|
-
if (!chunk.hasRuntime())
|
|
252
|
-
return;
|
|
253
|
-
if (runtimeRequirements.has(RuntimeGlobals.initializeSharing))
|
|
254
|
-
return;
|
|
255
|
-
if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope))
|
|
256
|
-
return;
|
|
257
|
-
if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap))
|
|
258
|
-
return;
|
|
259
|
-
if (runtimeRequirements.has(federationGlobal))
|
|
260
|
-
return;
|
|
261
|
-
handler(chunk, runtimeRequirements);
|
|
262
|
-
});
|
|
263
|
-
// if federation runtime requirements exist
|
|
264
|
-
// attach runtime module to the chunk
|
|
265
|
-
compilation.hooks.runtimeRequirementInTree
|
|
266
|
-
.for(RuntimeGlobals.initializeSharing)
|
|
267
|
-
.tap(this.constructor.name, handler);
|
|
268
|
-
compilation.hooks.runtimeRequirementInTree
|
|
269
|
-
.for(RuntimeGlobals.currentRemoteGetScope)
|
|
270
|
-
.tap(this.constructor.name, handler);
|
|
271
|
-
compilation.hooks.runtimeRequirementInTree
|
|
272
|
-
.for(RuntimeGlobals.shareScopeMap)
|
|
273
|
-
.tap(this.constructor.name, handler);
|
|
274
|
-
compilation.hooks.runtimeRequirementInTree
|
|
275
|
-
.for(federationGlobal)
|
|
276
|
-
.tap(this.constructor.name, handler);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
getRuntimeAlias(compiler) {
|
|
280
|
-
const { implementation } = this.options || {};
|
|
281
|
-
const alias = compiler.options.resolve.alias || {};
|
|
282
|
-
const resolvedPaths = resolveRuntimePaths(isEsmOutputBuild(compiler), implementation);
|
|
283
|
-
this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;
|
|
284
|
-
this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;
|
|
285
|
-
if (alias['@module-federation/runtime$']) {
|
|
286
|
-
this.runtimePath = alias['@module-federation/runtime$'];
|
|
287
|
-
return this.runtimePath;
|
|
288
|
-
}
|
|
289
|
-
this.runtimePath = resolvedPaths.runtimePath;
|
|
290
|
-
return this.runtimePath;
|
|
291
|
-
}
|
|
292
|
-
setRuntimeAlias(compiler) {
|
|
293
|
-
const { implementation } = this.options || {};
|
|
294
|
-
const alias = compiler.options.resolve.alias || {};
|
|
295
|
-
const runtimePath = this.getRuntimeAlias(compiler);
|
|
296
|
-
alias['@module-federation/runtime$'] =
|
|
297
|
-
alias['@module-federation/runtime$'] || runtimePath;
|
|
298
|
-
alias['@module-federation/runtime-tools$'] =
|
|
299
|
-
alias['@module-federation/runtime-tools$'] ||
|
|
300
|
-
implementation ||
|
|
301
|
-
this.runtimeToolsPath;
|
|
302
|
-
// Set up aliases for the federation runtime and tools
|
|
303
|
-
// This ensures that the correct versions are used throughout the project
|
|
304
|
-
compiler.options.resolve.alias = alias;
|
|
305
|
-
}
|
|
306
|
-
apply(compiler) {
|
|
307
|
-
const useSharedContainerPlugin = compiler.options.plugins.find((p) => {
|
|
308
|
-
if (typeof p !== 'object' || !p) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
return p['name'] === 'SharedContainerPlugin';
|
|
312
|
-
});
|
|
313
|
-
// share container plugin should not inject mf runtime
|
|
314
|
-
if (useSharedContainerPlugin) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const useModuleFederationPlugin = compiler.options.plugins.find((p) => {
|
|
318
|
-
if (typeof p !== 'object' || !p) {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
return p['name'] === 'ModuleFederationPlugin';
|
|
322
|
-
});
|
|
323
|
-
if (useModuleFederationPlugin && !this.options) {
|
|
324
|
-
this.options = useModuleFederationPlugin._options;
|
|
325
|
-
}
|
|
326
|
-
const useContainerPlugin = compiler.options.plugins.find((p) => {
|
|
327
|
-
if (typeof p !== 'object' || !p) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
return p['name'] === 'ContainerPlugin';
|
|
331
|
-
});
|
|
332
|
-
if (useContainerPlugin && !this.options) {
|
|
333
|
-
this.options = useContainerPlugin._options;
|
|
334
|
-
}
|
|
335
|
-
if (!useContainerPlugin && !useModuleFederationPlugin) {
|
|
336
|
-
this.options = {
|
|
337
|
-
remotes: {},
|
|
338
|
-
...this.options,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
if (this.options && !this.options?.name) {
|
|
342
|
-
//! the instance may get the same one if the name is the same https://github.com/module-federation/core/blob/main/packages/runtime/src/index.ts#L18
|
|
343
|
-
this.options.name =
|
|
344
|
-
compiler.options.output.uniqueName || `container_${Date.now()}`;
|
|
345
|
-
}
|
|
346
|
-
const resolvedPaths = resolveRuntimePaths(isEsmOutputBuild(compiler), this.options?.implementation);
|
|
347
|
-
this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;
|
|
348
|
-
this.runtimePath = resolvedPaths.runtimePath;
|
|
349
|
-
this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;
|
|
350
|
-
this.entryFilePath = this.getFilePath(compiler);
|
|
351
|
-
new EmbedFederationRuntimePlugin_1.default().apply(compiler);
|
|
352
|
-
new HoistContainerReferencesPlugin_1.default().apply(compiler);
|
|
353
|
-
// dont run multiple times on every apply()
|
|
354
|
-
if (!onceForCompiler.has(compiler)) {
|
|
355
|
-
this.prependEntry(compiler);
|
|
356
|
-
this.injectRuntime(compiler);
|
|
357
|
-
this.setRuntimeAlias(compiler);
|
|
358
|
-
onceForCompiler.add(compiler);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
45
|
+
function resolveRuntimePaths(implementation, resolve = require.resolve) {
|
|
46
|
+
const runtimeToolsPath = resolveRuntimeEntryWithFallback({
|
|
47
|
+
bundler: "@module-federation/runtime-tools/bundler",
|
|
48
|
+
esm: "@module-federation/runtime-tools/dist/index.js",
|
|
49
|
+
cjs: "@module-federation/runtime-tools/dist/index.cjs"
|
|
50
|
+
}, implementation, resolve);
|
|
51
|
+
const moduleBase = implementation || runtimeToolsPath;
|
|
52
|
+
return {
|
|
53
|
+
runtimeToolsPath,
|
|
54
|
+
bundlerRuntimePath: resolveRuntimeEntry({
|
|
55
|
+
bundler: "@module-federation/webpack-bundler-runtime/bundler",
|
|
56
|
+
esm: "@module-federation/webpack-bundler-runtime/dist/index.js",
|
|
57
|
+
cjs: "@module-federation/webpack-bundler-runtime/dist/index.cjs"
|
|
58
|
+
}, moduleBase, resolve),
|
|
59
|
+
runtimePath: resolveRuntimeEntry({
|
|
60
|
+
bundler: "@module-federation/runtime/bundler",
|
|
61
|
+
esm: "@module-federation/runtime/dist/index.js",
|
|
62
|
+
cjs: "@module-federation/runtime/dist/index.cjs"
|
|
63
|
+
}, moduleBase, resolve)
|
|
64
|
+
};
|
|
361
65
|
}
|
|
66
|
+
const { runtimeToolsPath: RuntimeToolsPath, bundlerRuntimePath: BundlerRuntimePath, runtimePath: RuntimePath } = resolveRuntimePaths();
|
|
67
|
+
const federationGlobal = require_lib_container_runtime_utils.getFederationGlobalScope(RuntimeGlobals);
|
|
68
|
+
const onceForCompiler = /* @__PURE__ */ new WeakSet();
|
|
69
|
+
const onceForCompilerEntryMap = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
var FederationRuntimePlugin = class FederationRuntimePlugin {
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.options = options ? { ...options } : void 0;
|
|
73
|
+
this.entryFilePath = "";
|
|
74
|
+
this.bundlerRuntimePath = BundlerRuntimePath;
|
|
75
|
+
this.runtimePath = RuntimePath;
|
|
76
|
+
this.runtimeToolsPath = RuntimeToolsPath;
|
|
77
|
+
this.federationRuntimeDependency = void 0;
|
|
78
|
+
}
|
|
79
|
+
static getTemplate(compiler, options, bundlerRuntimePath) {
|
|
80
|
+
const runtimePlugins = options.runtimePlugins;
|
|
81
|
+
const normalizedBundlerRuntimePath = require_lib_container_runtime_utils.normalizeToPosixPath(bundlerRuntimePath || BundlerRuntimePath);
|
|
82
|
+
let runtimePluginTemplates = "";
|
|
83
|
+
const runtimePluginCalls = [];
|
|
84
|
+
if (Array.isArray(runtimePlugins)) runtimePlugins.forEach((runtimePlugin, index) => {
|
|
85
|
+
if (!runtimePlugin) return;
|
|
86
|
+
const runtimePluginName = `plugin_${index}`;
|
|
87
|
+
const runtimePluginEntry = Array.isArray(runtimePlugin) ? runtimePlugin[0] : runtimePlugin;
|
|
88
|
+
const runtimePluginPath = require_lib_container_runtime_utils.normalizeToPosixPath(path.default.isAbsolute(runtimePluginEntry) ? runtimePluginEntry : path.default.join(process.cwd(), runtimePluginEntry));
|
|
89
|
+
const paramsStr = Array.isArray(runtimePlugin) && runtimePlugin.length > 1 ? JSON.stringify(runtimePlugin[1]) : "undefined";
|
|
90
|
+
runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
|
|
91
|
+
runtimePluginCalls.push(`${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`);
|
|
92
|
+
});
|
|
93
|
+
const embedRuntimeLines = Template.asString([
|
|
94
|
+
`if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,
|
|
95
|
+
Template.indent([
|
|
96
|
+
`var prevFederation = ${federationGlobal};`,
|
|
97
|
+
`${federationGlobal} = {}`,
|
|
98
|
+
`for(var key in federation){`,
|
|
99
|
+
Template.indent([`${federationGlobal}[key] = federation[key];`]),
|
|
100
|
+
"}",
|
|
101
|
+
`for(var key in prevFederation){`,
|
|
102
|
+
Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),
|
|
103
|
+
"}"
|
|
104
|
+
]),
|
|
105
|
+
"}"
|
|
106
|
+
]);
|
|
107
|
+
return Template.asString([
|
|
108
|
+
`import federation from '${normalizedBundlerRuntimePath}';`,
|
|
109
|
+
runtimePluginTemplates,
|
|
110
|
+
embedRuntimeLines,
|
|
111
|
+
`if(!${federationGlobal}.instance){`,
|
|
112
|
+
Template.indent([
|
|
113
|
+
runtimePluginCalls.length ? Template.asString([
|
|
114
|
+
`var pluginsToAdd = [`,
|
|
115
|
+
Template.indent(Template.indent(runtimePluginCalls.map((call) => `${call},`))),
|
|
116
|
+
`].filter(Boolean);`,
|
|
117
|
+
`${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,
|
|
118
|
+
`${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`
|
|
119
|
+
]) : "",
|
|
120
|
+
`${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,
|
|
121
|
+
`if(${federationGlobal}.attachShareScopeMap){`,
|
|
122
|
+
Template.indent([`${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`]),
|
|
123
|
+
"}",
|
|
124
|
+
`if(${federationGlobal}.installInitialConsumes){`,
|
|
125
|
+
Template.indent([`${federationGlobal}.installInitialConsumes()`]),
|
|
126
|
+
"}"
|
|
127
|
+
]),
|
|
128
|
+
_module_federation_data_prefetch_cli.PrefetchPlugin.addRuntime(compiler, { name: options.name }),
|
|
129
|
+
"}"
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
getFilePath(compiler) {
|
|
133
|
+
if (!this.options) return "";
|
|
134
|
+
const existedFilePath = onceForCompilerEntryMap.get(compiler);
|
|
135
|
+
if (existedFilePath) return existedFilePath;
|
|
136
|
+
let entryFilePath = "";
|
|
137
|
+
if (!this.options?.virtualRuntimeEntry) {
|
|
138
|
+
const containerName = this.options.name;
|
|
139
|
+
const hash = require_lib_container_runtime_utils.createHash(`${containerName} ${FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath)}`);
|
|
140
|
+
entryFilePath = path.default.join(require_lib_container_constant.TEMP_DIR, `entry.${hash}.js`);
|
|
141
|
+
} else entryFilePath = `data:text/javascript;charset=utf-8;base64,${(0, btoa.default)(FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath))}`;
|
|
142
|
+
onceForCompilerEntryMap.set(compiler, entryFilePath);
|
|
143
|
+
return entryFilePath;
|
|
144
|
+
}
|
|
145
|
+
ensureFile(compiler) {
|
|
146
|
+
if (!this.options) return;
|
|
147
|
+
if (this.options?.virtualRuntimeEntry) return;
|
|
148
|
+
const filePath = this.entryFilePath;
|
|
149
|
+
const outputFs = compiler.outputFileSystem;
|
|
150
|
+
const fsLike = outputFs && typeof outputFs.readFileSync === "function" && typeof outputFs.writeFileSync === "function" ? outputFs : fs.default;
|
|
151
|
+
try {
|
|
152
|
+
fsLike.readFileSync(filePath);
|
|
153
|
+
} catch {
|
|
154
|
+
mkdirpSync(fsLike, require_lib_container_constant.TEMP_DIR);
|
|
155
|
+
fsLike.writeFileSync(filePath, FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
getDependency(compiler) {
|
|
159
|
+
if (this.federationRuntimeDependency) return this.federationRuntimeDependency;
|
|
160
|
+
this.ensureFile(compiler);
|
|
161
|
+
this.federationRuntimeDependency = new require_lib_container_runtime_FederationRuntimeDependency.default(this.entryFilePath);
|
|
162
|
+
return this.federationRuntimeDependency;
|
|
163
|
+
}
|
|
164
|
+
prependEntry(compiler) {
|
|
165
|
+
if (!this.options?.virtualRuntimeEntry) this.ensureFile(compiler);
|
|
166
|
+
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation, { normalModuleFactory }) => {
|
|
167
|
+
compilation.dependencyFactories.set(require_lib_container_runtime_FederationRuntimeDependency.default, normalModuleFactory);
|
|
168
|
+
compilation.dependencyTemplates.set(require_lib_container_runtime_FederationRuntimeDependency.default, new ModuleDependency.Template());
|
|
169
|
+
});
|
|
170
|
+
compiler.hooks.make.tapAsync(this.constructor.name, (compilation, callback) => {
|
|
171
|
+
const federationRuntimeDependency = this.getDependency(compiler);
|
|
172
|
+
const hooks = require_lib_container_runtime_FederationModulesPlugin.default.getCompilationHooks(compilation);
|
|
173
|
+
compilation.addInclude(compiler.context, federationRuntimeDependency, { name: void 0 }, (err) => {
|
|
174
|
+
if (err) return callback(err);
|
|
175
|
+
hooks.addFederationRuntimeDependency.call(federationRuntimeDependency);
|
|
176
|
+
callback();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
injectRuntime(compiler) {
|
|
181
|
+
if (!this.options || !this.options.name) return;
|
|
182
|
+
const name = this.options.name;
|
|
183
|
+
const initOptionsWithoutShared = require_lib_container_runtime_utils.normalizeRuntimeInitOptionsWithOutShared(this.options);
|
|
184
|
+
const federationGlobal = require_lib_container_runtime_utils.getFederationGlobalScope(RuntimeGlobals || {});
|
|
185
|
+
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
|
|
186
|
+
const handler = (chunk, runtimeRequirements) => {
|
|
187
|
+
if (runtimeRequirements.has(federationGlobal)) return;
|
|
188
|
+
runtimeRequirements.add(federationGlobal);
|
|
189
|
+
runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);
|
|
190
|
+
runtimeRequirements.add(RuntimeGlobals.moduleCache);
|
|
191
|
+
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
|
192
|
+
compilation.addRuntimeModule(chunk, new require_lib_container_runtime_FederationRuntimeModule.default(runtimeRequirements, name, initOptionsWithoutShared));
|
|
193
|
+
};
|
|
194
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(this.constructor.name, (chunk, runtimeRequirements) => {
|
|
195
|
+
if (!chunk.hasRuntime()) return;
|
|
196
|
+
if (runtimeRequirements.has(RuntimeGlobals.initializeSharing)) return;
|
|
197
|
+
if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope)) return;
|
|
198
|
+
if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap)) return;
|
|
199
|
+
if (runtimeRequirements.has(federationGlobal)) return;
|
|
200
|
+
handler(chunk, runtimeRequirements);
|
|
201
|
+
});
|
|
202
|
+
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.initializeSharing).tap(this.constructor.name, handler);
|
|
203
|
+
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.currentRemoteGetScope).tap(this.constructor.name, handler);
|
|
204
|
+
compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.shareScopeMap).tap(this.constructor.name, handler);
|
|
205
|
+
compilation.hooks.runtimeRequirementInTree.for(federationGlobal).tap(this.constructor.name, handler);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
getRuntimeAlias(compiler) {
|
|
209
|
+
const { implementation } = this.options || {};
|
|
210
|
+
const alias = compiler.options.resolve.alias || {};
|
|
211
|
+
const resolvedPaths = resolveRuntimePaths(implementation);
|
|
212
|
+
this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;
|
|
213
|
+
this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;
|
|
214
|
+
if (alias["@module-federation/runtime$"]) {
|
|
215
|
+
this.runtimePath = alias["@module-federation/runtime$"];
|
|
216
|
+
return this.runtimePath;
|
|
217
|
+
}
|
|
218
|
+
this.runtimePath = resolvedPaths.runtimePath;
|
|
219
|
+
return this.runtimePath;
|
|
220
|
+
}
|
|
221
|
+
setRuntimeAlias(compiler) {
|
|
222
|
+
const { implementation } = this.options || {};
|
|
223
|
+
const alias = compiler.options.resolve.alias || {};
|
|
224
|
+
const runtimePath = this.getRuntimeAlias(compiler);
|
|
225
|
+
alias["@module-federation/runtime$"] = alias["@module-federation/runtime$"] || runtimePath;
|
|
226
|
+
alias["@module-federation/runtime-tools$"] = alias["@module-federation/runtime-tools$"] || implementation || this.runtimeToolsPath;
|
|
227
|
+
compiler.options.resolve.alias = alias;
|
|
228
|
+
}
|
|
229
|
+
apply(compiler) {
|
|
230
|
+
if (compiler.options.plugins.find((p) => {
|
|
231
|
+
if (typeof p !== "object" || !p) return false;
|
|
232
|
+
return p["name"] === "SharedContainerPlugin";
|
|
233
|
+
})) return;
|
|
234
|
+
const useModuleFederationPlugin = compiler.options.plugins.find((p) => {
|
|
235
|
+
if (typeof p !== "object" || !p) return false;
|
|
236
|
+
return p["name"] === "ModuleFederationPlugin";
|
|
237
|
+
});
|
|
238
|
+
if (useModuleFederationPlugin && !this.options) this.options = useModuleFederationPlugin._options;
|
|
239
|
+
const useContainerPlugin = compiler.options.plugins.find((p) => {
|
|
240
|
+
if (typeof p !== "object" || !p) return false;
|
|
241
|
+
return p["name"] === "ContainerPlugin";
|
|
242
|
+
});
|
|
243
|
+
if (useContainerPlugin && !this.options) this.options = useContainerPlugin._options;
|
|
244
|
+
if (!useContainerPlugin && !useModuleFederationPlugin) this.options = {
|
|
245
|
+
remotes: {},
|
|
246
|
+
...this.options
|
|
247
|
+
};
|
|
248
|
+
if (this.options && !this.options?.name)
|
|
249
|
+
//! the instance may get the same one if the name is the same https://github.com/module-federation/core/blob/main/packages/runtime/src/index.ts#L18
|
|
250
|
+
this.options.name = compiler.options.output.uniqueName || `container_${Date.now()}`;
|
|
251
|
+
const resolvedPaths = resolveRuntimePaths(this.options?.implementation);
|
|
252
|
+
this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;
|
|
253
|
+
this.runtimePath = resolvedPaths.runtimePath;
|
|
254
|
+
this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;
|
|
255
|
+
this.entryFilePath = this.getFilePath(compiler);
|
|
256
|
+
new require_lib_container_runtime_EmbedFederationRuntimePlugin.default().apply(compiler);
|
|
257
|
+
new require_lib_container_HoistContainerReferencesPlugin.default().apply(compiler);
|
|
258
|
+
if (!onceForCompiler.has(compiler)) {
|
|
259
|
+
this.prependEntry(compiler);
|
|
260
|
+
this.injectRuntime(compiler);
|
|
261
|
+
this.setRuntimeAlias(compiler);
|
|
262
|
+
onceForCompiler.add(compiler);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
362
268
|
exports.default = FederationRuntimePlugin;
|
|
269
|
+
exports.resolveRuntimePaths = resolveRuntimePaths;
|
|
363
270
|
//# sourceMappingURL=FederationRuntimePlugin.js.map
|