@module-federation/runtime-core 2.4.0 → 2.5.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.
Files changed (69) hide show
  1. package/dist/core.cjs +8 -1
  2. package/dist/core.cjs.map +1 -1
  3. package/dist/core.d.ts +62 -6
  4. package/dist/core.js +8 -1
  5. package/dist/core.js.map +1 -1
  6. package/dist/global.cjs +1 -1
  7. package/dist/global.js +1 -1
  8. package/dist/module/index.cjs +158 -21
  9. package/dist/module/index.cjs.map +1 -1
  10. package/dist/module/index.d.ts +5 -4
  11. package/dist/module/index.js +160 -23
  12. package/dist/module/index.js.map +1 -1
  13. package/dist/plugins/snapshot/SnapshotHandler.cjs +40 -16
  14. package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -1
  15. package/dist/plugins/snapshot/SnapshotHandler.d.ts +5 -2
  16. package/dist/plugins/snapshot/SnapshotHandler.js +42 -18
  17. package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -1
  18. package/dist/plugins/snapshot/index.cjs +6 -2
  19. package/dist/plugins/snapshot/index.cjs.map +1 -1
  20. package/dist/plugins/snapshot/index.js +6 -2
  21. package/dist/plugins/snapshot/index.js.map +1 -1
  22. package/dist/remote/index.cjs +163 -25
  23. package/dist/remote/index.cjs.map +1 -1
  24. package/dist/remote/index.d.ts +30 -4
  25. package/dist/remote/index.js +164 -26
  26. package/dist/remote/index.js.map +1 -1
  27. package/dist/shared/index.cjs +210 -95
  28. package/dist/shared/index.cjs.map +1 -1
  29. package/dist/shared/index.d.ts +22 -0
  30. package/dist/shared/index.js +211 -96
  31. package/dist/shared/index.js.map +1 -1
  32. package/dist/type/index.d.ts +2 -2
  33. package/dist/type/preload.d.ts +25 -1
  34. package/dist/types.d.ts +2 -2
  35. package/dist/utils/hooks/asyncHook.cjs +4 -1
  36. package/dist/utils/hooks/asyncHook.cjs.map +1 -1
  37. package/dist/utils/hooks/asyncHook.js +4 -1
  38. package/dist/utils/hooks/asyncHook.js.map +1 -1
  39. package/dist/utils/hooks/asyncWaterfallHooks.cjs +10 -8
  40. package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -1
  41. package/dist/utils/hooks/asyncWaterfallHooks.d.ts +2 -2
  42. package/dist/utils/hooks/asyncWaterfallHooks.js +10 -8
  43. package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -1
  44. package/dist/utils/hooks/pluginSystem.d.ts +1 -1
  45. package/dist/utils/hooks/syncHook.cjs +2 -1
  46. package/dist/utils/hooks/syncHook.cjs.map +1 -1
  47. package/dist/utils/hooks/syncHook.js +2 -1
  48. package/dist/utils/hooks/syncHook.js.map +1 -1
  49. package/dist/utils/hooks/syncWaterfallHook.cjs +1 -0
  50. package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -1
  51. package/dist/utils/hooks/syncWaterfallHook.d.ts +1 -1
  52. package/dist/utils/hooks/syncWaterfallHook.js +1 -0
  53. package/dist/utils/hooks/syncWaterfallHook.js.map +1 -1
  54. package/dist/utils/index.js +1 -1
  55. package/dist/utils/load.cjs +42 -10
  56. package/dist/utils/load.cjs.map +1 -1
  57. package/dist/utils/load.d.ts +2 -0
  58. package/dist/utils/load.js +42 -10
  59. package/dist/utils/load.js.map +1 -1
  60. package/dist/utils/manifest.cjs +5 -0
  61. package/dist/utils/manifest.cjs.map +1 -1
  62. package/dist/utils/manifest.js +5 -1
  63. package/dist/utils/manifest.js.map +1 -1
  64. package/dist/utils/preload.cjs +126 -63
  65. package/dist/utils/preload.cjs.map +1 -1
  66. package/dist/utils/preload.d.ts +2 -2
  67. package/dist/utils/preload.js +126 -63
  68. package/dist/utils/preload.js.map +1 -1
  69. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","formatPreloadArgs","getRemoteInfo","matchRemoteWithNameAndExpose","RUNTIME_004","runtimeDescMap","optionsToMFContext","Module","isBrowserEnvValue","DEFAULT_SCOPE","DEFAULT_REMOTE_TYPE","CurrentGlobal","getRemoteEntryUniqueKey","globalLoading","getGlobalShareScope","getGlobalRemoteInfo","getInfoWithoutType","Global"],"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 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 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 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 void\n >('onLoad'),\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 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 // not used yet\n afterPreloadRemote: new AsyncHook<{\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n }>(),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports>\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 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\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 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 const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n origin: host,\n });\n\n if (!failOver) {\n throw error;\n }\n\n return failOver as T;\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\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 await Promise.all(\n preloadOps.map(async (ops) => {\n const { remote } = ops;\n const remoteInfo = getRemoteInfo(remote);\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\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 preloadAssets(remoteInfo, host, assets);\n }),\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 error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\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 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 host.snapshotHandler.manifestCache.delete(remoteInfo.entry);\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 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 if (\n //eslint-disable-next-line no-extra-boolean-cast\n Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])\n ) {\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];\n }\n }\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":";;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,gBAAb,MAA2B;CAyGzB,YAAY,MAAwB;eArG5B,IAAIA,kCAAa;GACvB,sBAAsB,IAAIC,4CAGvB,uBAAuB;GAC1B,gBAAgB,IAAIA,4CAGjB,iBAAiB;GACpB,eAAe,IAAIC,+CAIhB,gBAAgB;GACnB,QAAQ,IAAIC,4BAeV,SAAS;GACX,qBAAqB,IAAIC,0BAYvB,sBAAsB;GACxB,iBAAiB,IAAID,4BAgBnB,kBAAkB;GACpB,qBAAqB,IAAIA,4BAQvB,sBAAsB;GACxB,uBAAuB,IAAIA,4BAYzB,wBAAwB;GAE1B,oBAAoB,IAAIA,6BAIpB;GAEJ,WAAW,IAAIA,6BASZ;GACJ,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;;CAGzB,wBAAwB,eAAwB,aAA0B;AAGxE,UAFoB,YAAY,WAAW,EAAE,EAE1B,QAAQ,KAAK,WAAW;AACzC,QAAK,eAAe,QAAQ,KAAK,EAAE,OAAO,OAAO,CAAC;AAClD,UAAO;KACN,cAAc,QAAQ;;CAG3B,iBAAiB,IAAY,iBAAkC;EAC7D,MAAM,EAAE,QAAQ,WAAW;EAC3B,MAAM,EAAE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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","RUNTIME_004","runtimeDescMap","optionsToMFContext","Module","isBrowserEnvValue","DEFAULT_SCOPE","DEFAULT_REMOTE_TYPE","CurrentGlobal","getRemoteEntryUniqueKey","globalLoading","getGlobalShareScope","getGlobalRemoteInfo","getInfoWithoutType","Global"],"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 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 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 host.snapshotHandler.manifestCache.delete(remoteInfo.entry);\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 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 if (\n //eslint-disable-next-line no-extra-boolean-cast\n Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])\n ) {\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];\n }\n }\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":";;;;;;;;;;;;;;;;;;;;;AA6DA,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,IAAID,4BAkBnB,kBAAkB;GACpB,qBAAqB,IAAIA,4BAQvB,sBAAsB;GACxB,uBAAuB,IAAIA,4BAYzB,wBAAwB;GAC1B,oBAAoB,IAAIA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Y,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,yBAAO,MACL,wBAAwB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACzE"}
