import * as runtime from '@module-federation/runtime'; import type { RemoteEntryInitOptions, SharedConfig, } from '@module-federation/runtime/types'; import { initializeSharing } from './initializeSharing'; import { attachShareScopeMap } from './attachShareScopeMap'; import { initContainerEntry } from './initContainerEntry'; // FIXME: ideal situation => import { GlobalShareScope,UserOptions } from '@module-federation/runtime/types' type ExcludeUndefined = T extends undefined ? never : T; type Shared = InitOptions['shared']; type NonUndefined = ExcludeUndefined; type InitOptions = Parameters[0]; type ModuleCache = runtime.FederationHost['moduleCache']; type InferModule = T extends Map ? U : never; type InferredModule = InferModule; export type ShareScopeMap = runtime.FederationHost['shareScopeMap']; type InitToken = Record>; export interface InitializeSharingOptions { shareScopeName: string; webpackRequire: WebpackRequire; initPromises: Record | boolean>; initTokens: InitToken; initScope: InitToken[]; } export type RemoteEntryExports = NonUndefined< InferredModule['remoteEntryExports'] >; type ExtractInitParameters = T extends { init: (shareScope: infer U, ...args: any[]) => void; } ? U : never; type InferredShareScope = ExtractInitParameters; type InferredGlobalShareScope = { [scope: string]: InferredShareScope; }; // shareScope, name, externalModuleId type IdToExternalAndNameMappingItem = [string, string, string | number]; interface IdToExternalAndNameMappingItemWithPromise extends IdToExternalAndNameMappingItem { p?: Promise | number; } export interface WebpackRequire { (moduleId: string | number): any; o: (obj: Record, key: string | number) => boolean; R: Array; m: Record any>; c: Record; I: ( scopeName: string, initScope?: InitializeSharingOptions['initScope'], ) => ReturnType; S?: InferredGlobalShareScope; federation: Federation; } interface ShareInfo { shareConfig: SharedConfig; scope: Array; } interface ModuleToHandlerMappingItem { // handler: (shareInfo: ShareInfo, type?: 'syn' | 'async') => Promise; getter: () => Promise; shareInfo: ShareInfo; shareKey: string; } interface IdToRemoteMapItem { externalType: string; name: string; externalModuleId?: string | number; } export interface RemotesOptions { chunkId: string | number; promises: Promise[]; chunkMapping: Record>; idToExternalAndNameMapping: Record< string, IdToExternalAndNameMappingItemWithPromise >; idToRemoteMap: Record; webpackRequire: WebpackRequire; } export interface HandleInitialConsumesOptions { moduleId: string | number; moduleToHandlerMapping: Record; webpackRequire: WebpackRequire; } export interface InstallInitialConsumesOptions { moduleToHandlerMapping: Record; webpackRequire: WebpackRequire; installedModules: Record | 0>; initialConsumes: Array; } export interface ConsumesOptions { chunkId: string | number; promises: Promise[]; chunkMapping: Record>; installedModules: Record | 0>; moduleToHandlerMapping: Record; webpackRequire: WebpackRequire; } export interface InitContainerEntryOptions { shareScope: ShareScopeMap[string]; shareScopeKey: string; webpackRequire: WebpackRequire; remoteEntryInitOptions?: RemoteEntryInitOptions; initScope?: InitializeSharingOptions['initScope']; } export interface Federation { runtime?: typeof runtime; instance?: runtime.FederationHost; initOptions?: InitOptions; installInitialConsumes?: (options: InstallInitialConsumesOptions) => any; bundlerRuntime?: { remotes: (options: RemotesOptions) => void; consumes: (options: ConsumesOptions) => void; I: typeof initializeSharing; S: InferredGlobalShareScope; installInitialConsumes: (options: InstallInitialConsumesOptions) => any; initContainerEntry: typeof initContainerEntry; }; bundlerRuntimeOptions: { remotes?: Exclude; }; attachShareScopeMap?: typeof attachShareScopeMap; hasAttachShareScopeMap?: boolean; prefetch?: () => void; }