@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,484 +1,317 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
|
|
4
|
-
*/
|
|
5
1
|
'use strict';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
|
+
const require_lib_container_options = require('../container/options.js');
|
|
6
|
+
const require_utils = require('../../utils.js');
|
|
7
|
+
const require_lib_container_runtime_FederationRuntimePlugin = require('../container/runtime/FederationRuntimePlugin.js');
|
|
8
|
+
const require_lib_sharing_resolveMatchedConfigs = require('./resolveMatchedConfigs.js');
|
|
9
|
+
const require_lib_sharing_utils = require('./utils.js');
|
|
10
|
+
const require_lib_sharing_ConsumeSharedFallbackDependency = require('./ConsumeSharedFallbackDependency.js');
|
|
11
|
+
const require_lib_sharing_ConsumeSharedModule = require('./ConsumeSharedModule.js');
|
|
12
|
+
const require_lib_sharing_ConsumeSharedRuntimeModule = require('./ConsumeSharedRuntimeModule.js');
|
|
13
|
+
const require_lib_sharing_ProvideForSharedDependency = require('./ProvideForSharedDependency.js');
|
|
14
|
+
const require_lib_sharing_ShareRuntimeModule = require('./ShareRuntimeModule.js');
|
|
15
|
+
const require_schemas_sharing_ConsumeSharedPlugin_check = require('../../schemas/sharing/ConsumeSharedPlugin.check.js');
|
|
16
|
+
const require_schemas_sharing_ConsumeSharedPlugin = require('../../schemas/sharing/ConsumeSharedPlugin.js');
|
|
17
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
18
|
+
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
19
|
+
let path = require("path");
|
|
20
|
+
path = require_runtime.__toESM(path);
|
|
21
|
+
|
|
22
|
+
//#region src/lib/sharing/ConsumeSharedPlugin.ts
|
|
11
23
|
const DIRECT_FALLBACK_REGEX = /^(\.\.?(\/|$)|\/|[A-Za-z]:|\\\\)/;
|
|
12
24
|
const ABSOLUTE_PATH_REGEX = /^(\/|[A-Za-z]:|\\\\)/;
|
|
13
25
|
const RELATIVE_OR_ABSOLUTE_PATH_REGEX = /^(?:\.{1,2}[\\/]|\/|[A-Za-z]:|\\\\)/;
|
|
14
26
|
const PACKAGE_NAME_REGEX = /^((?:@[^\\/]+[\\/])?[^\\/]+)/;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const ProvideForSharedDependency_1 = __importDefault(require("./ProvideForSharedDependency"));
|
|
24
|
-
const FederationRuntimePlugin_1 = __importDefault(require("../container/runtime/FederationRuntimePlugin"));
|
|
25
|
-
const ShareRuntimeModule_1 = __importDefault(require("./ShareRuntimeModule"));
|
|
26
|
-
const utils_2 = require("../../utils");
|
|
27
|
-
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const { satisfy, parseRange } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/semver'));
|
|
29
|
-
const utils_3 = require("./utils");
|
|
30
|
-
const ModuleNotFoundError = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/ModuleNotFoundError'));
|
|
31
|
-
const { RuntimeGlobals } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
32
|
-
const LazySet = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/LazySet'));
|
|
33
|
-
const WebpackError = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/WebpackError'));
|
|
34
|
-
const validate = (0, utils_2.createSchemaValidation)(
|
|
35
|
-
// eslint-disable-next-line
|
|
36
|
-
require('../../schemas/sharing/ConsumeSharedPlugin.check.js').validate, () => require('../../schemas/sharing/ConsumeSharedPlugin').default, {
|
|
37
|
-
name: 'Consume Shared Plugin',
|
|
38
|
-
baseDataPath: 'options',
|
|
27
|
+
const { satisfy, parseRange } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/semver"));
|
|
28
|
+
const ModuleNotFoundError = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/ModuleNotFoundError"));
|
|
29
|
+
const { RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
30
|
+
const LazySet = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/LazySet"));
|
|
31
|
+
const WebpackError = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/WebpackError"));
|
|
32
|
+
const validate = require_utils.createSchemaValidation((require_schemas_sharing_ConsumeSharedPlugin_check.init_ConsumeSharedPlugin_check(), require_runtime.__toCommonJS(require_schemas_sharing_ConsumeSharedPlugin_check.ConsumeSharedPlugin_check_exports)).validate, () => (require_schemas_sharing_ConsumeSharedPlugin.init_ConsumeSharedPlugin(), require_runtime.__toCommonJS(require_schemas_sharing_ConsumeSharedPlugin.ConsumeSharedPlugin_exports)).default, {
|
|
33
|
+
name: "Consume Shared Plugin",
|
|
34
|
+
baseDataPath: "options"
|
|
39
35
|
});
|
|
40
|
-
const RESOLVE_OPTIONS = {
|
|
41
|
-
|
|
36
|
+
const RESOLVE_OPTIONS = { dependencyType: "esm" };
|
|
37
|
+
const PLUGIN_NAME = "ConsumeSharedPlugin";
|
|
38
|
+
var ConsumeSharedPlugin = class {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
if (typeof options !== "string") validate(options);
|
|
41
|
+
this._consumes = require_lib_container_options.parseOptions(options.consumes, (item, key) => {
|
|
42
|
+
if (Array.isArray(item)) throw new Error("Unexpected array in options");
|
|
43
|
+
return item === key || !(0, _module_federation_sdk.isRequiredVersion)(item) ? {
|
|
44
|
+
import: key,
|
|
45
|
+
shareScope: options.shareScope || "default",
|
|
46
|
+
shareKey: key,
|
|
47
|
+
requiredVersion: void 0,
|
|
48
|
+
packageName: void 0,
|
|
49
|
+
strictVersion: false,
|
|
50
|
+
singleton: false,
|
|
51
|
+
eager: false,
|
|
52
|
+
issuerLayer: void 0,
|
|
53
|
+
layer: void 0,
|
|
54
|
+
request: key,
|
|
55
|
+
include: void 0,
|
|
56
|
+
exclude: void 0,
|
|
57
|
+
allowNodeModulesSuffixMatch: void 0,
|
|
58
|
+
treeShakingMode: void 0
|
|
59
|
+
} : {
|
|
60
|
+
import: key,
|
|
61
|
+
shareScope: options.shareScope || "default",
|
|
62
|
+
shareKey: key,
|
|
63
|
+
requiredVersion: item,
|
|
64
|
+
strictVersion: true,
|
|
65
|
+
packageName: void 0,
|
|
66
|
+
singleton: false,
|
|
67
|
+
eager: false,
|
|
68
|
+
issuerLayer: void 0,
|
|
69
|
+
layer: void 0,
|
|
70
|
+
request: key,
|
|
71
|
+
include: void 0,
|
|
72
|
+
exclude: void 0,
|
|
73
|
+
allowNodeModulesSuffixMatch: void 0,
|
|
74
|
+
treeShakingMode: void 0
|
|
75
|
+
};
|
|
76
|
+
}, (item, key) => {
|
|
77
|
+
const request = item.request || key;
|
|
78
|
+
return {
|
|
79
|
+
import: item.import === false ? void 0 : item.import || request,
|
|
80
|
+
shareScope: item.shareScope || options.shareScope || "default",
|
|
81
|
+
shareKey: item.shareKey || request,
|
|
82
|
+
requiredVersion: item.requiredVersion === false ? false : item.requiredVersion,
|
|
83
|
+
strictVersion: typeof item.strictVersion === "boolean" ? item.strictVersion : item.import !== false && !item.singleton,
|
|
84
|
+
packageName: item.packageName,
|
|
85
|
+
singleton: !!item.singleton,
|
|
86
|
+
eager: !!item.eager,
|
|
87
|
+
exclude: item.exclude,
|
|
88
|
+
include: item.include,
|
|
89
|
+
issuerLayer: item.issuerLayer ? item.issuerLayer : void 0,
|
|
90
|
+
layer: item.layer ? item.layer : void 0,
|
|
91
|
+
request,
|
|
92
|
+
allowNodeModulesSuffixMatch: item.allowNodeModulesSuffixMatch,
|
|
93
|
+
treeShakingMode: item.treeShakingMode
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
createConsumeSharedModule(compilation, context, request, config) {
|
|
98
|
+
const requiredVersionWarning = (details) => {
|
|
99
|
+
const error = new WebpackError(`No required version specified and unable to automatically determine one. ${details}`);
|
|
100
|
+
error.file = `shared module ${request}`;
|
|
101
|
+
compilation.warnings.push(error);
|
|
102
|
+
};
|
|
103
|
+
const directFallback = config.import && DIRECT_FALLBACK_REGEX.test(config.import);
|
|
104
|
+
const resolver = compilation.resolverFactory.get("normal", RESOLVE_OPTIONS);
|
|
105
|
+
return Promise.all([new Promise((resolve) => {
|
|
106
|
+
if (!config.import) return resolve(void 0);
|
|
107
|
+
const resolveContext = {
|
|
108
|
+
fileDependencies: new LazySet(),
|
|
109
|
+
contextDependencies: new LazySet(),
|
|
110
|
+
missingDependencies: new LazySet()
|
|
111
|
+
};
|
|
112
|
+
resolver.resolve({}, directFallback ? compilation.compiler.context : context, config.import, resolveContext, (err, result) => {
|
|
113
|
+
compilation.contextDependencies.addAll(resolveContext.contextDependencies);
|
|
114
|
+
compilation.fileDependencies.addAll(resolveContext.fileDependencies);
|
|
115
|
+
compilation.missingDependencies.addAll(resolveContext.missingDependencies);
|
|
116
|
+
if (err) {
|
|
117
|
+
compilation.errors.push(new ModuleNotFoundError(null, err, { name: `resolving fallback for shared module ${request}` }));
|
|
118
|
+
return resolve(void 0);
|
|
119
|
+
}
|
|
120
|
+
resolve(result);
|
|
121
|
+
});
|
|
122
|
+
}), new Promise((resolve) => {
|
|
123
|
+
if (config.requiredVersion !== void 0) return resolve(config.requiredVersion);
|
|
124
|
+
let packageName = config.packageName;
|
|
125
|
+
if (packageName === void 0) {
|
|
126
|
+
if (ABSOLUTE_PATH_REGEX.test(request)) return resolve(void 0);
|
|
127
|
+
const match = PACKAGE_NAME_REGEX.exec(request);
|
|
128
|
+
if (!match) {
|
|
129
|
+
requiredVersionWarning("Unable to extract the package name from request.");
|
|
130
|
+
return resolve(void 0);
|
|
131
|
+
}
|
|
132
|
+
packageName = match[0];
|
|
133
|
+
}
|
|
134
|
+
require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, context, ["package.json"], (err, result, checkedDescriptionFilePaths) => {
|
|
135
|
+
if (err) {
|
|
136
|
+
requiredVersionWarning(`Unable to read description file: ${err}`);
|
|
137
|
+
return resolve(void 0);
|
|
138
|
+
}
|
|
139
|
+
const { data } = result || {};
|
|
140
|
+
if (!data) {
|
|
141
|
+
if (checkedDescriptionFilePaths?.length) requiredVersionWarning([
|
|
142
|
+
`Unable to find required version for "${packageName}" in description file/s`,
|
|
143
|
+
checkedDescriptionFilePaths.join("\n"),
|
|
144
|
+
"It need to be in dependencies, devDependencies or peerDependencies."
|
|
145
|
+
].join("\n"));
|
|
146
|
+
else requiredVersionWarning(`Unable to find description file in ${context}.`);
|
|
147
|
+
return resolve(void 0);
|
|
148
|
+
}
|
|
149
|
+
if (data["name"] === packageName) return resolve(void 0);
|
|
150
|
+
resolve(require_lib_sharing_utils.getRequiredVersionFromDescriptionFile(data, packageName));
|
|
151
|
+
}, (result) => {
|
|
152
|
+
if (!result) return false;
|
|
153
|
+
const { data } = result;
|
|
154
|
+
const maybeRequiredVersion = require_lib_sharing_utils.getRequiredVersionFromDescriptionFile(data, packageName);
|
|
155
|
+
return data["name"] === packageName || typeof maybeRequiredVersion === "string";
|
|
156
|
+
});
|
|
157
|
+
})]).then(([importResolved, requiredVersion]) => {
|
|
158
|
+
const currentConfig = {
|
|
159
|
+
...config,
|
|
160
|
+
importResolved,
|
|
161
|
+
import: importResolved ? config.import : void 0,
|
|
162
|
+
requiredVersion
|
|
163
|
+
};
|
|
164
|
+
const consumedModule = new require_lib_sharing_ConsumeSharedModule.default(directFallback ? compilation.compiler.context : context, currentConfig);
|
|
165
|
+
if (config.include && typeof config.include.version === "string") {
|
|
166
|
+
if (!importResolved) return consumedModule;
|
|
167
|
+
return new Promise((resolveFilter) => {
|
|
168
|
+
require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, path.default.dirname(importResolved), ["package.json"], (err, result) => {
|
|
169
|
+
if (err) return resolveFilter(consumedModule);
|
|
170
|
+
const { data } = result || {};
|
|
171
|
+
if (!data || !data["version"] || data["name"] !== request) return resolveFilter(consumedModule);
|
|
172
|
+
if (config.include && satisfy(parseRange(config.include.version), data["version"])) {
|
|
173
|
+
if (config.include && config.include.version && config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "include", "version", config.include.version, request, importResolved);
|
|
174
|
+
return resolveFilter(consumedModule);
|
|
175
|
+
}
|
|
176
|
+
if (config.include && typeof config.include.fallbackVersion === "string" && config.include.fallbackVersion) {
|
|
177
|
+
if (satisfy(parseRange(config.include.version), config.include.fallbackVersion)) return resolveFilter(consumedModule);
|
|
178
|
+
return resolveFilter(void 0);
|
|
179
|
+
}
|
|
180
|
+
return resolveFilter(void 0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (config.exclude && typeof config.exclude.version === "string") {
|
|
185
|
+
if (!importResolved) return consumedModule;
|
|
186
|
+
if (config.exclude && typeof config.exclude.fallbackVersion === "string" && config.exclude.fallbackVersion) {
|
|
187
|
+
if (satisfy(parseRange(config.exclude.version), config.exclude.fallbackVersion)) return;
|
|
188
|
+
return consumedModule;
|
|
189
|
+
}
|
|
190
|
+
return new Promise((resolveFilter) => {
|
|
191
|
+
require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, path.default.dirname(importResolved), ["package.json"], (err, result) => {
|
|
192
|
+
if (err) return resolveFilter(consumedModule);
|
|
193
|
+
const { data } = result || {};
|
|
194
|
+
if (!data || !data["version"] || data["name"] !== request) return resolveFilter(consumedModule);
|
|
195
|
+
if (config.exclude && typeof config.exclude.version === "string" && satisfy(parseRange(config.exclude.version), data["version"])) return resolveFilter(void 0);
|
|
196
|
+
if (config.exclude && config.exclude.version && config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "exclude", "version", config.exclude.version, request, importResolved);
|
|
197
|
+
return resolveFilter(consumedModule);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return consumedModule;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
apply(compiler) {
|
|
205
|
+
new require_lib_container_runtime_FederationRuntimePlugin.default().apply(compiler);
|
|
206
|
+
process.env["FEDERATION_WEBPACK_PATH"] = process.env["FEDERATION_WEBPACK_PATH"] || (0, _module_federation_sdk_normalize_webpack_path.getWebpackPath)(compiler);
|
|
207
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
|
|
208
|
+
compilation.dependencyFactories.set(require_lib_sharing_ConsumeSharedFallbackDependency.default, normalModuleFactory);
|
|
209
|
+
let unresolvedConsumes, resolvedConsumes, prefixedConsumes;
|
|
210
|
+
const promise = require_lib_sharing_resolveMatchedConfigs.resolveMatchedConfigs(compilation, this._consumes).then(({ resolved, unresolved, prefixed }) => {
|
|
211
|
+
resolvedConsumes = resolved;
|
|
212
|
+
unresolvedConsumes = unresolved;
|
|
213
|
+
prefixedConsumes = prefixed;
|
|
214
|
+
});
|
|
215
|
+
normalModuleFactory.hooks.factorize.tapPromise(PLUGIN_NAME, async (resolveData) => {
|
|
216
|
+
const { context, request, dependencies, contextInfo } = resolveData;
|
|
217
|
+
const boundCreateConsumeSharedModule = this.createConsumeSharedModule.bind(this);
|
|
218
|
+
return promise.then(() => {
|
|
219
|
+
if (dependencies[0] instanceof require_lib_sharing_ConsumeSharedFallbackDependency.default || dependencies[0] instanceof require_lib_sharing_ProvideForSharedDependency.default) return;
|
|
220
|
+
const { context, request, contextInfo } = resolveData;
|
|
221
|
+
const match = unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(request, contextInfo.issuerLayer)) || unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(request, void 0));
|
|
222
|
+
if (match !== void 0) return boundCreateConsumeSharedModule(compilation, context, request, match);
|
|
223
|
+
let reconstructed = null;
|
|
224
|
+
let modulePathAfterNodeModules = null;
|
|
225
|
+
if (request && !path.default.isAbsolute(request) && RELATIVE_OR_ABSOLUTE_PATH_REGEX.test(request)) {
|
|
226
|
+
reconstructed = path.default.join(context, request);
|
|
227
|
+
modulePathAfterNodeModules = require_lib_sharing_utils.extractPathAfterNodeModules(reconstructed);
|
|
228
|
+
if (modulePathAfterNodeModules) {
|
|
229
|
+
const moduleMatch = unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(modulePathAfterNodeModules, contextInfo.issuerLayer)) || unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(modulePathAfterNodeModules, void 0));
|
|
230
|
+
if (moduleMatch !== void 0 && moduleMatch.allowNodeModulesSuffixMatch) return boundCreateConsumeSharedModule(compilation, context, modulePathAfterNodeModules, moduleMatch);
|
|
231
|
+
}
|
|
232
|
+
const reconstructedMatch = unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(reconstructed, contextInfo.issuerLayer)) || unresolvedConsumes.get(require_lib_sharing_utils.createLookupKeyForSharing(reconstructed, void 0));
|
|
233
|
+
if (reconstructedMatch !== void 0) return boundCreateConsumeSharedModule(compilation, context, reconstructed, reconstructedMatch);
|
|
234
|
+
}
|
|
235
|
+
for (const [prefix, options] of prefixedConsumes) {
|
|
236
|
+
const lookup = options.request || prefix;
|
|
237
|
+
if (options.issuerLayer) {
|
|
238
|
+
if (!contextInfo.issuerLayer) continue;
|
|
239
|
+
if (contextInfo.issuerLayer !== options.issuerLayer) continue;
|
|
240
|
+
}
|
|
241
|
+
if (request.startsWith(lookup)) {
|
|
242
|
+
const remainder = request.slice(lookup.length);
|
|
243
|
+
if (!require_lib_sharing_utils.testRequestFilters(remainder, options.include?.request, options.exclude?.request)) continue;
|
|
244
|
+
return boundCreateConsumeSharedModule(compilation, context, request, {
|
|
245
|
+
...options,
|
|
246
|
+
import: options.import ? options.import + remainder : void 0,
|
|
247
|
+
shareKey: options.shareKey + remainder,
|
|
248
|
+
layer: options.layer
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (modulePathAfterNodeModules) for (const [prefix, options] of prefixedConsumes) {
|
|
253
|
+
if (!options.allowNodeModulesSuffixMatch) continue;
|
|
254
|
+
if (options.issuerLayer) {
|
|
255
|
+
if (!contextInfo.issuerLayer) continue;
|
|
256
|
+
if (contextInfo.issuerLayer !== options.issuerLayer) continue;
|
|
257
|
+
}
|
|
258
|
+
const lookup = options.request || prefix;
|
|
259
|
+
if (modulePathAfterNodeModules.startsWith(lookup)) {
|
|
260
|
+
const remainder = modulePathAfterNodeModules.slice(lookup.length);
|
|
261
|
+
if (!require_lib_sharing_utils.testRequestFilters(remainder, options.include?.request, options.exclude?.request)) continue;
|
|
262
|
+
return boundCreateConsumeSharedModule(compilation, context, modulePathAfterNodeModules, {
|
|
263
|
+
...options,
|
|
264
|
+
import: options.import ? options.import + remainder : void 0,
|
|
265
|
+
shareKey: options.shareKey + remainder,
|
|
266
|
+
layer: options.layer
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
normalModuleFactory.hooks.createModule.tapPromise(PLUGIN_NAME, ({ resource }, { context, dependencies }) => {
|
|
273
|
+
const boundCreateConsumeSharedModule = this.createConsumeSharedModule.bind(this);
|
|
274
|
+
if (dependencies[0] instanceof require_lib_sharing_ConsumeSharedFallbackDependency.default || dependencies[0] instanceof require_lib_sharing_ProvideForSharedDependency.default) return Promise.resolve();
|
|
275
|
+
if (resource) {
|
|
276
|
+
const options = resolvedConsumes.get(resource);
|
|
277
|
+
if (options !== void 0) return boundCreateConsumeSharedModule(compilation, context, resource, options);
|
|
278
|
+
}
|
|
279
|
+
return Promise.resolve();
|
|
280
|
+
});
|
|
281
|
+
compilation.hooks.finishModules.tapAsync({
|
|
282
|
+
name: PLUGIN_NAME,
|
|
283
|
+
stage: 10
|
|
284
|
+
}, (modules, callback) => {
|
|
285
|
+
for (const module of modules) {
|
|
286
|
+
if (!(module instanceof require_lib_sharing_ConsumeSharedModule.default) || !module.options.import) continue;
|
|
287
|
+
let dependency;
|
|
288
|
+
if (module.options.eager) dependency = module.dependencies[0];
|
|
289
|
+
else dependency = module.blocks[0]?.dependencies[0];
|
|
290
|
+
if (dependency) {
|
|
291
|
+
const fallbackModule = compilation.moduleGraph.getModule(dependency);
|
|
292
|
+
if (fallbackModule && fallbackModule.buildMeta && fallbackModule.buildInfo) {
|
|
293
|
+
module.buildMeta = { ...fallbackModule.buildMeta };
|
|
294
|
+
module.buildInfo = { ...fallbackModule.buildInfo };
|
|
295
|
+
compilation.moduleGraph.getExportsInfo(module).setUnknownExportsProvided();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
callback();
|
|
300
|
+
});
|
|
301
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (chunk, set) => {
|
|
302
|
+
set.add(RuntimeGlobals.module);
|
|
303
|
+
set.add(RuntimeGlobals.moduleCache);
|
|
304
|
+
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
|
305
|
+
set.add(RuntimeGlobals.shareScopeMap);
|
|
306
|
+
set.add(RuntimeGlobals.initializeSharing);
|
|
307
|
+
set.add(RuntimeGlobals.hasOwnProperty);
|
|
308
|
+
compilation.addRuntimeModule(chunk, new require_lib_sharing_ConsumeSharedRuntimeModule.default(set));
|
|
309
|
+
compilation.addRuntimeModule(chunk, new require_lib_sharing_ShareRuntimeModule.default());
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
42
313
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
constructor(options) {
|
|
46
|
-
if (typeof options !== 'string') {
|
|
47
|
-
validate(options);
|
|
48
|
-
}
|
|
49
|
-
this._consumes = (0, options_1.parseOptions)(options.consumes, (item, key) => {
|
|
50
|
-
if (Array.isArray(item))
|
|
51
|
-
throw new Error('Unexpected array in options');
|
|
52
|
-
//@ts-ignore
|
|
53
|
-
const result = item === key || !(0, sdk_1.isRequiredVersion)(item)
|
|
54
|
-
? // item is a request/key
|
|
55
|
-
{
|
|
56
|
-
import: key,
|
|
57
|
-
shareScope: options.shareScope || 'default',
|
|
58
|
-
shareKey: key,
|
|
59
|
-
requiredVersion: undefined,
|
|
60
|
-
packageName: undefined,
|
|
61
|
-
strictVersion: false,
|
|
62
|
-
singleton: false,
|
|
63
|
-
eager: false,
|
|
64
|
-
issuerLayer: undefined,
|
|
65
|
-
layer: undefined,
|
|
66
|
-
request: key,
|
|
67
|
-
include: undefined,
|
|
68
|
-
exclude: undefined,
|
|
69
|
-
allowNodeModulesSuffixMatch: undefined,
|
|
70
|
-
treeShakingMode: undefined,
|
|
71
|
-
}
|
|
72
|
-
: // key is a request/key
|
|
73
|
-
// item is a version
|
|
74
|
-
{
|
|
75
|
-
import: key,
|
|
76
|
-
shareScope: options.shareScope || 'default',
|
|
77
|
-
shareKey: key,
|
|
78
|
-
// webpack internal semver has some issue, use runtime semver , related issue: https://github.com/webpack/webpack/issues/17756
|
|
79
|
-
requiredVersion: item,
|
|
80
|
-
strictVersion: true,
|
|
81
|
-
packageName: undefined,
|
|
82
|
-
singleton: false,
|
|
83
|
-
eager: false,
|
|
84
|
-
issuerLayer: undefined,
|
|
85
|
-
layer: undefined,
|
|
86
|
-
request: key,
|
|
87
|
-
include: undefined,
|
|
88
|
-
exclude: undefined,
|
|
89
|
-
allowNodeModulesSuffixMatch: undefined,
|
|
90
|
-
treeShakingMode: undefined,
|
|
91
|
-
};
|
|
92
|
-
return result;
|
|
93
|
-
}, (item, key) => {
|
|
94
|
-
const request = item.request || key;
|
|
95
|
-
return {
|
|
96
|
-
import: item.import === false ? undefined : item.import || request,
|
|
97
|
-
shareScope: item.shareScope || options.shareScope || 'default',
|
|
98
|
-
shareKey: item.shareKey || request,
|
|
99
|
-
requiredVersion: item.requiredVersion === false
|
|
100
|
-
? false
|
|
101
|
-
: // @ts-ignore webpack internal semver has some issue, use runtime semver , related issue: https://github.com/webpack/webpack/issues/17756
|
|
102
|
-
item.requiredVersion,
|
|
103
|
-
strictVersion: typeof item.strictVersion === 'boolean'
|
|
104
|
-
? item.strictVersion
|
|
105
|
-
: item.import !== false && !item.singleton,
|
|
106
|
-
packageName: item.packageName,
|
|
107
|
-
singleton: !!item.singleton,
|
|
108
|
-
eager: !!item.eager,
|
|
109
|
-
exclude: item.exclude,
|
|
110
|
-
include: item.include,
|
|
111
|
-
issuerLayer: item.issuerLayer ? item.issuerLayer : undefined,
|
|
112
|
-
layer: item.layer ? item.layer : undefined,
|
|
113
|
-
request,
|
|
114
|
-
allowNodeModulesSuffixMatch: item.allowNodeModulesSuffixMatch,
|
|
115
|
-
treeShakingMode: item.treeShakingMode,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
createConsumeSharedModule(compilation, context, request, config) {
|
|
120
|
-
const requiredVersionWarning = (details) => {
|
|
121
|
-
const error = new WebpackError(`No required version specified and unable to automatically determine one. ${details}`);
|
|
122
|
-
error.file = `shared module ${request}`;
|
|
123
|
-
compilation.warnings.push(error);
|
|
124
|
-
};
|
|
125
|
-
const directFallback = config.import && DIRECT_FALLBACK_REGEX.test(config.import);
|
|
126
|
-
const resolver = compilation.resolverFactory.get('normal', RESOLVE_OPTIONS);
|
|
127
|
-
return Promise.all([
|
|
128
|
-
new Promise((resolve) => {
|
|
129
|
-
if (!config.import)
|
|
130
|
-
return resolve(undefined);
|
|
131
|
-
const resolveContext = {
|
|
132
|
-
fileDependencies: new LazySet(),
|
|
133
|
-
contextDependencies: new LazySet(),
|
|
134
|
-
missingDependencies: new LazySet(),
|
|
135
|
-
};
|
|
136
|
-
resolver.resolve({}, directFallback ? compilation.compiler.context : context, config.import, resolveContext, (err, result) => {
|
|
137
|
-
compilation.contextDependencies.addAll(resolveContext.contextDependencies);
|
|
138
|
-
compilation.fileDependencies.addAll(resolveContext.fileDependencies);
|
|
139
|
-
compilation.missingDependencies.addAll(resolveContext.missingDependencies);
|
|
140
|
-
if (err) {
|
|
141
|
-
compilation.errors.push(new ModuleNotFoundError(null, err, {
|
|
142
|
-
name: `resolving fallback for shared module ${request}`,
|
|
143
|
-
}));
|
|
144
|
-
return resolve(undefined);
|
|
145
|
-
}
|
|
146
|
-
//@ts-ignore
|
|
147
|
-
resolve(result);
|
|
148
|
-
});
|
|
149
|
-
}),
|
|
150
|
-
new Promise((resolve) => {
|
|
151
|
-
if (config.requiredVersion !== undefined) {
|
|
152
|
-
return resolve(config.requiredVersion);
|
|
153
|
-
}
|
|
154
|
-
let packageName = config.packageName;
|
|
155
|
-
if (packageName === undefined) {
|
|
156
|
-
if (ABSOLUTE_PATH_REGEX.test(request)) {
|
|
157
|
-
// For relative or absolute requests we don't automatically use a packageName.
|
|
158
|
-
// If wished one can specify one with the packageName option.
|
|
159
|
-
return resolve(undefined);
|
|
160
|
-
}
|
|
161
|
-
const match = PACKAGE_NAME_REGEX.exec(request);
|
|
162
|
-
if (!match) {
|
|
163
|
-
requiredVersionWarning('Unable to extract the package name from request.');
|
|
164
|
-
return resolve(undefined);
|
|
165
|
-
}
|
|
166
|
-
packageName = match[0];
|
|
167
|
-
}
|
|
168
|
-
(0, utils_1.getDescriptionFile)(compilation.inputFileSystem, context, ['package.json'], (err, result, checkedDescriptionFilePaths) => {
|
|
169
|
-
if (err) {
|
|
170
|
-
requiredVersionWarning(`Unable to read description file: ${err}`);
|
|
171
|
-
return resolve(undefined);
|
|
172
|
-
}
|
|
173
|
-
const { data } = /** @type {DescriptionFile} */ result || {};
|
|
174
|
-
if (!data) {
|
|
175
|
-
if (checkedDescriptionFilePaths?.length) {
|
|
176
|
-
requiredVersionWarning([
|
|
177
|
-
`Unable to find required version for "${packageName}" in description file/s`,
|
|
178
|
-
checkedDescriptionFilePaths.join('\n'),
|
|
179
|
-
'It need to be in dependencies, devDependencies or peerDependencies.',
|
|
180
|
-
].join('\n'));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
requiredVersionWarning(`Unable to find description file in ${context}.`);
|
|
184
|
-
}
|
|
185
|
-
return resolve(undefined);
|
|
186
|
-
}
|
|
187
|
-
if (data['name'] === packageName) {
|
|
188
|
-
// Package self-referencing
|
|
189
|
-
return resolve(undefined);
|
|
190
|
-
}
|
|
191
|
-
const requiredVersion = (0, utils_1.getRequiredVersionFromDescriptionFile)(data, packageName);
|
|
192
|
-
//TODO: align with webpck semver parser again
|
|
193
|
-
// @ts-ignore webpack internal semver has some issue, use runtime semver , related issue: https://github.com/webpack/webpack/issues/17756
|
|
194
|
-
resolve(requiredVersion);
|
|
195
|
-
}, (result) => {
|
|
196
|
-
if (!result)
|
|
197
|
-
return false;
|
|
198
|
-
const { data } = result;
|
|
199
|
-
const maybeRequiredVersion = (0, utils_1.getRequiredVersionFromDescriptionFile)(data, packageName);
|
|
200
|
-
return (data['name'] === packageName ||
|
|
201
|
-
typeof maybeRequiredVersion === 'string');
|
|
202
|
-
});
|
|
203
|
-
}),
|
|
204
|
-
]).then(([importResolved, requiredVersion]) => {
|
|
205
|
-
const currentConfig = {
|
|
206
|
-
...config,
|
|
207
|
-
importResolved,
|
|
208
|
-
import: importResolved ? config.import : undefined,
|
|
209
|
-
requiredVersion,
|
|
210
|
-
};
|
|
211
|
-
const consumedModule = new ConsumeSharedModule_1.default(directFallback ? compilation.compiler.context : context, currentConfig);
|
|
212
|
-
// Check for include version first
|
|
213
|
-
if (config.include && typeof config.include.version === 'string') {
|
|
214
|
-
if (!importResolved) {
|
|
215
|
-
return consumedModule;
|
|
216
|
-
}
|
|
217
|
-
return new Promise((resolveFilter) => {
|
|
218
|
-
(0, utils_1.getDescriptionFile)(compilation.inputFileSystem, path_1.default.dirname(importResolved), ['package.json'], (err, result) => {
|
|
219
|
-
if (err) {
|
|
220
|
-
return resolveFilter(consumedModule);
|
|
221
|
-
}
|
|
222
|
-
const { data } = result || {};
|
|
223
|
-
if (!data || !data['version'] || data['name'] !== request) {
|
|
224
|
-
return resolveFilter(consumedModule);
|
|
225
|
-
}
|
|
226
|
-
// Only include if version satisfies the include constraint
|
|
227
|
-
if (config.include &&
|
|
228
|
-
satisfy(parseRange(config.include.version), data['version'])) {
|
|
229
|
-
// Validate singleton usage with include.version
|
|
230
|
-
if (config.include &&
|
|
231
|
-
config.include.version &&
|
|
232
|
-
config.singleton) {
|
|
233
|
-
(0, utils_3.addSingletonFilterWarning)(compilation, config.shareKey || request, 'include', 'version', config.include.version, request, // moduleRequest
|
|
234
|
-
importResolved);
|
|
235
|
-
}
|
|
236
|
-
return resolveFilter(consumedModule);
|
|
237
|
-
}
|
|
238
|
-
// Check fallback version
|
|
239
|
-
if (config.include &&
|
|
240
|
-
typeof config.include.fallbackVersion === 'string' &&
|
|
241
|
-
config.include.fallbackVersion) {
|
|
242
|
-
if (satisfy(parseRange(config.include.version), config.include.fallbackVersion)) {
|
|
243
|
-
return resolveFilter(consumedModule);
|
|
244
|
-
}
|
|
245
|
-
return resolveFilter(undefined);
|
|
246
|
-
}
|
|
247
|
-
return resolveFilter(undefined);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
// Check for exclude version (existing logic)
|
|
252
|
-
if (config.exclude && typeof config.exclude.version === 'string') {
|
|
253
|
-
if (!importResolved) {
|
|
254
|
-
return consumedModule;
|
|
255
|
-
}
|
|
256
|
-
if (config.exclude &&
|
|
257
|
-
typeof config.exclude.fallbackVersion === 'string' &&
|
|
258
|
-
config.exclude.fallbackVersion) {
|
|
259
|
-
if (satisfy(parseRange(config.exclude.version), config.exclude.fallbackVersion)) {
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
return consumedModule;
|
|
263
|
-
}
|
|
264
|
-
return new Promise((resolveFilter) => {
|
|
265
|
-
(0, utils_1.getDescriptionFile)(compilation.inputFileSystem, path_1.default.dirname(importResolved), ['package.json'], (err, result) => {
|
|
266
|
-
if (err) {
|
|
267
|
-
return resolveFilter(consumedModule);
|
|
268
|
-
}
|
|
269
|
-
const { data } = result || {};
|
|
270
|
-
if (!data || !data['version'] || data['name'] !== request) {
|
|
271
|
-
return resolveFilter(consumedModule);
|
|
272
|
-
}
|
|
273
|
-
if (config.exclude &&
|
|
274
|
-
typeof config.exclude.version === 'string' &&
|
|
275
|
-
satisfy(parseRange(config.exclude.version), data['version'])) {
|
|
276
|
-
return resolveFilter(undefined);
|
|
277
|
-
}
|
|
278
|
-
// Validate singleton usage with exclude.version
|
|
279
|
-
if (config.exclude &&
|
|
280
|
-
config.exclude.version &&
|
|
281
|
-
config.singleton) {
|
|
282
|
-
(0, utils_3.addSingletonFilterWarning)(compilation, config.shareKey || request, 'exclude', 'version', config.exclude.version, request, // moduleRequest
|
|
283
|
-
importResolved);
|
|
284
|
-
}
|
|
285
|
-
return resolveFilter(consumedModule);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
return consumedModule;
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
apply(compiler) {
|
|
293
|
-
new FederationRuntimePlugin_1.default().apply(compiler);
|
|
294
|
-
process.env['FEDERATION_WEBPACK_PATH'] =
|
|
295
|
-
process.env['FEDERATION_WEBPACK_PATH'] || (0, normalize_webpack_path_1.getWebpackPath)(compiler);
|
|
296
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
|
|
297
|
-
compilation.dependencyFactories.set(ConsumeSharedFallbackDependency_1.default, normalModuleFactory);
|
|
298
|
-
let unresolvedConsumes, resolvedConsumes, prefixedConsumes;
|
|
299
|
-
const promise = (0, resolveMatchedConfigs_1.resolveMatchedConfigs)(compilation, this._consumes).then(({ resolved, unresolved, prefixed }) => {
|
|
300
|
-
resolvedConsumes = resolved;
|
|
301
|
-
unresolvedConsumes = unresolved;
|
|
302
|
-
prefixedConsumes = prefixed;
|
|
303
|
-
});
|
|
304
|
-
normalModuleFactory.hooks.factorize.tapPromise(PLUGIN_NAME, async (resolveData) => {
|
|
305
|
-
const { context, request, dependencies, contextInfo } = resolveData;
|
|
306
|
-
// wait for resolving to be complete
|
|
307
|
-
// BIND `this` for createConsumeSharedModule call
|
|
308
|
-
const boundCreateConsumeSharedModule = this.createConsumeSharedModule.bind(this);
|
|
309
|
-
return promise.then(() => {
|
|
310
|
-
if (dependencies[0] instanceof ConsumeSharedFallbackDependency_1.default ||
|
|
311
|
-
dependencies[0] instanceof ProvideForSharedDependency_1.default) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const { context, request, contextInfo } = resolveData;
|
|
315
|
-
const match = unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(request, contextInfo.issuerLayer)) ||
|
|
316
|
-
unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(request, undefined));
|
|
317
|
-
// First check direct match with original request
|
|
318
|
-
if (match !== undefined) {
|
|
319
|
-
// Use the bound function
|
|
320
|
-
return boundCreateConsumeSharedModule(compilation, context, request, match);
|
|
321
|
-
}
|
|
322
|
-
// Then try relative path handling and node_modules paths
|
|
323
|
-
let reconstructed = null;
|
|
324
|
-
let modulePathAfterNodeModules = null;
|
|
325
|
-
if (request &&
|
|
326
|
-
!path_1.default.isAbsolute(request) &&
|
|
327
|
-
RELATIVE_OR_ABSOLUTE_PATH_REGEX.test(request)) {
|
|
328
|
-
reconstructed = path_1.default.join(context, request);
|
|
329
|
-
modulePathAfterNodeModules =
|
|
330
|
-
(0, utils_3.extractPathAfterNodeModules)(reconstructed);
|
|
331
|
-
// Try to match with module path after node_modules
|
|
332
|
-
if (modulePathAfterNodeModules) {
|
|
333
|
-
const moduleMatch = unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(modulePathAfterNodeModules, contextInfo.issuerLayer)) ||
|
|
334
|
-
unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(modulePathAfterNodeModules, undefined));
|
|
335
|
-
if (moduleMatch !== undefined &&
|
|
336
|
-
moduleMatch.allowNodeModulesSuffixMatch) {
|
|
337
|
-
return boundCreateConsumeSharedModule(compilation, context, modulePathAfterNodeModules, moduleMatch);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
// Try to match with the full reconstructed path
|
|
341
|
-
const reconstructedMatch = unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(reconstructed, contextInfo.issuerLayer)) ||
|
|
342
|
-
unresolvedConsumes.get((0, utils_3.createLookupKeyForSharing)(reconstructed, undefined));
|
|
343
|
-
if (reconstructedMatch !== undefined) {
|
|
344
|
-
return boundCreateConsumeSharedModule(compilation, context, reconstructed, reconstructedMatch);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
// Check for prefixed consumes with original request
|
|
348
|
-
for (const [prefix, options] of prefixedConsumes) {
|
|
349
|
-
const lookup = options.request || prefix;
|
|
350
|
-
// Refined issuerLayer matching logic
|
|
351
|
-
if (options.issuerLayer) {
|
|
352
|
-
if (!contextInfo.issuerLayer) {
|
|
353
|
-
continue; // Option is layered, request is not: skip
|
|
354
|
-
}
|
|
355
|
-
if (contextInfo.issuerLayer !== options.issuerLayer) {
|
|
356
|
-
continue; // Both are layered but do not match: skip
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
// If contextInfo.issuerLayer exists but options.issuerLayer does not, allow (non-layered option matches layered request)
|
|
360
|
-
if (request.startsWith(lookup)) {
|
|
361
|
-
const remainder = request.slice(lookup.length);
|
|
362
|
-
if (!(0, utils_3.testRequestFilters)(remainder, options.include?.request, options.exclude?.request)) {
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
// Use the bound function
|
|
366
|
-
return boundCreateConsumeSharedModule(compilation, context, request, {
|
|
367
|
-
...options,
|
|
368
|
-
import: options.import
|
|
369
|
-
? options.import + remainder
|
|
370
|
-
: undefined,
|
|
371
|
-
shareKey: options.shareKey + remainder,
|
|
372
|
-
layer: options.layer,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
// Also check prefixed consumes with modulePathAfterNodeModules
|
|
377
|
-
if (modulePathAfterNodeModules) {
|
|
378
|
-
for (const [prefix, options] of prefixedConsumes) {
|
|
379
|
-
if (!options.allowNodeModulesSuffixMatch) {
|
|
380
|
-
continue;
|
|
381
|
-
}
|
|
382
|
-
// Refined issuerLayer matching logic for reconstructed path
|
|
383
|
-
if (options.issuerLayer) {
|
|
384
|
-
if (!contextInfo.issuerLayer) {
|
|
385
|
-
continue; // Option is layered, request is not: skip
|
|
386
|
-
}
|
|
387
|
-
if (contextInfo.issuerLayer !== options.issuerLayer) {
|
|
388
|
-
continue; // Both are layered but do not match: skip
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
// If contextInfo.issuerLayer exists but options.issuerLayer does not, allow (non-layered option matches layered request)
|
|
392
|
-
const lookup = options.request || prefix;
|
|
393
|
-
if (modulePathAfterNodeModules.startsWith(lookup)) {
|
|
394
|
-
const remainder = modulePathAfterNodeModules.slice(lookup.length);
|
|
395
|
-
if (!(0, utils_3.testRequestFilters)(remainder, options.include?.request, options.exclude?.request)) {
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
return boundCreateConsumeSharedModule(compilation, context, modulePathAfterNodeModules, {
|
|
399
|
-
...options,
|
|
400
|
-
import: options.import
|
|
401
|
-
? options.import + remainder
|
|
402
|
-
: undefined,
|
|
403
|
-
shareKey: options.shareKey + remainder,
|
|
404
|
-
layer: options.layer,
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return;
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
normalModuleFactory.hooks.createModule.tapPromise(PLUGIN_NAME, ({ resource }, { context, dependencies }) => {
|
|
413
|
-
// BIND `this` for createConsumeSharedModule call
|
|
414
|
-
const boundCreateConsumeSharedModule = this.createConsumeSharedModule.bind(this);
|
|
415
|
-
if (dependencies[0] instanceof ConsumeSharedFallbackDependency_1.default ||
|
|
416
|
-
dependencies[0] instanceof ProvideForSharedDependency_1.default) {
|
|
417
|
-
return Promise.resolve();
|
|
418
|
-
}
|
|
419
|
-
if (resource) {
|
|
420
|
-
const options = resolvedConsumes.get(resource);
|
|
421
|
-
if (options !== undefined) {
|
|
422
|
-
// Use the bound function
|
|
423
|
-
return boundCreateConsumeSharedModule(compilation, context, resource, options);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return Promise.resolve();
|
|
427
|
-
});
|
|
428
|
-
// Add finishModules hook to copy buildMeta/buildInfo from fallback modules *after* webpack's export analysis
|
|
429
|
-
// Running earlier causes failures, so we intentionally execute later than plugins like FlagDependencyExportsPlugin.
|
|
430
|
-
// This still follows webpack's pattern used by FlagDependencyExportsPlugin and InferAsyncModulesPlugin, but with a
|
|
431
|
-
// later stage. Based on webpack's Compilation.js: finishModules (line 2833) runs before seal (line 2920).
|
|
432
|
-
compilation.hooks.finishModules.tapAsync({
|
|
433
|
-
name: PLUGIN_NAME,
|
|
434
|
-
stage: 10, // Run after FlagDependencyExportsPlugin (default stage 0)
|
|
435
|
-
}, (modules, callback) => {
|
|
436
|
-
for (const module of modules) {
|
|
437
|
-
// Only process ConsumeSharedModule instances with fallback dependencies
|
|
438
|
-
if (!(module instanceof ConsumeSharedModule_1.default) ||
|
|
439
|
-
!module.options.import) {
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
let dependency;
|
|
443
|
-
if (module.options.eager) {
|
|
444
|
-
// For eager mode, get the fallback directly from dependencies
|
|
445
|
-
dependency = module.dependencies[0];
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
// For async mode, get it from the async dependencies block
|
|
449
|
-
dependency = module.blocks[0]?.dependencies[0];
|
|
450
|
-
}
|
|
451
|
-
if (dependency) {
|
|
452
|
-
const fallbackModule = compilation.moduleGraph.getModule(dependency);
|
|
453
|
-
if (fallbackModule &&
|
|
454
|
-
fallbackModule.buildMeta &&
|
|
455
|
-
fallbackModule.buildInfo) {
|
|
456
|
-
// Copy buildMeta and buildInfo following webpack's DelegatedModule pattern: this.buildMeta = { ...delegateData.buildMeta };
|
|
457
|
-
// This ensures ConsumeSharedModule inherits ESM/CJS detection (exportsType) and other optimization metadata
|
|
458
|
-
module.buildMeta = { ...fallbackModule.buildMeta };
|
|
459
|
-
module.buildInfo = { ...fallbackModule.buildInfo };
|
|
460
|
-
// Mark all exports as provided, to avoid webpack's export analysis from marking them as unused since we copy buildMeta
|
|
461
|
-
compilation.moduleGraph
|
|
462
|
-
.getExportsInfo(module)
|
|
463
|
-
.setUnknownExportsProvided();
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
callback();
|
|
468
|
-
});
|
|
469
|
-
compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (chunk, set) => {
|
|
470
|
-
set.add(RuntimeGlobals.module);
|
|
471
|
-
set.add(RuntimeGlobals.moduleCache);
|
|
472
|
-
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
|
473
|
-
set.add(RuntimeGlobals.shareScopeMap);
|
|
474
|
-
set.add(RuntimeGlobals.initializeSharing);
|
|
475
|
-
set.add(RuntimeGlobals.hasOwnProperty);
|
|
476
|
-
compilation.addRuntimeModule(chunk, new ConsumeSharedRuntimeModule_1.default(set));
|
|
477
|
-
// FIXME: need to remove webpack internal inject ShareRuntimeModule, otherwise there will be two ShareRuntimeModule
|
|
478
|
-
compilation.addRuntimeModule(chunk, new ShareRuntimeModule_1.default());
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
483
316
|
exports.default = ConsumeSharedPlugin;
|
|
484
317
|
//# sourceMappingURL=ConsumeSharedPlugin.js.map
|