@@ -6,7 +6,7 @@ import { AsyncWaterfallHook } from "../utils/hooks/asyncWaterfallHooks.js";
6
6
  import { PluginSystem } from "../utils/hooks/pluginSystem.js";
7
7
  import { ModuleFederation } from "../core.js";
8
8
  import { CallFrom, Options, Remote, RemoteEntryExports, RemoteInfo, UserOptions } from "../type/config.js";
9
- import { PreloadAssets, PreloadOptions, PreloadRemoteArgs } from "../type/preload.js";
9
+ import { PreloadAssets, PreloadOptions, PreloadRemoteArgs, PreloadRemoteResult } from "../type/preload.js";
10
10
  import { GlobalModuleInfo, ModuleInfo } from "@module-federation/sdk";
11
11
 
12
12
  //#region src/remote/index.d.ts
@@ -40,6 +40,15 @@ declare class RemoteHandler {
40
40
  options: Options;
41
41
  origin: ModuleFederation;
42
42
  }>;
43
+ afterMatchRemote: AsyncHook<[{
44
+ id: string;
45
+ options: Options;
46
+ remote?: Remote;
47
+ expose?: string;
48
+ remoteInfo?: RemoteInfo;
49
+ error?: unknown;
50
+ origin: ModuleFederation;
51
+ }], void>;
43
52
  onLoad: AsyncHook<[{
44
53
  id: string;
45
54
  expose: string;
@@ -50,6 +59,18 @@ declare class RemoteHandler {
50
59
  exposeModule: any;
51
60
  exposeModuleFactory: any;
52
61
  moduleInstance: Module$1;
62
+ }], unknown>;
63
+ afterLoadRemote: AsyncHook<[{
64
+ id: string;
65
+ expose?: string;
66
+ remote?: RemoteInfo;
67
+ options?: {
68
+ loadFactory?: boolean;
69
+ from?: CallFrom;
70
+ };
71
+ error?: unknown;
72
+ recovered?: boolean;
73
+ origin: ModuleFederation;
53
74
  }], void>;
54
75
  handlePreloadModule: SyncHook<[{
55
76
  id: string;
@@ -65,6 +86,8 @@ declare class RemoteHandler {
65
86
  options?: any;
66
87
  from: CallFrom;
67
88
  lifecycle: "beforeRequest" | "beforeLoadShare" | "afterResolve" | "onLoad";
89
+ remote?: RemoteInfo;
90
+ expose?: string;
68
91
  origin: ModuleFederation;
69
92
  }], unknown>;
70
93
  beforePreloadRemote: AsyncHook<[{
@@ -80,16 +103,19 @@ declare class RemoteHandler {
80
103
  remoteSnapshot: ModuleInfo;
81
104
  globalSnapshot: GlobalModuleInfo;
82
105
  }], Promise<PreloadAssets>>;
83
- afterPreloadRemote: AsyncHook<{
106
+ afterPreloadRemote: AsyncHook<[{
84
107
  preloadOps: Array<PreloadRemoteArgs>;
85
108
  options: Options;
86
109
  origin: ModuleFederation;
87
- }, false | void | Promise<false | void>>;
110
+ results: PreloadRemoteResult[];
111
+ error?: unknown;
112
+ }], false | void | Promise<false | void>>;
88
113
  loadEntry: AsyncHook<[{
114
+ origin: ModuleFederation;
89
115
  loaderHook: ModuleFederation["loaderHook"];
90
116
  remoteInfo: RemoteInfo;
91
117
  remoteEntryExports?: RemoteEntryExports;
92
- }], Promise<RemoteEntryExports>>;
118
+ }], void | RemoteEntryExports | Promise<void | RemoteEntryExports>>;
93
119
  }>;
