@module-federation/enhanced 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +37 -0
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +1 -3
- package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js +20 -9
- package/dist/src/schemas/container/ModuleFederationPlugin.check.js.map +1 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.d.ts +4 -0
- package/dist/src/schemas/container/ModuleFederationPlugin.js +5 -1
- package/dist/src/schemas/container/ModuleFederationPlugin.js.map +1 -1
- package/package.json +13 -15
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @module-federation/enhanced
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @module-federation/rspack@2.3.1
|
|
8
|
+
- @module-federation/webpack-bundler-runtime@2.3.1
|
|
9
|
+
- @module-federation/sdk@2.3.1
|
|
10
|
+
- @module-federation/runtime-tools@2.3.1
|
|
11
|
+
- @module-federation/managers@2.3.1
|
|
12
|
+
- @module-federation/manifest@2.3.1
|
|
13
|
+
- @module-federation/dts-plugin@2.3.1
|
|
14
|
+
- @module-federation/bridge-react-webpack-plugin@2.3.1
|
|
15
|
+
- @module-federation/data-prefetch@2.3.1
|
|
16
|
+
- @module-federation/error-codes@2.3.1
|
|
17
|
+
- @module-federation/inject-external-runtime-core-plugin@2.3.1
|
|
18
|
+
- @module-federation/cli@2.3.1
|
|
19
|
+
|
|
20
|
+
## 2.3.0
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [eb26065]
|
|
25
|
+
- Updated dependencies [f1d79b2]
|
|
26
|
+
- Updated dependencies [8f2ec9b]
|
|
27
|
+
- @module-federation/dts-plugin@2.3.0
|
|
28
|
+
- @module-federation/sdk@2.3.0
|
|
29
|
+
- @module-federation/webpack-bundler-runtime@2.3.0
|
|
30
|
+
- @module-federation/error-codes@2.3.0
|
|
31
|
+
- @module-federation/cli@2.3.0
|
|
32
|
+
- @module-federation/manifest@2.3.0
|
|
33
|
+
- @module-federation/rspack@2.3.0
|
|
34
|
+
- @module-federation/bridge-react-webpack-plugin@2.3.0
|
|
35
|
+
- @module-federation/data-prefetch@2.3.0
|
|
36
|
+
- @module-federation/managers@2.3.0
|
|
37
|
+
- @module-federation/runtime-tools@2.3.0
|
|
38
|
+
- @module-federation/inject-external-runtime-core-plugin@2.3.0
|
|
39
|
+
|
|
3
40
|
## 2.2.3
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
|
@@ -13,8 +13,6 @@ let path = require("path");
|
|
|
13
13
|
path = require_runtime.__toESM(path);
|
|
14
14
|
let fs = require("fs");
|
|
15
15
|
fs = require_runtime.__toESM(fs);
|
|
16
|
-
let btoa = require("btoa");
|
|
17
|
-
btoa = require_runtime.__toESM(btoa);
|
|
18
16
|
|
|
19
17
|
//#region src/lib/container/runtime/FederationRuntimePlugin.ts
|
|
20
18
|
const ModuleDependency = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/dependencies/ModuleDependency"));
|
|
@@ -137,7 +135,7 @@ var FederationRuntimePlugin = class FederationRuntimePlugin {
|
|
|
137
135
|
const containerName = this.options.name;
|
|
138
136
|
const hash = require_lib_container_runtime_utils.createHash(`${containerName} ${FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath)}`);
|
|
139
137
|
entryFilePath = path.default.join(require_lib_container_constant.TEMP_DIR, `entry.${hash}.js`);
|
|
140
|
-
} else entryFilePath = `data:text/javascript;charset=utf-8;base64,${
|
|
138
|
+
} else entryFilePath = `data:text/javascript;charset=utf-8;base64,${Buffer.from(FederationRuntimePlugin.getTemplate(compiler, this.options, this.bundlerRuntimePath), "utf8").toString("base64")}`;
|
|
141
139
|
onceForCompilerEntryMap.set(compiler, entryFilePath);
|
|
142
140
|
return entryFilePath;
|
|
143
141
|
}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;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,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,QAA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T;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"}
|
|
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 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,${Buffer.from(\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n 'utf8',\n ).toString('base64')}`;\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":";;;;;;;;;;;;;;;;;AAwBA,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;E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MAAuD;AACtD,OAAI,OAAO,MAAM,YAAY,CAAC,EAC5B,QAAO;AAET,UAAO,EAAE,YAAY;IAExB;AAED,MAAI,6BAA6B,CAAC,KAAK,QACrC,MAAK,UAAU,0BAA0B;EAG3C,MAAM,qBAAqB,SAAS,QAAQ,QAAQ,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"}
|
|
@@ -1751,14 +1751,24 @@ function D(o, { instancePath: i = "", parentData: a, parentDataProperty: p, root
|
|
|
1751
1751
|
}
|
|
1752
1752
|
O = e === c;
|
|
1753
1753
|
} else O = !0;
|
|
1754
|
-
if (O)
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1754
|
+
if (O) {
|
|
1755
|
+
if (void 0 !== t.abortOnError) {
|
|
1756
|
+
const e = c;
|
|
1757
|
+
if ("boolean" != typeof t.abortOnError) {
|
|
1758
|
+
const e = { params: { type: "boolean" } };
|
|
1759
|
+
null === u ? u = [e] : u.push(e), c++;
|
|
1760
|
+
}
|
|
1761
|
+
O = e === c;
|
|
1762
|
+
} else O = !0;
|
|
1763
|
+
if (O) if (void 0 !== t.afterGenerate) {
|
|
1764
|
+
const e = c;
|
|
1765
|
+
if (!(t.afterGenerate instanceof Function)) {
|
|
1766
|
+
const e = { params: {} };
|
|
1767
|
+
null === u ? u = [e] : u.push(e), c++;
|
|
1768
|
+
}
|
|
1769
|
+
O = e === c;
|
|
1770
|
+
} else O = !0;
|
|
1771
|
+
}
|
|
1762
1772
|
}
|
|
1763
1773
|
}
|
|
1764
1774
|
}
|
|
@@ -2765,7 +2775,8 @@ var init_ModuleFederationPlugin_check = require_runtime.__esmMin((() => {
|
|
|
2765
2775
|
additionalProperties: !1
|
|
2766
2776
|
}] },
|
|
2767
2777
|
extractRemoteTypes: { type: "boolean" },
|
|
2768
|
-
abortOnError: { type: "boolean" }
|
|
2778
|
+
abortOnError: { type: "boolean" },
|
|
2779
|
+
afterGenerate: { instanceof: "Function" }
|
|
2769
2780
|
}
|
|
2770
2781
|
}] },
|
|
2771
2782
|
consumeTypes: { anyOf: [{ type: "boolean" }, {
|