@module-federation/runtime-core 2.7.0 → 2.8.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","matchRemoteWithNameAndExpose","getRemoteInfo","formatPreloadArgs","composeRemoteRequestId","preloadAssets","RUNTIME_004","runtimeDescMap","optionsToMFContext","Module","isBrowserEnvValue","DEFAULT_SCOPE","DEFAULT_REMOTE_TYPE","getInfoWithoutType","CurrentGlobal","getFMId","Global","getGlobalRemoteInfo","getRemoteEntryUniqueKey","globalLoading","getGlobalShareScope"],"sources":["../../src/remote/index.ts"],"sourcesContent":["import {\n isBrowserEnvValue,\n warn,\n composeKeyWithSeparator,\n ModuleInfo,\n GlobalModuleInfo,\n} from '@module-federation/sdk';\nimport { RUNTIME_004, runtimeDescMap } from '@module-federation/error-codes';\nimport {\n Global,\n getInfoWithoutType,\n globalLoading,\n CurrentGlobal,\n} from '../global';\nimport {\n Options,\n UserOptions,\n PreloadAssets,\n PreloadOptions,\n PreloadRemoteArgs,\n PreloadRemoteResult,\n Remote,\n RemoteInfo,\n RemoteEntryExports,\n CallFrom,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncHook,\n SyncWaterfallHook,\n} from '../utils/hooks';\nimport {\n assert,\n error,\n getRemoteInfo,\n getRemoteEntryUniqueKey,\n getFMId,\n composeRemoteRequestId,\n matchRemoteWithNameAndExpose,\n optionsToMFContext,\n logger,\n} from '../utils';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { Module, ModuleOptions } from '../module';\nimport { formatPreloadArgs, preloadAssets } from '../utils/preload';\nimport { getGlobalShareScope } from '../utils/share';\nimport { getGlobalRemoteInfo } from '../plugins/snapshot/SnapshotHandler';\n\nexport interface LoadRemoteMatch {\n id: string;\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n options: Options;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n}\n\nexport class RemoteHandler {\n host: ModuleFederation;\n idToRemoteMap: Record<string, { name: string; expose: string }>;\n\n hooks = new PluginSystem({\n beforeRegisterRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('beforeRegisterRemote'),\n registerRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('registerRemote'),\n beforeRequest: new AsyncWaterfallHook<{\n id: string;\n options: Options;\n origin: ModuleFederation;\n }>('beforeRequest'),\n afterMatchRemote: new AsyncHook<\n [\n {\n id: string;\n options: Options;\n remote?: Remote;\n expose?: string;\n remoteInfo?: RemoteInfo;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterMatchRemote'),\n onLoad: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n pkgNameOrAlias: string;\n remote: Remote;\n options: ModuleOptions;\n origin: ModuleFederation;\n exposeModule: any;\n exposeModuleFactory: any;\n moduleInstance: Module;\n },\n ],\n unknown\n >('onLoad'),\n afterLoadRemote: new AsyncHook<\n [\n {\n id: string;\n expose?: string;\n remote?: RemoteInfo;\n options?: {\n loadFactory?: boolean;\n from?: CallFrom;\n };\n error?: unknown;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadRemote'),\n handlePreloadModule: new SyncHook<\n [\n {\n id: string;\n name: string;\n remote: Remote;\n remoteSnapshot: ModuleInfo;\n preloadConfig: PreloadRemoteArgs;\n origin: ModuleFederation;\n },\n ],\n void\n >('handlePreloadModule'),\n errorLoadRemote: new AsyncHook<\n [\n {\n id: string;\n error: unknown;\n options?: any;\n from: CallFrom;\n lifecycle:\n | 'beforeRequest'\n | 'beforeLoadShare'\n | 'afterResolve'\n | 'onLoad';\n remote?: RemoteInfo;\n expose?: string;\n origin: ModuleFederation;\n },\n ],\n void | unknown\n >('errorLoadRemote'),\n beforePreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n },\n ]\n >('beforePreloadRemote'),\n generatePreloadAssets: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n preloadOptions: PreloadOptions[number];\n remote: Remote;\n remoteInfo: RemoteInfo;\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n },\n ],\n Promise<PreloadAssets>\n >('generatePreloadAssets'),\n afterPreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n results: PreloadRemoteResult[];\n error?: unknown;\n },\n ]\n >('afterPreloadRemote'),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports | void> | RemoteEntryExports | void\n >(),\n });\n\n constructor(host: ModuleFederation) {\n this.host = host;\n this.idToRemoteMap = {};\n }\n\n formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions) {\n const userRemotes = userOptions.remotes || [];\n\n return userRemotes.reduce((res, remote) => {\n this.registerRemote(remote, res, { force: false });\n return res;\n }, globalOptions.remotes);\n }\n\n setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch) {\n const { remote, expose } = remoteMatchInfo;\n const { name, alias } = remote;\n this.idToRemoteMap[id] = { name: remote.name, expose };\n if (alias && id.startsWith(name)) {\n const idWithAlias = id.replace(name, alias);\n this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };\n return;\n }\n\n if (alias && id.startsWith(alias)) {\n const idWithName = id.replace(alias, name);\n this.idToRemoteMap[idWithName] = { name: remote.name, expose };\n }\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n const { host } = this;\n const startMatchInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n id,\n );\n let completeRequestId = id;\n let completeExpose = startMatchInfo?.expose;\n let completeRemote = startMatchInfo\n ? getRemoteInfo(startMatchInfo.remote)\n : undefined;\n let afterLoadRemoteArgs:\n | Parameters<\n RemoteHandler['hooks']['lifecycle']['afterLoadRemote']['emit']\n >[0]\n | undefined;\n\n try {\n const { loadFactory = true } = options || {\n loadFactory: true,\n };\n // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.\n // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.\n // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)\n // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get\n // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n // id: alias(app1) + expose(button) = app1/button\n // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\n const { module, moduleOptions, remoteMatchInfo } =\n await this.getRemoteModuleAndOptions({\n id,\n });\n const {\n pkgNameOrAlias,\n remote,\n expose,\n id: idRes,\n remoteSnapshot,\n } = remoteMatchInfo;\n completeRequestId = idRes;\n completeExpose = expose;\n completeRemote = getRemoteInfo(remote);\n\n const moduleOrFactory = (await module.get(\n idRes,\n expose,\n options,\n remoteSnapshot,\n )) as T;\n\n const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({\n id: idRes,\n pkgNameOrAlias,\n expose,\n exposeModule: loadFactory ? moduleOrFactory : undefined,\n exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,\n remote,\n options: moduleOptions,\n moduleInstance: module,\n origin: host,\n });\n\n this.setIdToRemoteMap(id, remoteMatchInfo);\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n origin: host,\n };\n\n if (typeof moduleWrapper === 'function') {\n return moduleWrapper as T;\n }\n\n return moduleOrFactory;\n } catch (error) {\n const { from = 'runtime' } = options || { from: 'runtime' };\n\n let failOver;\n try {\n failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n expose: completeExpose,\n remote: completeRemote,\n origin: host,\n });\n } catch (hookError) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error: hookError,\n origin: host,\n };\n throw hookError;\n }\n\n if (!failOver) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n };\n throw error;\n }\n\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n recovered: true,\n };\n\n return failOver as T;\n } finally {\n if (afterLoadRemoteArgs) {\n await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n const { host } = this;\n const preloadResults: PreloadRemoteResult[] = [];\n\n await this.hooks.lifecycle.beforePreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n });\n\n const preloadOps: PreloadOptions = formatPreloadArgs(\n host.options.remotes,\n preloadOptions,\n );\n\n const createPreloadAssetOps = (ops: PreloadOptions[number]) => {\n const { preloadConfig, remote } = ops;\n const exposes = preloadConfig.exposes || [];\n\n if (!exposes.length) {\n return [\n {\n ops,\n id: `${remote.name}/*`,\n },\n ];\n }\n\n return exposes.map((expose) => ({\n ops: {\n ...ops,\n preloadConfig: {\n ...preloadConfig,\n exposes: [expose],\n },\n },\n id: composeRemoteRequestId(remote.name, expose),\n }));\n };\n\n let preloadError: Error | undefined;\n\n await Promise.all(\n preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {\n const { ops, id: preloadId } = assetOps;\n const { remote, preloadConfig } = ops;\n const remoteInfo = getRemoteInfo(remote);\n try {\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\n id: preloadId,\n initiator: 'preloadRemote',\n });\n\n const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({\n origin: host,\n preloadOptions: ops,\n remote,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n });\n if (!assets) {\n return;\n }\n const results = await preloadAssets(remoteInfo, host, assets, true, {\n initiator: 'preloadRemote',\n id: preloadId,\n });\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results,\n });\n } catch (error) {\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results: [\n {\n url: remoteInfo.entry,\n status: 'error',\n resourceType: /\\.json(?:$|[?#])/i.test(remoteInfo.entry)\n ? 'manifest'\n : 'remoteEntry',\n initiator: 'preloadRemote',\n id: preloadId,\n error,\n },\n ],\n });\n }\n }),\n );\n\n const failedResults = preloadResults.flatMap((preloadResult) =>\n preloadResult.results.filter(\n (result) => result.status === 'error' || result.status === 'timeout',\n ),\n );\n if (failedResults.length > 0) {\n preloadError = new Error(\n `preloadRemote failed to load ${failedResults.length} resource(s).`,\n );\n Object.assign(preloadError, {\n results: preloadResults,\n failedResults,\n });\n }\n\n await this.hooks.lifecycle.afterPreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n results: preloadResults,\n error: preloadError,\n });\n\n if (preloadError) {\n throw preloadError;\n }\n }\n\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n const { host } = this;\n remotes.forEach((remote) => {\n this.registerRemote(remote, host.options.remotes, {\n force: options?.force,\n });\n });\n }\n\n async getRemoteModuleAndOptions(options: { id: string }): Promise<{\n module: Module;\n moduleOptions: ModuleOptions;\n remoteMatchInfo: LoadRemoteMatch;\n }> {\n const { host } = this;\n const { id } = options;\n let loadRemoteArgs;\n\n try {\n loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({\n id,\n options: host.options,\n origin: host,\n });\n } catch (error) {\n loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n options: host.options,\n origin: host,\n from: 'runtime',\n error,\n lifecycle: 'beforeRequest',\n })) as {\n id: string;\n options: Options;\n origin: ModuleFederation;\n };\n\n if (!loadRemoteArgs) {\n throw error;\n }\n }\n\n const { id: idRes } = loadRemoteArgs;\n\n const remoteSplitInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n idRes,\n );\n if (!remoteSplitInfo) {\n try {\n error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (matchError) {\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n options: host.options,\n error: matchError,\n origin: host,\n });\n throw matchError;\n }\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n remoteInfo,\n origin: host,\n });\n const matchInfo =\n await host.sharedHandler.hooks.lifecycle.afterResolve.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n origin: host,\n remoteInfo,\n });\n\n const { remote, expose } = matchInfo;\n assert(\n remote && expose,\n `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`,\n );\n let module: Module | undefined = host.moduleCache.get(remote.name);\n\n const moduleOptions: ModuleOptions = {\n host: host,\n remoteInfo,\n };\n\n if (!module) {\n module = new Module(moduleOptions);\n host.moduleCache.set(remote.name, module);\n }\n return {\n module,\n moduleOptions,\n remoteMatchInfo: matchInfo,\n };\n }\n\n registerRemote(\n remote: Remote,\n targetRemotes: Remote[],\n options?: { force?: boolean },\n ): void {\n const { host } = this;\n const normalizeRemote = () => {\n if (remote.alias) {\n // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error\n // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported\n const findEqual = targetRemotes.find(\n (item) =>\n remote.alias &&\n (item.name.startsWith(remote.alias) ||\n item.alias?.startsWith(remote.alias)),\n );\n assert(\n !findEqual,\n `The alias ${remote.alias} of remote ${\n remote.name\n } is not allowed to be the prefix of ${\n findEqual && findEqual.name\n } name or alias`,\n );\n }\n // Set the remote entry to a complete path\n if ('entry' in remote) {\n if (\n isBrowserEnvValue &&\n typeof window !== 'undefined' &&\n !remote.entry.startsWith('http')\n ) {\n remote.entry = new URL(remote.entry, window.location.origin).href;\n }\n }\n if (!remote.shareScope) {\n remote.shareScope = DEFAULT_SCOPE;\n }\n if (!remote.type) {\n remote.type = DEFAULT_REMOTE_TYPE;\n }\n };\n this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });\n const registeredRemote = targetRemotes.find(\n (item) => item.name === remote.name,\n );\n if (!registeredRemote) {\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n } else {\n const messages = [\n `The remote \"${remote.name}\" is already registered.`,\n 'Please note that overriding it may cause unexpected errors.',\n ];\n if (options?.force) {\n // remove registered remote\n this.removeRemote(registeredRemote);\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n warn(messages.join(' '));\n }\n }\n }\n\n private removeRemote(remote: Remote): void {\n try {\n const { host } = this;\n const { name } = remote;\n const remoteIndex = host.options.remotes.findIndex(\n (item) => item.name === name,\n );\n if (remoteIndex !== -1) {\n host.options.remotes.splice(remoteIndex, 1);\n }\n const globalSnapshotKey = getInfoWithoutType(\n CurrentGlobal.__FEDERATION__.moduleInfo,\n getFMId(remote),\n ).key;\n delete CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];\n\n if ('entry' in remote) {\n host.snapshotHandler.manifestCache.delete(remote.entry);\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];\n }\n\n const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);\n if (hostGlobalSnapshot) {\n const remoteKey =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;\n if (remoteKey) {\n delete hostGlobalSnapshot.remotesInfo[remoteKey];\n }\n }\n\n const loadedModule = host.moduleCache.get(remote.name);\n if (loadedModule) {\n const remoteInfo = loadedModule.remoteInfo;\n const key = remoteInfo.entryGlobalName as keyof typeof CurrentGlobal;\n\n if (CurrentGlobal[key]) {\n if (\n Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable\n ) {\n delete CurrentGlobal[key];\n } else {\n // @ts-ignore\n CurrentGlobal[key] = undefined;\n }\n }\n const remoteEntryUniqueKey = getRemoteEntryUniqueKey(\n loadedModule.remoteInfo,\n );\n\n if (globalLoading[remoteEntryUniqueKey]) {\n delete globalLoading[remoteEntryUniqueKey];\n }\n\n // delete unloaded shared and instance\n let remoteInsId = remoteInfo.buildVersion\n ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)\n : remoteInfo.name;\n const remoteInsIndex =\n CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {\n if (remoteInfo.buildVersion) {\n return ins.options.id === remoteInsId;\n } else {\n return ins.name === remoteInsId;\n }\n });\n if (remoteInsIndex !== -1) {\n const remoteIns =\n CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];\n remoteInsId = remoteIns.options.id || remoteInsId;\n const globalShareScopeMap = getGlobalShareScope();\n\n let isAllSharedNotUsed = true;\n const needDeleteKeys: Array<[string, string, string, string]> = [];\n Object.keys(globalShareScopeMap).forEach((instId) => {\n const shareScopeMap = globalShareScopeMap[instId];\n shareScopeMap &&\n Object.keys(shareScopeMap).forEach((shareScope) => {\n const shareScopeVal = shareScopeMap[shareScope];\n shareScopeVal &&\n Object.keys(shareScopeVal).forEach((shareName) => {\n const sharedPkgs = shareScopeVal[shareName];\n sharedPkgs &&\n Object.keys(sharedPkgs).forEach((shareVersion) => {\n const shared = sharedPkgs[shareVersion];\n if (\n shared &&\n typeof shared === 'object' &&\n shared.from === remoteInfo.name\n ) {\n if (shared.loaded || shared.loading) {\n shared.useIn = shared.useIn.filter(\n (usedHostName) =>\n usedHostName !== remoteInfo.name,\n );\n if (shared.useIn.length) {\n isAllSharedNotUsed = false;\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n }\n });\n });\n });\n });\n\n if (isAllSharedNotUsed) {\n remoteIns.shareScopeMap = {};\n delete globalShareScopeMap[remoteInsId];\n }\n needDeleteKeys.forEach(\n ([insId, shareScope, shareName, shareVersion]) => {\n delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[\n shareVersion\n ];\n },\n );\n CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);\n }\n\n host.moduleCache.delete(remote.name);\n }\n } catch (err) {\n logger.error(\n `removeRemote failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBAAb,MAA2B;CAgJzB,YAAY,MAAwB;eA5I5B,IAAIA,kCAAa;GACvB,sBAAsB,IAAIC,4CAGvB,uBAAuB;GAC1B,gBAAgB,IAAIA,4CAGjB,iBAAiB;GACpB,eAAe,IAAIC,+CAIhB,gBAAgB;GACnB,kBAAkB,IAAIC,4BAapB,mBAAmB;GACrB,QAAQ,IAAIA,4BAeV,SAAS;GACX,iBAAiB,IAAIA,4BAgBnB,kBAAkB;GACpB,qBAAqB,IAAIC,0BAYvB,sBAAsB;GACxB,iBAAiB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B;AACtB,gBAAU,gBAAgB,EAAE;AAC5B,aAAO,oBAAoB;;AAE7B,oBAAe,SACZ,CAAC,OAAO,YAAY,WAAW,kBAAkB;AAChD,aAAO,oBAAoB,SAAS,cAAc,aAChD;OAGL;AACD,kCAAc,eAAe,cAAc,OAAO,gBAAgB,EAAE;;AAGtE,SAAK,YAAY,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,yBAAO,MACL,wBAAwB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACzE"}
1
+ {"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","matchRemoteWithNameAndExpose","getRemoteInfo","formatPreloadArgs","composeRemoteRequestId","preloadAssets","Module","RUNTIME_004","runtimeDescMap","optionsToMFContext","isBrowserEnvValue","DEFAULT_SCOPE","DEFAULT_REMOTE_TYPE","getInfoWithoutType","CurrentGlobal","getFMId","Global","getGlobalRemoteInfo","getRemoteEntryUniqueKey","globalLoading","getGlobalShareScope"],"sources":["../../src/remote/index.ts"],"sourcesContent":["import {\n isBrowserEnvValue,\n warn,\n composeKeyWithSeparator,\n ModuleInfo,\n GlobalModuleInfo,\n} from '@module-federation/sdk';\nimport { RUNTIME_004, runtimeDescMap } from '@module-federation/error-codes';\nimport {\n Global,\n getInfoWithoutType,\n globalLoading,\n CurrentGlobal,\n} from '../global';\nimport {\n Options,\n UserOptions,\n PreloadAssets,\n PreloadOptions,\n PreloadRemoteArgs,\n PreloadRemoteResult,\n Remote,\n RemoteInfo,\n RemoteEntryExports,\n CallFrom,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncHook,\n SyncWaterfallHook,\n} from '../utils/hooks';\nimport {\n assert,\n error,\n getRemoteInfo,\n getRemoteEntryUniqueKey,\n getFMId,\n composeRemoteRequestId,\n matchRemoteWithNameAndExpose,\n optionsToMFContext,\n logger,\n} from '../utils';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { Module, ModuleOptions } from '../module';\nimport { formatPreloadArgs, preloadAssets } from '../utils/preload';\nimport { getGlobalShareScope } from '../utils/share';\nimport { getGlobalRemoteInfo } from '../plugins/snapshot/SnapshotHandler';\n\nexport interface LoadRemoteMatch {\n id: string;\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n options: Options;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n}\n\nexport class RemoteHandler {\n host: ModuleFederation;\n idToRemoteMap: Record<string, { name: string; expose: string }>;\n\n hooks = new PluginSystem({\n beforeRegisterRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('beforeRegisterRemote'),\n registerRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('registerRemote'),\n beforeRequest: new AsyncWaterfallHook<{\n id: string;\n options: Options;\n origin: ModuleFederation;\n }>('beforeRequest'),\n afterMatchRemote: new AsyncHook<\n [\n {\n id: string;\n options: Options;\n remote?: Remote;\n expose?: string;\n remoteInfo?: RemoteInfo;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterMatchRemote'),\n onLoad: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n pkgNameOrAlias: string;\n remote: Remote;\n options: ModuleOptions;\n origin: ModuleFederation;\n exposeModule: any;\n exposeModuleFactory: any;\n moduleInstance: Module;\n },\n ],\n unknown\n >('onLoad'),\n afterLoadRemote: new AsyncHook<\n [\n {\n id: string;\n expose?: string;\n remote?: RemoteInfo;\n options?: {\n loadFactory?: boolean;\n from?: CallFrom;\n };\n error?: unknown;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadRemote'),\n handlePreloadModule: new SyncHook<\n [\n {\n id: string;\n name: string;\n remote: Remote;\n remoteSnapshot: ModuleInfo;\n preloadConfig: PreloadRemoteArgs;\n origin: ModuleFederation;\n },\n ],\n void\n >('handlePreloadModule'),\n errorLoadRemote: new AsyncHook<\n [\n {\n id: string;\n error: unknown;\n options?: any;\n from: CallFrom;\n lifecycle:\n | 'beforeRequest'\n | 'beforeLoadShare'\n | 'afterResolve'\n | 'onLoad';\n remote?: RemoteInfo;\n expose?: string;\n origin: ModuleFederation;\n },\n ],\n void | unknown\n >('errorLoadRemote'),\n beforePreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n },\n ]\n >('beforePreloadRemote'),\n generatePreloadAssets: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n preloadOptions: PreloadOptions[number];\n remote: Remote;\n remoteInfo: RemoteInfo;\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n },\n ],\n Promise<PreloadAssets>\n >('generatePreloadAssets'),\n afterPreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n results: PreloadRemoteResult[];\n error?: unknown;\n },\n ]\n >('afterPreloadRemote'),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports | void> | RemoteEntryExports | void\n >(),\n });\n\n constructor(host: ModuleFederation) {\n this.host = host;\n this.idToRemoteMap = {};\n }\n\n formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions) {\n const userRemotes = userOptions.remotes || [];\n\n return userRemotes.reduce((res, remote) => {\n this.registerRemote(remote, res, { force: false });\n return res;\n }, globalOptions.remotes);\n }\n\n setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch) {\n const { remote, expose } = remoteMatchInfo;\n const { name, alias } = remote;\n this.idToRemoteMap[id] = { name: remote.name, expose };\n if (alias && id.startsWith(name)) {\n const idWithAlias = id.replace(name, alias);\n this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };\n return;\n }\n\n if (alias && id.startsWith(alias)) {\n const idWithName = id.replace(alias, name);\n this.idToRemoteMap[idWithName] = { name: remote.name, expose };\n }\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n const { host } = this;\n const startMatchInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n id,\n );\n let completeRequestId = id;\n let completeExpose = startMatchInfo?.expose;\n let completeRemote = startMatchInfo\n ? getRemoteInfo(startMatchInfo.remote)\n : undefined;\n let afterLoadRemoteArgs:\n | Parameters<\n RemoteHandler['hooks']['lifecycle']['afterLoadRemote']['emit']\n >[0]\n | undefined;\n\n try {\n const { loadFactory = true } = options || {\n loadFactory: true,\n };\n // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.\n // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.\n // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)\n // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get\n // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n // id: alias(app1) + expose(button) = app1/button\n // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\n const { module, moduleOptions, remoteMatchInfo } =\n await this.getRemoteModuleAndOptions({\n id,\n });\n const {\n pkgNameOrAlias,\n remote,\n expose,\n id: idRes,\n remoteSnapshot,\n } = remoteMatchInfo;\n completeRequestId = idRes;\n completeExpose = expose;\n completeRemote = getRemoteInfo(remote);\n\n const moduleOrFactory = (await module.get(\n idRes,\n expose,\n options,\n remoteSnapshot,\n )) as T;\n\n const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({\n id: idRes,\n pkgNameOrAlias,\n expose,\n exposeModule: loadFactory ? moduleOrFactory : undefined,\n exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,\n remote,\n options: moduleOptions,\n moduleInstance: module,\n origin: host,\n });\n\n this.setIdToRemoteMap(id, remoteMatchInfo);\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n origin: host,\n };\n\n if (typeof moduleWrapper === 'function') {\n return moduleWrapper as T;\n }\n\n return moduleOrFactory;\n } catch (error) {\n const { from = 'runtime' } = options || { from: 'runtime' };\n\n let failOver;\n try {\n failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n expose: completeExpose,\n remote: completeRemote,\n origin: host,\n });\n } catch (hookError) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error: hookError,\n origin: host,\n };\n throw hookError;\n }\n\n if (!failOver) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n };\n throw error;\n }\n\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n recovered: true,\n };\n\n return failOver as T;\n } finally {\n if (afterLoadRemoteArgs) {\n await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n const { host } = this;\n const preloadResults: PreloadRemoteResult[] = [];\n\n await this.hooks.lifecycle.beforePreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n });\n\n const preloadOps: PreloadOptions = formatPreloadArgs(\n host.options.remotes,\n preloadOptions,\n );\n\n const createPreloadAssetOps = (ops: PreloadOptions[number]) => {\n const { preloadConfig, remote } = ops;\n const exposes = preloadConfig.exposes || [];\n\n if (!exposes.length) {\n return [\n {\n ops,\n id: `${remote.name}/*`,\n },\n ];\n }\n\n return exposes.map((expose) => ({\n ops: {\n ...ops,\n preloadConfig: {\n ...preloadConfig,\n exposes: [expose],\n },\n },\n id: composeRemoteRequestId(remote.name, expose),\n }));\n };\n\n let preloadError: Error | undefined;\n\n await Promise.all(\n preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {\n const { ops, id: preloadId } = assetOps;\n const { remote, preloadConfig } = ops;\n const remoteInfo = getRemoteInfo(remote);\n try {\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\n id: preloadId,\n initiator: 'preloadRemote',\n });\n\n const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({\n origin: host,\n preloadOptions: ops,\n remote,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n });\n if (!assets) {\n return;\n }\n const results = await preloadAssets(remoteInfo, host, assets, true, {\n initiator: 'preloadRemote',\n id: preloadId,\n });\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results,\n });\n } catch (error) {\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results: [\n {\n url: remoteInfo.entry,\n status: 'error',\n resourceType: /\\.json(?:$|[?#])/i.test(remoteInfo.entry)\n ? 'manifest'\n : 'remoteEntry',\n initiator: 'preloadRemote',\n id: preloadId,\n error,\n },\n ],\n });\n }\n }),\n );\n\n const failedResults = preloadResults.flatMap((preloadResult) =>\n preloadResult.results.filter(\n (result) => result.status === 'error' || result.status === 'timeout',\n ),\n );\n if (failedResults.length > 0) {\n preloadError = new Error(\n `preloadRemote failed to load ${failedResults.length} resource(s).`,\n );\n Object.assign(preloadError, {\n results: preloadResults,\n failedResults,\n });\n }\n\n await this.hooks.lifecycle.afterPreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n results: preloadResults,\n error: preloadError,\n });\n\n if (preloadError) {\n throw preloadError;\n }\n }\n\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n const { host } = this;\n remotes.forEach((remote) => {\n this.registerRemote(remote, host.options.remotes, {\n force: options?.force,\n });\n });\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const { host } = this;\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host, remoteInfo });\n\n module.remoteEntryExports = container;\n host.moduleCache.set(name, module);\n\n return module;\n }\n\n async getRemoteModuleAndOptions(options: { id: string }): Promise<{\n module: Module;\n moduleOptions: ModuleOptions;\n remoteMatchInfo: LoadRemoteMatch;\n }> {\n const { host } = this;\n const { id } = options;\n let loadRemoteArgs;\n\n try {\n loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({\n id,\n options: host.options,\n origin: host,\n });\n } catch (error) {\n loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n options: host.options,\n origin: host,\n from: 'runtime',\n error,\n lifecycle: 'beforeRequest',\n })) as {\n id: string;\n options: Options;\n origin: ModuleFederation;\n };\n\n if (!loadRemoteArgs) {\n throw error;\n }\n }\n\n const { id: idRes } = loadRemoteArgs;\n\n const remoteSplitInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n idRes,\n );\n if (!remoteSplitInfo) {\n try {\n error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (matchError) {\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n options: host.options,\n error: matchError,\n origin: host,\n });\n throw matchError;\n }\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n remoteInfo,\n origin: host,\n });\n const matchInfo =\n await host.sharedHandler.hooks.lifecycle.afterResolve.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n origin: host,\n remoteInfo,\n });\n\n const { remote, expose } = matchInfo;\n assert(\n remote && expose,\n `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`,\n );\n let module: Module | undefined = host.moduleCache.get(remote.name);\n\n const moduleOptions: ModuleOptions = {\n host: host,\n remoteInfo,\n };\n\n if (!module) {\n module = new Module(moduleOptions);\n host.moduleCache.set(remote.name, module);\n }\n return {\n module,\n moduleOptions,\n remoteMatchInfo: matchInfo,\n };\n }\n\n registerRemote(\n remote: Remote,\n targetRemotes: Remote[],\n options?: { force?: boolean },\n ): void {\n const { host } = this;\n const normalizeRemote = () => {\n if (remote.alias) {\n // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error\n // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported\n const findEqual = targetRemotes.find(\n (item) =>\n remote.alias &&\n (item.name.startsWith(remote.alias) ||\n item.alias?.startsWith(remote.alias)),\n );\n assert(\n !findEqual,\n `The alias ${remote.alias} of remote ${\n remote.name\n } is not allowed to be the prefix of ${\n findEqual && findEqual.name\n } name or alias`,\n );\n }\n // Set the remote entry to a complete path\n if ('entry' in remote) {\n if (\n isBrowserEnvValue &&\n typeof window !== 'undefined' &&\n !remote.entry.startsWith('http')\n ) {\n remote.entry = new URL(remote.entry, window.location.origin).href;\n }\n }\n if (!remote.shareScope) {\n remote.shareScope = DEFAULT_SCOPE;\n }\n if (!remote.type) {\n remote.type = DEFAULT_REMOTE_TYPE;\n }\n };\n this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });\n const registeredRemote = targetRemotes.find(\n (item) => item.name === remote.name,\n );\n if (!registeredRemote) {\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n } else {\n const messages = [\n `The remote \"${remote.name}\" is already registered.`,\n 'Please note that overriding it may cause unexpected errors.',\n ];\n if (options?.force) {\n // remove registered remote\n this.removeRemote(registeredRemote);\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n warn(messages.join(' '));\n }\n }\n }\n\n private removeRemote(remote: Remote): void {\n try {\n const { host } = this;\n const { name } = remote;\n const remoteIndex = host.options.remotes.findIndex(\n (item) => item.name === name,\n );\n if (remoteIndex !== -1) {\n host.options.remotes.splice(remoteIndex, 1);\n }\n const globalSnapshotKey = getInfoWithoutType(\n CurrentGlobal.__FEDERATION__.moduleInfo,\n getFMId(remote),\n ).key;\n delete CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];\n\n if ('entry' in remote) {\n host.snapshotHandler.manifestCache.delete(remote.entry);\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];\n }\n\n const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);\n if (hostGlobalSnapshot) {\n const remoteKey =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;\n if (remoteKey) {\n delete hostGlobalSnapshot.remotesInfo[remoteKey];\n }\n }\n\n const loadedModule = host.moduleCache.get(remote.name);\n if (loadedModule) {\n const remoteInfo = loadedModule.remoteInfo;\n const key = remoteInfo.entryGlobalName as keyof typeof CurrentGlobal;\n\n if (CurrentGlobal[key]) {\n if (\n Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable\n ) {\n delete CurrentGlobal[key];\n } else {\n // @ts-ignore\n CurrentGlobal[key] = undefined;\n }\n }\n const remoteEntryUniqueKey = getRemoteEntryUniqueKey(\n loadedModule.remoteInfo,\n );\n\n if (globalLoading[remoteEntryUniqueKey]) {\n delete globalLoading[remoteEntryUniqueKey];\n }\n\n // delete unloaded shared and instance\n let remoteInsId = remoteInfo.buildVersion\n ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)\n : remoteInfo.name;\n const remoteInsIndex =\n CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {\n if (remoteInfo.buildVersion) {\n return ins.options.id === remoteInsId;\n } else {\n return ins.name === remoteInsId;\n }\n });\n if (remoteInsIndex !== -1) {\n const remoteIns =\n CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];\n remoteInsId = remoteIns.options.id || remoteInsId;\n const globalShareScopeMap = getGlobalShareScope();\n\n let isAllSharedNotUsed = true;\n const needDeleteKeys: Array<[string, string, string, string]> = [];\n Object.keys(globalShareScopeMap).forEach((instId) => {\n const shareScopeMap = globalShareScopeMap[instId];\n shareScopeMap &&\n Object.keys(shareScopeMap).forEach((shareScope) => {\n const shareScopeVal = shareScopeMap[shareScope];\n shareScopeVal &&\n Object.keys(shareScopeVal).forEach((shareName) => {\n const sharedPkgs = shareScopeVal[shareName];\n sharedPkgs &&\n Object.keys(sharedPkgs).forEach((shareVersion) => {\n const shared = sharedPkgs[shareVersion];\n if (\n shared &&\n typeof shared === 'object' &&\n shared.from === remoteInfo.name\n ) {\n if (shared.loaded || shared.loading) {\n shared.useIn = shared.useIn.filter(\n (usedHostName) =>\n usedHostName !== remoteInfo.name,\n );\n if (shared.useIn.length) {\n isAllSharedNotUsed = false;\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n }\n });\n });\n });\n });\n\n if (isAllSharedNotUsed) {\n remoteIns.shareScopeMap = {};\n delete globalShareScopeMap[remoteInsId];\n }\n needDeleteKeys.forEach(\n ([insId, shareScope, shareName, shareVersion]) => {\n delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[\n shareVersion\n ];\n },\n );\n CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);\n }\n\n host.moduleCache.delete(remote.name);\n }\n } catch (err) {\n logger.error(\n `removeRemote failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;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D,MAAM,gBAAgB,oBAAoB;AAC1C,uBACE,OAAO,KAAK,cAAc,CAAC,SAAS,eAAe;OACjD,MAAM,gBAAgB,cAAc;AACpC,wBACE,OAAO,KAAK,cAAc,CAAC,SAAS,cAAc;QAChD,MAAM,aAAa,cAAc;AACjC,sBACE,OAAO,KAAK,WAAW,CAAC,SAAS,iBAAiB;SAChD,MAAM,SAAS,WAAW;AAC1B,aACE,UACA,OAAO,WAAW,YAClB,OAAO,SAAS,WAAW,KAE3B,KAAI,OAAO,UAAU,OAAO,SAAS;AACnC,iBAAO,QAAQ,OAAO,MAAM,QACzB,iBACC,iBAAiB,WAAW,KAC/B;AACD,cAAI,OAAO,MAAM,OACf,sBAAqB;cAErB,gBAAe,KAAK;WAClB;WACA;WACA;WACA;WACD,CAAC;eAGJ,gBAAe,KAAK;UAClB;UACA;UACA;UACA;UACD,CAAC;UAGN;SACJ;QACJ;OACJ;AAEF,SAAI,oBAAoB;AACtB,gBAAU,gBAAgB,EAAE;AAC5B,aAAO,oBAAoB;;AAE7B,oBAAe,SACZ,CAAC,OAAO,YAAY,WAAW,kBAAkB;AAChD,aAAO,oBAAoB,SAAS,cAAc,aAChD;OAGL;AACD,kCAAc,eAAe,cAAc,OAAO,gBAAgB,EAAE;;AAGtE,SAAK,YAAY,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,yBAAO,MACL,wBAAwB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACzE"}
@@ -128,6 +128,7 @@ declare class RemoteHandler {
128
128
  registerRemotes(remotes: Remote[], options?: {
129
129
  force?: boolean;
130
130
  }): void;
131
+ initRawContainer(name: string, url: string, container: RemoteEntryExports): Module$1;
131
132
  getRemoteModuleAndOptions(options: {
132
133
  id: string;
133
134
  }): Promise<{
@@ -251,6 +251,19 @@ var RemoteHandler = class {
251
251
  this.registerRemote(remote, host.options.remotes, { force: options?.force });
252
252
  });
253
253
  }
254
+ initRawContainer(name, url, container) {
255
+ const { host } = this;
256
+ const module = new Module$1({
257
+ host,
258
+ remoteInfo: getRemoteInfo({
259
+ name,
260
+ entry: url
261
+ })
262
+ });
263
+ module.remoteEntryExports = container;
264
+ host.moduleCache.set(name, module);
265
+ return module;
266
+ }
254
267
  async getRemoteModuleAndOptions(options) {
255
268
  const { host } = this;
256
269
  const { id } = options;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Module"],"sources":["../../src/remote/index.ts"],"sourcesContent":["import {\n isBrowserEnvValue,\n warn,\n composeKeyWithSeparator,\n ModuleInfo,\n GlobalModuleInfo,\n} from '@module-federation/sdk';\nimport { RUNTIME_004, runtimeDescMap } from '@module-federation/error-codes';\nimport {\n Global,\n getInfoWithoutType,\n globalLoading,\n CurrentGlobal,\n} from '../global';\nimport {\n Options,\n UserOptions,\n PreloadAssets,\n PreloadOptions,\n PreloadRemoteArgs,\n PreloadRemoteResult,\n Remote,\n RemoteInfo,\n RemoteEntryExports,\n CallFrom,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncHook,\n SyncWaterfallHook,\n} from '../utils/hooks';\nimport {\n assert,\n error,\n getRemoteInfo,\n getRemoteEntryUniqueKey,\n getFMId,\n composeRemoteRequestId,\n matchRemoteWithNameAndExpose,\n optionsToMFContext,\n logger,\n} from '../utils';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { Module, ModuleOptions } from '../module';\nimport { formatPreloadArgs, preloadAssets } from '../utils/preload';\nimport { getGlobalShareScope } from '../utils/share';\nimport { getGlobalRemoteInfo } from '../plugins/snapshot/SnapshotHandler';\n\nexport interface LoadRemoteMatch {\n id: string;\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n options: Options;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n}\n\nexport class RemoteHandler {\n host: ModuleFederation;\n idToRemoteMap: Record<string, { name: string; expose: string }>;\n\n hooks = new PluginSystem({\n beforeRegisterRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('beforeRegisterRemote'),\n registerRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('registerRemote'),\n beforeRequest: new AsyncWaterfallHook<{\n id: string;\n options: Options;\n origin: ModuleFederation;\n }>('beforeRequest'),\n afterMatchRemote: new AsyncHook<\n [\n {\n id: string;\n options: Options;\n remote?: Remote;\n expose?: string;\n remoteInfo?: RemoteInfo;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterMatchRemote'),\n onLoad: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n pkgNameOrAlias: string;\n remote: Remote;\n options: ModuleOptions;\n origin: ModuleFederation;\n exposeModule: any;\n exposeModuleFactory: any;\n moduleInstance: Module;\n },\n ],\n unknown\n >('onLoad'),\n afterLoadRemote: new AsyncHook<\n [\n {\n id: string;\n expose?: string;\n remote?: RemoteInfo;\n options?: {\n loadFactory?: boolean;\n from?: CallFrom;\n };\n error?: unknown;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadRemote'),\n handlePreloadModule: new SyncHook<\n [\n {\n id: string;\n name: string;\n remote: Remote;\n remoteSnapshot: ModuleInfo;\n preloadConfig: PreloadRemoteArgs;\n origin: ModuleFederation;\n },\n ],\n void\n >('handlePreloadModule'),\n errorLoadRemote: new AsyncHook<\n [\n {\n id: string;\n error: unknown;\n options?: any;\n from: CallFrom;\n lifecycle:\n | 'beforeRequest'\n | 'beforeLoadShare'\n | 'afterResolve'\n | 'onLoad';\n remote?: RemoteInfo;\n expose?: string;\n origin: ModuleFederation;\n },\n ],\n void | unknown\n >('errorLoadRemote'),\n beforePreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n },\n ]\n >('beforePreloadRemote'),\n generatePreloadAssets: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n preloadOptions: PreloadOptions[number];\n remote: Remote;\n remoteInfo: RemoteInfo;\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n },\n ],\n Promise<PreloadAssets>\n >('generatePreloadAssets'),\n afterPreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n results: PreloadRemoteResult[];\n error?: unknown;\n },\n ]\n >('afterPreloadRemote'),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports | void> | RemoteEntryExports | void\n >(),\n });\n\n constructor(host: ModuleFederation) {\n this.host = host;\n this.idToRemoteMap = {};\n }\n\n formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions) {\n const userRemotes = userOptions.remotes || [];\n\n return userRemotes.reduce((res, remote) => {\n this.registerRemote(remote, res, { force: false });\n return res;\n }, globalOptions.remotes);\n }\n\n setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch) {\n const { remote, expose } = remoteMatchInfo;\n const { name, alias } = remote;\n this.idToRemoteMap[id] = { name: remote.name, expose };\n if (alias && id.startsWith(name)) {\n const idWithAlias = id.replace(name, alias);\n this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };\n return;\n }\n\n if (alias && id.startsWith(alias)) {\n const idWithName = id.replace(alias, name);\n this.idToRemoteMap[idWithName] = { name: remote.name, expose };\n }\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n const { host } = this;\n const startMatchInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n id,\n );\n let completeRequestId = id;\n let completeExpose = startMatchInfo?.expose;\n let completeRemote = startMatchInfo\n ? getRemoteInfo(startMatchInfo.remote)\n : undefined;\n let afterLoadRemoteArgs:\n | Parameters<\n RemoteHandler['hooks']['lifecycle']['afterLoadRemote']['emit']\n >[0]\n | undefined;\n\n try {\n const { loadFactory = true } = options || {\n loadFactory: true,\n };\n // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.\n // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.\n // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)\n // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get\n // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n // id: alias(app1) + expose(button) = app1/button\n // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\n const { module, moduleOptions, remoteMatchInfo } =\n await this.getRemoteModuleAndOptions({\n id,\n });\n const {\n pkgNameOrAlias,\n remote,\n expose,\n id: idRes,\n remoteSnapshot,\n } = remoteMatchInfo;\n completeRequestId = idRes;\n completeExpose = expose;\n completeRemote = getRemoteInfo(remote);\n\n const moduleOrFactory = (await module.get(\n idRes,\n expose,\n options,\n remoteSnapshot,\n )) as T;\n\n const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({\n id: idRes,\n pkgNameOrAlias,\n expose,\n exposeModule: loadFactory ? moduleOrFactory : undefined,\n exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,\n remote,\n options: moduleOptions,\n moduleInstance: module,\n origin: host,\n });\n\n this.setIdToRemoteMap(id, remoteMatchInfo);\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n origin: host,\n };\n\n if (typeof moduleWrapper === 'function') {\n return moduleWrapper as T;\n }\n\n return moduleOrFactory;\n } catch (error) {\n const { from = 'runtime' } = options || { from: 'runtime' };\n\n let failOver;\n try {\n failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n expose: completeExpose,\n remote: completeRemote,\n origin: host,\n });\n } catch (hookError) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error: hookError,\n origin: host,\n };\n throw hookError;\n }\n\n if (!failOver) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n };\n throw error;\n }\n\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n recovered: true,\n };\n\n return failOver as T;\n } finally {\n if (afterLoadRemoteArgs) {\n await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n const { host } = this;\n const preloadResults: PreloadRemoteResult[] = [];\n\n await this.hooks.lifecycle.beforePreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n });\n\n const preloadOps: PreloadOptions = formatPreloadArgs(\n host.options.remotes,\n preloadOptions,\n );\n\n const createPreloadAssetOps = (ops: PreloadOptions[number]) => {\n const { preloadConfig, remote } = ops;\n const exposes = preloadConfig.exposes || [];\n\n if (!exposes.length) {\n return [\n {\n ops,\n id: `${remote.name}/*`,\n },\n ];\n }\n\n return exposes.map((expose) => ({\n ops: {\n ...ops,\n preloadConfig: {\n ...preloadConfig,\n exposes: [expose],\n },\n },\n id: composeRemoteRequestId(remote.name, expose),\n }));\n };\n\n let preloadError: Error | undefined;\n\n await Promise.all(\n preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {\n const { ops, id: preloadId } = assetOps;\n const { remote, preloadConfig } = ops;\n const remoteInfo = getRemoteInfo(remote);\n try {\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\n id: preloadId,\n initiator: 'preloadRemote',\n });\n\n const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({\n origin: host,\n preloadOptions: ops,\n remote,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n });\n if (!assets) {\n return;\n }\n const results = await preloadAssets(remoteInfo, host, assets, true, {\n initiator: 'preloadRemote',\n id: preloadId,\n });\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results,\n });\n } catch (error) {\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results: [\n {\n url: remoteInfo.entry,\n status: 'error',\n resourceType: /\\.json(?:$|[?#])/i.test(remoteInfo.entry)\n ? 'manifest'\n : 'remoteEntry',\n initiator: 'preloadRemote',\n id: preloadId,\n error,\n },\n ],\n });\n }\n }),\n );\n\n const failedResults = preloadResults.flatMap((preloadResult) =>\n preloadResult.results.filter(\n (result) => result.status === 'error' || result.status === 'timeout',\n ),\n );\n if (failedResults.length > 0) {\n preloadError = new Error(\n `preloadRemote failed to load ${failedResults.length} resource(s).`,\n );\n Object.assign(preloadError, {\n results: preloadResults,\n failedResults,\n });\n }\n\n await this.hooks.lifecycle.afterPreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n results: preloadResults,\n error: preloadError,\n });\n\n if (preloadError) {\n throw preloadError;\n }\n }\n\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n const { host } = this;\n remotes.forEach((remote) => {\n this.registerRemote(remote, host.options.remotes, {\n force: options?.force,\n });\n });\n }\n\n async getRemoteModuleAndOptions(options: { id: string }): Promise<{\n module: Module;\n moduleOptions: ModuleOptions;\n remoteMatchInfo: LoadRemoteMatch;\n }> {\n const { host } = this;\n const { id } = options;\n let loadRemoteArgs;\n\n try {\n loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({\n id,\n options: host.options,\n origin: host,\n });\n } catch (error) {\n loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n options: host.options,\n origin: host,\n from: 'runtime',\n error,\n lifecycle: 'beforeRequest',\n })) as {\n id: string;\n options: Options;\n origin: ModuleFederation;\n };\n\n if (!loadRemoteArgs) {\n throw error;\n }\n }\n\n const { id: idRes } = loadRemoteArgs;\n\n const remoteSplitInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n idRes,\n );\n if (!remoteSplitInfo) {\n try {\n error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (matchError) {\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n options: host.options,\n error: matchError,\n origin: host,\n });\n throw matchError;\n }\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n remoteInfo,\n origin: host,\n });\n const matchInfo =\n await host.sharedHandler.hooks.lifecycle.afterResolve.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n origin: host,\n remoteInfo,\n });\n\n const { remote, expose } = matchInfo;\n assert(\n remote && expose,\n `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`,\n );\n let module: Module | undefined = host.moduleCache.get(remote.name);\n\n const moduleOptions: ModuleOptions = {\n host: host,\n remoteInfo,\n };\n\n if (!module) {\n module = new Module(moduleOptions);\n host.moduleCache.set(remote.name, module);\n }\n return {\n module,\n moduleOptions,\n remoteMatchInfo: matchInfo,\n };\n }\n\n registerRemote(\n remote: Remote,\n targetRemotes: Remote[],\n options?: { force?: boolean },\n ): void {\n const { host } = this;\n const normalizeRemote = () => {\n if (remote.alias) {\n // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error\n // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported\n const findEqual = targetRemotes.find(\n (item) =>\n remote.alias &&\n (item.name.startsWith(remote.alias) ||\n item.alias?.startsWith(remote.alias)),\n );\n assert(\n !findEqual,\n `The alias ${remote.alias} of remote ${\n remote.name\n } is not allowed to be the prefix of ${\n findEqual && findEqual.name\n } name or alias`,\n );\n }\n // Set the remote entry to a complete path\n if ('entry' in remote) {\n if (\n isBrowserEnvValue &&\n typeof window !== 'undefined' &&\n !remote.entry.startsWith('http')\n ) {\n remote.entry = new URL(remote.entry, window.location.origin).href;\n }\n }\n if (!remote.shareScope) {\n remote.shareScope = DEFAULT_SCOPE;\n }\n if (!remote.type) {\n remote.type = DEFAULT_REMOTE_TYPE;\n }\n };\n this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });\n const registeredRemote = targetRemotes.find(\n (item) => item.name === remote.name,\n );\n if (!registeredRemote) {\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n } else {\n const messages = [\n `The remote \"${remote.name}\" is already registered.`,\n 'Please note that overriding it may cause unexpected errors.',\n ];\n if (options?.force) {\n // remove registered remote\n this.removeRemote(registeredRemote);\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n warn(messages.join(' '));\n }\n }\n }\n\n private removeRemote(remote: Remote): void {\n try {\n const { host } = this;\n const { name } = remote;\n const remoteIndex = host.options.remotes.findIndex(\n (item) => item.name === name,\n );\n if (remoteIndex !== -1) {\n host.options.remotes.splice(remoteIndex, 1);\n }\n const globalSnapshotKey = getInfoWithoutType(\n CurrentGlobal.__FEDERATION__.moduleInfo,\n getFMId(remote),\n ).key;\n delete CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];\n\n if ('entry' in remote) {\n host.snapshotHandler.manifestCache.delete(remote.entry);\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];\n }\n\n const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);\n if (hostGlobalSnapshot) {\n const remoteKey =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;\n if (remoteKey) {\n delete hostGlobalSnapshot.remotesInfo[remoteKey];\n }\n }\n\n const loadedModule = host.moduleCache.get(remote.name);\n if (loadedModule) {\n const remoteInfo = loadedModule.remoteInfo;\n const key = remoteInfo.entryGlobalName as keyof typeof CurrentGlobal;\n\n if (CurrentGlobal[key]) {\n if (\n Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable\n ) {\n delete CurrentGlobal[key];\n } else {\n // @ts-ignore\n CurrentGlobal[key] = undefined;\n }\n }\n const remoteEntryUniqueKey = getRemoteEntryUniqueKey(\n loadedModule.remoteInfo,\n );\n\n if (globalLoading[remoteEntryUniqueKey]) {\n delete globalLoading[remoteEntryUniqueKey];\n }\n\n // delete unloaded shared and instance\n let remoteInsId = remoteInfo.buildVersion\n ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)\n : remoteInfo.name;\n const remoteInsIndex =\n CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {\n if (remoteInfo.buildVersion) {\n return ins.options.id === remoteInsId;\n } else {\n return ins.name === remoteInsId;\n }\n });\n if (remoteInsIndex !== -1) {\n const remoteIns =\n CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];\n remoteInsId = remoteIns.options.id || remoteInsId;\n const globalShareScopeMap = getGlobalShareScope();\n\n let isAllSharedNotUsed = true;\n const needDeleteKeys: Array<[string, string, string, string]> = [];\n Object.keys(globalShareScopeMap).forEach((instId) => {\n const shareScopeMap = globalShareScopeMap[instId];\n shareScopeMap &&\n Object.keys(shareScopeMap).forEach((shareScope) => {\n const shareScopeVal = shareScopeMap[shareScope];\n shareScopeVal &&\n Object.keys(shareScopeVal).forEach((shareName) => {\n const sharedPkgs = shareScopeVal[shareName];\n sharedPkgs &&\n Object.keys(sharedPkgs).forEach((shareVersion) => {\n const shared = sharedPkgs[shareVersion];\n if (\n shared &&\n typeof shared === 'object' &&\n shared.from === remoteInfo.name\n ) {\n if (shared.loaded || shared.loading) {\n shared.useIn = shared.useIn.filter(\n (usedHostName) =>\n usedHostName !== remoteInfo.name,\n );\n if (shared.useIn.length) {\n isAllSharedNotUsed = false;\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n }\n });\n });\n });\n });\n\n if (isAllSharedNotUsed) {\n remoteIns.shareScopeMap = {};\n delete globalShareScopeMap[remoteInsId];\n }\n needDeleteKeys.forEach(\n ([insId, shareScope, shareName, shareVersion]) => {\n delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[\n shareVersion\n ];\n },\n );\n CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);\n }\n\n host.moduleCache.delete(remote.name);\n }\n } catch (err) {\n logger.error(\n `removeRemote failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBAAb,MAA2B;CAgJzB,YAAY,MAAwB;eA5I5B,IAAI,aAAa;GACvB,sBAAsB,IAAI,kBAGvB,uBAAuB;GAC1B,gBAAgB,IAAI,kBAGjB,iBAAiB;GACpB,eAAe,IAAI,mBAIhB,gBAAgB;GACnB,kBAAkB,IAAI,UAapB,mBAAmB;GACrB,QAAQ,IAAI,UAeV,SAAS;GACX,iBAAiB,IAAI,UAgBnB,kBAAkB;GACpB,qBAAqB,IAAI,SAYvB,sBAAsB;GACxB,iBAAiB,IAAI,UAkBnB,kBAAkB;GACpB,qBAAqB,IAAI,UAQvB,sBAAsB;GACxB,uBAAuB,IAAI,UAYzB,wBAAwB;GAC1B,oBAAoB,IAAI,UAUtB,qBAAqB;GAEvB,WAAW,IAAI,WAUZ;GACJ,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;;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,IAAI,UAAU,OAAO,IAAI,GACzE"}
1
+ {"version":3,"file":"index.js","names":["Module"],"sources":["../../src/remote/index.ts"],"sourcesContent":["import {\n isBrowserEnvValue,\n warn,\n composeKeyWithSeparator,\n ModuleInfo,\n GlobalModuleInfo,\n} from '@module-federation/sdk';\nimport { RUNTIME_004, runtimeDescMap } from '@module-federation/error-codes';\nimport {\n Global,\n getInfoWithoutType,\n globalLoading,\n CurrentGlobal,\n} from '../global';\nimport {\n Options,\n UserOptions,\n PreloadAssets,\n PreloadOptions,\n PreloadRemoteArgs,\n PreloadRemoteResult,\n Remote,\n RemoteInfo,\n RemoteEntryExports,\n CallFrom,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncHook,\n SyncWaterfallHook,\n} from '../utils/hooks';\nimport {\n assert,\n error,\n getRemoteInfo,\n getRemoteEntryUniqueKey,\n getFMId,\n composeRemoteRequestId,\n matchRemoteWithNameAndExpose,\n optionsToMFContext,\n logger,\n} from '../utils';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { Module, ModuleOptions } from '../module';\nimport { formatPreloadArgs, preloadAssets } from '../utils/preload';\nimport { getGlobalShareScope } from '../utils/share';\nimport { getGlobalRemoteInfo } from '../plugins/snapshot/SnapshotHandler';\n\nexport interface LoadRemoteMatch {\n id: string;\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n options: Options;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n}\n\nexport class RemoteHandler {\n host: ModuleFederation;\n idToRemoteMap: Record<string, { name: string; expose: string }>;\n\n hooks = new PluginSystem({\n beforeRegisterRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('beforeRegisterRemote'),\n registerRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('registerRemote'),\n beforeRequest: new AsyncWaterfallHook<{\n id: string;\n options: Options;\n origin: ModuleFederation;\n }>('beforeRequest'),\n afterMatchRemote: new AsyncHook<\n [\n {\n id: string;\n options: Options;\n remote?: Remote;\n expose?: string;\n remoteInfo?: RemoteInfo;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterMatchRemote'),\n onLoad: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n pkgNameOrAlias: string;\n remote: Remote;\n options: ModuleOptions;\n origin: ModuleFederation;\n exposeModule: any;\n exposeModuleFactory: any;\n moduleInstance: Module;\n },\n ],\n unknown\n >('onLoad'),\n afterLoadRemote: new AsyncHook<\n [\n {\n id: string;\n expose?: string;\n remote?: RemoteInfo;\n options?: {\n loadFactory?: boolean;\n from?: CallFrom;\n };\n error?: unknown;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadRemote'),\n handlePreloadModule: new SyncHook<\n [\n {\n id: string;\n name: string;\n remote: Remote;\n remoteSnapshot: ModuleInfo;\n preloadConfig: PreloadRemoteArgs;\n origin: ModuleFederation;\n },\n ],\n void\n >('handlePreloadModule'),\n errorLoadRemote: new AsyncHook<\n [\n {\n id: string;\n error: unknown;\n options?: any;\n from: CallFrom;\n lifecycle:\n | 'beforeRequest'\n | 'beforeLoadShare'\n | 'afterResolve'\n | 'onLoad';\n remote?: RemoteInfo;\n expose?: string;\n origin: ModuleFederation;\n },\n ],\n void | unknown\n >('errorLoadRemote'),\n beforePreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n },\n ]\n >('beforePreloadRemote'),\n generatePreloadAssets: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n preloadOptions: PreloadOptions[number];\n remote: Remote;\n remoteInfo: RemoteInfo;\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n },\n ],\n Promise<PreloadAssets>\n >('generatePreloadAssets'),\n afterPreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n results: PreloadRemoteResult[];\n error?: unknown;\n },\n ]\n >('afterPreloadRemote'),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports | void> | RemoteEntryExports | void\n >(),\n });\n\n constructor(host: ModuleFederation) {\n this.host = host;\n this.idToRemoteMap = {};\n }\n\n formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions) {\n const userRemotes = userOptions.remotes || [];\n\n return userRemotes.reduce((res, remote) => {\n this.registerRemote(remote, res, { force: false });\n return res;\n }, globalOptions.remotes);\n }\n\n setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch) {\n const { remote, expose } = remoteMatchInfo;\n const { name, alias } = remote;\n this.idToRemoteMap[id] = { name: remote.name, expose };\n if (alias && id.startsWith(name)) {\n const idWithAlias = id.replace(name, alias);\n this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };\n return;\n }\n\n if (alias && id.startsWith(alias)) {\n const idWithName = id.replace(alias, name);\n this.idToRemoteMap[idWithName] = { name: remote.name, expose };\n }\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n const { host } = this;\n const startMatchInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n id,\n );\n let completeRequestId = id;\n let completeExpose = startMatchInfo?.expose;\n let completeRemote = startMatchInfo\n ? getRemoteInfo(startMatchInfo.remote)\n : undefined;\n let afterLoadRemoteArgs:\n | Parameters<\n RemoteHandler['hooks']['lifecycle']['afterLoadRemote']['emit']\n >[0]\n | undefined;\n\n try {\n const { loadFactory = true } = options || {\n loadFactory: true,\n };\n // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.\n // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.\n // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)\n // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get\n // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n // id: alias(app1) + expose(button) = app1/button\n // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\n const { module, moduleOptions, remoteMatchInfo } =\n await this.getRemoteModuleAndOptions({\n id,\n });\n const {\n pkgNameOrAlias,\n remote,\n expose,\n id: idRes,\n remoteSnapshot,\n } = remoteMatchInfo;\n completeRequestId = idRes;\n completeExpose = expose;\n completeRemote = getRemoteInfo(remote);\n\n const moduleOrFactory = (await module.get(\n idRes,\n expose,\n options,\n remoteSnapshot,\n )) as T;\n\n const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({\n id: idRes,\n pkgNameOrAlias,\n expose,\n exposeModule: loadFactory ? moduleOrFactory : undefined,\n exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,\n remote,\n options: moduleOptions,\n moduleInstance: module,\n origin: host,\n });\n\n this.setIdToRemoteMap(id, remoteMatchInfo);\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n origin: host,\n };\n\n if (typeof moduleWrapper === 'function') {\n return moduleWrapper as T;\n }\n\n return moduleOrFactory;\n } catch (error) {\n const { from = 'runtime' } = options || { from: 'runtime' };\n\n let failOver;\n try {\n failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n expose: completeExpose,\n remote: completeRemote,\n origin: host,\n });\n } catch (hookError) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error: hookError,\n origin: host,\n };\n throw hookError;\n }\n\n if (!failOver) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n };\n throw error;\n }\n\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n recovered: true,\n };\n\n return failOver as T;\n } finally {\n if (afterLoadRemoteArgs) {\n await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n const { host } = this;\n const preloadResults: PreloadRemoteResult[] = [];\n\n await this.hooks.lifecycle.beforePreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n });\n\n const preloadOps: PreloadOptions = formatPreloadArgs(\n host.options.remotes,\n preloadOptions,\n );\n\n const createPreloadAssetOps = (ops: PreloadOptions[number]) => {\n const { preloadConfig, remote } = ops;\n const exposes = preloadConfig.exposes || [];\n\n if (!exposes.length) {\n return [\n {\n ops,\n id: `${remote.name}/*`,\n },\n ];\n }\n\n return exposes.map((expose) => ({\n ops: {\n ...ops,\n preloadConfig: {\n ...preloadConfig,\n exposes: [expose],\n },\n },\n id: composeRemoteRequestId(remote.name, expose),\n }));\n };\n\n let preloadError: Error | undefined;\n\n await Promise.all(\n preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {\n const { ops, id: preloadId } = assetOps;\n const { remote, preloadConfig } = ops;\n const remoteInfo = getRemoteInfo(remote);\n try {\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\n id: preloadId,\n initiator: 'preloadRemote',\n });\n\n const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({\n origin: host,\n preloadOptions: ops,\n remote,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n });\n if (!assets) {\n return;\n }\n const results = await preloadAssets(remoteInfo, host, assets, true, {\n initiator: 'preloadRemote',\n id: preloadId,\n });\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results,\n });\n } catch (error) {\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results: [\n {\n url: remoteInfo.entry,\n status: 'error',\n resourceType: /\\.json(?:$|[?#])/i.test(remoteInfo.entry)\n ? 'manifest'\n : 'remoteEntry',\n initiator: 'preloadRemote',\n id: preloadId,\n error,\n },\n ],\n });\n }\n }),\n );\n\n const failedResults = preloadResults.flatMap((preloadResult) =>\n preloadResult.results.filter(\n (result) => result.status === 'error' || result.status === 'timeout',\n ),\n );\n if (failedResults.length > 0) {\n preloadError = new Error(\n `preloadRemote failed to load ${failedResults.length} resource(s).`,\n );\n Object.assign(preloadError, {\n results: preloadResults,\n failedResults,\n });\n }\n\n await this.hooks.lifecycle.afterPreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n results: preloadResults,\n error: preloadError,\n });\n\n if (preloadError) {\n throw preloadError;\n }\n }\n\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n const { host } = this;\n remotes.forEach((remote) => {\n this.registerRemote(remote, host.options.remotes, {\n force: options?.force,\n });\n });\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const { host } = this;\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host, remoteInfo });\n\n module.remoteEntryExports = container;\n host.moduleCache.set(name, module);\n\n return module;\n }\n\n async getRemoteModuleAndOptions(options: { id: string }): Promise<{\n module: Module;\n moduleOptions: ModuleOptions;\n remoteMatchInfo: LoadRemoteMatch;\n }> {\n const { host } = this;\n const { id } = options;\n let loadRemoteArgs;\n\n try {\n loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({\n id,\n options: host.options,\n origin: host,\n });\n } catch (error) {\n loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n options: host.options,\n origin: host,\n from: 'runtime',\n error,\n lifecycle: 'beforeRequest',\n })) as {\n id: string;\n options: Options;\n origin: ModuleFederation;\n };\n\n if (!loadRemoteArgs) {\n throw error;\n }\n }\n\n const { id: idRes } = loadRemoteArgs;\n\n const remoteSplitInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n idRes,\n );\n if (!remoteSplitInfo) {\n try {\n error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (matchError) {\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n options: host.options,\n error: matchError,\n origin: host,\n });\n throw matchError;\n }\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n remoteInfo,\n origin: host,\n });\n const matchInfo =\n await host.sharedHandler.hooks.lifecycle.afterResolve.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n origin: host,\n remoteInfo,\n });\n\n const { remote, expose } = matchInfo;\n assert(\n remote && expose,\n `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`,\n );\n let module: Module | undefined = host.moduleCache.get(remote.name);\n\n const moduleOptions: ModuleOptions = {\n host: host,\n remoteInfo,\n };\n\n if (!module) {\n module = new Module(moduleOptions);\n host.moduleCache.set(remote.name, module);\n }\n return {\n module,\n moduleOptions,\n remoteMatchInfo: matchInfo,\n };\n }\n\n registerRemote(\n remote: Remote,\n targetRemotes: Remote[],\n options?: { force?: boolean },\n ): void {\n const { host } = this;\n const normalizeRemote = () => {\n if (remote.alias) {\n // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error\n // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported\n const findEqual = targetRemotes.find(\n (item) =>\n remote.alias &&\n (item.name.startsWith(remote.alias) ||\n item.alias?.startsWith(remote.alias)),\n );\n assert(\n !findEqual,\n `The alias ${remote.alias} of remote ${\n remote.name\n } is not allowed to be the prefix of ${\n findEqual && findEqual.name\n } name or alias`,\n );\n }\n // Set the remote entry to a complete path\n if ('entry' in remote) {\n if (\n isBrowserEnvValue &&\n typeof window !== 'undefined' &&\n !remote.entry.startsWith('http')\n ) {\n remote.entry = new URL(remote.entry, window.location.origin).href;\n }\n }\n if (!remote.shareScope) {\n remote.shareScope = DEFAULT_SCOPE;\n }\n if (!remote.type) {\n remote.type = DEFAULT_REMOTE_TYPE;\n }\n };\n this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });\n const registeredRemote = targetRemotes.find(\n (item) => item.name === remote.name,\n );\n if (!registeredRemote) {\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n } else {\n const messages = [\n `The remote \"${remote.name}\" is already registered.`,\n 'Please note that overriding it may cause unexpected errors.',\n ];\n if (options?.force) {\n // remove registered remote\n this.removeRemote(registeredRemote);\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n warn(messages.join(' '));\n }\n }\n }\n\n private removeRemote(remote: Remote): void {\n try {\n const { host } = this;\n const { name } = remote;\n const remoteIndex = host.options.remotes.findIndex(\n (item) => item.name === name,\n );\n if (remoteIndex !== -1) {\n host.options.remotes.splice(remoteIndex, 1);\n }\n const globalSnapshotKey = getInfoWithoutType(\n CurrentGlobal.__FEDERATION__.moduleInfo,\n getFMId(remote),\n ).key;\n delete CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];\n\n if ('entry' in remote) {\n host.snapshotHandler.manifestCache.delete(remote.entry);\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];\n }\n\n const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);\n if (hostGlobalSnapshot) {\n const remoteKey =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;\n if (remoteKey) {\n delete hostGlobalSnapshot.remotesInfo[remoteKey];\n }\n }\n\n const loadedModule = host.moduleCache.get(remote.name);\n if (loadedModule) {\n const remoteInfo = loadedModule.remoteInfo;\n const key = remoteInfo.entryGlobalName as keyof typeof CurrentGlobal;\n\n if (CurrentGlobal[key]) {\n if (\n Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable\n ) {\n delete CurrentGlobal[key];\n } else {\n // @ts-ignore\n CurrentGlobal[key] = undefined;\n }\n }\n const remoteEntryUniqueKey = getRemoteEntryUniqueKey(\n loadedModule.remoteInfo,\n );\n\n if (globalLoading[remoteEntryUniqueKey]) {\n delete globalLoading[remoteEntryUniqueKey];\n }\n\n // delete unloaded shared and instance\n let remoteInsId = remoteInfo.buildVersion\n ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)\n : remoteInfo.name;\n const remoteInsIndex =\n CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {\n if (remoteInfo.buildVersion) {\n return ins.options.id === remoteInsId;\n } else {\n return ins.name === remoteInsId;\n }\n });\n if (remoteInsIndex !== -1) {\n const remoteIns =\n CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];\n remoteInsId = remoteIns.options.id || remoteInsId;\n const globalShareScopeMap = getGlobalShareScope();\n\n let isAllSharedNotUsed = true;\n const needDeleteKeys: Array<[string, string, string, string]> = [];\n Object.keys(globalShareScopeMap).forEach((instId) => {\n const shareScopeMap = globalShareScopeMap[instId];\n shareScopeMap &&\n Object.keys(shareScopeMap).forEach((shareScope) => {\n const shareScopeVal = shareScopeMap[shareScope];\n shareScopeVal &&\n Object.keys(shareScopeVal).forEach((shareName) => {\n const sharedPkgs = shareScopeVal[shareName];\n sharedPkgs &&\n Object.keys(sharedPkgs).forEach((shareVersion) => {\n const shared = sharedPkgs[shareVersion];\n if (\n shared &&\n typeof shared === 'object' &&\n shared.from === remoteInfo.name\n ) {\n if (shared.loaded || shared.loading) {\n shared.useIn = shared.useIn.filter(\n (usedHostName) =>\n usedHostName !== remoteInfo.name,\n );\n if (shared.useIn.length) {\n isAllSharedNotUsed = false;\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n }\n });\n });\n });\n });\n\n if (isAllSharedNotUsed) {\n remoteIns.shareScopeMap = {};\n delete globalShareScopeMap[remoteInsId];\n }\n needDeleteKeys.forEach(\n ([insId, shareScope, shareName, shareVersion]) => {\n delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[\n shareVersion\n ];\n },\n );\n CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);\n }\n\n host.moduleCache.delete(remote.name);\n }\n } catch (err) {\n logger.error(\n `removeRemote failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBAAb,MAA2B;CAgJzB,YAAY,MAAwB;eA5I5B,IAAI,aAAa;GACvB,sBAAsB,IAAI,kBAGvB,uBAAuB;GAC1B,gBAAgB,IAAI,kBAGjB,iBAAiB;GACpB,eAAe,IAAI,mBAIhB,gBAAgB;GACnB,kBAAkB,IAAI,UAapB,mBAAmB;GACrB,QAAQ,IAAI,UAeV,SAAS;GACX,iBAAiB,IAAI,UAgBnB,kBAAkB;GACpB,qBAAqB,IAAI,SAYvB,sBAAsB;GACxB,iBAAiB,IAAI,UAkBnB,kBAAkB;GACpB,qBAAqB,IAAI,UAQvB,sBAAsB;GACxB,uBAAuB,IAAI,UAYzB,wBAAwB;GAC1B,oBAAoB,IAAI,UAUtB,qBAAqB;GAEvB,WAAW,IAAI,WAUZ;GACJ,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;;CAGzB,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CAAC,OAAO,YAAY,WAAW,kBAAkB;AAChD,aAAO,oBAAoB,SAAS,cAAc,aAChD;OAGL;AACD,mBAAc,eAAe,cAAc,OAAO,gBAAgB,EAAE;;AAGtE,SAAK,YAAY,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,UAAO,MACL,wBAAwB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACzE"}
@@ -0,0 +1,33 @@
1
+ const require_asyncWaterfallHooks = require('../utils/hooks/asyncWaterfallHooks.cjs');
2
+ const require_pluginSystem = require('../utils/hooks/pluginSystem.cjs');
3
+ require('../utils/hooks/index.cjs');
4
+
5
+ //#region src/shared/disabled.ts
6
+ var DisabledSharedHandler = class {
7
+ constructor() {
8
+ this.shareScopeMap = {};
9
+ this.hooks = new require_pluginSystem.PluginSystem({ afterResolve: new require_asyncWaterfallHooks.AsyncWaterfallHook("afterResolve") });
10
+ }
11
+ registerShared() {
12
+ return {
13
+ newShareInfos: {},
14
+ allShareInfos: {}
15
+ };
16
+ }
17
+ loadShare() {
18
+ throw new Error("Shared dependency loading is disabled by experiments.optimization.disableShared.");
19
+ }
20
+ loadShareSync() {
21
+ throw new Error("Shared dependency loading is disabled by experiments.optimization.disableShared.");
22
+ }
23
+ initializeSharing() {
24
+ return [];
25
+ }
26
+ initShareScopeMap(scopeName, shareScope) {
27
+ this.shareScopeMap[scopeName] = shareScope;
28
+ }
29
+ };
30
+
31
+ //#endregion
32
+ exports.DisabledSharedHandler = DisabledSharedHandler;
33
+ //# sourceMappingURL=disabled.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disabled.cjs","names":["PluginSystem","AsyncWaterfallHook"],"sources":["../../src/shared/disabled.ts"],"sourcesContent":["import type { LoadRemoteMatch } from '../remote';\nimport type { ShareScopeMap } from '../type';\nimport { AsyncWaterfallHook, PluginSystem } from '../utils/hooks';\n\nexport class DisabledSharedHandler {\n shareScopeMap: ShareScopeMap = {};\n hooks = new PluginSystem({\n afterResolve: new AsyncWaterfallHook<LoadRemoteMatch>('afterResolve'),\n });\n\n registerShared() {\n return {\n newShareInfos: {},\n allShareInfos: {},\n };\n }\n\n loadShare(): never {\n throw new Error(\n 'Shared dependency loading is disabled by experiments.optimization.disableShared.',\n );\n }\n\n loadShareSync(): never {\n throw new Error(\n 'Shared dependency loading is disabled by experiments.optimization.disableShared.',\n );\n }\n\n initializeSharing(): [] {\n return [];\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n ): void {\n this.shareScopeMap[scopeName] = shareScope;\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,wBAAb,MAAmC;;uBACF,EAAE;eACzB,IAAIA,kCAAa,EACvB,cAAc,IAAIC,+CAAoC,eAAe,EACtE,CAAC;;CAEF,iBAAiB;AACf,SAAO;GACL,eAAe,EAAE;GACjB,eAAe,EAAE;GAClB;;CAGH,YAAmB;AACjB,QAAM,IAAI,MACR,mFACD;;CAGH,gBAAuB;AACrB,QAAM,IAAI,MACR,mFACD;;CAGH,oBAAwB;AACtB,SAAO,EAAE;;CAGX,kBACE,WACA,YACM;AACN,OAAK,cAAc,aAAa"}
@@ -0,0 +1,33 @@
1
+ import { AsyncWaterfallHook } from "../utils/hooks/asyncWaterfallHooks.js";
2
+ import { PluginSystem } from "../utils/hooks/pluginSystem.js";
3
+ import "../utils/hooks/index.js";
4
+
5
+ //#region src/shared/disabled.ts
6
+ var DisabledSharedHandler = class {
7
+ constructor() {
8
+ this.shareScopeMap = {};
9
+ this.hooks = new PluginSystem({ afterResolve: new AsyncWaterfallHook("afterResolve") });
10
+ }
11
+ registerShared() {
12
+ return {
13
+ newShareInfos: {},
14
+ allShareInfos: {}
15
+ };
16
+ }
17
+ loadShare() {
18
+ throw new Error("Shared dependency loading is disabled by experiments.optimization.disableShared.");
19
+ }
20
+ loadShareSync() {
21
+ throw new Error("Shared dependency loading is disabled by experiments.optimization.disableShared.");
22
+ }
23
+ initializeSharing() {
24
+ return [];
25
+ }
26
+ initShareScopeMap(scopeName, shareScope) {
27
+ this.shareScopeMap[scopeName] = shareScope;
28
+ }
29
+ };
30
+
31
+ //#endregion
32
+ export { DisabledSharedHandler };
33
+ //# sourceMappingURL=disabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disabled.js","names":[],"sources":["../../src/shared/disabled.ts"],"sourcesContent":["import type { LoadRemoteMatch } from '../remote';\nimport type { ShareScopeMap } from '../type';\nimport { AsyncWaterfallHook, PluginSystem } from '../utils/hooks';\n\nexport class DisabledSharedHandler {\n shareScopeMap: ShareScopeMap = {};\n hooks = new PluginSystem({\n afterResolve: new AsyncWaterfallHook<LoadRemoteMatch>('afterResolve'),\n });\n\n registerShared() {\n return {\n newShareInfos: {},\n allShareInfos: {},\n };\n }\n\n loadShare(): never {\n throw new Error(\n 'Shared dependency loading is disabled by experiments.optimization.disableShared.',\n );\n }\n\n loadShareSync(): never {\n throw new Error(\n 'Shared dependency loading is disabled by experiments.optimization.disableShared.',\n );\n }\n\n initializeSharing(): [] {\n return [];\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n ): void {\n this.shareScopeMap[scopeName] = shareScope;\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,wBAAb,MAAmC;;uBACF,EAAE;eACzB,IAAI,aAAa,EACvB,cAAc,IAAI,mBAAoC,eAAe,EACtE,CAAC;;CAEF,iBAAiB;AACf,SAAO;GACL,eAAe,EAAE;GACjB,eAAe,EAAE;GAClB;;CAGH,YAAmB;AACjB,QAAM,IAAI,MACR,mFACD;;CAGH,gBAAuB;AACrB,QAAM,IAAI,MACR,mFACD;;CAGH,oBAAwB;AACtB,SAAO,EAAE;;CAGX,kBACE,WACA,YACM;AACN,OAAK,cAAc,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","formatShareConfigs","getTargetSharedOptions","getRegisteredShare","directShare","shouldUseTreeShaking","DEFAULT_SCOPE","RUNTIME_005","RUNTIME_006","runtimeDescMap","optionsToMFContext","getGlobalShareScope"],"sources":["../../src/shared/index.ts"],"sourcesContent":["import {\n RUNTIME_005,\n RUNTIME_006,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Federation } from '../global';\nimport {\n Options,\n ShareScopeMap,\n ShareInfos,\n Shared,\n RemoteEntryExports,\n UserOptions,\n ShareStrategy,\n InitScope,\n InitTokens,\n CallFrom,\n TreeShakingArgs,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncWaterfallHook,\n SyncHook,\n} from '../utils/hooks';\nimport {\n formatShareConfigs,\n getRegisteredShare,\n getTargetSharedOptions,\n getGlobalShareScope,\n directShare,\n shouldUseTreeShaking,\n addUseIn,\n} from '../utils/share';\nimport {\n assert,\n error,\n addUniqueItem,\n optionsToMFContext,\n warn,\n} from '../utils';\nimport { DEFAULT_SCOPE } from '../constant';\nimport { LoadRemoteMatch } from '../remote';\nimport { createRemoteEntryInitOptions } from '../module';\n\nexport class SharedHandler {\n host: ModuleFederation;\n shareScopeMap: ShareScopeMap;\n hooks = new PluginSystem({\n beforeRegisterShare: new SyncWaterfallHook<{\n pkgName: string;\n shared: Shared;\n origin: ModuleFederation;\n }>('beforeRegisterShare'),\n afterResolve: new AsyncWaterfallHook<LoadRemoteMatch>('afterResolve'),\n beforeLoadShare: new AsyncWaterfallHook<{\n pkgName: string;\n shareInfo?: Shared;\n shared: Options['shared'];\n origin: ModuleFederation;\n }>('beforeLoadShare'),\n // not used yet\n loadShare: new AsyncHook<[ModuleFederation, string, ShareInfos]>(),\n afterLoadShare: new SyncHook<\n [\n {\n pkgName: string;\n shareInfo?: Partial<Shared>;\n selectedShared?: Partial<Shared>;\n shared: Options['shared'];\n shareScopeMap: ShareScopeMap;\n lifecycle: 'loadShare' | 'loadShareSync';\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadShare'),\n errorLoadShare: new SyncHook<\n [\n {\n pkgName: string;\n shareInfo?: Partial<Shared>;\n shared: Options['shared'];\n shareScopeMap: ShareScopeMap;\n lifecycle: 'loadShare' | 'loadShareSync';\n origin: ModuleFederation;\n error?: unknown;\n recovered?: boolean;\n },\n ],\n void\n >('errorLoadShare'),\n resolveShare: new SyncWaterfallHook<{\n shareScopeMap: ShareScopeMap;\n scope: string;\n pkgName: string;\n version: string;\n shareInfo: Shared;\n GlobalFederation: Federation;\n resolver: () => { shared: Shared; useTreesShaking: boolean } | undefined;\n }>('resolveShare'),\n // maybe will change, temporarily for internal use only\n initContainerShareScopeMap: new SyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n options: Options;\n origin: ModuleFederation;\n scopeName: string;\n hostShareScopeMap?: ShareScopeMap;\n }>('initContainerShareScopeMap'),\n });\n initTokens: InitTokens;\n constructor(host: ModuleFederation) {\n this.host = host;\n this.shareScopeMap = {};\n this.initTokens = {};\n this._setGlobalShareScopeMap(host.options);\n }\n\n private emitAfterLoadShare({\n lifecycle,\n pkgName,\n shareInfo,\n selectedShared,\n }: {\n lifecycle: 'loadShare' | 'loadShareSync';\n pkgName: string;\n shareInfo?: Partial<Shared>;\n selectedShared?: Partial<Shared>;\n }): void {\n try {\n this.hooks.lifecycle.afterLoadShare.emit({\n pkgName,\n shareInfo,\n selectedShared,\n shared: this.host.options.shared,\n shareScopeMap: this.shareScopeMap,\n lifecycle,\n origin: this.host,\n });\n } catch (error) {\n warn(error);\n }\n }\n\n private emitErrorLoadShare({\n lifecycle,\n pkgName,\n shareInfo,\n error,\n recovered,\n }: {\n lifecycle: 'loadShare' | 'loadShareSync';\n pkgName: string;\n shareInfo?: Partial<Shared>;\n error?: unknown;\n recovered?: boolean;\n }): void {\n try {\n this.hooks.lifecycle.errorLoadShare.emit({\n pkgName,\n shareInfo,\n shared: this.host.options.shared,\n shareScopeMap: this.shareScopeMap,\n lifecycle,\n origin: this.host,\n error,\n recovered,\n });\n } catch (hookError) {\n warn(hookError);\n }\n }\n\n // register shared in shareScopeMap\n registerShared(globalOptions: Options, userOptions: UserOptions) {\n const { newShareInfos, allShareInfos } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n\n const sharedKeys = Object.keys(newShareInfos);\n sharedKeys.forEach((sharedKey) => {\n const sharedVals = newShareInfos[sharedKey];\n sharedVals.forEach((sharedVal) => {\n sharedVal.scope.forEach((sc) => {\n this.hooks.lifecycle.beforeRegisterShare.emit({\n origin: this.host,\n pkgName: sharedKey,\n shared: sharedVal,\n });\n const registeredShared = this.shareScopeMap[sc]?.[sharedKey];\n if (!registeredShared) {\n this.setShared({\n pkgName: sharedKey,\n lib: sharedVal.lib,\n get: sharedVal.get,\n loaded: sharedVal.loaded || Boolean(sharedVal.lib),\n shared: sharedVal,\n from: userOptions.name,\n });\n }\n });\n });\n });\n\n return {\n newShareInfos,\n allShareInfos,\n };\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n const { host } = this;\n // This function performs the following steps:\n // 1. Checks if the currently loaded share already exists, if not, it throws an error\n // 2. Searches globally for a matching share, if found, it uses it directly\n // 3. If not found, it retrieves it from the current share and stores the obtained share globally.\n\n const shareOptions = getTargetSharedOptions({\n pkgName,\n extraOptions,\n shareInfos: host.options.shared,\n });\n let shareOptionsRes: Shared | undefined = shareOptions;\n\n try {\n if (shareOptions?.scope) {\n await Promise.all(\n shareOptions.scope.map(async (shareScope) => {\n await Promise.all(\n this.initializeSharing(shareScope, {\n strategy: shareOptions.strategy,\n }),\n );\n return;\n }),\n );\n }\n const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({\n pkgName,\n shareInfo: shareOptions,\n shared: host.options.shared,\n origin: host,\n });\n\n shareOptionsRes = loadShareRes.shareInfo;\n\n // Assert that shareInfoRes exists, if not, throw an error\n assert(\n shareOptionsRes,\n `Cannot find shared \"${pkgName}\" in host \"${host.options.name}\". Ensure the shared config for \"${pkgName}\" is declared in the federation plugin options and the host has been initialized before loading shares.`,\n );\n const resolvedShareOptions = shareOptionsRes;\n\n const { shared: registeredShared, useTreesShaking } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n shareOptionsRes,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n\n if (registeredShared) {\n const targetShared = directShare(registeredShared, useTreesShaking);\n if (targetShared.lib) {\n addUseIn(targetShared, host.options.name);\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return targetShared.lib as () => T;\n } else if (targetShared.loading && !targetShared.loaded) {\n const factory = await targetShared.loading;\n targetShared.loaded = true;\n if (!targetShared.lib) {\n targetShared.lib = factory;\n }\n addUseIn(targetShared, host.options.name);\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return factory;\n } else {\n const asyncLoadProcess = async () => {\n const factory = await targetShared.get!();\n addUseIn(targetShared, host.options.name);\n targetShared.loaded = true;\n targetShared.lib = factory;\n return factory as () => T;\n };\n const loading = asyncLoadProcess();\n this.setShared({\n pkgName,\n loaded: false,\n shared: registeredShared,\n from: host.options.name,\n lib: null,\n loading,\n treeShaking: useTreesShaking\n ? (targetShared as TreeShakingArgs)\n : undefined,\n });\n const factory = await loading;\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return factory;\n }\n } else {\n if (extraOptions?.customShareInfo) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n recovered: true,\n });\n return false;\n }\n const _useTreeShaking = shouldUseTreeShaking(\n resolvedShareOptions.treeShaking,\n );\n const targetShared = directShare(resolvedShareOptions, _useTreeShaking);\n\n const asyncLoadProcess = async () => {\n const factory = await targetShared.get!();\n targetShared.lib = factory;\n targetShared.loaded = true;\n addUseIn(targetShared, host.options.name);\n const { shared: gShared, useTreesShaking: gUseTreeShaking } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n resolvedShareOptions,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n if (gShared) {\n const targetGShared = directShare(gShared, gUseTreeShaking);\n targetGShared.lib = factory;\n targetGShared.loaded = true;\n gShared.from = resolvedShareOptions.from;\n }\n return factory as () => T;\n };\n const loading = asyncLoadProcess();\n this.setShared({\n pkgName,\n loaded: false,\n shared: resolvedShareOptions,\n from: host.options.name,\n lib: null,\n loading,\n treeShaking: _useTreeShaking\n ? (targetShared as TreeShakingArgs)\n : undefined,\n });\n const factory = await loading;\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: resolvedShareOptions,\n });\n return factory;\n }\n } catch (shareError) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: shareOptionsRes,\n error: shareError,\n });\n throw shareError;\n }\n }\n\n /**\n * This function initializes the sharing sequence (executed only once per share scope).\n * It accepts one argument, the name of the share scope.\n * If the share scope does not exist, it creates one.\n */\n // eslint-disable-next-line @typescript-eslint/member-ordering\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: ShareStrategy;\n },\n ): Array<Promise<void>> {\n const { host } = this;\n const from = extraOptions?.from;\n const strategy = extraOptions?.strategy;\n let initScope = extraOptions?.initScope;\n const promises: Promise<any>[] = [];\n if (from !== 'build') {\n const { initTokens } = this;\n if (!initScope) initScope = [];\n let initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: this.host.name };\n if (initScope.indexOf(initToken) >= 0) return promises;\n initScope.push(initToken);\n }\n\n const shareScope = this.shareScopeMap;\n const hostName = host.options.name;\n // Creates a new share scope if necessary\n if (!shareScope[shareScopeName]) {\n shareScope[shareScopeName] = {};\n }\n // Executes all initialization snippets from all accessible modules\n const scope = shareScope[shareScopeName];\n const register = (name: string, shared: Shared) => {\n const { version, eager } = shared;\n scope[name] = scope[name] || {};\n const versions = scope[name];\n const activeVersion: Shared =\n versions[version] && (directShare(versions[version]) as Shared);\n const activeVersionEager = Boolean(\n activeVersion &&\n (('eager' in activeVersion && activeVersion.eager) ||\n ('shareConfig' in activeVersion && activeVersion.shareConfig?.eager)),\n );\n if (\n !activeVersion ||\n (activeVersion.strategy !== 'loaded-first' &&\n !activeVersion.loaded &&\n (Boolean(!eager) !== !activeVersionEager\n ? eager\n : hostName > versions[version].from))\n ) {\n versions[version] = shared;\n }\n };\n\n const initRemoteModule = async (key: string): Promise<void> => {\n const { module } = await host.remoteHandler.getRemoteModuleAndOptions({\n id: key,\n });\n let remoteEntryExports: RemoteEntryExports | undefined = undefined;\n try {\n remoteEntryExports = await module.getEntry();\n } catch (error) {\n remoteEntryExports =\n (await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({\n id: key,\n error,\n from: 'runtime',\n lifecycle: 'beforeLoadShare',\n remote: module.remoteInfo,\n origin: host,\n })) as RemoteEntryExports;\n if (!remoteEntryExports) {\n return;\n }\n } finally {\n // prevent self load loop: when host load self , the initTokens is not the same\n if (remoteEntryExports?.init && !module.initing) {\n module.remoteEntryExports = remoteEntryExports;\n await module.init(undefined, undefined, initScope);\n }\n }\n };\n Object.keys(host.options.shared).forEach((shareName) => {\n const sharedArr = host.options.shared[shareName];\n sharedArr.forEach((shared) => {\n if (shared.scope.includes(shareScopeName)) {\n register(shareName, shared);\n }\n });\n });\n // TODO: strategy==='version-first' need to be removed in the future\n if (\n host.options.shareStrategy === 'version-first' ||\n strategy === 'version-first'\n ) {\n host.options.remotes.forEach((remote) => {\n if (remote.shareScope === shareScopeName) {\n promises.push(initRemoteModule(remote.name));\n }\n });\n }\n\n return promises;\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n from?: 'build' | 'runtime';\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n const { host } = this;\n const shareOptions = getTargetSharedOptions({\n pkgName,\n extraOptions,\n shareInfos: host.options.shared,\n });\n\n try {\n if (shareOptions?.scope) {\n shareOptions.scope.forEach((shareScope) => {\n this.initializeSharing(shareScope, {\n strategy: shareOptions.strategy,\n });\n });\n }\n const { shared: registeredShared } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n shareOptions,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n\n if (registeredShared) {\n if (typeof registeredShared.lib === 'function') {\n addUseIn(registeredShared, host.options.name);\n if (!registeredShared.loaded) {\n registeredShared.loaded = true;\n if (registeredShared.from === host.options.name) {\n shareOptions.loaded = true;\n }\n }\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: registeredShared,\n });\n return registeredShared.lib as () => T;\n }\n if (typeof registeredShared.get === 'function') {\n const module = registeredShared.get();\n if (!(module instanceof Promise)) {\n addUseIn(registeredShared, host.options.name);\n this.setShared({\n pkgName,\n loaded: true,\n from: host.options.name,\n lib: module,\n shared: registeredShared,\n });\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: registeredShared,\n });\n return module;\n }\n }\n }\n\n if (shareOptions.lib) {\n if (!shareOptions.loaded) {\n shareOptions.loaded = true;\n }\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: shareOptions,\n });\n return shareOptions.lib as () => T;\n }\n\n if (shareOptions.get) {\n const module = shareOptions.get();\n\n if (module instanceof Promise) {\n const errorCode =\n extraOptions?.from === 'build' ? RUNTIME_005 : RUNTIME_006;\n error(\n errorCode,\n runtimeDescMap,\n {\n hostName: host.options.name,\n sharedPkgName: pkgName,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n }\n\n shareOptions.lib = module;\n\n this.setShared({\n pkgName,\n loaded: true,\n from: host.options.name,\n lib: shareOptions.lib,\n shared: shareOptions,\n });\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: shareOptions,\n });\n return shareOptions.lib as () => T;\n }\n\n error(\n RUNTIME_006,\n runtimeDescMap,\n {\n hostName: host.options.name,\n sharedPkgName: pkgName,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (shareError) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n error: shareError,\n });\n throw shareError;\n }\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n const { host } = this;\n this.shareScopeMap[scopeName] = shareScope;\n this.hooks.lifecycle.initContainerShareScopeMap.emit({\n shareScope,\n options: host.options,\n origin: host,\n scopeName,\n hostShareScopeMap: extraOptions.hostShareScopeMap,\n });\n }\n\n private setShared({\n pkgName,\n shared,\n from,\n lib,\n loading,\n loaded,\n get,\n treeShaking,\n }: {\n pkgName: string;\n shared: Shared;\n from: string;\n lib: any;\n loaded?: boolean;\n loading?: Shared['loading'];\n get?: Shared['get'];\n treeShaking?: TreeShakingArgs;\n }): void {\n const { version, scope = 'default', ...shareInfo } = shared;\n const scopes: string[] = Array.isArray(scope) ? scope : [scope];\n\n const mergeAttrs = (shared: Shared) => {\n const merge = <K extends keyof TreeShakingArgs>(\n s: TreeShakingArgs,\n key: K,\n val: TreeShakingArgs[K],\n ): void => {\n if (val && !s[key]) {\n s[key] = val;\n }\n };\n const targetShared = (\n treeShaking ? shared.treeShaking! : shared\n ) as TreeShakingArgs;\n merge(targetShared, 'loaded', loaded);\n merge(targetShared, 'loading', loading);\n merge(targetShared, 'get', get);\n };\n scopes.forEach((sc) => {\n if (!this.shareScopeMap[sc]) {\n this.shareScopeMap[sc] = {};\n }\n if (!this.shareScopeMap[sc][pkgName]) {\n this.shareScopeMap[sc][pkgName] = {};\n }\n\n if (!this.shareScopeMap[sc][pkgName][version]) {\n this.shareScopeMap[sc][pkgName][version] = {\n version,\n scope: [sc],\n ...shareInfo,\n lib,\n };\n }\n\n const registeredShared = this.shareScopeMap[sc][pkgName][version];\n mergeAttrs(registeredShared);\n if (from && registeredShared.from !== from) {\n registeredShared.from = from;\n }\n });\n }\n\n private _setGlobalShareScopeMap(hostOptions: Options): void {\n const globalShareScopeMap = getGlobalShareScope();\n const identifier = hostOptions.id || hostOptions.name;\n if (identifier && !globalShareScopeMap[identifier]) {\n globalShareScopeMap[identifier] = this.shareScopeMap;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,MAA2B;CAkEzB,YAAY,MAAwB;eA/D5B,IAAIA,kCAAa;GACvB,qBAAqB,IAAIC,4CAItB,sBAAsB;GACzB,cAAc,IAAIC,+CAAoC,eAAe;GACrE,iBAAiB,IAAIA,+CAKlB,kBAAkB;GAErB,WAAW,IAAIC,6BAAmD;GAClE,gBAAgB,IAAIC,0BAalB,iBAAiB;GACnB,gBAAgB,IAAIA,0BAclB,iBAAiB;GACnB,cAAc,IAAIH,4CAQf,eAAe;GAElB,4BAA4B,IAAIA,4CAM7B,6BAA6B;GACjC,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;AACvB,OAAK,aAAa,EAAE;AACpB,OAAK,wBAAwB,KAAK,QAAQ;;CAG5C,AAAQ,mBAAmB,EACzB,WACA,SACA,WACA,kBAMO;AACP,MAAI;AACF,QAAK,MAAM,UAAU,eAAe,KAAK;IACvC;IACA;IACA;IACA,QAAQ,KAAK,KAAK,QAAQ;IAC1B,eAAe,K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e;AAEtC,SAAM,cAAc,UAAU,OAAO;AACrC,SAAM,cAAc,WAAW,QAAQ;AACvC,SAAM,cAAc,OAAO,IAAI;;AAEjC,SAAO,SAAS,OAAO;AACrB,OAAI,CAAC,KAAK,cAAc,IACtB,MAAK,cAAc,MAAM,EAAE;AAE7B,OAAI,CAAC,KAAK,cAAc,IAAI,SAC1B,MAAK,cAAc,IAAI,WAAW,EAAE;AAGtC,OAAI,CAAC,KAAK,cAAc,IAAI,SAAS,SACnC,MAAK,cAAc,IAAI,SAAS,WAAW;IACzC;IACA,OAAO,CAAC,GAAG;IACX,GAAG;IACH;IACD;GAGH,MAAM,mBAAmB,KAAK,cAAc,IAAI,SAAS;AACzD,cAAW,iBAAiB;AAC5B,OAAI,QAAQ,iBAAiB,SAAS,KACpC,kBAAiB,OAAO;IAE1B;;CAGJ,AAAQ,wBAAwB,aAA4B;EAC1D,MAAM,sBAAsBC,mCAAqB;EACjD,MAAM,aAAa,YAAY,MAAM,YAAY;AACjD,MAAI,cAAc,CAAC,oBAAoB,YACrC,qBAAoB,cAAc,KAAK"}
1
+ {"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","formatShareConfigs","getTargetSharedOptions","getRegisteredShare","directShare","shouldUseTreeShaking","DEFAULT_SCOPE","RUNTIME_005","RUNTIME_006","runtimeDescMap","optionsToMFContext","getGlobalShareScope"],"sources":["../../src/shared/index.ts"],"sourcesContent":["import {\n RUNTIME_005,\n RUNTIME_006,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Federation } from '../global';\nimport {\n Options,\n ShareScopeMap,\n ShareInfos,\n Shared,\n RemoteEntryExports,\n UserOptions,\n ShareStrategy,\n InitScope,\n InitTokens,\n CallFrom,\n TreeShakingArgs,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncWaterfallHook,\n SyncHook,\n} from '../utils/hooks';\nimport {\n formatShareConfigs,\n getRegisteredShare,\n getTargetSharedOptions,\n getGlobalShareScope,\n directShare,\n shouldUseTreeShaking,\n addUseIn,\n} from '../utils/share';\nimport {\n assert,\n error,\n addUniqueItem,\n optionsToMFContext,\n warn,\n} from '../utils';\nimport { DEFAULT_SCOPE } from '../constant';\nimport type { LoadRemoteMatch } from '../remote';\nimport { createRemoteEntryInitOptions } from '../module';\n\nexport class SharedHandler {\n host: ModuleFederation;\n shareScopeMap: ShareScopeMap;\n hooks = new PluginSystem({\n beforeRegisterShare: new SyncWaterfallHook<{\n pkgName: string;\n shared: Shared;\n origin: ModuleFederation;\n }>('beforeRegisterShare'),\n afterResolve: new AsyncWaterfallHook<LoadRemoteMatch>('afterResolve'),\n beforeLoadShare: new AsyncWaterfallHook<{\n pkgName: string;\n shareInfo?: Shared;\n shared: Options['shared'];\n origin: ModuleFederation;\n }>('beforeLoadShare'),\n // not used yet\n loadShare: new AsyncHook<[ModuleFederation, string, ShareInfos]>(),\n afterLoadShare: new SyncHook<\n [\n {\n pkgName: string;\n shareInfo?: Partial<Shared>;\n selectedShared?: Partial<Shared>;\n shared: Options['shared'];\n shareScopeMap: ShareScopeMap;\n lifecycle: 'loadShare' | 'loadShareSync';\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadShare'),\n errorLoadShare: new SyncHook<\n [\n {\n pkgName: string;\n shareInfo?: Partial<Shared>;\n shared: Options['shared'];\n shareScopeMap: ShareScopeMap;\n lifecycle: 'loadShare' | 'loadShareSync';\n origin: ModuleFederation;\n error?: unknown;\n recovered?: boolean;\n },\n ],\n void\n >('errorLoadShare'),\n resolveShare: new SyncWaterfallHook<{\n shareScopeMap: ShareScopeMap;\n scope: string;\n pkgName: string;\n version: string;\n shareInfo: Shared;\n GlobalFederation: Federation;\n resolver: () => { shared: Shared; useTreesShaking: boolean } | undefined;\n }>('resolveShare'),\n // maybe will change, temporarily for internal use only\n initContainerShareScopeMap: new SyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n options: Options;\n origin: ModuleFederation;\n scopeName: string;\n hostShareScopeMap?: ShareScopeMap;\n }>('initContainerShareScopeMap'),\n });\n initTokens: InitTokens;\n constructor(host: ModuleFederation) {\n this.host = host;\n this.shareScopeMap = {};\n this.initTokens = {};\n this._setGlobalShareScopeMap(host.options);\n }\n\n private emitAfterLoadShare({\n lifecycle,\n pkgName,\n shareInfo,\n selectedShared,\n }: {\n lifecycle: 'loadShare' | 'loadShareSync';\n pkgName: string;\n shareInfo?: Partial<Shared>;\n selectedShared?: Partial<Shared>;\n }): void {\n try {\n this.hooks.lifecycle.afterLoadShare.emit({\n pkgName,\n shareInfo,\n selectedShared,\n shared: this.host.options.shared,\n shareScopeMap: this.shareScopeMap,\n lifecycle,\n origin: this.host,\n });\n } catch (error) {\n warn(error);\n }\n }\n\n private emitErrorLoadShare({\n lifecycle,\n pkgName,\n shareInfo,\n error,\n recovered,\n }: {\n lifecycle: 'loadShare' | 'loadShareSync';\n pkgName: string;\n shareInfo?: Partial<Shared>;\n error?: unknown;\n recovered?: boolean;\n }): void {\n try {\n this.hooks.lifecycle.errorLoadShare.emit({\n pkgName,\n shareInfo,\n shared: this.host.options.shared,\n shareScopeMap: this.shareScopeMap,\n lifecycle,\n origin: this.host,\n error,\n recovered,\n });\n } catch (hookError) {\n warn(hookError);\n }\n }\n\n // register shared in shareScopeMap\n registerShared(globalOptions: Options, userOptions: UserOptions) {\n const { newShareInfos, allShareInfos } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n\n const sharedKeys = Object.keys(newShareInfos);\n sharedKeys.forEach((sharedKey) => {\n const sharedVals = newShareInfos[sharedKey];\n sharedVals.forEach((sharedVal) => {\n sharedVal.scope.forEach((sc) => {\n this.hooks.lifecycle.beforeRegisterShare.emit({\n origin: this.host,\n pkgName: sharedKey,\n shared: sharedVal,\n });\n const registeredShared = this.shareScopeMap[sc]?.[sharedKey];\n if (!registeredShared) {\n this.setShared({\n pkgName: sharedKey,\n lib: sharedVal.lib,\n get: sharedVal.get,\n loaded: sharedVal.loaded || Boolean(sharedVal.lib),\n shared: sharedVal,\n from: userOptions.name,\n });\n }\n });\n });\n });\n\n return {\n newShareInfos,\n allShareInfos,\n };\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n const { host } = this;\n // This function performs the following steps:\n // 1. Checks if the currently loaded share already exists, if not, it throws an error\n // 2. Searches globally for a matching share, if found, it uses it directly\n // 3. If not found, it retrieves it from the current share and stores the obtained share globally.\n\n const shareOptions = getTargetSharedOptions({\n pkgName,\n extraOptions,\n shareInfos: host.options.shared,\n });\n let shareOptionsRes: Shared | undefined = shareOptions;\n\n try {\n if (shareOptions?.scope) {\n await Promise.all(\n shareOptions.scope.map(async (shareScope) => {\n await Promise.all(\n this.initializeSharing(shareScope, {\n strategy: shareOptions.strategy,\n }),\n );\n return;\n }),\n );\n }\n const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({\n pkgName,\n shareInfo: shareOptions,\n shared: host.options.shared,\n origin: host,\n });\n\n shareOptionsRes = loadShareRes.shareInfo;\n\n // Assert that shareInfoRes exists, if not, throw an error\n assert(\n shareOptionsRes,\n `Cannot find shared \"${pkgName}\" in host \"${host.options.name}\". Ensure the shared config for \"${pkgName}\" is declared in the federation plugin options and the host has been initialized before loading shares.`,\n );\n const resolvedShareOptions = shareOptionsRes;\n\n const { shared: registeredShared, useTreesShaking } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n shareOptionsRes,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n\n if (registeredShared) {\n const targetShared = directShare(registeredShared, useTreesShaking);\n if (targetShared.lib) {\n addUseIn(targetShared, host.options.name);\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return targetShared.lib as () => T;\n } else if (targetShared.loading && !targetShared.loaded) {\n const factory = await targetShared.loading;\n targetShared.loaded = true;\n if (!targetShared.lib) {\n targetShared.lib = factory;\n }\n addUseIn(targetShared, host.options.name);\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return factory;\n } else {\n const asyncLoadProcess = async () => {\n const factory = await targetShared.get!();\n addUseIn(targetShared, host.options.name);\n targetShared.loaded = true;\n targetShared.lib = factory;\n return factory as () => T;\n };\n const loading = asyncLoadProcess();\n this.setShared({\n pkgName,\n loaded: false,\n shared: registeredShared,\n from: host.options.name,\n lib: null,\n loading,\n treeShaking: useTreesShaking\n ? (targetShared as TreeShakingArgs)\n : undefined,\n });\n const factory = await loading;\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: registeredShared,\n });\n return factory;\n }\n } else {\n if (extraOptions?.customShareInfo) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n recovered: true,\n });\n return false;\n }\n const _useTreeShaking = shouldUseTreeShaking(\n resolvedShareOptions.treeShaking,\n );\n const targetShared = directShare(resolvedShareOptions, _useTreeShaking);\n\n const asyncLoadProcess = async () => {\n const factory = await targetShared.get!();\n targetShared.lib = factory;\n targetShared.loaded = true;\n addUseIn(targetShared, host.options.name);\n const { shared: gShared, useTreesShaking: gUseTreeShaking } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n resolvedShareOptions,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n if (gShared) {\n const targetGShared = directShare(gShared, gUseTreeShaking);\n targetGShared.lib = factory;\n targetGShared.loaded = true;\n gShared.from = resolvedShareOptions.from;\n }\n return factory as () => T;\n };\n const loading = asyncLoadProcess();\n this.setShared({\n pkgName,\n loaded: false,\n shared: resolvedShareOptions,\n from: host.options.name,\n lib: null,\n loading,\n treeShaking: _useTreeShaking\n ? (targetShared as TreeShakingArgs)\n : undefined,\n });\n const factory = await loading;\n this.emitAfterLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: resolvedShareOptions,\n selectedShared: resolvedShareOptions,\n });\n return factory;\n }\n } catch (shareError) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShare',\n pkgName,\n shareInfo: shareOptionsRes,\n error: shareError,\n });\n throw shareError;\n }\n }\n\n /**\n * This function initializes the sharing sequence (executed only once per share scope).\n * It accepts one argument, the name of the share scope.\n * If the share scope does not exist, it creates one.\n */\n // eslint-disable-next-line @typescript-eslint/member-ordering\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: ShareStrategy;\n },\n ): Array<Promise<void>> {\n const { host } = this;\n const from = extraOptions?.from;\n const strategy = extraOptions?.strategy;\n let initScope = extraOptions?.initScope;\n const promises: Promise<any>[] = [];\n if (from !== 'build') {\n const { initTokens } = this;\n if (!initScope) initScope = [];\n let initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: this.host.name };\n if (initScope.indexOf(initToken) >= 0) return promises;\n initScope.push(initToken);\n }\n\n const shareScope = this.shareScopeMap;\n const hostName = host.options.name;\n // Creates a new share scope if necessary\n if (!shareScope[shareScopeName]) {\n shareScope[shareScopeName] = {};\n }\n // Executes all initialization snippets from all accessible modules\n const scope = shareScope[shareScopeName];\n const register = (name: string, shared: Shared) => {\n const { version, eager } = shared;\n scope[name] = scope[name] || {};\n const versions = scope[name];\n const activeVersion: Shared =\n versions[version] && (directShare(versions[version]) as Shared);\n const activeVersionEager = Boolean(\n activeVersion &&\n (('eager' in activeVersion && activeVersion.eager) ||\n ('shareConfig' in activeVersion && activeVersion.shareConfig?.eager)),\n );\n if (\n !activeVersion ||\n (activeVersion.strategy !== 'loaded-first' &&\n !activeVersion.loaded &&\n (Boolean(!eager) !== !activeVersionEager\n ? eager\n : hostName > versions[version].from))\n ) {\n versions[version] = shared;\n }\n };\n\n const initRemoteModule = async (key: string): Promise<void> => {\n const { module } = await host.remoteHandler.getRemoteModuleAndOptions({\n id: key,\n });\n let remoteEntryExports: RemoteEntryExports | undefined = undefined;\n try {\n remoteEntryExports = await module.getEntry();\n } catch (error) {\n remoteEntryExports =\n (await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({\n id: key,\n error,\n from: 'runtime',\n lifecycle: 'beforeLoadShare',\n remote: module.remoteInfo,\n origin: host,\n })) as RemoteEntryExports;\n if (!remoteEntryExports) {\n return;\n }\n } finally {\n // prevent self load loop: when host load self , the initTokens is not the same\n if (remoteEntryExports?.init && !module.initing) {\n module.remoteEntryExports = remoteEntryExports;\n await module.init(undefined, undefined, initScope);\n }\n }\n };\n Object.keys(host.options.shared).forEach((shareName) => {\n const sharedArr = host.options.shared[shareName];\n sharedArr.forEach((shared) => {\n if (shared.scope.includes(shareScopeName)) {\n register(shareName, shared);\n }\n });\n });\n // TODO: strategy==='version-first' need to be removed in the future\n if (\n host.options.shareStrategy === 'version-first' ||\n strategy === 'version-first'\n ) {\n host.options.remotes.forEach((remote) => {\n if (remote.shareScope === shareScopeName) {\n promises.push(initRemoteModule(remote.name));\n }\n });\n }\n\n return promises;\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n from?: 'build' | 'runtime';\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n const { host } = this;\n const shareOptions = getTargetSharedOptions({\n pkgName,\n extraOptions,\n shareInfos: host.options.shared,\n });\n\n try {\n if (shareOptions?.scope) {\n shareOptions.scope.forEach((shareScope) => {\n this.initializeSharing(shareScope, {\n strategy: shareOptions.strategy,\n });\n });\n }\n const { shared: registeredShared } =\n getRegisteredShare(\n this.shareScopeMap,\n pkgName,\n shareOptions,\n this.hooks.lifecycle.resolveShare,\n ) || {};\n\n if (registeredShared) {\n if (typeof registeredShared.lib === 'function') {\n addUseIn(registeredShared, host.options.name);\n if (!registeredShared.loaded) {\n registeredShared.loaded = true;\n if (registeredShared.from === host.options.name) {\n shareOptions.loaded = true;\n }\n }\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: registeredShared,\n });\n return registeredShared.lib as () => T;\n }\n if (typeof registeredShared.get === 'function') {\n const module = registeredShared.get();\n if (!(module instanceof Promise)) {\n addUseIn(registeredShared, host.options.name);\n this.setShared({\n pkgName,\n loaded: true,\n from: host.options.name,\n lib: module,\n shared: registeredShared,\n });\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: registeredShared,\n });\n return module;\n }\n }\n }\n\n if (shareOptions.lib) {\n if (!shareOptions.loaded) {\n shareOptions.loaded = true;\n }\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: shareOptions,\n });\n return shareOptions.lib as () => T;\n }\n\n if (shareOptions.get) {\n const module = shareOptions.get();\n\n if (module instanceof Promise) {\n const errorCode =\n extraOptions?.from === 'build' ? RUNTIME_005 : RUNTIME_006;\n error(\n errorCode,\n runtimeDescMap,\n {\n hostName: host.options.name,\n sharedPkgName: pkgName,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n }\n\n shareOptions.lib = module;\n\n this.setShared({\n pkgName,\n loaded: true,\n from: host.options.name,\n lib: shareOptions.lib,\n shared: shareOptions,\n });\n this.emitAfterLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n selectedShared: shareOptions,\n });\n return shareOptions.lib as () => T;\n }\n\n error(\n RUNTIME_006,\n runtimeDescMap,\n {\n hostName: host.options.name,\n sharedPkgName: pkgName,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (shareError) {\n this.emitErrorLoadShare({\n lifecycle: 'loadShareSync',\n pkgName,\n shareInfo: shareOptions,\n error: shareError,\n });\n throw shareError;\n }\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n const { host } = this;\n this.shareScopeMap[scopeName] = shareScope;\n this.hooks.lifecycle.initContainerShareScopeMap.emit({\n shareScope,\n options: host.options,\n origin: host,\n scopeName,\n hostShareScopeMap: extraOptions.hostShareScopeMap,\n });\n }\n\n private setShared({\n pkgName,\n shared,\n from,\n lib,\n loading,\n loaded,\n get,\n treeShaking,\n }: {\n pkgName: string;\n shared: Shared;\n from: string;\n lib: any;\n loaded?: boolean;\n loading?: Shared['loading'];\n get?: Shared['get'];\n treeShaking?: TreeShakingArgs;\n }): void {\n const { version, scope = 'default', ...shareInfo } = shared;\n const scopes: string[] = Array.isArray(scope) ? scope : [scope];\n\n const mergeAttrs = (shared: Shared) => {\n const merge = <K extends keyof TreeShakingArgs>(\n s: TreeShakingArgs,\n key: K,\n val: TreeShakingArgs[K],\n ): void => {\n if (val && !s[key]) {\n s[key] = val;\n }\n };\n const targetShared = (\n treeShaking ? shared.treeShaking! : shared\n ) as TreeShakingArgs;\n merge(targetShared, 'loaded', loaded);\n merge(targetShared, 'loading', loading);\n merge(targetShared, 'get', get);\n };\n scopes.forEach((sc) => {\n if (!this.shareScopeMap[sc]) {\n this.shareScopeMap[sc] = {};\n }\n if (!this.shareScopeMap[sc][pkgName]) {\n this.shareScopeMap[sc][pkgName] = {};\n }\n\n if (!this.shareScopeMap[sc][pkgName][version]) {\n this.shareScopeMap[sc][pkgName][version] = {\n version,\n scope: [sc],\n ...shareInfo,\n lib,\n };\n }\n\n const registeredShared = this.shareScopeMap[sc][pkgName][version];\n mergeAttrs(registeredShared);\n if (from && registeredShared.from !== from) {\n registeredShared.from = from;\n }\n });\n }\n\n private _setGlobalShareScopeMap(hostOptions: Options): void {\n const globalShareScopeMap = getGlobalShareScope();\n const identifier = hostOptions.id || hostOptions.name;\n if (identifier && !globalShareScopeMap[identifier]) {\n globalShareScopeMap[identifier] = this.shareScopeMap;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,MAA2B;CAkEzB,YAAY,MAAwB;eA/D5B,IAAIA,kCAAa;GACvB,qBAAqB,IAAIC,4CAItB,sBAAsB;GACzB,cAAc,IAAIC,+CAAoC,eAAe;GACrE,iBAAiB,IAAIA,+CAKlB,kBAAkB;GAErB,WAAW,IAAIC,6BAAmD;GAClE,gBAAgB,IAAIC,0BAalB,iBAAiB;GACnB,gBAAgB,IAAIA,0BAclB,iBAAiB;GACnB,cAAc,IAAIH,4CAQf,eAAe;GAElB,4BAA4B,IAAIA,4CAM7B,6BAA6B;GACjC,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;AACvB,OAAK,aAAa,EAAE;AACpB,OAAK,wBAAwB,KAAK,QAAQ;;CAG5C,AAAQ,mBAAmB,EACzB,WACA,SACA,WACA,kBAMO;AACP,MAAI;AACF,QAAK,MAAM,UAAU,eAAe,KAAK;IACvC;IACA;IACA;IACA,QAAQ,KAAK,KAAK,QAAQ;IAC1B,eAAe,KAAK;IACpB;IACA,QAAQ,KAAK;IACd,CAAC;WACK,OAAO;AACd,uBAAK,MAAM;;;CAIf,AAAQ,mBAAmB,EACzB,WACA,SACA,WACA,OACA,aAOO;AACP,MAAI;AACF,QAAK,MAAM,UAAU,eAAe,KAAK;IACvC;IACA;IACA,QAAQ,KAAK,KAAK,QAAQ;IAC1B,eAAe,KAAK;IACpB;IACA,QAAQ,KAAK;IACb;IACA;IACD,CAAC;WACK,WAAW;AAClB,uBAAK,UAAU;;;CAKnB,eAAe,eAAwB,aAA0B;EAC/D,MAAM,EAAE,eAAe,kBAAkBI,iCACvC,eACA,YACD;AAGD,EADmB,OAAO,KAAK,cAAc,C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