94
120
  constructor(host: ModuleFederation);
95
121
  formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions): Remote[];
@@ -2,7 +2,7 @@ import { assert, error, logger } from "../utils/logger.js";
2
2
  import { CurrentGlobal, Global, getInfoWithoutType, globalLoading } from "../global.js";
3
3
  import { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from "../constant.js";
4
4
  import { getGlobalShareScope } from "../utils/share.js";
5
- import { matchRemoteWithNameAndExpose } from "../utils/manifest.js";
5
+ import { composeRemoteRequestId, matchRemoteWithNameAndExpose } from "../utils/manifest.js";
6
6
  import { getRemoteEntryUniqueKey, getRemoteInfo } from "../utils/load.js";
7
7
  import { optionsToMFContext } from "../utils/context.js";
8
8
  import "../utils/index.js";
@@ -25,12 +25,14 @@ var RemoteHandler = class {
25
25
  beforeRegisterRemote: new SyncWaterfallHook("beforeRegisterRemote"),
26
26
  registerRemote: new SyncWaterfallHook("registerRemote"),
27
27
  beforeRequest: new AsyncWaterfallHook("beforeRequest"),
28
+ afterMatchRemote: new AsyncHook("afterMatchRemote"),
28
29
  onLoad: new AsyncHook("onLoad"),
30
+ afterLoadRemote: new AsyncHook("afterLoadRemote"),
29
31
  handlePreloadModule: new SyncHook("handlePreloadModule"),
30
32
  errorLoadRemote: new AsyncHook("errorLoadRemote"),
31
33
  beforePreloadRemote: new AsyncHook("beforePreloadRemote"),
32
34
  generatePreloadAssets: new AsyncHook("generatePreloadAssets"),
33
- afterPreloadRemote: new AsyncHook(),
35
+ afterPreloadRemote: new AsyncHook("afterPreloadRemote"),
34
36
  loadEntry: new AsyncHook()
35
37
  });
