import type { RemoteWithEntry, RemoteWithVersion, Module, RemoteEntryType, } from '@module-federation/sdk'; import { FederationRuntimePlugin } from './plugin'; export type Optional = Omit & Partial; export type PartialOptional = Omit & { [P in K]-?: T[P]; }; export interface RemoteInfoCommon { alias?: string; shareScope?: string; type?: RemoteEntryType; entryGlobalName?: string; } export type RemoteInfoOptionalVersion = { name: string; version?: string; } & RemoteInfoCommon; export type Remote = (RemoteWithEntry | RemoteWithVersion) & RemoteInfoCommon; export type LoadShareExtraOptions = { customShareInfo?: Partial; resolver?: (sharedOptions: ShareInfos[string]) => Shared; }; export interface RemoteInfo { name: string; version?: string; buildVersion?: string; entry: string; type: RemoteEntryType; entryGlobalName: string; shareScope: string; } export type HostInfo = Pick< Options, 'name' | 'version' | 'remotes' | 'version' >; export interface SharedConfig { singleton?: boolean; requiredVersion: false | string; eager?: boolean; strictVersion?: boolean; } type SharedBaseArgs = { version?: string; shareConfig?: SharedConfig; scope?: string | Array; deps?: Array; strategy?: 'version-first' | 'loaded-first'; loaded?: boolean; }; export type SharedGetter = (() => () => Module) | (() => Promise<() => Module>); export type ShareArgs = | (SharedBaseArgs & { get: SharedGetter }) | (SharedBaseArgs & { lib: () => Module }) | SharedBaseArgs; export type ShareStrategy = 'version-first' | 'loaded-first'; export type Shared = { version: string; get: SharedGetter; shareConfig: SharedConfig; scope: Array; useIn: Array; from: string; deps: Array; lib?: () => Module; loaded?: boolean; loading?: null | Promise; // compatibility with previous shared eager?: boolean; /** * @deprecated set in initOptions.shareStrategy instead */ strategy: ShareStrategy; }; export type ShareScopeMap = { [scope: string]: { [pkgName: string]: { [sharedVersion: string]: Shared; }; }; }; export type GlobalShareScopeMap = { [instanceName: string]: ShareScopeMap; }; export type ShareInfos = { [pkgName: string]: Shared[]; }; export interface Options { id?: string; name: string; version?: string; remotes: Array; shared: ShareInfos; plugins: Array; inBrowser: boolean; shareStrategy?: ShareStrategy; } export type UserOptions = Omit< Optional, 'shared' | 'inBrowser' > & { shared?: { [pkgName: string]: ShareArgs | ShareArgs[]; }; }; export type LoadModuleOptions = { version?: string; }; // Only for legacy federation provider export type RemoteEntryInitOptions = { version: string; shareScopeMap: ShareScopeMap; }; export type InitTokens = Record>; export type InitScope = InitTokens[]; export type CallFrom = 'build' | 'runtime'; export type RemoteEntryExports = { get: (id: string) => () => Promise; init: ( shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions, ) => void | Promise; };