@module-federation/enhanced 2.2.0 → 2.2.2
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 +38 -0
- package/dist/src/lib/container/ContainerPlugin.js +1 -2
- package/dist/src/lib/container/ContainerPlugin.js.map +1 -1
- package/dist/src/lib/container/ContainerReferencePlugin.js +1 -2
- package/dist/src/lib/container/ContainerReferencePlugin.js.map +1 -1
- package/dist/src/lib/container/HoistContainerReferencesPlugin.js +0 -1
- package/dist/src/lib/container/HoistContainerReferencesPlugin.js.map +1 -1
- package/dist/src/lib/container/ModuleFederationPlugin.js +1 -2
- package/dist/src/lib/container/ModuleFederationPlugin.js.map +1 -1
- package/dist/src/lib/container/RemoteModule.js +1 -2
- package/dist/src/lib/container/RemoteModule.js.map +1 -1
- package/dist/src/lib/container/runtime/EmbedFederationRuntimePlugin.js +1 -2
- package/dist/src/lib/container/runtime/EmbedFederationRuntimePlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationModulesPlugin.js +30 -46
- package/dist/src/lib/container/runtime/FederationModulesPlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +2 -3
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/lib/container/runtime/utils.js +2 -2
- package/dist/src/wrapper/BaseWrapperPlugin.js +2 -1
- package/dist/src/wrapper/BaseWrapperPlugin.js.map +1 -1
- package/dist/src/wrapper/FederationModulesPlugin.js +2 -2
- package/dist/src/wrapper/FederationModulesPlugin.js.map +1 -1
- package/dist/src/wrapper/ModuleFederationPlugin.js +2 -4
- package/dist/src/wrapper/ModuleFederationPlugin.js.map +1 -1
- package/package.json +16 -14
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @module-federation/enhanced
|
|
2
2
|
|
|
3
|
+
## 2.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8b8da62: fix(enhanced): replace require with lazyRequire to ensure proper initialization ordering in plugins
|
|
8
|
+
- Updated dependencies [95282ac]
|
|
9
|
+
- Updated dependencies [f81bbea]
|
|
10
|
+
- @module-federation/dts-plugin@2.2.2
|
|
11
|
+
- @module-federation/webpack-bundler-runtime@2.2.2
|
|
12
|
+
- @module-federation/cli@2.2.2
|
|
13
|
+
- @module-federation/manifest@2.2.2
|
|
14
|
+
- @module-federation/rspack@2.2.2
|
|
15
|
+
- @module-federation/runtime-tools@2.2.2
|
|
16
|
+
- @module-federation/inject-external-runtime-core-plugin@2.2.2
|
|
17
|
+
- @module-federation/sdk@2.2.2
|
|
18
|
+
- @module-federation/managers@2.2.2
|
|
19
|
+
- @module-federation/bridge-react-webpack-plugin@2.2.2
|
|
20
|
+
- @module-federation/data-prefetch@2.2.2
|
|
21
|
+
- @module-federation/error-codes@2.2.2
|
|
22
|
+
|
|
23
|
+
## 2.2.1
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- fix(enhanced): fix missed deps
|
|
28
|
+
- @module-federation/rspack@2.2.1
|
|
29
|
+
- @module-federation/webpack-bundler-runtime@2.2.1
|
|
30
|
+
- @module-federation/sdk@2.2.1
|
|
31
|
+
- @module-federation/runtime-tools@2.2.1
|
|
32
|
+
- @module-federation/managers@2.2.1
|
|
33
|
+
- @module-federation/manifest@2.2.1
|
|
34
|
+
- @module-federation/dts-plugin@2.2.1
|
|
35
|
+
- @module-federation/bridge-react-webpack-plugin@2.2.1
|
|
36
|
+
- @module-federation/data-prefetch@2.2.1
|
|
37
|
+
- @module-federation/error-codes@2.2.1
|
|
38
|
+
- @module-federation/inject-external-runtime-core-plugin@2.2.1
|
|
39
|
+
- @module-federation/cli@2.2.1
|
|
40
|
+
|
|
3
41
|
## 2.2.0
|
|
4
42
|
|
|
5
43
|
### Patch Changes
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
4
3
|
const require_lib_container_options = require('./options.js');
|
|
5
4
|
const require_lib_container_ContainerEntryDependency = require('./ContainerEntryDependency.js');
|
|
6
5
|
const require_lib_container_ContainerExposedDependency = require('./ContainerExposedDependency.js');
|
|
7
6
|
const require_lib_container_ContainerEntryModuleFactory = require('./ContainerEntryModuleFactory.js');
|
|
7
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
8
8
|
const require_lib_container_runtime_FederationRuntimeDependency = require('./runtime/FederationRuntimeDependency.js');
|
|
9
9
|
const require_lib_container_runtime_FederationRuntimePlugin = require('./runtime/FederationRuntimePlugin.js');
|
|
10
10
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
11
11
|
|
|
12
12
|
//#region src/lib/container/ContainerPlugin.ts
|
|
13
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
14
13
|
const ModuleDependency = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/dependencies/ModuleDependency"));
|
|
15
14
|
const EntryDependency = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/dependencies/EntryDependency"));
|
|
16
15
|
require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/create-schema-validation"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerPlugin.js","names":["parseOptions","FederationRuntimePlugin","FederationModulesPlugin","ContainerEntryDependency","ContainerEntryModuleFactory","ContainerExposedDependency","FederationRuntimeDependency"],"sources":["../../../../src/lib/container/ContainerPlugin.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport ContainerEntryModuleFactory from './ContainerEntryModuleFactory';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { parseOptions } from './options';\nimport type {\n Compiler,\n Compilation,\n WebpackError,\n WebpackPluginInstance,\n WebpackPluginFunction,\n} from 'webpack';\nimport type { containerPlugin } from '@module-federation/sdk';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport checkOptions from '../../schemas/container/ContainerPlugin.check';\nimport schema from '../../schemas/container/ContainerPlugin';\nimport FederationRuntimeDependency from './runtime/FederationRuntimeDependency';\nimport type { OptimizationSplitChunksCacheGroup } from 'webpack/lib/optimize/SplitChunksPlugin';\nimport type { Falsy } from 'webpack/declarations/WebpackOptions';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\n// const validate = createSchemaValidation(checkOptions, () => schema, {\n// name: 'Container Plugin',\n// baseDataPath: 'options',\n// });\n\nconst PLUGIN_NAME = 'ContainerPlugin';\n\nclass ContainerPlugin {\n _options: containerPlugin.ContainerPluginOptions;\n name: string;\n\n constructor(options: containerPlugin.ContainerPluginOptions) {\n // validate(options);\n this.name = PLUGIN_NAME;\n\n this._options = {\n name: options.name,\n shareScope: options.shareScope || 'default',\n library: options.library || {\n type: 'global',\n name: options.name,\n },\n runtime: options.runtime,\n filename: options.filename || undefined,\n //@ts-ignore\n exposes: parseOptions(\n options.exposes,\n (item) => ({\n import: Array.isArray(item) ? item : [item],\n name: undefined,\n }),\n (item) => ({\n import: Array.isArray(item.import) ? item.import : [item.import],\n name: item.name || undefined,\n }),\n ),\n runtimePlugins: options.runtimePlugins,\n dataPrefetch: options.dataPrefetch,\n };\n }\n\n // container should not be affected by splitChunks\n static patchChunkSplit(compiler: Compiler, name: string): void {\n const { splitChunks } = compiler.options.optimization;\n const patchChunkSplit = (\n cacheGroup:\n | string\n | false\n | ((...args: any[]) => any)\n | RegExp\n | OptimizationSplitChunksCacheGroup,\n ) => {\n switch (typeof cacheGroup) {\n case 'boolean':\n case 'string':\n case 'function':\n break;\n // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately\n case 'object':\n {\n if (cacheGroup instanceof RegExp) {\n break;\n }\n if (!cacheGroup.chunks) {\n break;\n }\n if (typeof cacheGroup.chunks === 'function') {\n const prevChunks = cacheGroup.chunks;\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return prevChunks(chunk);\n };\n break;\n }\n\n if (cacheGroup.chunks === 'all') {\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return true;\n };\n break;\n }\n if (cacheGroup.chunks === 'initial') {\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return chunk.isOnlyInitial();\n };\n break;\n }\n }\n break;\n }\n };\n\n if (!splitChunks) {\n return;\n }\n // patch splitChunk.chunks\n patchChunkSplit(splitChunks);\n\n const cacheGroups = splitChunks.cacheGroups;\n if (!cacheGroups) {\n return;\n }\n\n // patch splitChunk.cacheGroups[key].chunks\n Object.keys(cacheGroups).forEach((cacheGroupKey) => {\n patchChunkSplit(cacheGroups[cacheGroupKey]);\n });\n }\n\n apply(compiler: Compiler): void {\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p: Falsy | WebpackPluginInstance | WebpackPluginFunction) => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (!useModuleFederationPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, this._options.name);\n }\n\n const federationRuntimePluginInstance = new FederationRuntimePlugin();\n federationRuntimePluginInstance.apply(compiler);\n\n const { name, exposes, shareScope, filename, library, runtime } =\n this._options;\n\n if (\n library &&\n compiler.options.output &&\n compiler.options.output.enabledLibraryTypes &&\n !compiler.options.output.enabledLibraryTypes.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes.push(library.type);\n }\n\n compiler.hooks.make.tapAsync(\n PLUGIN_NAME,\n async (\n compilation: Compilation,\n callback: (error?: WebpackError | null | undefined) => void,\n ) => {\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const federationRuntimeDependency =\n federationRuntimePluginInstance.getDependency(compiler);\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n federationRuntimePluginInstance.entryFilePath,\n this._options.dataPrefetch,\n );\n dep.loc = { name };\n\n await new Promise((resolve, reject) => {\n compilation.addEntry(\n compilation.options.context || '',\n dep,\n {\n name,\n filename,\n runtime,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return reject(error);\n hooks.addContainerEntryDependency.call(dep);\n resolve(undefined);\n },\n );\n }).catch(callback);\n\n await new Promise((resolve, reject) => {\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err, module) => {\n if (err) {\n return reject(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n resolve(undefined);\n },\n );\n }).catch(callback);\n\n callback();\n },\n );\n\n // this will still be copied into child compiler, so it needs a check to avoid running hook on child\n // we have to use finishMake in order to check the entries created and see if there are multiple runtime chunks\n compiler.hooks.finishMake.tapAsync(\n PLUGIN_NAME,\n (compilation: Compilation, callback) => {\n if (\n compilation.compiler.parentCompilation &&\n compilation.compiler.parentCompilation !== compilation\n ) {\n return callback();\n }\n\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const createdRuntimes = new Set<string>();\n\n for (const entry of compilation.entries.values()) {\n const runtime = entry.options.runtime;\n if (runtime) {\n createdRuntimes.add(runtime);\n }\n }\n\n if (\n createdRuntimes.size === 0 &&\n !compilation.options?.optimization?.runtimeChunk\n ) {\n return callback();\n }\n\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n federationRuntimePluginInstance.entryFilePath,\n this._options.dataPrefetch,\n );\n\n dep.loc = { name };\n\n compilation.addInclude(\n compilation.options.context || '',\n dep,\n { name: undefined },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n hooks.addContainerEntryDependency.call(dep);\n callback();\n },\n );\n },\n );\n\n // add the container entry module\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n ContainerEntryDependency,\n new ContainerEntryModuleFactory(),\n );\n\n compilation.dependencyFactories.set(\n ContainerExposedDependency,\n normalModuleFactory,\n );\n\n if (!compilation.dependencyFactories.has(EntryDependency)) {\n compilation.dependencyFactories.set(\n EntryDependency,\n normalModuleFactory,\n );\n }\n },\n );\n\n // add include of federation runtime\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n }\n}\n\nexport default ContainerPlugin;\n"],"mappings":";;;;;;;;;;;;oFAkBwE;AAOxE,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,kBAAkB,gFACD,2CAA2C,CACjE;AAE8B,gFACR,4CAA4C,CAClE;AAOD,MAA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B,IAC9BA,mEACA,IAAI,iBAAiB,UAAU,CAChC;IAEJ"}
|
|
1
|
+
{"version":3,"file":"ContainerPlugin.js","names":["parseOptions","FederationRuntimePlugin","FederationModulesPlugin","ContainerEntryDependency","ContainerEntryModuleFactory","ContainerExposedDependency","FederationRuntimeDependency"],"sources":["../../../../src/lib/container/ContainerPlugin.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy, Marais Rossouw @maraisr\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport ContainerEntryModuleFactory from './ContainerEntryModuleFactory';\nimport ContainerExposedDependency from './ContainerExposedDependency';\nimport { parseOptions } from './options';\nimport type {\n Compiler,\n Compilation,\n WebpackError,\n WebpackPluginInstance,\n WebpackPluginFunction,\n} from 'webpack';\nimport type { containerPlugin } from '@module-federation/sdk';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport checkOptions from '../../schemas/container/ContainerPlugin.check';\nimport schema from '../../schemas/container/ContainerPlugin';\nimport FederationRuntimeDependency from './runtime/FederationRuntimeDependency';\nimport type { OptimizationSplitChunksCacheGroup } from 'webpack/lib/optimize/SplitChunksPlugin';\nimport type { Falsy } from 'webpack/declarations/WebpackOptions';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst EntryDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/EntryDependency'),\n) as typeof import('webpack/lib/dependencies/EntryDependency');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\n// const validate = createSchemaValidation(checkOptions, () => schema, {\n// name: 'Container Plugin',\n// baseDataPath: 'options',\n// });\n\nconst PLUGIN_NAME = 'ContainerPlugin';\n\nclass ContainerPlugin {\n _options: containerPlugin.ContainerPluginOptions;\n name: string;\n\n constructor(options: containerPlugin.ContainerPluginOptions) {\n // validate(options);\n this.name = PLUGIN_NAME;\n\n this._options = {\n name: options.name,\n shareScope: options.shareScope || 'default',\n library: options.library || {\n type: 'global',\n name: options.name,\n },\n runtime: options.runtime,\n filename: options.filename || undefined,\n //@ts-ignore\n exposes: parseOptions(\n options.exposes,\n (item) => ({\n import: Array.isArray(item) ? item : [item],\n name: undefined,\n }),\n (item) => ({\n import: Array.isArray(item.import) ? item.import : [item.import],\n name: item.name || undefined,\n }),\n ),\n runtimePlugins: options.runtimePlugins,\n dataPrefetch: options.dataPrefetch,\n };\n }\n\n // container should not be affected by splitChunks\n static patchChunkSplit(compiler: Compiler, name: string): void {\n const { splitChunks } = compiler.options.optimization;\n const patchChunkSplit = (\n cacheGroup:\n | string\n | false\n | ((...args: any[]) => any)\n | RegExp\n | OptimizationSplitChunksCacheGroup,\n ) => {\n switch (typeof cacheGroup) {\n case 'boolean':\n case 'string':\n case 'function':\n break;\n // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately\n case 'object':\n {\n if (cacheGroup instanceof RegExp) {\n break;\n }\n if (!cacheGroup.chunks) {\n break;\n }\n if (typeof cacheGroup.chunks === 'function') {\n const prevChunks = cacheGroup.chunks;\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return prevChunks(chunk);\n };\n break;\n }\n\n if (cacheGroup.chunks === 'all') {\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return true;\n };\n break;\n }\n if (cacheGroup.chunks === 'initial') {\n cacheGroup.chunks = (chunk) => {\n if (\n chunk.name &&\n (chunk.name === name || chunk.name === name + '_partial')\n ) {\n return false;\n }\n return chunk.isOnlyInitial();\n };\n break;\n }\n }\n break;\n }\n };\n\n if (!splitChunks) {\n return;\n }\n // patch splitChunk.chunks\n patchChunkSplit(splitChunks);\n\n const cacheGroups = splitChunks.cacheGroups;\n if (!cacheGroups) {\n return;\n }\n\n // patch splitChunk.cacheGroups[key].chunks\n Object.keys(cacheGroups).forEach((cacheGroupKey) => {\n patchChunkSplit(cacheGroups[cacheGroupKey]);\n });\n }\n\n apply(compiler: Compiler): void {\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p: Falsy | WebpackPluginInstance | WebpackPluginFunction) => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (!useModuleFederationPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, this._options.name);\n }\n\n const federationRuntimePluginInstance = new FederationRuntimePlugin();\n federationRuntimePluginInstance.apply(compiler);\n\n const { name, exposes, shareScope, filename, library, runtime } =\n this._options;\n\n if (\n library &&\n compiler.options.output &&\n compiler.options.output.enabledLibraryTypes &&\n !compiler.options.output.enabledLibraryTypes.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes.push(library.type);\n }\n\n compiler.hooks.make.tapAsync(\n PLUGIN_NAME,\n async (\n compilation: Compilation,\n callback: (error?: WebpackError | null | undefined) => void,\n ) => {\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const federationRuntimeDependency =\n federationRuntimePluginInstance.getDependency(compiler);\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n federationRuntimePluginInstance.entryFilePath,\n this._options.dataPrefetch,\n );\n dep.loc = { name };\n\n await new Promise((resolve, reject) => {\n compilation.addEntry(\n compilation.options.context || '',\n dep,\n {\n name,\n filename,\n runtime,\n library,\n },\n (error: WebpackError | null | undefined) => {\n if (error) return reject(error);\n hooks.addContainerEntryDependency.call(dep);\n resolve(undefined);\n },\n );\n }).catch(callback);\n\n await new Promise((resolve, reject) => {\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err, module) => {\n if (err) {\n return reject(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n resolve(undefined);\n },\n );\n }).catch(callback);\n\n callback();\n },\n );\n\n // this will still be copied into child compiler, so it needs a check to avoid running hook on child\n // we have to use finishMake in order to check the entries created and see if there are multiple runtime chunks\n compiler.hooks.finishMake.tapAsync(\n PLUGIN_NAME,\n (compilation: Compilation, callback) => {\n if (\n compilation.compiler.parentCompilation &&\n compilation.compiler.parentCompilation !== compilation\n ) {\n return callback();\n }\n\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const createdRuntimes = new Set<string>();\n\n for (const entry of compilation.entries.values()) {\n const runtime = entry.options.runtime;\n if (runtime) {\n createdRuntimes.add(runtime);\n }\n }\n\n if (\n createdRuntimes.size === 0 &&\n !compilation.options?.optimization?.runtimeChunk\n ) {\n return callback();\n }\n\n const dep = new ContainerEntryDependency(\n name,\n //@ts-ignore\n exposes,\n shareScope,\n federationRuntimePluginInstance.entryFilePath,\n this._options.dataPrefetch,\n );\n\n dep.loc = { name };\n\n compilation.addInclude(\n compilation.options.context || '',\n dep,\n { name: undefined },\n (error: WebpackError | null | undefined) => {\n if (error) return callback(error);\n hooks.addContainerEntryDependency.call(dep);\n callback();\n },\n );\n },\n );\n\n // add the container entry module\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n ContainerEntryDependency,\n new ContainerEntryModuleFactory(),\n );\n\n compilation.dependencyFactories.set(\n ContainerExposedDependency,\n normalModuleFactory,\n );\n\n if (!compilation.dependencyFactories.has(EntryDependency)) {\n compilation.dependencyFactories.set(\n EntryDependency,\n normalModuleFactory,\n );\n }\n },\n );\n\n // add include of federation runtime\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n }\n}\n\nexport default ContainerPlugin;\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,kBAAkB,gFACD,2CAA2C,CACjE;AAE8B,gFACR,4CAA4C,CAClE;AAOD,MAAM,cAAc;AAEpB,IAAM,kBAAN,MAAM,gBAAgB;CAIpB,YAAY,SAAiD;AAE3D,OAAK,OAAO;AAEZ,OAAK,WAAW;GACd,MAAM,QAAQ;GACd,YAAY,QAAQ,cAAc;GAClC,SAAS,QAAQ,WAAW;IAC1B,MAAM;IACN,MAAM,QAAQ;IACf;GACD,SAAS,QAAQ;GACjB,UAAU,QAAQ,YAAY;GAE9B,SAASA,2CACP,QAAQ,UACP,UAAU;IACT,QAAQ,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC,KAAK;IAC3C,MAAM;IACP,IACA,UAAU;IACT,QAAQ,MAAM,QAAQ,KAAK,OAAO,GAAG,KAAK,SAAS,CAAC,KAAK,OAAO;IAChE,MAAM,KAAK,QAAQ;IACpB,EACF;GACD,gBAAgB,QAAQ;GACxB,cAAc,QAAQ;GACvB;;CAIH,OAAO,gBAAgB,UAAoB,MAAoB;EAC7D,MAAM,EAAE,gBAAgB,SAAS,QAAQ;EACzC,MAAM,mBACJ,eAMG;AACH,WAAQ,OAAO,YAAf;IACE,KAAK;IACL,KAAK;IACL,KAAK,WACH;IAEF,KAAK;AAED,SAAI,sBAAsB,OACxB;AAEF,SAAI,CAAC,WAAW,OACd;AAEF,SAAI,OAAO,WAAW,WAAW,YAAY;MAC3C,MAAM,aAAa,WAAW;AAC9B,iBAAW,UAAU,UAAU;AAC7B,WACE,MAAM,SACL,MAAM,SAAS,QAAQ,MAAM,SAAS,OAAO,YAE9C,QAAO;AAET,cAAO,WAAW,MAAM;;AAE1B;;AAGF,SAAI,WAAW,W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2DAA6B,CAClC;AAED,eAAY,oBAAoB,IAC9BC,0DACA,oBACD;AAED,OAAI,CAAC,YAAY,oBAAoB,IAAI,gBAAgB,CACvD,aAAY,oBAAoB,IAC9B,iBACA,oBACD;IAGN;AAGD,WAAS,MAAM,gBAAgB,IAC7B,cACC,aAA0B,EAAE,0BAA0B;AACrD,eAAY,oBAAoB,IAC9BC,mEACA,oBACD;AACD,eAAY,oBAAoB,IAC9BA,mEACA,IAAI,iBAAiB,UAAU,CAChC;IAEJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
4
3
|
const require_lib_container_options = require('./options.js');
|
|
4
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
5
5
|
const require_lib_container_runtime_FederationRuntimePlugin = require('./runtime/FederationRuntimePlugin.js');
|
|
6
6
|
const require_lib_container_FallbackDependency = require('./FallbackDependency.js');
|
|
7
7
|
const require_lib_container_FallbackItemDependency = require('./FallbackItemDependency.js');
|
|
@@ -12,7 +12,6 @@ const require_lib_container_RemoteRuntimeModule = require('./RemoteRuntimeModule
|
|
|
12
12
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
13
13
|
|
|
14
14
|
//#region src/lib/container/ContainerReferencePlugin.ts
|
|
15
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
16
15
|
const { ExternalsPlugin } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
17
16
|
require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/create-schema-validation"));
|
|
18
17
|
const slashCode = "/".charCodeAt(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerReferencePlugin.js","names":["parseOptions","FederationRuntimePlugin","RemoteToExternalDependency","FallbackItemDependency","FallbackDependency","FallbackModuleFactory","FederationModulesPlugin","RemoteModule","RemoteRuntimeModule"],"sources":["../../../../src/lib/container/ContainerReferencePlugin.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\nimport type { Compiler } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\n// import * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport FallbackDependency from './FallbackDependency';\nimport FallbackItemDependency from './FallbackItemDependency';\nimport FallbackModuleFactory from './FallbackModuleFactory';\nimport RemoteModule from './RemoteModule';\nimport RemoteRuntimeModule from './RemoteRuntimeModule';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { parseOptions } from './options';\nimport type {\n containerReferencePlugin,\n moduleFederationPlugin,\n} from '@module-federation/sdk';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport schema from '../../schemas/container/ContainerReferencePlugin';\nimport checkOptions from '../../schemas/container/ContainerReferencePlugin.check';\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\n// const validate = createSchemaValidation(\n// //eslint-disable-next-line\n// checkOptions,\n// () => schema,\n// {\n// name: 'Container Reference Plugin',\n// baseDataPath: 'options',\n// },\n// );\n\nconst slashCode = '/'.charCodeAt(0);\n\nclass ContainerReferencePlugin {\n private _remoteType: moduleFederationPlugin.ExternalsType;\n private _remotes: [string, moduleFederationPlugin.RemotesConfig][];\n\n constructor(\n options: containerReferencePlugin.ContainerReferencePluginOptions,\n ) {\n // validate(options);\n\n this._remoteType = options.remoteType;\n this._remotes = parseOptions(\n options.remotes,\n (item) => ({\n external: Array.isArray(item) ? item : [item],\n shareScope: options.shareScope || 'default',\n }),\n (item) => ({\n external: Array.isArray(item.external)\n ? item.external\n : [item.external],\n shareScope: item.shareScope || options.shareScope || 'default',\n }),\n );\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n const { _remotes: remotes, _remoteType: remoteType } = this;\n new FederationRuntimePlugin().apply(compiler);\n /** @type {Record<string, string>} */\n const remoteExternals: Record<string, string> = {};\n\n for (const [key, config] of remotes) {\n let i = 0;\n for (const external of config.external) {\n if (typeof external === 'string' && external.startsWith('internal ')) {\n continue;\n }\n remoteExternals[\n `webpack/container/reference/${key}${i ? `/fallback-${i}` : ''}`\n ] = external;\n i++;\n }\n }\n const Externals = compiler.webpack.ExternalsPlugin || ExternalsPlugin;\n new Externals(remoteType, remoteExternals).apply(compiler);\n\n compiler.hooks.compilation.tap(\n 'ContainerReferencePlugin',\n (compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n RemoteToExternalDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackItemDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackDependency,\n new FallbackModuleFactory(),\n );\n\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n\n normalModuleFactory.hooks.factorize.tap(\n 'ContainerReferencePlugin',\n //@ts-ignore\n (data) => {\n if (!data.request.includes('!')) {\n for (const [key, config] of remotes) {\n if (\n data.request.startsWith(`${key}`) &&\n (data.request.length === key.length ||\n data.request.charCodeAt(key.length) === slashCode)\n ) {\n const remoteModule = new RemoteModule(\n data.request,\n //@ts-ignore\n config.external.map((external: any, i: any) =>\n external.startsWith('internal ')\n ? external.slice(9)\n : `webpack/container/reference/${key}${\n i ? `/fallback-${i}` : ''\n }`,\n ),\n `.${data.request.slice(key.length)}`,\n //@ts-ignore\n config.shareScope,\n );\n hooks.addRemoteDependency.call(remoteModule);\n return remoteModule;\n }\n }\n }\n },\n );\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.ensureChunkHandlers)\n .tap('ContainerReferencePlugin', (chunk, set) => {\n set.add(compiler.webpack.RuntimeGlobals.module);\n set.add(compiler.webpack.RuntimeGlobals.moduleFactoriesAddOnly);\n set.add(compiler.webpack.RuntimeGlobals.hasOwnProperty);\n set.add(compiler.webpack.RuntimeGlobals.initializeSharing);\n set.add(compiler.webpack.RuntimeGlobals.shareScopeMap);\n compilation.addRuntimeModule(chunk, new RemoteRuntimeModule());\n });\n },\n );\n }\n}\n\nexport default ContainerReferencePlugin;\n"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ContainerReferencePlugin.js","names":["parseOptions","FederationRuntimePlugin","RemoteToExternalDependency","FallbackItemDependency","FallbackDependency","FallbackModuleFactory","FederationModulesPlugin","RemoteModule","RemoteRuntimeModule"],"sources":["../../../../src/lib/container/ContainerReferencePlugin.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\nimport type { Compiler } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\n// import * as RuntimeGlobals from 'webpack/lib/RuntimeGlobals';\nimport FallbackDependency from './FallbackDependency';\nimport FallbackItemDependency from './FallbackItemDependency';\nimport FallbackModuleFactory from './FallbackModuleFactory';\nimport RemoteModule from './RemoteModule';\nimport RemoteRuntimeModule from './RemoteRuntimeModule';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { parseOptions } from './options';\nimport type {\n containerReferencePlugin,\n moduleFederationPlugin,\n} from '@module-federation/sdk';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport schema from '../../schemas/container/ContainerReferencePlugin';\nimport checkOptions from '../../schemas/container/ContainerReferencePlugin.check';\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst createSchemaValidation = require(\n normalizeWebpackPath('webpack/lib/util/create-schema-validation'),\n) as typeof import('webpack/lib/util/create-schema-validation');\n\n// const validate = createSchemaValidation(\n// //eslint-disable-next-line\n// checkOptions,\n// () => schema,\n// {\n// name: 'Container Reference Plugin',\n// baseDataPath: 'options',\n// },\n// );\n\nconst slashCode = '/'.charCodeAt(0);\n\nclass ContainerReferencePlugin {\n private _remoteType: moduleFederationPlugin.ExternalsType;\n private _remotes: [string, moduleFederationPlugin.RemotesConfig][];\n\n constructor(\n options: containerReferencePlugin.ContainerReferencePluginOptions,\n ) {\n // validate(options);\n\n this._remoteType = options.remoteType;\n this._remotes = parseOptions(\n options.remotes,\n (item) => ({\n external: Array.isArray(item) ? item : [item],\n shareScope: options.shareScope || 'default',\n }),\n (item) => ({\n external: Array.isArray(item.external)\n ? item.external\n : [item.external],\n shareScope: item.shareScope || options.shareScope || 'default',\n }),\n );\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n const { _remotes: remotes, _remoteType: remoteType } = this;\n new FederationRuntimePlugin().apply(compiler);\n /** @type {Record<string, string>} */\n const remoteExternals: Record<string, string> = {};\n\n for (const [key, config] of remotes) {\n let i = 0;\n for (const external of config.external) {\n if (typeof external === 'string' && external.startsWith('internal ')) {\n continue;\n }\n remoteExternals[\n `webpack/container/reference/${key}${i ? `/fallback-${i}` : ''}`\n ] = external;\n i++;\n }\n }\n const Externals = compiler.webpack.ExternalsPlugin || ExternalsPlugin;\n new Externals(remoteType, remoteExternals).apply(compiler);\n\n compiler.hooks.compilation.tap(\n 'ContainerReferencePlugin',\n (compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n RemoteToExternalDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackItemDependency,\n normalModuleFactory,\n );\n\n compilation.dependencyFactories.set(\n FallbackDependency,\n new FallbackModuleFactory(),\n );\n\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n\n normalModuleFactory.hooks.factorize.tap(\n 'ContainerReferencePlugin',\n //@ts-ignore\n (data) => {\n if (!data.request.includes('!')) {\n for (const [key, config] of remotes) {\n if (\n data.request.startsWith(`${key}`) &&\n (data.request.length === key.length ||\n data.request.charCodeAt(key.length) === slashCode)\n ) {\n const remoteModule = new RemoteModule(\n data.request,\n //@ts-ignore\n config.external.map((external: any, i: any) =>\n external.startsWith('internal ')\n ? external.slice(9)\n : `webpack/container/reference/${key}${\n i ? `/fallback-${i}` : ''\n }`,\n ),\n `.${data.request.slice(key.length)}`,\n //@ts-ignore\n config.shareScope,\n );\n hooks.addRemoteDependency.call(remoteModule);\n return remoteModule;\n }\n }\n }\n },\n );\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.ensureChunkHandlers)\n .tap('ContainerReferencePlugin', (chunk, set) => {\n set.add(compiler.webpack.RuntimeGlobals.module);\n set.add(compiler.webpack.RuntimeGlobals.moduleFactoriesAddOnly);\n set.add(compiler.webpack.RuntimeGlobals.hasOwnProperty);\n set.add(compiler.webpack.RuntimeGlobals.initializeSharing);\n set.add(compiler.webpack.RuntimeGlobals.shareScopeMap);\n compilation.addRuntimeModule(chunk, new RemoteRuntimeModule());\n });\n },\n );\n }\n}\n\nexport default ContainerReferencePlugin;\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAM,EAAE,oBAAoB,gFACL,UAAU,CAChC;AAE8B,gFACR,4CAA4C,CAClE;AAYD,MAAM,YAAY,IAAI,WAAW,EAAE;AAEnC,IAAM,2BAAN,MAA+B;CAI7B,YACE,SACA;AAGA,OAAK,cAAc,QAAQ;AAC3B,OAAK,WAAWA,2CACd,QAAQ,UACP,UAAU;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MAAM,EAAE,GACjB,+BAA+B,MAC7B,IAAI,aAAa,MAAM,KAE9B,EACD,IAAI,KAAK,QAAQ,MAAM,IAAI,OAAO,IAElC,OAAO,WACR;AACD,YAAM,oBAAoB,KAAK,aAAa;AAC5C,aAAO;;;KAKhB;AAED,eAAY,MAAM,yBACf,IAAI,SAAS,QAAQ,eAAe,oBAAoB,CACxD,IAAI,6BAA6B,OAAO,QAAQ;AAC/C,QAAI,IAAI,SAAS,QAAQ,eAAe,OAAO;AAC/C,QAAI,IAAI,SAAS,QAAQ,eAAe,uBAAuB;AAC/D,QAAI,IAAI,SAAS,QAAQ,eAAe,eAAe;AACvD,QAAI,IAAI,SAAS,QAAQ,eAAe,kBAAkB;AAC1D,QAAI,IAAI,SAAS,QAAQ,eAAe,cAAc;AACtD,gBAAY,iBAAiB,OAAO,IAAIC,mDAAqB,CAAC;KAC9D;IAEP"}
|
|
@@ -4,7 +4,6 @@ const require_lib_container_runtime_FederationModulesPlugin = require('./runtime
|
|
|
4
4
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
5
5
|
|
|
6
6
|
//#region src/lib/container/HoistContainerReferencesPlugin.ts
|
|
7
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
8
7
|
const { AsyncDependenciesBlock, ExternalModule } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
9
8
|
const PLUGIN_NAME = "HoistContainerReferences";
|
|
10
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HoistContainerReferencesPlugin.js","names":["FederationModulesPlugin"],"sources":["../../../../src/lib/container/HoistContainerReferencesPlugin.ts"],"sourcesContent":["import type {\n Chunk,\n Compiler,\n Compilation,\n WebpackPluginInstance,\n Module,\n Dependency,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport FederationRuntimeDependency from './runtime/FederationRuntimeDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport FallbackDependency from './FallbackDependency';\n\nconst { AsyncDependenciesBlock, ExternalModule } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst PLUGIN_NAME = 'HoistContainerReferences';\n\n/**\n * This plugin hoists container-related modules into runtime chunks when using runtimeChunk: single configuration.\n */\nclass HoistContainerReferences implements WebpackPluginInstance {\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation) => {\n const logger = compilation.getLogger(PLUGIN_NAME);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const containerEntryDependencies = new Set<Dependency>();\n const federationRuntimeDependencies = new Set<Dependency>();\n const remoteDependencies = new Set<Dependency>();\n\n hooks.addContainerEntryDependency.tap(\n 'HoistContainerReferences',\n (dep: ContainerEntryDependency) => {\n containerEntryDependencies.add(dep);\n },\n );\n hooks.addFederationRuntimeDependency.tap(\n 'HoistContainerReferences',\n (dep: FederationRuntimeDependency) => {\n federationRuntimeDependencies.add(dep);\n },\n );\n hooks.addRemoteDependency.tap(\n 'HoistContainerReferences',\n (dep: RemoteToExternalDependency | FallbackDependency) => {\n remoteDependencies.add(dep);\n },\n );\n\n // Hook into the optimizeChunks phase\n compilation.hooks.optimizeChunks.tap(\n {\n name: PLUGIN_NAME,\n // advanced stage is where SplitChunksPlugin runs.\n stage: 11, // advanced + 1\n },\n (chunks: Iterable<Chunk>) => {\n const runtimeChunks = this.getRuntimeChunks(compilation);\n this.hoistModulesInChunks(\n compilation,\n runtimeChunks,\n logger,\n containerEntryDependencies,\n federationRuntimeDependencies,\n remoteDependencies,\n );\n },\n );\n },\n );\n }\n\n // Method to hoist modules in chunks\n private hoistModulesInChunks(\n compilation: Compilation,\n runtimeChunks: Set<Chunk>,\n logger: ReturnType<Compilation['getLogger']>,\n containerEntryDependencies: Set<Dependency>,\n federationRuntimeDependencies: Set<Dependency>,\n remoteDependencies: Set<Dependency>,\n ): void {\n const { chunkGraph, moduleGraph } = compilation;\n const allModulesToHoist = new Set<Module>();\n\n // Process container entry dependencies (needed for nextjs-mf exposed modules)\n for (const dep of containerEntryDependencies) {\n const containerEntryModule = moduleGraph.getModule(dep);\n if (!containerEntryModule) continue;\n const referencedModules = getAllReferencedModules(\n compilation,\n containerEntryModule,\n 'initial',\n );\n referencedModules.forEach((m: Module) => allModulesToHoist.add(m));\n const moduleRuntimes = chunkGraph.getModuleRuntimes(containerEntryModule);\n const runtimes = new Set<string>();\n for (const runtimeSpec of moduleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) {\n runtimes.add(runtimeKey);\n }\n },\n );\n }\n for (const runtime of runtimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n // Federation Runtime Dependencies: use 'initial' (not 'all')\n for (const dep of federationRuntimeDependencies) {\n const runtimeModule = moduleGraph.getModule(dep);\n if (!runtimeModule) continue;\n const referencedModules = getAllReferencedModules(\n compilation,\n runtimeModule,\n 'initial',\n );\n referencedModules.forEach((m: Module) => allModulesToHoist.add(m));\n const moduleRuntimes = chunkGraph.getModuleRuntimes(runtimeModule);\n const runtimes = new Set<string>();\n for (const runtimeSpec of moduleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) {\n runtimes.add(runtimeKey);\n }\n },\n );\n }\n for (const runtime of runtimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n // Process remote dependencies\n for (const remoteDep of remoteDependencies) {\n const remoteModule = moduleGraph.getModule(remoteDep);\n if (!remoteModule) continue;\n const referencedRemoteModules = getAllReferencedModules(\n compilation,\n remoteModule,\n 'initial',\n );\n referencedRemoteModules.forEach((m: Module) => allModulesToHoist.add(m));\n const remoteModuleRuntimes = chunkGraph.getModuleRuntimes(remoteModule);\n const remoteRuntimes = new Set<string>();\n for (const runtimeSpec of remoteModuleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) remoteRuntimes.add(runtimeKey);\n },\n );\n }\n for (const runtime of remoteRuntimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedRemoteModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n this.cleanUpChunks(compilation, allModulesToHoist);\n }\n\n // Method to clean up chunks by disconnecting unused modules\n private cleanUpChunks(compilation: Compilation, modules: Set<Module>): void {\n const { chunkGraph } = compilation;\n for (const module of modules) {\n for (const chunk of chunkGraph.getModuleChunks(module)) {\n if (!chunk.hasRuntime()) {\n chunkGraph.disconnectChunkAndModule(chunk, module);\n }\n }\n }\n }\n\n // Method to get runtime chunks\n private getRuntimeChunks(compilation: Compilation): Set<Chunk> {\n const runtimeChunks = new Set<Chunk>();\n for (const chunk of compilation.chunks) {\n if (chunk.hasRuntime()) {\n runtimeChunks.add(chunk);\n }\n }\n return runtimeChunks;\n }\n}\n\n// Helper method to collect all referenced modules recursively\nexport function getAllReferencedModules(\n compilation: Compilation,\n module: Module,\n type?: 'all' | 'initial' | 'external',\n): Set<Module> {\n const collectedModules = new Set<Module>([module]);\n const visitedModules = new WeakSet<Module>([module]);\n const stack = [module];\n\n while (stack.length > 0) {\n const currentModule = stack.pop();\n if (!currentModule) continue;\n\n const mgm = compilation.moduleGraph._getModuleGraphModule(currentModule);\n if (!mgm?.outgoingConnections) continue;\n for (const connection of mgm.outgoingConnections) {\n const connectedModule = connection.module;\n\n // Skip if module has already been visited\n if (!connectedModule || visitedModules.has(connectedModule)) {\n continue;\n }\n\n // Handle 'initial' type (skipping async blocks)\n if (type === 'initial') {\n const parentBlock = compilation.moduleGraph.getParentBlock(\n connection.dependency,\n );\n if (parentBlock instanceof AsyncDependenciesBlock) {\n continue;\n }\n }\n\n // Handle 'external' type (collecting only external modules)\n if (type === 'external') {\n if (connection.module instanceof ExternalModule) {\n collectedModules.add(connectedModule);\n }\n } else {\n // Handle 'all' or unspecified types\n collectedModules.add(connectedModule);\n }\n\n // Add connected module to the stack and mark it as visited\n visitedModules.add(connectedModule);\n stack.push(connectedModule);\n }\n }\n\n return collectedModules;\n}\n\nexport default HoistContainerReferences;\n"],"mappings":";;;;;;oFASwE;AAMxE,MAAM,EAAE,wBAAwB,mBAAmB,gFAC5B,UAAU,CAChC;AAED,MAAM,cAAc;;;;AAKpB,IAAM,2BAAN,MAAgE;CAC9D,MAAM,UAA0B;AAC9B,WAAS,MAAM,gBAAgB,IAC7B,cACC,gBAA6B;GAC5B,MAAM,SAAS,YAAY,UAAU,YAAY;GACjD,MAAM,QAAQA,8DAAwB,oBAAoB,YAAY;GACtE,MAAM,6CAA6B,IAAI,KAAiB;GACxD,MAAM,gDAAgC,IAAI,KAAiB;GAC3D,MAAM,qCAAqB,IAAI,KAAiB;AAEhD,SAAM,4BAA4B,IAChC,6BACC,QAAkC;AACjC,+BAA2B,IAAI,IAAI;KAEtC;AACD,SAAM,+BAA+B,IACnC,6BACC,QAAqC;AACpC,kCAA8B,IAAI,IAAI;KAEzC;AACD,SAAM,oBAAoB,IACxB,6BACC,QAAyD;AACxD,uBAAmB,IAAI,IAAI;KAE9B;AAGD,eAAY,MAAM,eAAe,IAC/B;IACE,MAAM;IAEN,OAAO;IACR,GACA,WAA4B;IA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AC;CAClD,MAAM,iBAAiB,IAAI,QAAgB,CAAC,OAAO,CAAC;CACpD,MAAM,QAAQ,CAAC,OAAO;AAEtB,QAAO,MAAM,SAAS,GAAG;EACvB,MAAM,gBAAgB,MAAM,KAAK;AACjC,MAAI,CAAC,cAAe;EAEpB,MAAM,MAAM,YAAY,YAAY,sBAAsB,cAAc;AACxE,MAAI,CAAC,KAAK,oBAAqB;AAC/B,OAAK,MAAM,cAAc,IAAI,qBAAqB;GAChD,MAAM,kBAAkB,WAAW;AAGnC,OAAI,CAAC,mBAAmB,eAAe,IAAI,gBAAgB,CACzD;AAIF,OAAI,SAAS,WAIX;QAHoB,YAAY,YAAY,eAC1C,WAAW,WACZ,YAC0B,uBACzB;;AAKJ,OAAI,SAAS,YACX;QAAI,WAAW,kBAAkB,eAC/B,kBAAiB,IAAI,gBAAgB;SAIvC,kBAAiB,IAAI,gBAAgB;AAIvC,kBAAe,IAAI,gBAAgB;AACnC,SAAM,KAAK,gBAAgB;;;AAI/B,QAAO"}
|
|
1
|
+
{"version":3,"file":"HoistContainerReferencesPlugin.js","names":["FederationModulesPlugin"],"sources":["../../../../src/lib/container/HoistContainerReferencesPlugin.ts"],"sourcesContent":["import type {\n Chunk,\n Compiler,\n Compilation,\n WebpackPluginInstance,\n Module,\n Dependency,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport ContainerEntryDependency from './ContainerEntryDependency';\nimport FederationRuntimeDependency from './runtime/FederationRuntimeDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport FallbackDependency from './FallbackDependency';\n\nconst { AsyncDependenciesBlock, ExternalModule } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst PLUGIN_NAME = 'HoistContainerReferences';\n\n/**\n * This plugin hoists container-related modules into runtime chunks when using runtimeChunk: single configuration.\n */\nclass HoistContainerReferences implements WebpackPluginInstance {\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation) => {\n const logger = compilation.getLogger(PLUGIN_NAME);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const containerEntryDependencies = new Set<Dependency>();\n const federationRuntimeDependencies = new Set<Dependency>();\n const remoteDependencies = new Set<Dependency>();\n\n hooks.addContainerEntryDependency.tap(\n 'HoistContainerReferences',\n (dep: ContainerEntryDependency) => {\n containerEntryDependencies.add(dep);\n },\n );\n hooks.addFederationRuntimeDependency.tap(\n 'HoistContainerReferences',\n (dep: FederationRuntimeDependency) => {\n federationRuntimeDependencies.add(dep);\n },\n );\n hooks.addRemoteDependency.tap(\n 'HoistContainerReferences',\n (dep: RemoteToExternalDependency | FallbackDependency) => {\n remoteDependencies.add(dep);\n },\n );\n\n // Hook into the optimizeChunks phase\n compilation.hooks.optimizeChunks.tap(\n {\n name: PLUGIN_NAME,\n // advanced stage is where SplitChunksPlugin runs.\n stage: 11, // advanced + 1\n },\n (chunks: Iterable<Chunk>) => {\n const runtimeChunks = this.getRuntimeChunks(compilation);\n this.hoistModulesInChunks(\n compilation,\n runtimeChunks,\n logger,\n containerEntryDependencies,\n federationRuntimeDependencies,\n remoteDependencies,\n );\n },\n );\n },\n );\n }\n\n // Method to hoist modules in chunks\n private hoistModulesInChunks(\n compilation: Compilation,\n runtimeChunks: Set<Chunk>,\n logger: ReturnType<Compilation['getLogger']>,\n containerEntryDependencies: Set<Dependency>,\n federationRuntimeDependencies: Set<Dependency>,\n remoteDependencies: Set<Dependency>,\n ): void {\n const { chunkGraph, moduleGraph } = compilation;\n const allModulesToHoist = new Set<Module>();\n\n // Process container entry dependencies (needed for nextjs-mf exposed modules)\n for (const dep of containerEntryDependencies) {\n const containerEntryModule = moduleGraph.getModule(dep);\n if (!containerEntryModule) continue;\n const referencedModules = getAllReferencedModules(\n compilation,\n containerEntryModule,\n 'initial',\n );\n referencedModules.forEach((m: Module) => allModulesToHoist.add(m));\n const moduleRuntimes = chunkGraph.getModuleRuntimes(containerEntryModule);\n const runtimes = new Set<string>();\n for (const runtimeSpec of moduleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) {\n runtimes.add(runtimeKey);\n }\n },\n );\n }\n for (const runtime of runtimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n // Federation Runtime Dependencies: use 'initial' (not 'all')\n for (const dep of federationRuntimeDependencies) {\n const runtimeModule = moduleGraph.getModule(dep);\n if (!runtimeModule) continue;\n const referencedModules = getAllReferencedModules(\n compilation,\n runtimeModule,\n 'initial',\n );\n referencedModules.forEach((m: Module) => allModulesToHoist.add(m));\n const moduleRuntimes = chunkGraph.getModuleRuntimes(runtimeModule);\n const runtimes = new Set<string>();\n for (const runtimeSpec of moduleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) {\n runtimes.add(runtimeKey);\n }\n },\n );\n }\n for (const runtime of runtimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n // Process remote dependencies\n for (const remoteDep of remoteDependencies) {\n const remoteModule = moduleGraph.getModule(remoteDep);\n if (!remoteModule) continue;\n const referencedRemoteModules = getAllReferencedModules(\n compilation,\n remoteModule,\n 'initial',\n );\n referencedRemoteModules.forEach((m: Module) => allModulesToHoist.add(m));\n const remoteModuleRuntimes = chunkGraph.getModuleRuntimes(remoteModule);\n const remoteRuntimes = new Set<string>();\n for (const runtimeSpec of remoteModuleRuntimes) {\n compilation.compiler.webpack.util.runtime.forEachRuntime(\n runtimeSpec,\n (runtimeKey) => {\n if (runtimeKey) remoteRuntimes.add(runtimeKey);\n },\n );\n }\n for (const runtime of remoteRuntimes) {\n const runtimeChunk = compilation.namedChunks.get(runtime);\n if (!runtimeChunk) continue;\n for (const module of referencedRemoteModules) {\n if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {\n chunkGraph.connectChunkAndModule(runtimeChunk, module);\n }\n }\n }\n }\n\n this.cleanUpChunks(compilation, allModulesToHoist);\n }\n\n // Method to clean up chunks by disconnecting unused modules\n private cleanUpChunks(compilation: Compilation, modules: Set<Module>): void {\n const { chunkGraph } = compilation;\n for (const module of modules) {\n for (const chunk of chunkGraph.getModuleChunks(module)) {\n if (!chunk.hasRuntime()) {\n chunkGraph.disconnectChunkAndModule(chunk, module);\n }\n }\n }\n }\n\n // Method to get runtime chunks\n private getRuntimeChunks(compilation: Compilation): Set<Chunk> {\n const runtimeChunks = new Set<Chunk>();\n for (const chunk of compilation.chunks) {\n if (chunk.hasRuntime()) {\n runtimeChunks.add(chunk);\n }\n }\n return runtimeChunks;\n }\n}\n\n// Helper method to collect all referenced modules recursively\nexport function getAllReferencedModules(\n compilation: Compilation,\n module: Module,\n type?: 'all' | 'initial' | 'external',\n): Set<Module> {\n const collectedModules = new Set<Module>([module]);\n const visitedModules = new WeakSet<Module>([module]);\n const stack = [module];\n\n while (stack.length > 0) {\n const currentModule = stack.pop();\n if (!currentModule) continue;\n\n const mgm = compilation.moduleGraph._getModuleGraphModule(currentModule);\n if (!mgm?.outgoingConnections) continue;\n for (const connection of mgm.outgoingConnections) {\n const connectedModule = connection.module;\n\n // Skip if module has already been visited\n if (!connectedModule || visitedModules.has(connectedModule)) {\n continue;\n }\n\n // Handle 'initial' type (skipping async blocks)\n if (type === 'initial') {\n const parentBlock = compilation.moduleGraph.getParentBlock(\n connection.dependency,\n );\n if (parentBlock instanceof AsyncDependenciesBlock) {\n continue;\n }\n }\n\n // Handle 'external' type (collecting only external modules)\n if (type === 'external') {\n if (connection.module instanceof ExternalModule) {\n collectedModules.add(connectedModule);\n }\n } else {\n // Handle 'all' or unspecified types\n collectedModules.add(connectedModule);\n }\n\n // Add connected module to the stack and mark it as visited\n visitedModules.add(connectedModule);\n stack.push(connectedModule);\n }\n }\n\n return collectedModules;\n}\n\nexport default HoistContainerReferences;\n"],"mappings":";;;;;;AAeA,MAAM,EAAE,wBAAwB,mBAAmB,gFAC5B,UAAU,CAChC;AAED,MAAM,cAAc;;;;AAKpB,IAAM,2BAAN,MAAgE;CAC9D,MAAM,UAA0B;AAC9B,WAAS,MAAM,gBAAgB,IAC7B,cACC,gBAA6B;GAC5B,MAAM,SAAS,YAAY,UAAU,YAAY;GACjD,MAAM,QAAQA,8DAAwB,oBAAoB,YAAY;GACtE,MAAM,6CAA6B,IAAI,KAAiB;GACxD,MAAM,gDAAgC,IAAI,KAAiB;GAC3D,MAAM,qCAAqB,IAAI,KAAiB;AAEhD,SAAM,4BAA4B,IAChC,6BACC,QAAkC;AACjC,+BAA2B,IAAI,IAAI;KAEtC;AACD,SAAM,+BAA+B,IACnC,6BACC,QAAqC;AACpC,kCAA8B,IAAI,IAAI;KAEzC;AACD,SAAM,oBAAoB,IACxB,6BACC,QAAyD;AACxD,uBAAmB,IAAI,IAAI;KAE9B;AAGD,eAAY,MAAM,eAAe,IAC/B;IACE,MAAM;IAEN,OAAO;IACR,GACA,WAA4B;IAC3B,MAAM,gBAAgB,KAAK,iBAAiB,YAAY;AACxD,SAAK,qBACH,aACA,eACA,QACA,4BACA,+BACA,mBACD;KAEJ;IAEJ;;CAIH,AAAQ,qBACN,aACA,eACA,QACA,4BACA,+BACA,oBACM;EACN,MAAM,EAAE,YAAY,gBAAgB;EACpC,MAAM,oCAAoB,IAAI,KAAa;AAG3C,OAAK,MAAM,OAAO,4BAA4B;GAC5C,MAAM,uBAAuB,YAAY,UAAU,IAAI;AACvD,OAAI,CAAC,qBAAsB;GAC3B,MAAM,oBAAoB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AmB,eAAe,IAAI,gBAAgB,CACzD;AAIF,OAAI,SAAS,WAIX;QAHoB,YAAY,YAAY,eAC1C,WAAW,WACZ,YAC0B,uBACzB;;AAKJ,OAAI,SAAS,YACX;QAAI,WAAW,kBAAkB,eAC/B,kBAAiB,IAAI,gBAAgB;SAIvC,kBAAiB,IAAI,gBAAgB;AAIvC,kBAAe,IAAI,gBAAgB;AACnC,SAAM,KAAK,gBAAgB;;;AAI/B,QAAO"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
6
5
|
const require_utils = require('../../utils.js');
|
|
6
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
7
7
|
const require_lib_container_runtime_FederationRuntimePlugin = require('./runtime/FederationRuntimePlugin.js');
|
|
8
8
|
const require_lib_container_ContainerPlugin = require('./ContainerPlugin.js');
|
|
9
9
|
const require_lib_container_ContainerReferencePlugin = require('./ContainerReferencePlugin.js');
|
|
@@ -25,7 +25,6 @@ let _module_federation_manifest = require("@module-federation/manifest");
|
|
|
25
25
|
let _module_federation_rspack_remote_entry_plugin = require("@module-federation/rspack/remote-entry-plugin");
|
|
26
26
|
|
|
27
27
|
//#region src/lib/container/ModuleFederationPlugin.ts
|
|
28
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
29
28
|
const isValidExternalsType = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/schemas/plugins/container/ExternalsType.check.js"));
|
|
30
29
|
const { ExternalsPlugin } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
31
30
|
const validate = require_utils.createSchemaValidation((require_schemas_container_ModuleFederationPlugin_check.init_ModuleFederationPlugin_check(), require_runtime.__toCommonJS(require_schemas_container_ModuleFederationPlugin_check.ModuleFederationPlugin_check_exports)).validate, () => (require_schemas_container_ModuleFederationPlugin.init_ModuleFederationPlugin(), require_runtime.__toCommonJS(require_schemas_container_ModuleFederationPlugin.ModuleFederationPlugin_exports)).default, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleFederationPlugin.js","names":["createSchemaValidation","path","fs","utils","infrastructureLogger","RemoteEntryPlugin","FederationModulesPlugin","StartupChunkDependenciesPlugin","DtsPlugin","PrefetchPlugin","FederationRuntimePlugin","ContainerManager","ContainerPlugin","ContainerReferencePlugin","TreeShakingSharedPlugin","SharePlugin","StatsPlugin"],"sources":["../../../../src/lib/container/ModuleFederationPlugin.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { DtsPlugin } from '@module-federation/dts-plugin';\nimport { ContainerManager, utils } from '@module-federation/managers';\nimport { StatsPlugin } from '@module-federation/manifest';\nimport {\n bindLoggerToCompiler,\n composeKeyWithSeparator,\n type moduleFederationPlugin,\n infrastructureLogger,\n} from '@module-federation/sdk';\nimport { PrefetchPlugin } from '@module-federation/data-prefetch/cli';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport SharePlugin from '../sharing/SharePlugin';\nimport ContainerPlugin from './ContainerPlugin';\nimport ContainerReferencePlugin from './ContainerReferencePlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport { RemoteEntryPlugin } from '@module-federation/rspack/remote-entry-plugin';\nimport StartupChunkDependenciesPlugin from '../startup/MfStartupChunkDependenciesPlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport { createSchemaValidation } from '../../utils';\nimport TreeShakingSharedPlugin from '../sharing/tree-shaking/TreeShakingSharedPlugin';\n\nconst isValidExternalsType = require(\n normalizeWebpackPath(\n 'webpack/schemas/plugins/container/ExternalsType.check.js',\n ),\n) as typeof import('webpack/schemas/plugins/container/ExternalsType.check.js');\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n require('../../schemas/container/ModuleFederationPlugin.check.js').validate,\n () => require('../../schemas/container/ModuleFederationPlugin').default,\n {\n name: 'Module Federation Plugin',\n baseDataPath: 'options',\n },\n);\n\nfunction getEnhancedPackageVersion(): string {\n let currentDir = __dirname;\n\n while (true) {\n const packageJsonPath = path.join(currentDir, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n version?: string;\n };\n\n if (pkg.name === '@module-federation/enhanced' && pkg.version) {\n return pkg.version;\n }\n }\n\n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) {\n break;\n }\n currentDir = parentDir;\n }\n\n throw new Error('Unable to resolve @module-federation/enhanced package.json');\n}\n\nclass ModuleFederationPlugin implements WebpackPluginInstance {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _statsPlugin?: StatsPlugin;\n /**\n * @param {moduleFederationPlugin.ModuleFederationPluginOptions} options options\n */\n constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions) {\n validate(options);\n this._options = options;\n }\n\n private _patchBundlerConfig(compiler: Compiler): void {\n const { name, experiments } = this._options;\n const definePluginOptions: Record<string, string | boolean> = {};\n\n const MFPluginNum = compiler.options.plugins.filter(\n (p): p is WebpackPluginInstance =>\n !!p && (p as any).name === 'ModuleFederationPlugin',\n ).length;\n\n if (name && MFPluginNum < 2) {\n definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(\n composeKeyWithSeparator(name, utils.getBuildVersion()),\n );\n }\n\n const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;\n definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] =\n disableSnapshot;\n\n // Determine ENV_TARGET: only if manually specified in experiments.optimization.target\n if (\n experiments?.optimization &&\n typeof experiments.optimization === 'object' &&\n experiments.optimization !== null &&\n 'target' in experiments.optimization\n ) {\n const manualTarget = experiments.optimization.target as\n | 'web'\n | 'node'\n | undefined;\n // Ensure the target is one of the expected values before setting\n if (manualTarget === 'web' || manualTarget === 'node') {\n definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);\n }\n }\n // No inference for ENV_TARGET. If not manually set and valid, it's not defined.\n\n new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n bindLoggerToCompiler(\n infrastructureLogger,\n compiler,\n 'EnhancedModuleFederationPlugin',\n );\n const { _options: options } = this;\n const { name, experiments, dts, remotes, shared, shareScope } = options;\n if (!name) {\n // TODO: remove the comment\n throw new Error('ModuleFederationPlugin name is required');\n }\n // must before ModuleFederationPlugin\n (new RemoteEntryPlugin(options) as unknown as WebpackPluginInstance).apply(\n compiler,\n );\n const useContainerPlugin =\n options.exposes &&\n (Array.isArray(options.exposes)\n ? options.exposes.length > 0\n : Object.keys(options.exposes).length > 0);\n\n if (experiments?.provideExternalRuntime) {\n if (useContainerPlugin) {\n throw new Error(\n 'You can only set provideExternalRuntime: true in pure consumer which not expose modules.',\n );\n }\n const runtimePlugins = options.runtimePlugins || [];\n options.runtimePlugins = runtimePlugins.concat(\n require.resolve('@module-federation/inject-external-runtime-core-plugin'),\n );\n }\n\n if (experiments?.externalRuntime === true) {\n const Externals = compiler.webpack.ExternalsPlugin || ExternalsPlugin;\n new Externals(compiler.options.externalsType || 'global', {\n '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE',\n }).apply(compiler);\n }\n\n // federation hooks\n new FederationModulesPlugin().apply(compiler);\n\n if (experiments?.asyncStartup) {\n new StartupChunkDependenciesPlugin({\n asyncChunkLoading: true,\n }).apply(compiler);\n }\n\n if (dts !== false) {\n const dtsPlugin = new DtsPlugin(options);\n dtsPlugin.apply(compiler);\n dtsPlugin.addRuntimePlugins();\n }\n // TODO: REMOVE in next major version\n if (options.dataPrefetch) {\n new PrefetchPlugin(options).apply(compiler);\n }\n\n new FederationRuntimePlugin(options).apply(compiler);\n\n const library = options.library || { type: 'var', name: name };\n const remoteType =\n options.remoteType ||\n (options.library && isValidExternalsType(options.library.type)\n ? (options.library.type as moduleFederationPlugin.ExternalsType)\n : ('script' as moduleFederationPlugin.ExternalsType));\n const containerRemoteType =\n remoteType as moduleFederationPlugin.ExternalsType;\n\n let disableManifest = options.manifest === false;\n if (useContainerPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, name);\n }\n this._patchBundlerConfig(compiler);\n if (!disableManifest && useContainerPlugin) {\n try {\n const containerManager = new ContainerManager();\n containerManager.init(options);\n options.exposes = containerManager.containerPluginExposesOptions;\n } catch (err) {\n if (err instanceof Error) {\n err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;\n }\n infrastructureLogger.warn(err);\n disableManifest = true;\n }\n }\n\n if (\n library &&\n !compiler.options.output.enabledLibraryTypes?.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes?.push(library.type);\n }\n\n compiler.hooks.afterPlugins.tap('ModuleFederationPlugin', () => {\n if (useContainerPlugin) {\n new ContainerPlugin({\n name,\n library,\n filename: options.filename,\n runtime: options.runtime,\n shareScope: options.shareScope,\n exposes: options.exposes!,\n runtimePlugins: options.runtimePlugins,\n }).apply(compiler);\n }\n if (\n remotes &&\n (Array.isArray(remotes)\n ? remotes.length > 0\n : Object.keys(remotes).length > 0)\n ) {\n new ContainerReferencePlugin({\n remoteType: containerRemoteType,\n shareScope,\n remotes,\n }).apply(compiler);\n }\n if (shared) {\n new TreeShakingSharedPlugin({\n mfConfig: options,\n }).apply(compiler);\n new SharePlugin({\n shared,\n shareScope,\n }).apply(compiler);\n }\n });\n\n if (!disableManifest) {\n this._statsPlugin = new StatsPlugin(options, {\n pluginVersion: getEnhancedPackageVersion(),\n bundler: 'webpack',\n });\n this._statsPlugin.apply(compiler);\n }\n }\n}\n\nexport default ModuleFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;oFA0BwE;AAIxE,MAAM,uBAAuB,gFAEzB,2DACD,CACF;AAED,MAAM,EAAE,oBAAoB,gFACL,UAAU,CAChC;AAED,MAAM,WAAWA,6PAEoD,gNACH,SAChE;CACE,MAAM;CACN,cAAc;CACf,CACF;AAED,SAAS,4BAAoC;CAC3C,IAAI,aAAa;AAEjB,QAAO,MAAM;EACX,MAAM,kBAAkBC,kBAAK,KAAK,YAAY,eAAe;AAE7D,MAAIC,gBAAG,WAAW,gBAAgB,EAAE;GAClC,MAAM,MAAM,KAAK,MAAMA,gBAAG,aAAa,iBAAiB,QAAQ,CAAC;AAKjE,OAAI,IAAI,SAAS,iCAAiC,IAAI,QACpD,QAAO,IAAI;;EAIf,MAAM,YAAYD,kBAAK,QAAQ,WAAW;AAC1C,MAAI,cAAc,WAChB;AAEF,eAAa;;AAGf,OAAM,IAAI,MAAM,6DAA6D;;AAG/E,IAAM,yBAAN,MAA8D;;;;CAM5D,YAAY,SAA+D;AACzE,WAAS,QAAQ;AACjB,OAAK,WAAW;;CAGlB,AAAQ,oBAAoB,UAA0B;EACpD,MAAM,EAAE,MAAM,gBAAgB,KAAK;EACnC,MAAM,sBAAwD,EAAE;EAEhE,MAAM,cAAc,SAAS,QAAQ,QAAQ,QAC1C,MACC,CAAC,CAAC,KAAM,EAAU,SAAS,yBAC9B,CAAC;AAEF,MAAI,QAAQ,cAAc,EACxB,qBAAoB,iCAAiC,KAAK,8DAChC,MAAME,kCAAM,iBAAiB,CAAC,CACvD;AAIH,sBAAoB,4CADI,aAAa,cAAc,mB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C,iBAAiB;AACpB,QAAK,eAAe,IAAIC,wCAAY,SAAS;IAC3C,eAAe,2BAA2B;IAC1C,SAAS;IACV,CAAC;AACF,QAAK,aAAa,MAAM,SAAS"}
|
|
1
|
+
{"version":3,"file":"ModuleFederationPlugin.js","names":["createSchemaValidation","path","fs","utils","infrastructureLogger","RemoteEntryPlugin","FederationModulesPlugin","StartupChunkDependenciesPlugin","DtsPlugin","PrefetchPlugin","FederationRuntimePlugin","ContainerManager","ContainerPlugin","ContainerReferencePlugin","TreeShakingSharedPlugin","SharePlugin","StatsPlugin"],"sources":["../../../../src/lib/container/ModuleFederationPlugin.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra and Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { DtsPlugin } from '@module-federation/dts-plugin';\nimport { ContainerManager, utils } from '@module-federation/managers';\nimport { StatsPlugin } from '@module-federation/manifest';\nimport {\n bindLoggerToCompiler,\n composeKeyWithSeparator,\n type moduleFederationPlugin,\n infrastructureLogger,\n} from '@module-federation/sdk';\nimport { PrefetchPlugin } from '@module-federation/data-prefetch/cli';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport SharePlugin from '../sharing/SharePlugin';\nimport ContainerPlugin from './ContainerPlugin';\nimport ContainerReferencePlugin from './ContainerReferencePlugin';\nimport FederationRuntimePlugin from './runtime/FederationRuntimePlugin';\nimport { RemoteEntryPlugin } from '@module-federation/rspack/remote-entry-plugin';\nimport StartupChunkDependenciesPlugin from '../startup/MfStartupChunkDependenciesPlugin';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\nimport { createSchemaValidation } from '../../utils';\nimport TreeShakingSharedPlugin from '../sharing/tree-shaking/TreeShakingSharedPlugin';\n\nconst isValidExternalsType = require(\n normalizeWebpackPath(\n 'webpack/schemas/plugins/container/ExternalsType.check.js',\n ),\n) as typeof import('webpack/schemas/plugins/container/ExternalsType.check.js');\n\nconst { ExternalsPlugin } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst validate = createSchemaValidation(\n //eslint-disable-next-line\n require('../../schemas/container/ModuleFederationPlugin.check.js').validate,\n () => require('../../schemas/container/ModuleFederationPlugin').default,\n {\n name: 'Module Federation Plugin',\n baseDataPath: 'options',\n },\n);\n\nfunction getEnhancedPackageVersion(): string {\n let currentDir = __dirname;\n\n while (true) {\n const packageJsonPath = path.join(currentDir, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n version?: string;\n };\n\n if (pkg.name === '@module-federation/enhanced' && pkg.version) {\n return pkg.version;\n }\n }\n\n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) {\n break;\n }\n currentDir = parentDir;\n }\n\n throw new Error('Unable to resolve @module-federation/enhanced package.json');\n}\n\nclass ModuleFederationPlugin implements WebpackPluginInstance {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _statsPlugin?: StatsPlugin;\n /**\n * @param {moduleFederationPlugin.ModuleFederationPluginOptions} options options\n */\n constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions) {\n validate(options);\n this._options = options;\n }\n\n private _patchBundlerConfig(compiler: Compiler): void {\n const { name, experiments } = this._options;\n const definePluginOptions: Record<string, string | boolean> = {};\n\n const MFPluginNum = compiler.options.plugins.filter(\n (p): p is WebpackPluginInstance =>\n !!p && (p as any).name === 'ModuleFederationPlugin',\n ).length;\n\n if (name && MFPluginNum < 2) {\n definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify(\n composeKeyWithSeparator(name, utils.getBuildVersion()),\n );\n }\n\n const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;\n definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] =\n disableSnapshot;\n\n // Determine ENV_TARGET: only if manually specified in experiments.optimization.target\n if (\n experiments?.optimization &&\n typeof experiments.optimization === 'object' &&\n experiments.optimization !== null &&\n 'target' in experiments.optimization\n ) {\n const manualTarget = experiments.optimization.target as\n | 'web'\n | 'node'\n | undefined;\n // Ensure the target is one of the expected values before setting\n if (manualTarget === 'web' || manualTarget === 'node') {\n definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);\n }\n }\n // No inference for ENV_TARGET. If not manually set and valid, it's not defined.\n\n new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);\n }\n\n /**\n * Apply the plugin\n * @param {Compiler} compiler the compiler instance\n * @returns {void}\n */\n apply(compiler: Compiler): void {\n bindLoggerToCompiler(\n infrastructureLogger,\n compiler,\n 'EnhancedModuleFederationPlugin',\n );\n const { _options: options } = this;\n const { name, experiments, dts, remotes, shared, shareScope } = options;\n if (!name) {\n // TODO: remove the comment\n throw new Error('ModuleFederationPlugin name is required');\n }\n // must before ModuleFederationPlugin\n (new RemoteEntryPlugin(options) as unknown as WebpackPluginInstance).apply(\n compiler,\n );\n const useContainerPlugin =\n options.exposes &&\n (Array.isArray(options.exposes)\n ? options.exposes.length > 0\n : Object.keys(options.exposes).length > 0);\n\n if (experiments?.provideExternalRuntime) {\n if (useContainerPlugin) {\n throw new Error(\n 'You can only set provideExternalRuntime: true in pure consumer which not expose modules.',\n );\n }\n const runtimePlugins = options.runtimePlugins || [];\n options.runtimePlugins = runtimePlugins.concat(\n require.resolve('@module-federation/inject-external-runtime-core-plugin'),\n );\n }\n\n if (experiments?.externalRuntime === true) {\n const Externals = compiler.webpack.ExternalsPlugin || ExternalsPlugin;\n new Externals(compiler.options.externalsType || 'global', {\n '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE',\n }).apply(compiler);\n }\n\n // federation hooks\n new FederationModulesPlugin().apply(compiler);\n\n if (experiments?.asyncStartup) {\n new StartupChunkDependenciesPlugin({\n asyncChunkLoading: true,\n }).apply(compiler);\n }\n\n if (dts !== false) {\n const dtsPlugin = new DtsPlugin(options);\n dtsPlugin.apply(compiler);\n dtsPlugin.addRuntimePlugins();\n }\n // TODO: REMOVE in next major version\n if (options.dataPrefetch) {\n new PrefetchPlugin(options).apply(compiler);\n }\n\n new FederationRuntimePlugin(options).apply(compiler);\n\n const library = options.library || { type: 'var', name: name };\n const remoteType =\n options.remoteType ||\n (options.library && isValidExternalsType(options.library.type)\n ? (options.library.type as moduleFederationPlugin.ExternalsType)\n : ('script' as moduleFederationPlugin.ExternalsType));\n const containerRemoteType =\n remoteType as moduleFederationPlugin.ExternalsType;\n\n let disableManifest = options.manifest === false;\n if (useContainerPlugin) {\n ContainerPlugin.patchChunkSplit(compiler, name);\n }\n this._patchBundlerConfig(compiler);\n if (!disableManifest && useContainerPlugin) {\n try {\n const containerManager = new ContainerManager();\n containerManager.init(options);\n options.exposes = containerManager.containerPluginExposesOptions;\n } catch (err) {\n if (err instanceof Error) {\n err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;\n }\n infrastructureLogger.warn(err);\n disableManifest = true;\n }\n }\n\n if (\n library &&\n !compiler.options.output.enabledLibraryTypes?.includes(library.type)\n ) {\n compiler.options.output.enabledLibraryTypes?.push(library.type);\n }\n\n compiler.hooks.afterPlugins.tap('ModuleFederationPlugin', () => {\n if (useContainerPlugin) {\n new ContainerPlugin({\n name,\n library,\n filename: options.filename,\n runtime: options.runtime,\n shareScope: options.shareScope,\n exposes: options.exposes!,\n runtimePlugins: options.runtimePlugins,\n }).apply(compiler);\n }\n if (\n remotes &&\n (Array.isArray(remotes)\n ? remotes.length > 0\n : Object.keys(remotes).length > 0)\n ) {\n new ContainerReferencePlugin({\n remoteType: containerRemoteType,\n shareScope,\n remotes,\n }).apply(compiler);\n }\n if (shared) {\n new TreeShakingSharedPlugin({\n mfConfig: options,\n }).apply(compiler);\n new SharePlugin({\n shared,\n shareScope,\n }).apply(compiler);\n }\n });\n\n if (!disableManifest) {\n this._statsPlugin = new StatsPlugin(options, {\n pluginVersion: getEnhancedPackageVersion(),\n bundler: 'webpack',\n });\n this._statsPlugin.apply(compiler);\n }\n }\n}\n\nexport default ModuleFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,uBAAuB,gFAEzB,2DACD,CACF;AAED,MAAM,EAAE,oBAAoB,gFACL,UAAU,CAChC;AAED,MAAM,WAAWA,6PAEoD,gNACH,SAChE;CACE,MAAM;CACN,cAAc;CACf,CACF;AAED,SAAS,4BAAoC;CAC3C,IAAI,aAAa;AAEjB,QAAO,MAAM;EACX,MAAM,kBAAkBC,kBAAK,KAAK,YAAY,eAAe;AAE7D,MAAIC,gBAAG,WAAW,gBAAgB,EAAE;GAClC,MAAM,MAAM,KAAK,MAAMA,gBAAG,aAAa,iBAAiB,QAAQ,CAAC;AAKjE,OAAI,IAAI,SAAS,iCAAiC,IAAI,QACpD,QAAO,IAAI;;EAIf,MAAM,YAAYD,kBAAK,QAAQ,WAAW;AAC1C,MAAI,cAAc,WAChB;AAEF,eAAa;;AAGf,OAAM,IAAI,MAAM,6DAA6D;;AAG/E,IAAM,yBAAN,MAA8D;;;;CAM5D,YAAY,SAA+D;AACzE,WAAS,QAAQ;AACjB,OAAK,WAAW;;CAGlB,AAAQ,oBAAoB,UAA0B;EACpD,MAAM,EAAE,MAAM,gBAAgB,KAAK;EACnC,MAAM,sBAAwD,EAAE;EAEhE,MAAM,cAAc,SAAS,QAAQ,QAAQ,QAC1C,MACC,CAAC,CAAC,KAAM,EAAU,SAAS,yBAC9B,CAAC;AAEF,MAAI,QAAQ,cAAc,EACxB,qBAAoB,iCAAiC,KAAK,8DAChC,MAAME,kCAAM,iBAAiB,CAAC,CACvD;AAIH,sBAAoB,4CADI,aAAa,cAAc,mBAAmB;AAKtE,MACE,aAAa,gBACb,OAAO,YAAY,iBAAiB,YACpC,YAAY,iBAAiB,QAC7B,YAAY,YAAY,cACxB;GACA,MAAM,eAAe,YAAY,a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AS"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
4
3
|
const require_lib_Constants = require('../Constants.js');
|
|
4
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./runtime/FederationModulesPlugin.js');
|
|
5
5
|
const require_lib_container_FallbackDependency = require('./FallbackDependency.js');
|
|
6
6
|
const require_lib_container_RemoteToExternalDependency = require('./RemoteToExternalDependency.js');
|
|
7
7
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
8
8
|
|
|
9
9
|
//#region src/lib/container/RemoteModule.ts
|
|
10
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
11
10
|
const { sources: webpackSources } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
12
11
|
const { Module, RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
13
12
|
const makeSerializable = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/makeSerializable"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteModule.js","names":["WEBPACK_MODULE_TYPE_REMOTE","RemoteToExternalDependency","FederationModulesPlugin","FallbackDependency"],"sources":["../../../../src/lib/container/RemoteModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation, WebpackOptionsNormalized } from 'webpack';\nimport type {\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n WebpackError,\n} from 'webpack/lib/Module';\nimport FallbackDependency from './FallbackDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { WEBPACK_MODULE_TYPE_REMOTE } from '../Constants';\nimport type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';\nimport type { InputFileSystem } from 'webpack/lib/FileSystemInfo';\nimport type { RequestShortener } from 'webpack/lib/RuntimeModule';\nimport type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\nconst TYPES: Set<string> = new Set(['remote', 'share-init']);\nconst RUNTIME_REQUIREMENTS: Set<string> = new Set([RuntimeGlobals.module]);\n\nclass RemoteModule extends Module {\n private _identifier: string;\n public request: string;\n public externalRequests: string[];\n public internalRequest: string;\n public shareScope: string | string[];\n\n /**\n * @param {string} request request string\n * @param {string[]} externalRequests list of external requests to containers\n * @param {string} internalRequest name of exposed module in container\n * @param {string|string[]} shareScope scope in which modules are shared\n */\n constructor(\n request: string,\n externalRequests: string[],\n internalRequest: string,\n shareScope: string | string[],\n ) {\n super(WEBPACK_MODULE_TYPE_REMOTE);\n this.request = request;\n this.externalRequests = externalRequests;\n this.internalRequest = internalRequest;\n this.shareScope = shareScope;\n const scopeStr = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n this._identifier = `remote (${scopeStr}) ${this.externalRequests.join(\n ' ',\n )} ${this.internalRequest}`;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\n\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n return `remote ${this.request}`;\n }\n\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n return `${this.layer ? `(${this.layer})/` : ''}webpack/container/remote/${\n this.request\n }`;\n }\n\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (err: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\n\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError=): void} callback callback function\n * @returns {void}\n */\n // @ts-ignore\n override build(\n options: WebpackOptionsNormalized,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError | undefined) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n if (this.externalRequests.length === 1) {\n const dep = new RemoteToExternalDependency(this.externalRequests[0]);\n this.addDependency(dep);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n hooks.addRemoteDependency.call(dep);\n } else {\n const dep = new FallbackDependency(this.externalRequests);\n this.addDependency(dep);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n hooks.addRemoteDependency.call(dep);\n }\n\n callback();\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 6;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)\n */\n override nameForCondition(): string | null {\n return this.request;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration(\n context: CodeGenerationContext,\n ): CodeGenerationResult {\n const { moduleGraph, chunkGraph } = context;\n const module = moduleGraph.getModule(this.dependencies[0]);\n const id = module && chunkGraph.getModuleId(module);\n const sources = new Map();\n sources.set('remote', new webpackSources.RawSource(''));\n const data = new Map();\n data.set('share-init', [\n {\n shareScope: this.shareScope,\n initStage: 20,\n init: id === undefined ? '' : `initExternal(${JSON.stringify(id)});`,\n },\n ]);\n return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n override serialize(context: any) {\n const { write } = context;\n write(this.request);\n write(this.externalRequests);\n write(this.internalRequest);\n write(this.shareScope);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {RemoteModule} deserialized module\n */\n static deserialize(context: ObjectDeserializerContext): RemoteModule {\n const { read } = context;\n const obj = new RemoteModule(read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(RemoteModule, 'enhanced/lib/container/RemoteModule');\n\nexport default RemoteModule;\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteModule.js","names":["WEBPACK_MODULE_TYPE_REMOTE","RemoteToExternalDependency","FederationModulesPlugin","FallbackDependency"],"sources":["../../../../src/lib/container/RemoteModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation, WebpackOptionsNormalized } from 'webpack';\nimport type {\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n WebpackError,\n} from 'webpack/lib/Module';\nimport FallbackDependency from './FallbackDependency';\nimport RemoteToExternalDependency from './RemoteToExternalDependency';\nimport { WEBPACK_MODULE_TYPE_REMOTE } from '../Constants';\nimport type { ResolverWithOptions } from 'webpack/lib/ResolverFactory';\nimport type { InputFileSystem } from 'webpack/lib/FileSystemInfo';\nimport type { RequestShortener } from 'webpack/lib/RuntimeModule';\nimport type { ObjectDeserializerContext } from 'webpack/lib/serialization/ObjectMiddleware';\nimport FederationModulesPlugin from './runtime/FederationModulesPlugin';\n\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\nconst TYPES: Set<string> = new Set(['remote', 'share-init']);\nconst RUNTIME_REQUIREMENTS: Set<string> = new Set([RuntimeGlobals.module]);\n\nclass RemoteModule extends Module {\n private _identifier: string;\n public request: string;\n public externalRequests: string[];\n public internalRequest: string;\n public shareScope: string | string[];\n\n /**\n * @param {string} request request string\n * @param {string[]} externalRequests list of external requests to containers\n * @param {string} internalRequest name of exposed module in container\n * @param {string|string[]} shareScope scope in which modules are shared\n */\n constructor(\n request: string,\n externalRequests: string[],\n internalRequest: string,\n shareScope: string | string[],\n ) {\n super(WEBPACK_MODULE_TYPE_REMOTE);\n this.request = request;\n this.externalRequests = externalRequests;\n this.internalRequest = internalRequest;\n this.shareScope = shareScope;\n const scopeStr = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n this._identifier = `remote (${scopeStr}) ${this.externalRequests.join(\n ' ',\n )} ${this.internalRequest}`;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n return this._identifier;\n }\n\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n return `remote ${this.request}`;\n }\n\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n return `${this.layer ? `(${this.layer})/` : ''}webpack/container/remote/${\n this.request\n }`;\n }\n\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (err: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\n\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError=): void} callback callback function\n * @returns {void}\n */\n // @ts-ignore\n override build(\n options: WebpackOptionsNormalized,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (err?: WebpackError | undefined) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {\n strict: true,\n };\n\n this.clearDependenciesAndBlocks();\n if (this.externalRequests.length === 1) {\n const dep = new RemoteToExternalDependency(this.externalRequests[0]);\n this.addDependency(dep);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n hooks.addRemoteDependency.call(dep);\n } else {\n const dep = new FallbackDependency(this.externalRequests);\n this.addDependency(dep);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n hooks.addRemoteDependency.call(dep);\n }\n\n callback();\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 6;\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n /**\n * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)\n */\n override nameForCondition(): string | null {\n return this.request;\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n // @ts-ignore\n override codeGeneration(\n context: CodeGenerationContext,\n ): CodeGenerationResult {\n const { moduleGraph, chunkGraph } = context;\n const module = moduleGraph.getModule(this.dependencies[0]);\n const id = module && chunkGraph.getModuleId(module);\n const sources = new Map();\n sources.set('remote', new webpackSources.RawSource(''));\n const data = new Map();\n data.set('share-init', [\n {\n shareScope: this.shareScope,\n initStage: 20,\n init: id === undefined ? '' : `initExternal(${JSON.stringify(id)});`,\n },\n ]);\n return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };\n }\n override serialize(context: any) {\n const { write } = context;\n write(this.request);\n write(this.externalRequests);\n write(this.internalRequest);\n write(this.shareScope);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n * @returns {RemoteModule} deserialized module\n */\n static deserialize(context: ObjectDeserializerContext): RemoteModule {\n const { read } = context;\n const obj = new RemoteModule(read(), read(), read(), read());\n obj.deserialize(context);\n return obj;\n }\n}\n\nmakeSerializable(RemoteModule, 'enhanced/lib/container/RemoteModule');\n\nexport default RemoteModule;\n"],"mappings":";;;;;;;;;AAsBA,MAAM,EAAE,SAAS,mBAAmB,gFACb,UAAU,CAChC;AACD,MAAM,EAAE,QAAQ,mBAAmB,gFACZ,UAAU,CAChC;AACD,MAAM,mBAAmB,gFACF,oCAAoC,CAC1D;AAED,MAAM,QAAqB,IAAI,IAAI,CAAC,UAAU,aAAa,CAAC;AAC5D,MAAM,uBAAoC,IAAI,IAAI,CAAC,eAAe,OAAO,CAAC;AAE1E,IAAM,eAAN,MAAM,qBAAqB,OAAO;;;;;;;CAahC,YACE,SACA,kBACA,iBACA,YACA;AACA,QAAMA,iDAA2B;AACjC,OAAK,UAAU;AACf,OAAK,mBAAmB;AACxB,OAAK,kBAAkB;AACvB,OAAK,aAAa;AAIlB,OAAK,cAAc,WAHF,MAAM,QAAQ,WAAW,GACtC,WAAW,KAAK,IAAI,GACpB,WACmC,IAAI,KAAK,iBAAiB,KAC/D,IACD,CAAC,GAAG,KAAK;;;;;CAMZ,AAAS,aAAqB;AAC5B,SAAO,KAAK;;;;;;CAOd,AAAS,mBAAmB,kBAA4C;AACtE,SAAO,UAAU,KAAK;;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,SAAc;EAC/B,MAAM,EAAE,UAAU;AAClB,QAAM,KAAK,QAAQ;AACnB,QAAM,KAAK,iBAAiB;AAC5B,QAAM,KAAK,gBAAgB;AAC3B,QAAM,KAAK,WAAW;AACtB,QAAM,UAAU,QAAQ;;;;;;CAO1B,OAAO,YAAY,SAAkD;EACnE,MAAM,EAAE,SAAS;EACjB,MAAM,MAAM,IAAI,aAAa,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAC5D,MAAI,YAAY,QAAQ;AACxB,SAAO;;;AAIX,iBAAiB,cAAc,sCAAsC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./FederationModulesPlugin.js');
|
|
4
3
|
const require_lib_container_runtime_utils = require('./utils.js');
|
|
5
4
|
const require_lib_container_runtime_EmbedFederationRuntimeModule = require('./EmbedFederationRuntimeModule.js');
|
|
5
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./FederationModulesPlugin.js');
|
|
6
6
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
7
7
|
|
|
8
8
|
//#region src/lib/container/runtime/EmbedFederationRuntimePlugin.ts
|
|
9
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
10
9
|
const { RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
11
10
|
const PLUGIN_NAME = "EmbedFederationRuntimePlugin";
|
|
12
11
|
const federationGlobal = require_lib_container_runtime_utils.getFederationGlobalScope(RuntimeGlobals);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbedFederationRuntimePlugin.js","names":["getFederationGlobalScope","FederationModulesPlugin","EmbedFederationRuntimeModule"],"sources":["../../../../../src/lib/container/runtime/EmbedFederationRuntimePlugin.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport EmbedFederationRuntimeModule from './EmbedFederationRuntimeModule';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport type { Compiler, Chunk, Compilation } from 'webpack';\nimport { getFederationGlobalScope } from './utils';\nimport ContainerEntryDependency from '../ContainerEntryDependency';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst { RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst PLUGIN_NAME = 'EmbedFederationRuntimePlugin';\n\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\ninterface EmbedFederationRuntimePluginOptions {\n /**\n * Whether to enable runtime module embedding for all chunks.\n * If false, only chunks that explicitly require it will be embedded.\n */\n enableForAllChunks?: boolean;\n}\n\n/**\n * Plugin that embeds Module Federation runtime code into chunks.\n * It ensures proper initialization of federated modules and manages runtime requirements.\n */\nclass EmbedFederationRuntimePlugin {\n private readonly options: EmbedFederationRuntimePluginOptions;\n private readonly processedChunks = new WeakMap<Chunk, boolean>();\n\n constructor(options: EmbedFederationRuntimePluginOptions = {}) {\n this.options = {\n enableForAllChunks: false,\n ...options,\n };\n }\n\n /**\n * Determines if runtime embedding should be enabled for a given chunk.\n */\n private isEnabledForChunk(chunk: Chunk): boolean {\n // Disable for our special \"build time chunk\"\n if (chunk.id === 'build time chunk') return false;\n return this.options.enableForAllChunks || chunk.hasRuntime();\n }\n\n /**\n * Checks if a hook has already been tapped by this plugin.\n */\n private isHookAlreadyTapped(\n taps: Array<{ name: string }>,\n hookName: string,\n ): boolean {\n return taps.some((tap) => tap.name === hookName);\n }\n\n apply(compiler: Compiler): void {\n // Prevent double application of the plugin.\n const compilationTaps = compiler.hooks.thisCompilation.taps || [];\n if (this.isHookAlreadyTapped(compilationTaps, PLUGIN_NAME)) {\n return;\n }\n\n // Tap into the compilation to modify renderStartup and runtime requirements.\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation) => {\n // --- Part 1: Modify renderStartup to append a startup call when none is added automatically ---\n const { renderStartup } =\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n );\n\n renderStartup.tap(\n PLUGIN_NAME,\n (startupSource, _lastInlinedModule, renderContext) => {\n const { chunk, chunkGraph } = renderContext;\n\n if (!this.isEnabledForChunk(chunk)) {\n return startupSource;\n }\n\n const runtimeRequirements =\n chunkGraph.getTreeRuntimeRequirements(chunk);\n const entryModuleCount = chunkGraph.getNumberOfEntryModules(chunk);\n\n // The default renderBootstrap automatically pushes a startup call when either:\n // - There is at least one entry module, OR\n // - runtimeRequirements.has(RuntimeGlobals.startupNoDefault) is true.\n if (\n entryModuleCount > 0 ||\n runtimeRequirements.has(RuntimeGlobals.startupNoDefault)\n ) {\n return startupSource;\n }\n\n // Otherwise, append a startup call.\n return new compiler.webpack.sources.ConcatSource(\n startupSource,\n '\\n// Custom hook: appended startup call because none was added automatically\\n',\n `${RuntimeGlobals.startup}();\\n`,\n );\n },\n );\n\n // --- Part 2: Embed Federation Runtime Module and adjust runtime requirements ---\n const federationHooks =\n FederationModulesPlugin.getCompilationHooks(compilation);\n const containerEntrySet: Set<\n ContainerEntryDependency | FederationRuntimeDependency\n > = new Set();\n\n // Proactively add startupOnlyBefore target chunks.\n compilation.hooks.additionalChunkRuntimeRequirements.tap(\n PLUGIN_NAME,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!this.isEnabledForChunk(chunk)) {\n return;\n }\n runtimeRequirements.add(RuntimeGlobals.startupOnlyBefore);\n },\n );\n\n // Collect federation runtime dependencies.\n federationHooks.addFederationRuntimeDependency.tap(\n PLUGIN_NAME,\n (dependency: FederationRuntimeDependency) => {\n containerEntrySet.add(dependency);\n },\n );\n\n // Handle additional runtime requirements when federation is enabled.\n const handleRuntimeRequirements = (\n chunk: Chunk,\n runtimeRequirements: Set<string>,\n ) => {\n if (!this.isEnabledForChunk(chunk)) {\n return;\n }\n // Skip if already processed or if not a federation chunk.\n if (runtimeRequirements.has('embeddedFederationRuntime')) return;\n if (!runtimeRequirements.has(federationGlobal)) {\n return;\n }\n\n // Mark as embedded and add the runtime module.\n runtimeRequirements.add('embeddedFederationRuntime');\n const runtimeModule = new EmbedFederationRuntimeModule(\n containerEntrySet,\n );\n compilation.addRuntimeModule(chunk, runtimeModule);\n };\n\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(PLUGIN_NAME, handleRuntimeRequirements);\n },\n );\n }\n}\n\nexport default EmbedFederationRuntimePlugin;\n"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"EmbedFederationRuntimePlugin.js","names":["getFederationGlobalScope","FederationModulesPlugin","EmbedFederationRuntimeModule"],"sources":["../../../../../src/lib/container/runtime/EmbedFederationRuntimePlugin.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport EmbedFederationRuntimeModule from './EmbedFederationRuntimeModule';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport type { Compiler, Chunk, Compilation } from 'webpack';\nimport { getFederationGlobalScope } from './utils';\nimport ContainerEntryDependency from '../ContainerEntryDependency';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst { RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nconst PLUGIN_NAME = 'EmbedFederationRuntimePlugin';\n\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\ninterface EmbedFederationRuntimePluginOptions {\n /**\n * Whether to enable runtime module embedding for all chunks.\n * If false, only chunks that explicitly require it will be embedded.\n */\n enableForAllChunks?: boolean;\n}\n\n/**\n * Plugin that embeds Module Federation runtime code into chunks.\n * It ensures proper initialization of federated modules and manages runtime requirements.\n */\nclass EmbedFederationRuntimePlugin {\n private readonly options: EmbedFederationRuntimePluginOptions;\n private readonly processedChunks = new WeakMap<Chunk, boolean>();\n\n constructor(options: EmbedFederationRuntimePluginOptions = {}) {\n this.options = {\n enableForAllChunks: false,\n ...options,\n };\n }\n\n /**\n * Determines if runtime embedding should be enabled for a given chunk.\n */\n private isEnabledForChunk(chunk: Chunk): boolean {\n // Disable for our special \"build time chunk\"\n if (chunk.id === 'build time chunk') return false;\n return this.options.enableForAllChunks || chunk.hasRuntime();\n }\n\n /**\n * Checks if a hook has already been tapped by this plugin.\n */\n private isHookAlreadyTapped(\n taps: Array<{ name: string }>,\n hookName: string,\n ): boolean {\n return taps.some((tap) => tap.name === hookName);\n }\n\n apply(compiler: Compiler): void {\n // Prevent double application of the plugin.\n const compilationTaps = compiler.hooks.thisCompilation.taps || [];\n if (this.isHookAlreadyTapped(compilationTaps, PLUGIN_NAME)) {\n return;\n }\n\n // Tap into the compilation to modify renderStartup and runtime requirements.\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: Compilation) => {\n // --- Part 1: Modify renderStartup to append a startup call when none is added automatically ---\n const { renderStartup } =\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n );\n\n renderStartup.tap(\n PLUGIN_NAME,\n (startupSource, _lastInlinedModule, renderContext) => {\n const { chunk, chunkGraph } = renderContext;\n\n if (!this.isEnabledForChunk(chunk)) {\n return startupSource;\n }\n\n const runtimeRequirements =\n chunkGraph.getTreeRuntimeRequirements(chunk);\n const entryModuleCount = chunkGraph.getNumberOfEntryModules(chunk);\n\n // The default renderBootstrap automatically pushes a startup call when either:\n // - There is at least one entry module, OR\n // - runtimeRequirements.has(RuntimeGlobals.startupNoDefault) is true.\n if (\n entryModuleCount > 0 ||\n runtimeRequirements.has(RuntimeGlobals.startupNoDefault)\n ) {\n return startupSource;\n }\n\n // Otherwise, append a startup call.\n return new compiler.webpack.sources.ConcatSource(\n startupSource,\n '\\n// Custom hook: appended startup call because none was added automatically\\n',\n `${RuntimeGlobals.startup}();\\n`,\n );\n },\n );\n\n // --- Part 2: Embed Federation Runtime Module and adjust runtime requirements ---\n const federationHooks =\n FederationModulesPlugin.getCompilationHooks(compilation);\n const containerEntrySet: Set<\n ContainerEntryDependency | FederationRuntimeDependency\n > = new Set();\n\n // Proactively add startupOnlyBefore target chunks.\n compilation.hooks.additionalChunkRuntimeRequirements.tap(\n PLUGIN_NAME,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!this.isEnabledForChunk(chunk)) {\n return;\n }\n runtimeRequirements.add(RuntimeGlobals.startupOnlyBefore);\n },\n );\n\n // Collect federation runtime dependencies.\n federationHooks.addFederationRuntimeDependency.tap(\n PLUGIN_NAME,\n (dependency: FederationRuntimeDependency) => {\n containerEntrySet.add(dependency);\n },\n );\n\n // Handle additional runtime requirements when federation is enabled.\n const handleRuntimeRequirements = (\n chunk: Chunk,\n runtimeRequirements: Set<string>,\n ) => {\n if (!this.isEnabledForChunk(chunk)) {\n return;\n }\n // Skip if already processed or if not a federation chunk.\n if (runtimeRequirements.has('embeddedFederationRuntime')) return;\n if (!runtimeRequirements.has(federationGlobal)) {\n return;\n }\n\n // Mark as embedded and add the runtime module.\n runtimeRequirements.add('embeddedFederationRuntime');\n const runtimeModule = new EmbedFederationRuntimeModule(\n containerEntrySet,\n );\n compilation.addRuntimeModule(chunk, runtimeModule);\n };\n\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(PLUGIN_NAME, handleRuntimeRequirements);\n },\n );\n }\n}\n\nexport default EmbedFederationRuntimePlugin;\n"],"mappings":";;;;;;;;AAQA,MAAM,EAAE,mBAAmB,gFACJ,UAAU,CAChC;AAED,MAAM,cAAc;AAEpB,MAAM,mBAAmBA,6DAAyB,eAAe;;;;;AAcjE,IAAM,+BAAN,MAAmC;CAIjC,YAAY,UAA+C,EAAE,EAAE;yCAF5B,IAAI,SAAyB;AAG9D,OAAK,UAAU;GACb,oBAAoB;GACpB,GAAG;GACJ;;;;;CAMH,AAAQ,kBAAkB,OAAuB;AAE/C,MAA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M,gBAAgB,IAAIC,mEACxB,kBACD;AACD,gBAAY,iBAAiB,OAAO,cAAc;;AAGpD,eAAY,MAAM,yBACf,IAAI,iBAAiB,CACrB,IAAI,aAAa,0BAA0B;IAEjD"}
|
|
@@ -4,54 +4,38 @@ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/
|
|
|
4
4
|
let tapable = require("tapable");
|
|
5
5
|
|
|
6
6
|
//#region src/lib/container/runtime/FederationModulesPlugin.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
compilationHooksMap.set(compilation, hooks);
|
|
28
|
-
}
|
|
29
|
-
return hooks;
|
|
7
|
+
require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/Compilation"));
|
|
8
|
+
/** @type {WeakMap<import("webpack").Compilation, CompilationHooks>} */
|
|
9
|
+
const compilationHooksMap = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
const PLUGIN_NAME = "FederationModulesPlugin";
|
|
11
|
+
var FederationModulesPlugin = class FederationModulesPlugin {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Compilation} compilation the compilation
|
|
14
|
+
* @returns {CompilationHooks} the attached hooks
|
|
15
|
+
*/
|
|
16
|
+
static getCompilationHooks(compilation) {
|
|
17
|
+
if (!(compilation && typeof compilation === "object" && typeof compilation.hooks === "object" && typeof compilation.hooks.processAssets?.tap === "function")) throw new TypeError("Invalid 'compilation' argument: expected a Webpack Compilation-like object");
|
|
18
|
+
let hooks = compilationHooksMap.get(compilation);
|
|
19
|
+
if (hooks === void 0) {
|
|
20
|
+
hooks = {
|
|
21
|
+
addContainerEntryDependency: new tapable.SyncHook(["dependency"]),
|
|
22
|
+
addFederationRuntimeDependency: new tapable.SyncHook(["dependency"]),
|
|
23
|
+
addRemoteDependency: new tapable.SyncHook(["dependency"])
|
|
24
|
+
};
|
|
25
|
+
compilationHooksMap.set(compilation, hooks);
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
27
|
+
return hooks;
|
|
28
|
+
}
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
apply(compiler) {
|
|
33
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
|
|
34
|
+
FederationModulesPlugin.getCompilationHooks(compilation);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
41
38
|
|
|
42
39
|
//#endregion
|
|
43
|
-
init_FederationModulesPlugin();
|
|
44
|
-
Object.defineProperty(exports, 'FederationModulesPlugin_exports', {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return FederationModulesPlugin_exports;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
40
|
exports.default = FederationModulesPlugin;
|
|
51
|
-
Object.defineProperty(exports, 'init_FederationModulesPlugin', {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return init_FederationModulesPlugin;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
41
|
//# sourceMappingURL=FederationModulesPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FederationModulesPlugin.js","names":["SyncHook"],"sources":["../../../../../src/lib/container/runtime/FederationModulesPlugin.ts"],"sourcesContent":["import type { Compiler, Compilation as CompilationType } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nconst Compilation = require(\n normalizeWebpackPath('webpack/lib/Compilation'),\n) as typeof import('webpack/lib/Compilation');\nimport { SyncHook } from 'tapable';\nimport ContainerEntryDependency from '../ContainerEntryDependency';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\n/** @type {WeakMap<import(\"webpack\").Compilation, CompilationHooks>} */\nconst compilationHooksMap = new WeakMap<CompilationType, CompilationHooks>();\n\nconst PLUGIN_NAME = 'FederationModulesPlugin';\n\n/** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */\n\ntype CompilationHooks = {\n addContainerEntryDependency: SyncHook<[ContainerEntryDependency], void>;\n addFederationRuntimeDependency: SyncHook<[FederationRuntimeDependency], void>;\n addRemoteDependency: SyncHook<[any], void>;\n};\n\nclass FederationModulesPlugin {\n options: any;\n\n /**\n * @param {Compilation} compilation the compilation\n * @returns {CompilationHooks} the attached hooks\n */\n static getCompilationHooks(compilation: CompilationType): CompilationHooks {\n // Avoid cross-realm instanceof checks (e.g., Jest VM modules) by using\n // a duck-typed verification of a Webpack Compilation-like object.\n const isLikelyCompilation =\n compilation &&\n typeof compilation === 'object' &&\n // @ts-ignore\n typeof (compilation as any).hooks === 'object' &&\n // A couple of well-known hooks available on Webpack 5 compilations\n // @ts-ignore\n typeof (compilation as any).hooks.processAssets?.tap === 'function';\n\n if (!isLikelyCompilation) {\n throw new TypeError(\n \"Invalid 'compilation' argument: expected a Webpack Compilation-like object\",\n );\n }\n let hooks = compilationHooksMap.get(compilation);\n if (hooks === undefined) {\n hooks = {\n addContainerEntryDependency: new SyncHook(['dependency']),\n addFederationRuntimeDependency: new SyncHook(['dependency']),\n addRemoteDependency: new SyncHook(['dependency']),\n };\n compilationHooksMap.set(compilation, hooks);\n }\n return hooks;\n }\n\n constructor(options = {}) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: CompilationType, { normalModuleFactory }) => {\n //@ts-ignore\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n },\n );\n }\n}\n\nexport default FederationModulesPlugin;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FederationModulesPlugin.js","names":["SyncHook"],"sources":["../../../../../src/lib/container/runtime/FederationModulesPlugin.ts"],"sourcesContent":["import type { Compiler, Compilation as CompilationType } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nconst Compilation = require(\n normalizeWebpackPath('webpack/lib/Compilation'),\n) as typeof import('webpack/lib/Compilation');\nimport { SyncHook } from 'tapable';\nimport ContainerEntryDependency from '../ContainerEntryDependency';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\n/** @type {WeakMap<import(\"webpack\").Compilation, CompilationHooks>} */\nconst compilationHooksMap = new WeakMap<CompilationType, CompilationHooks>();\n\nconst PLUGIN_NAME = 'FederationModulesPlugin';\n\n/** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */\n\ntype CompilationHooks = {\n addContainerEntryDependency: SyncHook<[ContainerEntryDependency], void>;\n addFederationRuntimeDependency: SyncHook<[FederationRuntimeDependency], void>;\n addRemoteDependency: SyncHook<[any], void>;\n};\n\nclass FederationModulesPlugin {\n options: any;\n\n /**\n * @param {Compilation} compilation the compilation\n * @returns {CompilationHooks} the attached hooks\n */\n static getCompilationHooks(compilation: CompilationType): CompilationHooks {\n // Avoid cross-realm instanceof checks (e.g., Jest VM modules) by using\n // a duck-typed verification of a Webpack Compilation-like object.\n const isLikelyCompilation =\n compilation &&\n typeof compilation === 'object' &&\n // @ts-ignore\n typeof (compilation as any).hooks === 'object' &&\n // A couple of well-known hooks available on Webpack 5 compilations\n // @ts-ignore\n typeof (compilation as any).hooks.processAssets?.tap === 'function';\n\n if (!isLikelyCompilation) {\n throw new TypeError(\n \"Invalid 'compilation' argument: expected a Webpack Compilation-like object\",\n );\n }\n let hooks = compilationHooksMap.get(compilation);\n if (hooks === undefined) {\n hooks = {\n addContainerEntryDependency: new SyncHook(['dependency']),\n addFederationRuntimeDependency: new SyncHook(['dependency']),\n addRemoteDependency: new SyncHook(['dependency']),\n };\n compilationHooksMap.set(compilation, hooks);\n }\n return hooks;\n }\n\n constructor(options = {}) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: CompilationType, { normalModuleFactory }) => {\n //@ts-ignore\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n },\n );\n }\n}\n\nexport default FederationModulesPlugin;\n"],"mappings":";;;;;;AAGoB,gFACG,0BAA0B,CAChD;;AAMD,MAAM,sCAAsB,IAAI,SAA4C;AAE5E,MAAM,cAAc;AAUpB,IAAM,0BAAN,MAAM,wBAAwB;;;;;CAO5B,OAAO,oBAAoB,aAAgD;AAYzE,MAAI,EARF,eACA,OAAO,gBAAgB,YAEvB,OAAQ,YAAoB,UAAU,YAGtC,OAAQ,YAAoB,MAAM,eAAe,QAAQ,YAGzD,OAAM,IAAI,UACR,6EACD;EAEH,IAAI,QAAQ,oBAAoB,IAAI,YAAY;AAChD,MAAI,UAAU,QAAW;AACvB,WAAQ;IACN,6BAA6B,IAAIA,iBAAS,CAAC,aAAa,CAAC;IACzD,gCAAgC,IAAIA,iBAAS,CAAC,aAAa,CAAC;IAC5D,qBAAqB,IAAIA,iBAAS,CAAC,aAAa,CAAC;IAClD;AACD,uBAAoB,IAAI,aAAa,MAAM;;AAE7C,SAAO;;CAGT,YAAY,UAAU,EAAE,EAAE;AACxB,OAAK,UAAU;;CAGjB,MAAM,UAAoB;AACxB,WAAS,MAAM,YAAY,IACzB,cACC,aAA8B,EAAE,0BAA0B;AAE3C,2BAAwB,oBAAoB,YAAY;IAEzE"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('./FederationModulesPlugin.js');
|
|
4
3
|
const require_lib_container_runtime_utils = require('./utils.js');
|
|
5
4
|
const require_lib_container_runtime_FederationRuntimeModule = require('./FederationRuntimeModule.js');
|
|
6
5
|
const require_lib_container_constant = require('../constant.js');
|
|
6
|
+
const require_lib_container_runtime_FederationModulesPlugin = require('./FederationModulesPlugin.js');
|
|
7
7
|
const require_lib_container_runtime_EmbedFederationRuntimePlugin = require('./EmbedFederationRuntimePlugin.js');
|
|
8
8
|
const require_lib_container_HoistContainerReferencesPlugin = require('../HoistContainerReferencesPlugin.js');
|
|
9
9
|
const require_lib_container_runtime_FederationRuntimeDependency = require('./FederationRuntimeDependency.js');
|
|
10
10
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
11
|
+
let _module_federation_data_prefetch_cli = require("@module-federation/data-prefetch/cli");
|
|
11
12
|
let path = require("path");
|
|
12
13
|
path = require_runtime.__toESM(path);
|
|
13
14
|
let fs = require("fs");
|
|
14
15
|
fs = require_runtime.__toESM(fs);
|
|
15
|
-
let _module_federation_data_prefetch_cli = require("@module-federation/data-prefetch/cli");
|
|
16
16
|
let btoa = require("btoa");
|
|
17
17
|
btoa = require_runtime.__toESM(btoa);
|
|
18
18
|
|
|
19
19
|
//#region src/lib/container/runtime/FederationRuntimePlugin.ts
|
|
20
|
-
require_lib_container_runtime_FederationModulesPlugin.init_FederationModulesPlugin();
|
|
21
20
|
const ModuleDependency = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/dependencies/ModuleDependency"));
|
|
22
21
|
const { RuntimeGlobals, Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
23
22
|
const { mkdirpSync } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/fs"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FederationRuntimePlugin.js","names":["getFederationGlobalScope","normalizeToPosixPath","PrefetchPlugin","createHash","TEMP_DIR","FederationRuntimeDependency","FederationModulesPlugin","normalizeRuntimeInitOptionsWithOutShared","FederationRuntimeModule","EmbedFederationRuntimePlugin","HoistContainerReferences"],"sources":["../../../../../src/lib/container/runtime/FederationRuntimePlugin.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport pBtoa from 'btoa';\nimport type {\n Compiler,\n WebpackPluginInstance,\n Compilation,\n Chunk,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { PrefetchPlugin } from '@module-federation/data-prefetch/cli';\nimport { moduleFederationPlugin } from '@module-federation/sdk';\nimport FederationRuntimeModule from './FederationRuntimeModule';\nimport {\n getFederationGlobalScope,\n normalizeRuntimeInitOptionsWithOutShared,\n createHash,\n normalizeToPosixPath,\n} from './utils';\nimport { TEMP_DIR } from '../constant';\nimport EmbedFederationRuntimePlugin from './EmbedFederationRuntimePlugin';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport HoistContainerReferences from '../HoistContainerReferencesPlugin';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst { RuntimeGlobals, Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { mkdirpSync } = require(\n normalizeWebpackPath('webpack/lib/util/fs'),\n) as typeof import('webpack/lib/util/fs');\n\ntype ResolveFn = typeof require.resolve;\ntype RuntimeEntrySpec = {\n bundler: string;\n esm: string;\n cjs: string;\n};\n\nfunction resolveRuntimeEntry(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n const candidates = [spec.bundler, spec.esm, spec.cjs];\n const modulePaths = implementation ? [implementation] : undefined;\n let lastError: unknown;\n\n for (const candidate of candidates) {\n try {\n return modulePaths\n ? resolve(candidate, { paths: modulePaths })\n : resolve(candidate);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction resolveRuntimeEntryWithFallback(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n if (implementation) {\n try {\n return resolveRuntimeEntry(spec, implementation, resolve);\n } catch {\n // Fall back to the workspace runtime packages when a custom\n // implementation hasn't published the newer subpath yet.\n }\n }\n\n return resolveRuntimeEntry(spec, undefined, resolve);\n}\nexport function resolveRuntimePaths(\n implementation?: string,\n resolve: ResolveFn = require.resolve,\n) {\n // Prefer the dedicated bundler subpath so webpack can tree-shake across the\n // runtime package boundary. Fall back to the legacy dist contract for older\n // custom implementations that have not published /bundler yet.\n const runtimeToolsPath = resolveRuntimeEntryWithFallback(\n {\n bundler: '@module-federation/runtime-tools/bundler',\n esm: '@module-federation/runtime-tools/dist/index.js',\n cjs: '@module-federation/runtime-tools/dist/index.cjs',\n },\n implementation,\n resolve,\n );\n const moduleBase = implementation || runtimeToolsPath;\n\n return {\n runtimeToolsPath,\n bundlerRuntimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/webpack-bundler-runtime/bundler',\n esm: '@module-federation/webpack-bundler-runtime/dist/index.js',\n cjs: '@module-federation/webpack-bundler-runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n runtimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/runtime/bundler',\n esm: '@module-federation/runtime/dist/index.js',\n cjs: '@module-federation/runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n };\n}\n\nconst {\n runtimeToolsPath: RuntimeToolsPath,\n bundlerRuntimePath: BundlerRuntimePath,\n runtimePath: RuntimePath,\n} = resolveRuntimePaths();\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\nconst onceForCompiler = new WeakSet<Compiler>();\nconst onceForCompilerEntryMap = new WeakMap<Compiler, string>();\n\nclass FederationRuntimePlugin {\n options?: moduleFederationPlugin.ModuleFederationPluginOptions;\n entryFilePath: string;\n bundlerRuntimePath: string;\n runtimePath: string;\n runtimeToolsPath: string;\n federationRuntimeDependency?: FederationRuntimeDependency; // Add this line\n\n constructor(options?: moduleFederationPlugin.ModuleFederationPluginOptions) {\n this.options = options ? { ...options } : undefined;\n this.entryFilePath = '';\n this.bundlerRuntimePath = BundlerRuntimePath;\n this.runtimePath = RuntimePath;\n this.runtimeToolsPath = RuntimeToolsPath;\n this.federationRuntimeDependency = undefined; // Initialize as undefined\n }\n\n static getTemplate(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n bundlerRuntimePath?: string,\n ) {\n // internal runtime plugin\n const runtimePlugins = options.runtimePlugins;\n const normalizedBundlerRuntimePath = normalizeToPosixPath(\n bundlerRuntimePath || BundlerRuntimePath,\n );\n\n let runtimePluginTemplates = '';\n const runtimePluginCalls: string[] = [];\n\n if (Array.isArray(runtimePlugins)) {\n runtimePlugins.forEach((runtimePlugin, index) => {\n if (!runtimePlugin) {\n return;\n }\n const runtimePluginName = `plugin_${index}`;\n const runtimePluginEntry = Array.isArray(runtimePlugin)\n ? runtimePlugin[0]\n : runtimePlugin;\n const runtimePluginPath = normalizeToPosixPath(\n path.isAbsolute(runtimePluginEntry)\n ? runtimePluginEntry\n : path.join(process.cwd(), runtimePluginEntry),\n );\n const paramsStr =\n Array.isArray(runtimePlugin) && runtimePlugin.length > 1\n ? JSON.stringify(runtimePlugin[1])\n : 'undefined';\n runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\\n`;\n runtimePluginCalls.push(\n `${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`,\n );\n });\n }\n const embedRuntimeLines = Template.asString([\n `if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,\n Template.indent([\n `var prevFederation = ${federationGlobal};`,\n `${federationGlobal} = {}`,\n `for(var key in federation){`,\n Template.indent([`${federationGlobal}[key] = federation[key];`]),\n '}',\n `for(var key in prevFederation){`,\n Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),\n '}',\n ]),\n '}',\n ]);\n\n return Template.asString([\n `import federation from '${normalizedBundlerRuntimePath}';`,\n runtimePluginTemplates,\n embedRuntimeLines,\n `if(!${federationGlobal}.instance){`,\n Template.indent([\n runtimePluginCalls.length\n ? Template.asString([\n `var pluginsToAdd = [`,\n Template.indent(\n Template.indent(runtimePluginCalls.map((call) => `${call},`)),\n ),\n `].filter(Boolean);`,\n `${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,\n `${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`,\n ])\n : '',\n // `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,\n `${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,\n `if(${federationGlobal}.attachShareScopeMap){`,\n Template.indent([\n `${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,\n ]),\n '}',\n `if(${federationGlobal}.installInitialConsumes){`,\n Template.indent([`${federationGlobal}.installInitialConsumes()`]),\n '}',\n ]),\n PrefetchPlugin.addRuntime(compiler, {\n name: options.name!,\n }),\n '}',\n ]);\n }\n\n getFilePath(compiler: Compiler) {\n if (!this.options) {\n return '';\n }\n\n const existedFilePath = onceForCompilerEntryMap.get(compiler);\n\n if (existedFilePath) {\n return existedFilePath;\n }\n\n let entryFilePath = '';\n if (!this.options?.virtualRuntimeEntry) {\n const containerName = this.options.name;\n const hash = createHash(\n `${containerName} ${FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n )}`,\n );\n entryFilePath = path.join(TEMP_DIR, `entry.${hash}.js`);\n } else {\n entryFilePath = `data:text/javascript;charset=utf-8;base64,${pBtoa(\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n )}`;\n }\n\n onceForCompilerEntryMap.set(compiler, entryFilePath);\n\n return entryFilePath;\n }\n\n ensureFile(compiler: Compiler) {\n if (!this.options) {\n return;\n }\n // skip virtual entry\n if (this.options?.virtualRuntimeEntry) {\n return;\n }\n const filePath = this.entryFilePath;\n const outputFs = (compiler as unknown as { outputFileSystem?: unknown })\n .outputFileSystem;\n const fsLike =\n outputFs &&\n typeof (outputFs as typeof fs).readFileSync === 'function' &&\n typeof (outputFs as typeof fs).writeFileSync === 'function'\n ? (outputFs as typeof fs)\n : fs;\n try {\n fsLike.readFileSync(filePath);\n } catch {\n mkdirpSync(fsLike as any, TEMP_DIR);\n fsLike.writeFileSync(\n filePath,\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n );\n }\n }\n\n getDependency(compiler: Compiler) {\n if (this.federationRuntimeDependency)\n return this.federationRuntimeDependency;\n\n this.ensureFile(compiler);\n\n this.federationRuntimeDependency = new FederationRuntimeDependency(\n this.entryFilePath,\n );\n return this.federationRuntimeDependency;\n }\n\n prependEntry(compiler: Compiler) {\n if (!this.options?.virtualRuntimeEntry) {\n this.ensureFile(compiler);\n }\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n compiler.hooks.make.tapAsync(\n this.constructor.name,\n (compilation: Compilation, callback) => {\n const federationRuntimeDependency = this.getDependency(compiler);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err) => {\n if (err) {\n return callback(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n callback();\n },\n );\n },\n );\n }\n\n injectRuntime(compiler: Compiler) {\n if (!this.options || !this.options.name) {\n return;\n }\n const name = this.options.name;\n const initOptionsWithoutShared = normalizeRuntimeInitOptionsWithOutShared(\n this.options,\n );\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation) => {\n const handler = (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (runtimeRequirements.has(federationGlobal)) return;\n runtimeRequirements.add(federationGlobal);\n runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);\n runtimeRequirements.add(RuntimeGlobals.moduleCache);\n runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);\n\n compilation.addRuntimeModule(\n chunk,\n new FederationRuntimeModule(\n runtimeRequirements,\n name,\n initOptionsWithoutShared,\n ),\n );\n };\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n this.constructor.name,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!chunk.hasRuntime()) return;\n if (runtimeRequirements.has(RuntimeGlobals.initializeSharing))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap)) return;\n if (runtimeRequirements.has(federationGlobal)) return;\n handler(chunk, runtimeRequirements);\n },\n );\n\n // if federation runtime requirements exist\n // attach runtime module to the chunk\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.initializeSharing)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.currentRemoteGetScope)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.shareScopeMap)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(this.constructor.name, handler);\n },\n );\n }\n\n getRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n\n const resolvedPaths = resolveRuntimePaths(implementation);\n\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n\n if (alias['@module-federation/runtime$']) {\n this.runtimePath = alias['@module-federation/runtime$'];\n return this.runtimePath;\n }\n\n this.runtimePath = resolvedPaths.runtimePath;\n\n return this.runtimePath;\n }\n\n setRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n const runtimePath = this.getRuntimeAlias(compiler);\n alias['@module-federation/runtime$'] =\n alias['@module-federation/runtime$'] || runtimePath;\n alias['@module-federation/runtime-tools$'] =\n alias['@module-federation/runtime-tools$'] ||\n implementation ||\n this.runtimeToolsPath;\n\n // Set up aliases for the federation runtime and tools\n // This ensures that the correct versions are used throughout the project\n compiler.options.resolve.alias = alias;\n }\n\n apply(compiler: Compiler) {\n const useSharedContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'SharedContainerPlugin';\n },\n );\n // share container plugin should not inject mf runtime\n if (useSharedContainerPlugin) {\n return;\n }\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (useModuleFederationPlugin && !this.options) {\n this.options = useModuleFederationPlugin._options;\n }\n\n const useContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ContainerPlugin';\n },\n );\n\n if (useContainerPlugin && !this.options) {\n this.options = useContainerPlugin._options;\n }\n\n if (!useContainerPlugin && !useModuleFederationPlugin) {\n this.options = {\n remotes: {},\n ...this.options,\n };\n }\n if (this.options && !this.options?.name) {\n //! 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\n this.options.name =\n compiler.options.output.uniqueName || `container_${Date.now()}`;\n }\n\n const resolvedPaths = resolveRuntimePaths(this.options?.implementation);\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n this.runtimePath = resolvedPaths.runtimePath;\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n\n this.entryFilePath = this.getFilePath(compiler);\n\n new EmbedFederationRuntimePlugin().apply(compiler);\n\n new HoistContainerReferences().apply(compiler);\n\n // dont run multiple times on every apply()\n if (!onceForCompiler.has(compiler)) {\n this.prependEntry(compiler);\n this.injectRuntime(compiler);\n this.setRuntimeAlias(compiler);\n onceForCompiler.add(compiler);\n }\n }\n}\n\nexport default FederationRuntimePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;oFAqBgE;AAIhE,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,EAAE,gBAAgB,aAAa,gFACd,UAAU,CAChC;AACD,MAAM,EAAE,eAAe,gFACA,sBAAsB,CAC5C;AASD,SAAS,oBACP,MACA,gBACA,UAAqB,QAAQ,SAC7B;CACA,MAAM,aAAa;EAAC,KAAK;EAAS,KAAK;EAAK,KAAK;EAAI;CACrD,MAAM,cAAc,iBAAiB,CAAC,eAAe,GAAG;CACxD,IAAI;AAEJ,MAAK,MAAM,aAAa,WACtB,KAAI;AACF,SAAO,cACH,QAAQ,WAAW,EAAE,OAAO,aAAa,CAAC,GAC1C,QAAQ,UAAU;UACf,OAAO;AACd,cAAY;;AAIhB,OAAM;;AAGR,SAAS,gCACP,MACA,gBACA,UAAqB,QAAQ,SAC7B;AACA,KAAI,eACF,KAAI;AACF,SAAO,oBAAoB,MAAM,gBAAgB,QAAQ;SACnD;AAMV,QAAO,oBAAoB,MAAM,QAAW,QAAQ;;AAEtD,SAAgB,oBACd,gBACA,UAAqB,QAAQ,SAC7B;CAIA,MAAM,mBAAmB,gCACvB;EACE,SAAS;EACT,KAAK;EACL,KAAK;EACN,EACD,gBACA,QACD;CACD,MAAM,aA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AK,SAAS,eAAe;AACvE,OAAK,qBAAqB,cAAc;AACxC,OAAK,cAAc,cAAc;AACjC,OAAK,mBAAmB,cAAc;AAEtC,OAAK,gBAAgB,KAAK,YAAY,SAAS;AAE/C,MAAIC,oEAA8B,CAAC,MAAM,SAAS;AAElD,MAAIC,8DAA0B,CAAC,MAAM,SAAS;AAG9C,MAAI,CAAC,gBAAgB,IAAI,SAAS,EAAE;AAClC,QAAK,aAAa,SAAS;AAC3B,QAAK,cAAc,SAAS;AAC5B,QAAK,gBAAgB,SAAS;AAC9B,mBAAgB,IAAI,SAAS"}
|
|
1
|
+
{"version":3,"file":"FederationRuntimePlugin.js","names":["getFederationGlobalScope","normalizeToPosixPath","PrefetchPlugin","createHash","TEMP_DIR","FederationRuntimeDependency","FederationModulesPlugin","normalizeRuntimeInitOptionsWithOutShared","FederationRuntimeModule","EmbedFederationRuntimePlugin","HoistContainerReferences"],"sources":["../../../../../src/lib/container/runtime/FederationRuntimePlugin.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport pBtoa from 'btoa';\nimport type {\n Compiler,\n WebpackPluginInstance,\n Compilation,\n Chunk,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { PrefetchPlugin } from '@module-federation/data-prefetch/cli';\nimport { moduleFederationPlugin } from '@module-federation/sdk';\nimport FederationRuntimeModule from './FederationRuntimeModule';\nimport {\n getFederationGlobalScope,\n normalizeRuntimeInitOptionsWithOutShared,\n createHash,\n normalizeToPosixPath,\n} from './utils';\nimport { TEMP_DIR } from '../constant';\nimport EmbedFederationRuntimePlugin from './EmbedFederationRuntimePlugin';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport HoistContainerReferences from '../HoistContainerReferencesPlugin';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst { RuntimeGlobals, Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { mkdirpSync } = require(\n normalizeWebpackPath('webpack/lib/util/fs'),\n) as typeof import('webpack/lib/util/fs');\n\ntype ResolveFn = typeof require.resolve;\ntype RuntimeEntrySpec = {\n bundler: string;\n esm: string;\n cjs: string;\n};\n\nfunction resolveRuntimeEntry(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n const candidates = [spec.bundler, spec.esm, spec.cjs];\n const modulePaths = implementation ? [implementation] : undefined;\n let lastError: unknown;\n\n for (const candidate of candidates) {\n try {\n return modulePaths\n ? resolve(candidate, { paths: modulePaths })\n : resolve(candidate);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction resolveRuntimeEntryWithFallback(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n if (implementation) {\n try {\n return resolveRuntimeEntry(spec, implementation, resolve);\n } catch {\n // Fall back to the workspace runtime packages when a custom\n // implementation hasn't published the newer subpath yet.\n }\n }\n\n return resolveRuntimeEntry(spec, undefined, resolve);\n}\nexport function resolveRuntimePaths(\n implementation?: string,\n resolve: ResolveFn = require.resolve,\n) {\n // Prefer the dedicated bundler subpath so webpack can tree-shake across the\n // runtime package boundary. Fall back to the legacy dist contract for older\n // custom implementations that have not published /bundler yet.\n const runtimeToolsPath = resolveRuntimeEntryWithFallback(\n {\n bundler: '@module-federation/runtime-tools/bundler',\n esm: '@module-federation/runtime-tools/dist/index.js',\n cjs: '@module-federation/runtime-tools/dist/index.cjs',\n },\n implementation,\n resolve,\n );\n const moduleBase = implementation || runtimeToolsPath;\n\n return {\n runtimeToolsPath,\n bundlerRuntimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/webpack-bundler-runtime/bundler',\n esm: '@module-federation/webpack-bundler-runtime/dist/index.js',\n cjs: '@module-federation/webpack-bundler-runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n runtimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/runtime/bundler',\n esm: '@module-federation/runtime/dist/index.js',\n cjs: '@module-federation/runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n };\n}\n\nconst {\n runtimeToolsPath: RuntimeToolsPath,\n bundlerRuntimePath: BundlerRuntimePath,\n runtimePath: RuntimePath,\n} = resolveRuntimePaths();\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\nconst onceForCompiler = new WeakSet<Compiler>();\nconst onceForCompilerEntryMap = new WeakMap<Compiler, string>();\n\nclass FederationRuntimePlugin {\n options?: moduleFederationPlugin.ModuleFederationPluginOptions;\n entryFilePath: string;\n bundlerRuntimePath: string;\n runtimePath: string;\n runtimeToolsPath: string;\n federationRuntimeDependency?: FederationRuntimeDependency; // Add this line\n\n constructor(options?: moduleFederationPlugin.ModuleFederationPluginOptions) {\n this.options = options ? { ...options } : undefined;\n this.entryFilePath = '';\n this.bundlerRuntimePath = BundlerRuntimePath;\n this.runtimePath = RuntimePath;\n this.runtimeToolsPath = RuntimeToolsPath;\n this.federationRuntimeDependency = undefined; // Initialize as undefined\n }\n\n static getTemplate(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n bundlerRuntimePath?: string,\n ) {\n // internal runtime plugin\n const runtimePlugins = options.runtimePlugins;\n const normalizedBundlerRuntimePath = normalizeToPosixPath(\n bundlerRuntimePath || BundlerRuntimePath,\n );\n\n let runtimePluginTemplates = '';\n const runtimePluginCalls: string[] = [];\n\n if (Array.isArray(runtimePlugins)) {\n runtimePlugins.forEach((runtimePlugin, index) => {\n if (!runtimePlugin) {\n return;\n }\n const runtimePluginName = `plugin_${index}`;\n const runtimePluginEntry = Array.isArray(runtimePlugin)\n ? runtimePlugin[0]\n : runtimePlugin;\n const runtimePluginPath = normalizeToPosixPath(\n path.isAbsolute(runtimePluginEntry)\n ? runtimePluginEntry\n : path.join(process.cwd(), runtimePluginEntry),\n );\n const paramsStr =\n Array.isArray(runtimePlugin) && runtimePlugin.length > 1\n ? JSON.stringify(runtimePlugin[1])\n : 'undefined';\n runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\\n`;\n runtimePluginCalls.push(\n `${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`,\n );\n });\n }\n const embedRuntimeLines = Template.asString([\n `if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,\n Template.indent([\n `var prevFederation = ${federationGlobal};`,\n `${federationGlobal} = {}`,\n `for(var key in federation){`,\n Template.indent([`${federationGlobal}[key] = federation[key];`]),\n '}',\n `for(var key in prevFederation){`,\n Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),\n '}',\n ]),\n '}',\n ]);\n\n return Template.asString([\n `import federation from '${normalizedBundlerRuntimePath}';`,\n runtimePluginTemplates,\n embedRuntimeLines,\n `if(!${federationGlobal}.instance){`,\n Template.indent([\n runtimePluginCalls.length\n ? Template.asString([\n `var pluginsToAdd = [`,\n Template.indent(\n Template.indent(runtimePluginCalls.map((call) => `${call},`)),\n ),\n `].filter(Boolean);`,\n `${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,\n `${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`,\n ])\n : '',\n // `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,\n `${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,\n `if(${federationGlobal}.attachShareScopeMap){`,\n Template.indent([\n `${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,\n ]),\n '}',\n `if(${federationGlobal}.installInitialConsumes){`,\n Template.indent([`${federationGlobal}.installInitialConsumes()`]),\n '}',\n ]),\n PrefetchPlugin.addRuntime(compiler, {\n name: options.name!,\n }),\n '}',\n ]);\n }\n\n getFilePath(compiler: Compiler) {\n if (!this.options) {\n return '';\n }\n\n const existedFilePath = onceForCompilerEntryMap.get(compiler);\n\n if (existedFilePath) {\n return existedFilePath;\n }\n\n let entryFilePath = '';\n if (!this.options?.virtualRuntimeEntry) {\n const containerName = this.options.name;\n const hash = createHash(\n `${containerName} ${FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n )}`,\n );\n entryFilePath = path.join(TEMP_DIR, `entry.${hash}.js`);\n } else {\n entryFilePath = `data:text/javascript;charset=utf-8;base64,${pBtoa(\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n )}`;\n }\n\n onceForCompilerEntryMap.set(compiler, entryFilePath);\n\n return entryFilePath;\n }\n\n ensureFile(compiler: Compiler) {\n if (!this.options) {\n return;\n }\n // skip virtual entry\n if (this.options?.virtualRuntimeEntry) {\n return;\n }\n const filePath = this.entryFilePath;\n const outputFs = (compiler as unknown as { outputFileSystem?: unknown })\n .outputFileSystem;\n const fsLike =\n outputFs &&\n typeof (outputFs as typeof fs).readFileSync === 'function' &&\n typeof (outputFs as typeof fs).writeFileSync === 'function'\n ? (outputFs as typeof fs)\n : fs;\n try {\n fsLike.readFileSync(filePath);\n } catch {\n mkdirpSync(fsLike as any, TEMP_DIR);\n fsLike.writeFileSync(\n filePath,\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n );\n }\n }\n\n getDependency(compiler: Compiler) {\n if (this.federationRuntimeDependency)\n return this.federationRuntimeDependency;\n\n this.ensureFile(compiler);\n\n this.federationRuntimeDependency = new FederationRuntimeDependency(\n this.entryFilePath,\n );\n return this.federationRuntimeDependency;\n }\n\n prependEntry(compiler: Compiler) {\n if (!this.options?.virtualRuntimeEntry) {\n this.ensureFile(compiler);\n }\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n compiler.hooks.make.tapAsync(\n this.constructor.name,\n (compilation: Compilation, callback) => {\n const federationRuntimeDependency = this.getDependency(compiler);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err) => {\n if (err) {\n return callback(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n callback();\n },\n );\n },\n );\n }\n\n injectRuntime(compiler: Compiler) {\n if (!this.options || !this.options.name) {\n return;\n }\n const name = this.options.name;\n const initOptionsWithoutShared = normalizeRuntimeInitOptionsWithOutShared(\n this.options,\n );\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation) => {\n const handler = (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (runtimeRequirements.has(federationGlobal)) return;\n runtimeRequirements.add(federationGlobal);\n runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);\n runtimeRequirements.add(RuntimeGlobals.moduleCache);\n runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);\n\n compilation.addRuntimeModule(\n chunk,\n new FederationRuntimeModule(\n runtimeRequirements,\n name,\n initOptionsWithoutShared,\n ),\n );\n };\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n this.constructor.name,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!chunk.hasRuntime()) return;\n if (runtimeRequirements.has(RuntimeGlobals.initializeSharing))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap)) return;\n if (runtimeRequirements.has(federationGlobal)) return;\n handler(chunk, runtimeRequirements);\n },\n );\n\n // if federation runtime requirements exist\n // attach runtime module to the chunk\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.initializeSharing)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.currentRemoteGetScope)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.shareScopeMap)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(this.constructor.name, handler);\n },\n );\n }\n\n getRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n\n const resolvedPaths = resolveRuntimePaths(implementation);\n\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n\n if (alias['@module-federation/runtime$']) {\n this.runtimePath = alias['@module-federation/runtime$'];\n return this.runtimePath;\n }\n\n this.runtimePath = resolvedPaths.runtimePath;\n\n return this.runtimePath;\n }\n\n setRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n const runtimePath = this.getRuntimeAlias(compiler);\n alias['@module-federation/runtime$'] =\n alias['@module-federation/runtime$'] || runtimePath;\n alias['@module-federation/runtime-tools$'] =\n alias['@module-federation/runtime-tools$'] ||\n implementation ||\n this.runtimeToolsPath;\n\n // Set up aliases for the federation runtime and tools\n // This ensures that the correct versions are used throughout the project\n compiler.options.resolve.alias = alias;\n }\n\n apply(compiler: Compiler) {\n const useSharedContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'SharedContainerPlugin';\n },\n );\n // share container plugin should not inject mf runtime\n if (useSharedContainerPlugin) {\n return;\n }\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (useModuleFederationPlugin && !this.options) {\n this.options = useModuleFederationPlugin._options;\n }\n\n const useContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ContainerPlugin';\n },\n );\n\n if (useContainerPlugin && !this.options) {\n this.options = useContainerPlugin._options;\n }\n\n if (!useContainerPlugin && !useModuleFederationPlugin) {\n this.options = {\n remotes: {},\n ...this.options,\n };\n }\n if (this.options && !this.options?.name) {\n //! 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\n this.options.name =\n compiler.options.output.uniqueName || `container_${Date.now()}`;\n }\n\n const resolvedPaths = resolveRuntimePaths(this.options?.implementation);\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n this.runtimePath = resolvedPaths.runtimePath;\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n\n this.entryFilePath = this.getFilePath(compiler);\n\n new EmbedFederationRuntimePlugin().apply(compiler);\n\n new HoistContainerReferences().apply(compiler);\n\n // dont run multiple times on every apply()\n if (!onceForCompiler.has(compiler)) {\n this.prependEntry(compiler);\n this.injectRuntime(compiler);\n this.setRuntimeAlias(compiler);\n onceForCompiler.add(compiler);\n }\n }\n}\n\nexport default FederationRuntimePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,EAAE,gBAAgB,aAAa,gFACd,UAAU,CAChC;AACD,MAAM,EAAE,eAAe,gFACA,sBAAsB,CAC5C;AASD,SAAS,oBACP,MACA,gBACA,UAAqB,QAAQ,SAC7B;CACA,MAAM,aAAa;EAAC,KAAK;EAAS,KAAK;EAAK,KAAK;EAAI;CACrD,MAAM,cAAc,iBAAiB,CAAC,eAAe,GAAG;CACxD,IAAI;AAEJ,MAAK,MAAM,aAAa,WACtB,KAAI;AACF,SAAO,cACH,QAAQ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,MACjD,MAAuD;AACtD,OAAI,OAAO,MAAM,YAAY,CAAC,EAC5B,QAAO;AAGT,UAAO,EAAE,YAAY;IAExB;AAED,MAAI,sBAAsB,CAAC,KAAK,QAC9B,MAAK,UAAU,mBAAmB;AAGpC,MAAI,CAAC,sBAAsB,CAAC,0BAC1B,MAAK,UAAU;GACb,SAAS,EAAE;GACX,GAAG,KAAK;GACT;AAEH,MAAI,KAAK,WAAW,CAAC,KAAK,SAAS;;AAEjC,OAAK,QAAQ,OACX,SAAS,QAAQ,OAAO,cAAc,aAAa,KAAK,KAAK;EAGjE,MAAM,gBAAgB,oBAAoB,KAAK,SAAS,eAAe;AACvE,OAAK,qBAAqB,cAAc;AACxC,OAAK,cAAc,cAAc;AACjC,OAAK,mBAAmB,cAAc;AAEtC,OAAK,gBAAgB,KAAK,YAAY,SAAS;AAE/C,MAAIC,oEAA8B,CAAC,MAAM,SAAS;AAElD,MAAIC,8DAA0B,CAAC,MAAM,SAAS;AAG9C,MAAI,CAAC,gBAAgB,IAAI,SAAS,EAAE;AAClC,QAAK,aAAa,SAAS;AAC3B,QAAK,cAAc,SAAS;AAC5B,QAAK,gBAAgB,SAAS;AAC9B,mBAAgB,IAAI,SAAS"}
|
|
@@ -2,10 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
3
3
|
const require_lib_container_options = require('../options.js');
|
|
4
4
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
5
|
-
let path = require("path");
|
|
6
|
-
path = require_runtime.__toESM(path);
|
|
7
5
|
let upath = require("upath");
|
|
8
6
|
upath = require_runtime.__toESM(upath);
|
|
7
|
+
let path = require("path");
|
|
8
|
+
path = require_runtime.__toESM(path);
|
|
9
9
|
let crypto = require("crypto");
|
|
10
10
|
crypto = require_runtime.__toESM(crypto);
|
|
11
11
|
|
|
@@ -3,6 +3,7 @@ const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
|
3
3
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
4
|
|
|
5
5
|
//#region src/wrapper/BaseWrapperPlugin.ts
|
|
6
|
+
const lazyRequire = (id) => module.require(id);
|
|
6
7
|
/**
|
|
7
8
|
* Base Wrapper Plugin Class
|
|
8
9
|
*
|
|
@@ -25,7 +26,7 @@ var BaseWrapperPlugin = class {
|
|
|
25
26
|
}
|
|
26
27
|
apply(compiler) {
|
|
27
28
|
process.env["FEDERATION_WEBPACK_PATH"] = process.env["FEDERATION_WEBPACK_PATH"] || (0, _module_federation_sdk_normalize_webpack_path.getWebpackPath)(compiler);
|
|
28
|
-
const CorePlugin =
|
|
29
|
+
const CorePlugin = lazyRequire(this.coreModulePath).default;
|
|
29
30
|
this.createCorePluginInstance(CorePlugin, compiler);
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseWrapperPlugin.js","names":[],"sources":["../../../src/wrapper/BaseWrapperPlugin.ts"],"sourcesContent":["import type { WebpackPluginInstance, Compiler } from 'webpack';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\n/**\n * Base Wrapper Plugin Class\n *\n * Why we need a Wrapper layer:\n * 1. Prevent direct references to peer dependency webpack in CommonJS environment, which can lead to inconsistent instances\n * 2. Ensure the FEDERATION_WEBPACK_PATH environment variable is set correctly, which is crucial for module federation to work properly\n * 3. Provide unified plugin initialization logic, reducing code duplication\n *\n * Why we need to set FEDERATION_WEBPACK_PATH:\n * In CommonJS environment, require('webpack') might get a different webpack version than the current compiler instance,\n * which can cause module federation to malfunction. By setting FEDERATION_WEBPACK_PATH, we ensure all internal\n * dependencies use the same webpack instance as the current compiler.\n */\nexport default abstract class BaseWrapperPlugin implements WebpackPluginInstance {\n protected _options: any;\n name: string;\n protected pluginName: string;\n protected coreModulePath: string;\n\n constructor(options: any, pluginName: string, coreModulePath: string) {\n this._options = options;\n this.pluginName = pluginName;\n this.coreModulePath = coreModulePath;\n this.name = pluginName;\n }\n\n apply(compiler: Compiler): void {\n // Ensure FEDERATION_WEBPACK_PATH environment variable is set correctly\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] || getWebpackPath(compiler);\n\n // Lazily load core plugin after webpack path is set.\n const CorePlugin =
|
|
1
|
+
{"version":3,"file":"BaseWrapperPlugin.js","names":[],"sources":["../../../src/wrapper/BaseWrapperPlugin.ts"],"sourcesContent":["import type { WebpackPluginInstance, Compiler } from 'webpack';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\n// Use module.require instead of require to prevent bundlers (rolldown/tsdown) from\n// hoisting the call to the top of the file. This ensures the require only executes\n// at call time, preserving strict initialization ordering. CJS-only.\nconst lazyRequire = (id: string): any => module.require(id);\n\n/**\n * Base Wrapper Plugin Class\n *\n * Why we need a Wrapper layer:\n * 1. Prevent direct references to peer dependency webpack in CommonJS environment, which can lead to inconsistent instances\n * 2. Ensure the FEDERATION_WEBPACK_PATH environment variable is set correctly, which is crucial for module federation to work properly\n * 3. Provide unified plugin initialization logic, reducing code duplication\n *\n * Why we need to set FEDERATION_WEBPACK_PATH:\n * In CommonJS environment, require('webpack') might get a different webpack version than the current compiler instance,\n * which can cause module federation to malfunction. By setting FEDERATION_WEBPACK_PATH, we ensure all internal\n * dependencies use the same webpack instance as the current compiler.\n */\nexport default abstract class BaseWrapperPlugin implements WebpackPluginInstance {\n protected _options: any;\n name: string;\n protected pluginName: string;\n protected coreModulePath: string;\n\n constructor(options: any, pluginName: string, coreModulePath: string) {\n this._options = options;\n this.pluginName = pluginName;\n this.coreModulePath = coreModulePath;\n this.name = pluginName;\n }\n\n apply(compiler: Compiler): void {\n // Ensure FEDERATION_WEBPACK_PATH environment variable is set correctly\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] || getWebpackPath(compiler);\n\n // Lazily load core plugin after webpack path is set.\n const CorePlugin = lazyRequire(this.coreModulePath).default as any;\n\n // Create core plugin instance and apply it\n this.createCorePluginInstance(CorePlugin, compiler);\n }\n\n /**\n * Create core plugin instance\n * Subclasses can override this method to customize instantiation logic\n */\n protected createCorePluginInstance(\n CorePlugin: any,\n compiler: Compiler,\n ): void {\n new CorePlugin(this._options).apply(compiler);\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,eAAe,OAAoB,OAAO,QAAQ,GAAG;;;;;;;;;;;;;;AAe3D,IAA8B,oBAA9B,MAAiF;CAM/E,YAAY,SAAc,YAAoB,gBAAwB;AACpE,OAAK,WAAW;AAChB,OAAK,aAAa;AAClB,OAAK,iBAAiB;AACtB,OAAK,OAAO;;CAGd,MAAM,UAA0B;AAE9B,UAAQ,IAAI,6BACV,QAAQ,IAAI,gGAA6C,SAAS;EAGpE,MAAM,aAAa,YAAY,KAAK,eAAe,CAAC;AAGpD,OAAK,yBAAyB,YAAY,SAAS;;;;;;CAOrD,AAAU,yBACR,YACA,UACM;AACN,MAAI,WAAW,KAAK,SAAS,CAAC,MAAM,SAAS"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
3
|
const require_wrapper_BaseWrapperPlugin = require('./BaseWrapperPlugin.js');
|
|
4
|
-
const require_lib_container_runtime_FederationModulesPlugin = require('../lib/container/runtime/FederationModulesPlugin.js');
|
|
5
4
|
|
|
6
5
|
//#region src/wrapper/FederationModulesPlugin.ts
|
|
6
|
+
const lazyRequire = (id) => module.require(id);
|
|
7
7
|
const PLUGIN_NAME = "FederationModulesPlugin";
|
|
8
8
|
var FederationModulesPlugin = class extends require_wrapper_BaseWrapperPlugin.default {
|
|
9
9
|
constructor() {
|
|
10
10
|
super({}, PLUGIN_NAME, "../lib/container/runtime/FederationModulesPlugin");
|
|
11
11
|
}
|
|
12
12
|
static getCompilationHooks(compilation) {
|
|
13
|
-
return (
|
|
13
|
+
return lazyRequire("../lib/container/runtime/FederationModulesPlugin").default.getCompilationHooks(compilation);
|
|
14
14
|
}
|
|
15
15
|
createCorePluginInstance(CorePlugin, compiler) {
|
|
16
16
|
new CorePlugin().apply(compiler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FederationModulesPlugin.js","names":["BaseWrapperPlugin"],"sources":["../../../src/wrapper/FederationModulesPlugin.ts"],"sourcesContent":["import type { Compilation } from 'webpack';\nimport BaseWrapperPlugin from './BaseWrapperPlugin';\n\nconst PLUGIN_NAME = 'FederationModulesPlugin';\n\nexport default class FederationModulesPlugin extends BaseWrapperPlugin {\n constructor() {\n super({}, PLUGIN_NAME, '../lib/container/runtime/FederationModulesPlugin');\n }\n\n static getCompilationHooks(compilation: Compilation) {\n const CoreFederationModulesPlugin
|
|
1
|
+
{"version":3,"file":"FederationModulesPlugin.js","names":["BaseWrapperPlugin"],"sources":["../../../src/wrapper/FederationModulesPlugin.ts"],"sourcesContent":["import type { Compilation } from 'webpack';\nimport BaseWrapperPlugin from './BaseWrapperPlugin';\n\n// Use module.require instead of require to prevent bundlers (rolldown/tsdown) from\n// hoisting the call to the top of the file. This ensures the require only executes\n// at call time, preserving strict initialization ordering. CJS-only.\nconst lazyRequire = (id: string): any => module.require(id);\n\nconst PLUGIN_NAME = 'FederationModulesPlugin';\n\nexport default class FederationModulesPlugin extends BaseWrapperPlugin {\n constructor() {\n super({}, PLUGIN_NAME, '../lib/container/runtime/FederationModulesPlugin');\n }\n\n static getCompilationHooks(compilation: Compilation) {\n const CoreFederationModulesPlugin = lazyRequire(\n '../lib/container/runtime/FederationModulesPlugin',\n )\n .default as typeof import('../lib/container/runtime/FederationModulesPlugin').default;\n return CoreFederationModulesPlugin.getCompilationHooks(compilation);\n }\n\n protected override createCorePluginInstance(\n CorePlugin: any,\n compiler: any,\n ): void {\n new CorePlugin().apply(compiler);\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,eAAe,OAAoB,OAAO,QAAQ,GAAG;AAE3D,MAAM,cAAc;AAEpB,IAAqB,0BAArB,cAAqDA,0CAAkB;CACrE,cAAc;AACZ,QAAM,EAAE,EAAE,aAAa,mDAAmD;;CAG5E,OAAO,oBAAoB,aAA0B;AAKnD,SAJoC,YAClC,mDACD,CACE,QACgC,oBAAoB,YAAY;;CAGrE,AAAmB,yBACjB,YACA,UACM;AACN,MAAI,YAAY,CAAC,MAAM,SAAS"}
|
|
@@ -50,10 +50,8 @@ var ModuleFederationPlugin = class extends require_wrapper_BaseWrapperPlugin.def
|
|
|
50
50
|
const enableBridgePlugin = shouldEnableBridgePlugin();
|
|
51
51
|
if (!enableBridgePlugin && hasBridgeReact) compiler.hooks.afterPlugins.tap("BridgeReactBaseAliasPlugin", () => {
|
|
52
52
|
try {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const bridgeReactBasePath = path.resolve(compiler.context, "node_modules/@module-federation/bridge-react/dist/base.es.js");
|
|
56
|
-
if (!fs.existsSync(bridgeReactBasePath)) {
|
|
53
|
+
const bridgeReactBasePath = node_path.default.resolve(compiler.context, "node_modules/@module-federation/bridge-react/dist/base.es.js");
|
|
54
|
+
if (!node_fs.default.existsSync(bridgeReactBasePath)) {
|
|
57
55
|
_module_federation_sdk.infrastructureLogger.warn("⚠️ [ModuleFederationPlugin] bridge-react /base entry not found, falling back to default entry");
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleFederationPlugin.js","names":["BaseWrapperPlugin","infrastructureLogger","path","fs","ReactBridgePlugin"],"sources":["../../../src/wrapper/ModuleFederationPlugin.ts"],"sourcesContent":["import {\n bindLoggerToCompiler,\n infrastructureLogger,\n type moduleFederationPlugin,\n} from '@module-federation/sdk';\nimport type IModuleFederationPlugin from '../lib/container/ModuleFederationPlugin';\n\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport ReactBridgePlugin from '@module-federation/bridge-react-webpack-plugin';\nimport BaseWrapperPlugin from './BaseWrapperPlugin';\n\nexport const PLUGIN_NAME = 'ModuleFederationPlugin';\n\nexport default class ModuleFederationPlugin extends BaseWrapperPlugin {\n private _mfPlugin?: IModuleFederationPlugin;\n\n constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions) {\n super(options, PLUGIN_NAME, '../lib/container/ModuleFederationPlugin');\n }\n\n protected override createCorePluginInstance(\n CorePlugin: any,\n compiler: any,\n ): void {\n bindLoggerToCompiler(\n infrastructureLogger,\n compiler,\n 'EnhancedModuleFederationPlugin',\n );\n\n this._mfPlugin = new CorePlugin(this._options);\n this._mfPlugin!.apply(compiler);\n\n const checkBridgeReactInstalled = () => {\n try {\n const userPackageJsonPath = path.resolve(\n compiler.context,\n 'package.json',\n );\n if (fs.existsSync(userPackageJsonPath)) {\n const userPackageJson = JSON.parse(\n fs.readFileSync(userPackageJsonPath, 'utf-8'),\n );\n const userDependencies = {\n ...userPackageJson.dependencies,\n ...userPackageJson.devDependencies,\n };\n return !!userDependencies['@module-federation/bridge-react'];\n }\n return false;\n } catch (error) {\n return false;\n }\n };\n const hasBridgeReact = checkBridgeReactInstalled();\n\n const shouldEnableBridgePlugin = () => {\n // Priority 1: Explicit enableBridgeRouter configuration\n if (this._options?.bridge?.enableBridgeRouter === true) {\n return true;\n }\n\n // Priority 2: Explicit disable via enableBridgeRouter:false or disableAlias:true\n if (\n this._options?.bridge?.enableBridgeRouter === false ||\n this._options?.bridge?.disableAlias === true\n ) {\n if (this._options?.bridge?.disableAlias === true) {\n infrastructureLogger.warn(\n '⚠️ [ModuleFederationPlugin] The `disableAlias` option is deprecated and will be removed in a future version.\\n' +\n ' Please use `enableBridgeRouter: false` instead:\\n' +\n ' {\\n' +\n ' bridge: {\\n' +\n ' enableBridgeRouter: false // Use this instead of disableAlias: true\\n' +\n ' }\\n' +\n ' }',\n );\n }\n return false;\n }\n\n // Priority 3: Automatic detection based on bridge-react installation\n if (hasBridgeReact) {\n infrastructureLogger.info(\n '💡 [ModuleFederationPlugin] Detected @module-federation/bridge-react in your dependencies.\\n' +\n ' For better control and to avoid future breaking changes, please explicitly set:\\n' +\n ' {\\n' +\n ' bridge: {\\n' +\n ' enableBridgeRouter: true // Explicitly enable bridge router\\n' +\n ' }\\n' +\n ' }',\n );\n return true;\n }\n\n return false;\n };\n\n const enableBridgePlugin = shouldEnableBridgePlugin();\n\n // When bridge plugin is disabled (router disabled), alias to /base entry\n if (!enableBridgePlugin && hasBridgeReact) {\n compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', () => {\n try {\n const
|
|
1
|
+
{"version":3,"file":"ModuleFederationPlugin.js","names":["BaseWrapperPlugin","infrastructureLogger","path","fs","ReactBridgePlugin"],"sources":["../../../src/wrapper/ModuleFederationPlugin.ts"],"sourcesContent":["import {\n bindLoggerToCompiler,\n infrastructureLogger,\n type moduleFederationPlugin,\n} from '@module-federation/sdk';\nimport type IModuleFederationPlugin from '../lib/container/ModuleFederationPlugin';\n\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport ReactBridgePlugin from '@module-federation/bridge-react-webpack-plugin';\nimport BaseWrapperPlugin from './BaseWrapperPlugin';\n\nexport const PLUGIN_NAME = 'ModuleFederationPlugin';\n\nexport default class ModuleFederationPlugin extends BaseWrapperPlugin {\n private _mfPlugin?: IModuleFederationPlugin;\n\n constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions) {\n super(options, PLUGIN_NAME, '../lib/container/ModuleFederationPlugin');\n }\n\n protected override createCorePluginInstance(\n CorePlugin: any,\n compiler: any,\n ): void {\n bindLoggerToCompiler(\n infrastructureLogger,\n compiler,\n 'EnhancedModuleFederationPlugin',\n );\n\n this._mfPlugin = new CorePlugin(this._options);\n this._mfPlugin!.apply(compiler);\n\n const checkBridgeReactInstalled = () => {\n try {\n const userPackageJsonPath = path.resolve(\n compiler.context,\n 'package.json',\n );\n if (fs.existsSync(userPackageJsonPath)) {\n const userPackageJson = JSON.parse(\n fs.readFileSync(userPackageJsonPath, 'utf-8'),\n );\n const userDependencies = {\n ...userPackageJson.dependencies,\n ...userPackageJson.devDependencies,\n };\n return !!userDependencies['@module-federation/bridge-react'];\n }\n return false;\n } catch (error) {\n return false;\n }\n };\n const hasBridgeReact = checkBridgeReactInstalled();\n\n const shouldEnableBridgePlugin = () => {\n // Priority 1: Explicit enableBridgeRouter configuration\n if (this._options?.bridge?.enableBridgeRouter === true) {\n return true;\n }\n\n // Priority 2: Explicit disable via enableBridgeRouter:false or disableAlias:true\n if (\n this._options?.bridge?.enableBridgeRouter === false ||\n this._options?.bridge?.disableAlias === true\n ) {\n if (this._options?.bridge?.disableAlias === true) {\n infrastructureLogger.warn(\n '⚠️ [ModuleFederationPlugin] The `disableAlias` option is deprecated and will be removed in a future version.\\n' +\n ' Please use `enableBridgeRouter: false` instead:\\n' +\n ' {\\n' +\n ' bridge: {\\n' +\n ' enableBridgeRouter: false // Use this instead of disableAlias: true\\n' +\n ' }\\n' +\n ' }',\n );\n }\n return false;\n }\n\n // Priority 3: Automatic detection based on bridge-react installation\n if (hasBridgeReact) {\n infrastructureLogger.info(\n '💡 [ModuleFederationPlugin] Detected @module-federation/bridge-react in your dependencies.\\n' +\n ' For better control and to avoid future breaking changes, please explicitly set:\\n' +\n ' {\\n' +\n ' bridge: {\\n' +\n ' enableBridgeRouter: true // Explicitly enable bridge router\\n' +\n ' }\\n' +\n ' }',\n );\n return true;\n }\n\n return false;\n };\n\n const enableBridgePlugin = shouldEnableBridgePlugin();\n\n // When bridge plugin is disabled (router disabled), alias to /base entry\n if (!enableBridgePlugin && hasBridgeReact) {\n compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', () => {\n try {\n const bridgeReactBasePath = path.resolve(\n compiler.context,\n 'node_modules/@module-federation/bridge-react/dist/base.es.js',\n );\n\n if (!fs.existsSync(bridgeReactBasePath)) {\n infrastructureLogger.warn(\n '⚠️ [ModuleFederationPlugin] bridge-react /base entry not found, falling back to default entry',\n );\n return;\n }\n\n compiler.options.resolve.alias = {\n ...compiler.options.resolve.alias,\n '@module-federation/bridge-react$': bridgeReactBasePath,\n };\n infrastructureLogger.info(\n '✅ [ModuleFederationPlugin] Router disabled - using /base entry (no react-router-dom)',\n );\n } catch (error) {\n infrastructureLogger.warn(\n '⚠️ [ModuleFederationPlugin] Failed to set /base alias, using default entry',\n );\n }\n });\n }\n\n if (enableBridgePlugin) {\n new ReactBridgePlugin({\n moduleFederationOptions: this._options,\n }).apply(compiler);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,cAAc;AAE3B,IAAqB,yBAArB,cAAoDA,0CAAkB;CAGpE,YAAY,SAA+D;AACzE,QAAM,SAAS,aAAa,0CAA0C;;CAGxE,AAAmB,yBACjB,YACA,UACM;AACN,mDACEC,6CACA,UACA,iCACD;AAED,OAAK,YAAY,IAAI,WAAW,KAAK,SAAS;AAC9C,OAAK,UAAW,MAAM,SAAS;EAE/B,MAAM,kCAAkC;AACtC,OAAI;IACF,MAAM,sBAAsBC,kBAAK,QAC/B,SAAS,SACT,eACD;AACD,QAAIC,gBAAG,WAAW,oBAAoB,EAAE;KACtC,MAAM,kBAAkB,KAAK,MAC3BA,gBAAG,aAAa,qBAAqB,QAAQ,CAC9C;AAKD,YAAO,CAAC,CAJiB;MACvB,GAAG,gBAAgB;MACnB,GAAG,gBAAgB;MACpB,CACyB;;AAE5B,WAAO;YACA,OAAO;AACd,WAAO;;;EAGX,MAAM,iBAAiB,2BAA2B;EAElD,MAAM,iCAAiC;AAErC,OAAI,KAAK,UAAU,QAAQ,uBAAuB,KAChD,QAAO;AAIT,OACE,KAAK,UAAU,QAAQ,uBAAuB,SAC9C,KAAK,UAAU,QAAQ,iBAAiB,MACxC;AACA,QAAI,KAAK,UAAU,QAAQ,iBAAiB,KAC1C,6CAAqB,KACnB,qRAOD;AAEH,WAAO;;AAIT,OAAI,gBAAgB;AAClB,gDAAqB,KACnB,0RAOD;AACD,WAAO;;AAGT,UAAO;;EAGT,MAAM,qBAAqB,0BAA0B;AAGrD,MAAI,CAAC,sBAAsB,eACzB,UAAS,MAAM,aAAa,IAAI,oCAAoC;AAClE,OAAI;IACF,MAAM,sBAAsBD,kBAAK,QAC/B,SAAS,SACT,+DACD;AAED,QAAI,CAACC,gBAAG,WAAW,oBAAoB,EAAE;AACvC,iDAAqB,KACnB,iGACD;AACD;;AAGF,aAAS,QAAQ,QAAQ,QAAQ;KAC/B,GAAG,SAAS,QAAQ,QAAQ;KAC5B,oCAAoC;KACrC;AACD,gDAAqB,KACnB,uFACD;YACM,OAAO;AACd,gDAAqB,KACnB,8EACD;;IAEH;AAGJ,MAAI,mBACF,KAAIC,uDAAkB,EACpB,yBAAyB,KAAK,UAC/B,CAAC,CAAC,MAAM,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/enhanced",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -87,24 +87,26 @@
|
|
|
87
87
|
"ajv": "^8.18.0",
|
|
88
88
|
"enhanced-resolve": "^5.0.0",
|
|
89
89
|
"terser": "^5.37.0",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
90
|
+
"fast-glob": "3.3.3",
|
|
91
|
+
"memfs": "4.46.0"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"btoa": "^1.2.1",
|
|
95
95
|
"upath": "2.0.1",
|
|
96
96
|
"schema-utils": "^4.3.0",
|
|
97
|
-
"
|
|
98
|
-
"@module-federation/
|
|
99
|
-
"@module-federation/
|
|
100
|
-
"@module-federation/
|
|
101
|
-
"@module-federation/
|
|
102
|
-
"@module-federation/
|
|
103
|
-
"@module-federation/
|
|
104
|
-
"@module-federation/
|
|
105
|
-
"@module-federation/
|
|
106
|
-
"@module-federation/
|
|
107
|
-
"@module-federation/
|
|
97
|
+
"tapable": "2.3.0",
|
|
98
|
+
"@module-federation/webpack-bundler-runtime": "2.2.2",
|
|
99
|
+
"@module-federation/bridge-react-webpack-plugin": "2.2.2",
|
|
100
|
+
"@module-federation/data-prefetch": "2.2.2",
|
|
101
|
+
"@module-federation/dts-plugin": "2.2.2",
|
|
102
|
+
"@module-federation/inject-external-runtime-core-plugin": "2.2.2",
|
|
103
|
+
"@module-federation/error-codes": "2.2.2",
|
|
104
|
+
"@module-federation/managers": "2.2.2",
|
|
105
|
+
"@module-federation/manifest": "2.2.2",
|
|
106
|
+
"@module-federation/rspack": "2.2.2",
|
|
107
|
+
"@module-federation/runtime-tools": "2.2.2",
|
|
108
|
+
"@module-federation/sdk": "2.2.2",
|
|
109
|
+
"@module-federation/cli": "2.2.2"
|
|
108
110
|
},
|
|
109
111
|
"scripts": {
|
|
110
112
|
"generate:schema": "node src/scripts/compile-schema.js && node src/scripts/generate-sdk-types.js",
|