36
38
  this.host = host;
@@ -67,10 +69,18 @@ var RemoteHandler = class {
67
69
  }
68
70
  async loadRemote(id, options) {
69
71
  const { host } = this;
72
+ const startMatchInfo = matchRemoteWithNameAndExpose(host.options.remotes, id);
73
+ let completeRequestId = id;
74
+ let completeExpose = startMatchInfo?.expose;
75
+ let completeRemote = startMatchInfo ? getRemoteInfo(startMatchInfo.remote) : void 0;
76
+ let afterLoadRemoteArgs;
70
77
  try {
71
78
  const { loadFactory = true } = options || { loadFactory: true };
72
79
  const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({ id });
73
80
  const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
81
+ completeRequestId = idRes;
82
+ completeExpose = expose;
83
+ completeRemote = getRemoteInfo(remote);
74
84
  const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
75
85
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
76
86
  id: idRes,
@@ -84,44 +94,155 @@ var RemoteHandler = class {
84
94
  origin: host
85
95
  });
86
96
  this.setIdToRemoteMap(id, remoteMatchInfo);
97
+ afterLoadRemoteArgs = {
98
+ id: completeRequestId,
99
+ expose: completeExpose,
100
+ remote: completeRemote,
101
+ options,
102
+ origin: host
103
+ };
87
104
  if (typeof moduleWrapper === "function") return moduleWrapper;
88
105
  return moduleOrFactory;
89
106
  } catch (error) {
90
107
  const { from = "runtime" } = options || { from: "runtime" };
91
- const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
92
- id,
108
+ let failOver;
109
+ try {
110
+ failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
111
+ id,
112
+ error,
113
+ from,
114
+ lifecycle: "onLoad",
115
+ expose: completeExpose,
116
+ remote: completeRemote,
117
+ origin: host
118
+ });
119
+ } catch (hookError) {
120
+ afterLoadRemoteArgs = {
121
+ id: completeRequestId,
122
+ expose: completeExpose,
123
+ remote: completeRemote,
124
+ options,
125
+ error: hookError,
126
+ origin: host
127
+ };
128
+ throw hookError;
129
+ }
130
+ if (!failOver) {
131
+ afterLoadRemoteArgs = {
132
+ id: completeRequestId,
133
+ expose: completeExpose,
134
+ remote: completeRemote,
135
+ options,
136
+ error,
137
+ origin: host
138
+ };
139
+ throw error;
140
+ }
141
+ afterLoadRemoteArgs = {
142
+ id: completeRequestId,
143
+ expose: completeExpose,
144
+ remote: completeRemote,
145
+ options,
93
146
  error,
94
- from,
95
- lifecycle: "onLoad",
96
- origin: host
97
- });
98
- if (!failOver) throw error;
147
+ origin: host,
148
+ recovered: true
149
+ };
99
150
  return failOver;
151
+ } finally {
152
+ if (afterLoadRemoteArgs) await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);
100
153
  }
101
154
  }
102
155
  async preloadRemote(preloadOptions) {
103
156
  const { host } = this;
157
+ const preloadResults = [];
104
158
  await this.hooks.lifecycle.beforePreloadRemote.emit({
105
159
  preloadOps: preloadOptions,
106
160
  options: host.options,
107
161
  origin: host
108
162
  });
109
163
  const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
110
- await Promise.all(preloadOps.map(async (ops) => {
111
- const { remote } = ops;
164
+ const createPreloadAssetOps = (ops) => {
165
+ const { preloadConfig, remote } = ops;
166
+ const exposes = preloadConfig.exposes || [];
167
+ if (!exposes.length) return [{
168
+ ops,
169
+ id: `${remote.name}/*`
170
+ }];
171
+ return exposes.map((expose) => ({
172
+ ops: {
173
+ ...ops,
174
+ preloadConfig: {
175
+ ...preloadConfig,
176
+ exposes: [expose]
177
+ }
178
+ },
179
+ id: composeRemoteRequestId(remote.name, expose)
180
+ }));
181
+ };
182
+ let preloadError;
183
+ await Promise.all(preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {
184
+ const { ops, id: preloadId } = assetOps;
185
+ const { remote, preloadConfig } = ops;
112
186
  const remoteInfo = getRemoteInfo(remote);
113
- const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({ moduleInfo: remote });
114
- const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
115
- origin: host,
116
- preloadOptions: ops,
117
- remote,
118
- remoteInfo,
119
- globalSnapshot,
120
- remoteSnapshot
121
- });
122
- if (!assets) return;
123
- preloadAssets(remoteInfo, host, assets);
187
+ try {
188
+ const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
189
+ moduleInfo: remote,
190
+ id: preloadId,
191
+ initiator: "preloadRemote"
192
+ });
193
+ const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
194
+ origin: host,
195
+ preloadOptions: ops,
196
+ remote,
197
+ remoteInfo,
198
+ globalSnapshot,
199
+ remoteSnapshot
200
+ });
201
+ if (!assets) return;
202
+ const results = await preloadAssets(remoteInfo, host, assets, true, {
203
+ initiator: "preloadRemote",
204
+ id: preloadId
205
+ });
206
+ preloadResults.push({
207
+ remote,
208
+ remoteInfo,
209
+ preloadConfig,
210
+ id: preloadId,
211
+ results
212
+ });
213
+ } catch (error) {
214
+ preloadResults.push({
215
+ remote,
216
+ remoteInfo,
217
+ preloadConfig,
218
+ id: preloadId,
219
+ results: [{
220
+ url: remoteInfo.entry,
221
+ status: "error",
222
+ resourceType: /\.json(?:$|[?#])/i.test(remoteInfo.entry) ? "manifest" : "remoteEntry",
223
+ initiator: "preloadRemote",
224
+ id: preloadId,
225
+ error
226
+ }]
227
+ });
228
+ }
124
229
  }));
230
+ const failedResults = preloadResults.flatMap((preloadResult) => preloadResult.results.filter((result) => result.status === "error" || result.status === "timeout"));
231
+ if (failedResults.length > 0) {
232
+ preloadError = /* @__PURE__ */ new Error(`preloadRemote failed to load ${failedResults.length} resource(s).`);
233
+ Object.assign(preloadError, {
234
+ results: preloadResults,
235
+ failedResults
236
+ });
237
+ }
238
+ await this.hooks.lifecycle.afterPreloadRemote.emit({
239
+ preloadOps: preloadOptions,
240
+ options: host.options,
241
+ origin: host,
242
+ results: preloadResults,
243
+ error: preloadError
244
+ });
245
+ if (preloadError) throw preloadError;
125
246
  }
126
247
  registerRemotes(remotes, options) {
127
248
  const { host } = this;
@@ -152,12 +273,29 @@ var RemoteHandler = class {
152
273
  }
153
274
  const { id: idRes } = loadRemoteArgs;
154
275
  const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
155
- if (!remoteSplitInfo) error(RUNTIME_004, runtimeDescMap, {
156
- hostName: host.options.name,
157
- requestId: idRes
158
- }, void 0, optionsToMFContext(host.options));
276
+ if (!remoteSplitInfo) try {
277
+ error(RUNTIME_004, runtimeDescMap, {
278
+ hostName: host.options.name,
279
+ requestId: idRes
280
+ }, void 0, optionsToMFContext(host.options));
281
+ } catch (matchError) {
282
+ await this.hooks.lifecycle.afterMatchRemote.emit({
283
+ id: idRes,
284
+ options: host.options,
285
+ error: matchError,
286
+ origin: host
287
+ });
288
+ throw matchError;
289
+ }
159
290
  const { remote: rawRemote } = remoteSplitInfo;
160
291
  const remoteInfo = getRemoteInfo(rawRemote);
292
+ await this.hooks.lifecycle.afterMatchRemote.emit({
293
+ id: idRes,
294
+ ...remoteSplitInfo,
295
+ options: host.options,
296
+ remoteInfo,
297
+ origin: host
298
+ });
161
299
  const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
162
300
  id: idRes,
163
301
  ...remoteSplitInfo,
@@ -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 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 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 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 void\n >('onLoad'),\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 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 // not used yet\n afterPreloadRemote: new AsyncHook<{\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n }>(),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n },\n ],\n Promise<RemoteEntryExports>\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 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\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 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 const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n origin: host,\n });\n\n if (!failOver) {\n throw error;\n }\n\n return failOver as T;\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\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 await Promise.all(\n preloadOps.map(async (ops) => {\n const { remote } = ops;\n const remoteInfo = getRemoteInfo(remote);\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\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 preloadAssets(remoteInfo, host, assets);\n }),\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 error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\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 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 host.snapshotHandler.manifestCache.delete(remoteInfo.entry);\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 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 if (\n //eslint-disable-next-line no-extra-boolean-cast\n Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])\n ) {\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];\n }\n }\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":";;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,gBAAb,MAA2B;CAyGzB,YAAY,MAAwB;eArG5B,IAAI,aAAa;GACvB,sBAAsB,IAAI,kBAGvB,uBAAuB;GAC1B,gBAAgB,IAAI,kBAGjB,iBAAiB;GACpB,eAAe,IAAI,mBAIhB,gBAAgB;GACnB,QAAQ,IAAI,UAeV,SAAS;GACX,qBAAqB,IAAI,SAYvB,sBAAsB;GACxB,iBAAiB,IAAI,UAgBnB,kBAAkB;GACpB,qBAAqB,IAAI,UAQvB,sBAAsB;GACxB,uBAAuB,IAAI,UAYzB,wBAAwB;GAE1B,oBAAoB,IAAI,WAIpB;GAEJ,WAAW,IAAI,WASZ;GACJ,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;;CAGzB,wBAAwB,eAAwB,aAA0B;AAGxE,UAFoB,YAAY,WAAW,EAAE,EAE1B,QAAQ,KAAK,WAAW;AACzC,QAAK,eAAe,QAAQ,KAAK,EAAE,OAAO,OAAO,CAAC;AAClD,UAAO;KACN,cAAc,QAAQ;;CAG3B,iBAAiB,IAAY,iBAAkC;EAC7D,MAAM,EAAE,QAAQ,WAAW;EAC3B,MAAM,EAAE,MAAM,UAAU;AACxB,OAAK,cAAc,MAAM;GAAE,MAAM,OAAO;GAAM;GAAQ;AACtD,MAAI,SAAS,GAAG,WAAW,KAAK,EAAE;GAChC,MAAM,cA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c,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,mBAAc,eAAe,cAAc,OAAO,gBAAgB,EAAE;;IAGtE,MAAM,EAAE,uBAAuB,oBAAoB,QAAQ,KAAK;AAChE,QAAI,oBAAoB;KACtB,MAAM,YACJ,sBACA,iBAAiB,sBACjB,mBAAmB,eACnB,mBAAmB,mBAAmB,aAAa,OAAO,KAAK,CAAC;AAClE,SAAI,WAAW;AACb,aAAO,mBAAmB,YAAY;AACtC,UAEE,QAAQ,OAAO,eAAe,qBAAqB,WAAW,CAE9D,QAAO,OAAO,eAAe,qBAAqB;;;AAKxD,SAAK,YAAY,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,UAAO,MACL,wBAAwB,eAAe,QAAQ,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 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 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 host.snapshotHandler.manifestCache.delete(remoteInfo.entry);\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 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 if (\n //eslint-disable-next-line no-extra-boolean-cast\n Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])\n ) {\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];\n }\n }\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":";;;;;;;;;;;;;;;;;;;;;AA6DA,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,wBAAwB,eAAwB,aAA0B;AAGxE,UAFoB,YAAY,WAAW,EAAE,EAE1B,QAAQ,KAAK,WAAW;AACzC,QAAK,eAAe,QAAQ,KAAK,EAAE,OAAO,OAAO,CAAC;AAClD,UAAO;KACN,cAAc,QAAQ;;CAG3B,iBAAiB,IAAY,iBAAkC;EAC7D,MAAM,EAAE,QAAQ,WAAW;EAC3B,MAAM,EAAE,MAAM,UAAU;AACxB,OAAK,cAAc,MAAM;GAAE,MAAM,OAAO;GAAM;GAAQ;AACtD,MAAI,SAAS,GAAG,WAAW,KAAK,EAAE;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