@module-federation/runtime-core 0.0.0-next-20241115035905

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/index.cjs.d.ts +1 -0
  5. package/dist/index.cjs.js +3010 -0
  6. package/dist/index.esm.d.ts +1 -0
  7. package/dist/index.esm.js +2980 -0
  8. package/dist/package.json +42 -0
  9. package/dist/polyfills.cjs.js +28 -0
  10. package/dist/polyfills.esm.js +25 -0
  11. package/dist/src/constant.d.ts +2 -0
  12. package/dist/src/core.d.ts +105 -0
  13. package/dist/src/global.d.ts +42 -0
  14. package/dist/src/helpers.d.ts +31 -0
  15. package/dist/src/index.d.ts +14 -0
  16. package/dist/src/module/index.d.ts +21 -0
  17. package/dist/src/plugins/generate-preload-assets.d.ts +8 -0
  18. package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +58 -0
  19. package/dist/src/plugins/snapshot/index.d.ts +5 -0
  20. package/dist/src/remote/index.d.ts +109 -0
  21. package/dist/src/shared/index.d.ts +66 -0
  22. package/dist/src/type/config.d.ts +112 -0
  23. package/dist/src/type/index.d.ts +3 -0
  24. package/dist/src/type/plugin.d.ts +34 -0
  25. package/dist/src/type/preload.d.ts +26 -0
  26. package/dist/src/types.d.ts +1 -0
  27. package/dist/src/utils/env.d.ts +3 -0
  28. package/dist/src/utils/hooks/asyncHook.d.ts +6 -0
  29. package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +10 -0
  30. package/dist/src/utils/hooks/index.d.ts +6 -0
  31. package/dist/src/utils/hooks/pluginSystem.d.ts +15 -0
  32. package/dist/src/utils/hooks/syncHook.d.ts +12 -0
  33. package/dist/src/utils/hooks/syncWaterfallHook.d.ts +9 -0
  34. package/dist/src/utils/index.d.ts +6 -0
  35. package/dist/src/utils/load.d.ts +9 -0
  36. package/dist/src/utils/logger.d.ts +6 -0
  37. package/dist/src/utils/manifest.d.ts +7 -0
  38. package/dist/src/utils/plugin.d.ts +4 -0
  39. package/dist/src/utils/preload.d.ts +6 -0
  40. package/dist/src/utils/semver/compare.d.ts +9 -0
  41. package/dist/src/utils/semver/constants.d.ts +10 -0
  42. package/dist/src/utils/semver/index.d.ts +2 -0
  43. package/dist/src/utils/semver/parser.d.ts +9 -0
  44. package/dist/src/utils/semver/utils.d.ts +11 -0
  45. package/dist/src/utils/share.d.ts +27 -0
  46. package/dist/src/utils/tool.d.ts +18 -0
  47. package/dist/types.cjs.d.ts +1 -0
  48. package/dist/types.cjs.js +2 -0
  49. package/dist/types.esm.d.ts +1 -0
  50. package/dist/types.esm.js +1 -0
  51. package/package.json +42 -0
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@module-federation/runtime-core",
3
+ "version": "0.6.14",
4
+ "author": "zhouxiao <codingzx@gmail.com>",
5
+ "main": "./index.cjs.js",
6
+ "module": "./index.esm.js",
7
+ "types": "./dist/index.cjs.d.ts",
8
+ "license": "MIT",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "dist/",
14
+ "README.md"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.cjs.d.ts",
19
+ "import": "./dist/index.esm.js",
20
+ "require": "./dist/index.cjs.js"
21
+ },
22
+ "./types": {
23
+ "types": "./dist/types.cjs.d.ts",
24
+ "import": "./dist/types.esm.js",
25
+ "require": "./dist/types.cjs.js"
26
+ }
27
+ },
28
+ "typesVersions": {
29
+ "*": {
30
+ ".": [
31
+ "./dist/index.cjs.d.ts"
32
+ ],
33
+ "types": [
34
+ "./dist/types.cjs.d.ts"
35
+ ]
36
+ }
37
+ },
38
+ "dependencies": {
39
+ "@module-federation/sdk": "workspace:*",
40
+ "@module-federation/error-codes": "workspace:*"
41
+ }
42
+ }
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ function _extends() {
4
+ _extends = Object.assign || function assign(target) {
5
+ for(var i = 1; i < arguments.length; i++){
6
+ var source = arguments[i];
7
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
8
+ }
9
+ return target;
10
+ };
11
+ return _extends.apply(this, arguments);
12
+ }
13
+
14
+ function _object_without_properties_loose(source, excluded) {
15
+ if (source == null) return {};
16
+ var target = {};
17
+ var sourceKeys = Object.keys(source);
18
+ var key, i;
19
+ for(i = 0; i < sourceKeys.length; i++){
20
+ key = sourceKeys[i];
21
+ if (excluded.indexOf(key) >= 0) continue;
22
+ target[key] = source[key];
23
+ }
24
+ return target;
25
+ }
26
+
27
+ exports._extends = _extends;
28
+ exports._object_without_properties_loose = _object_without_properties_loose;
@@ -0,0 +1,25 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function assign(target) {
3
+ for(var i = 1; i < arguments.length; i++){
4
+ var source = arguments[i];
5
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
6
+ }
7
+ return target;
8
+ };
9
+ return _extends.apply(this, arguments);
10
+ }
11
+
12
+ function _object_without_properties_loose(source, excluded) {
13
+ if (source == null) return {};
14
+ var target = {};
15
+ var sourceKeys = Object.keys(source);
16
+ var key, i;
17
+ for(i = 0; i < sourceKeys.length; i++){
18
+ key = sourceKeys[i];
19
+ if (excluded.indexOf(key) >= 0) continue;
20
+ target[key] = source[key];
21
+ }
22
+ return target;
23
+ }
24
+
25
+ export { _extends as _, _object_without_properties_loose as a };
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_SCOPE = "default";
2
+ export declare const DEFAULT_REMOTE_TYPE = "global";
@@ -0,0 +1,105 @@
1
+ import type { CreateScriptHookReturn, ModuleInfo } from '@module-federation/sdk';
2
+ import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions, CallFrom } from './type';
3
+ import { Module } from './module';
4
+ import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
5
+ import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
6
+ import { SharedHandler } from './shared';
7
+ import { RemoteHandler } from './remote';
8
+ export declare class FederationHost {
9
+ options: Options;
10
+ hooks: PluginSystem<{
11
+ beforeInit: SyncWaterfallHook<{
12
+ userOptions: UserOptions;
13
+ options: Options;
14
+ origin: FederationHost;
15
+ shareInfo: ShareInfos;
16
+ }>;
17
+ init: SyncHook<[{
18
+ options: Options;
19
+ origin: FederationHost;
20
+ }], void>;
21
+ beforeInitContainer: AsyncWaterfallHook<{
22
+ shareScope: ShareScopeMap[string];
23
+ initScope: InitScope;
24
+ remoteEntryInitOptions: RemoteEntryInitOptions;
25
+ remoteInfo: RemoteInfo;
26
+ origin: FederationHost;
27
+ }>;
28
+ initContainer: AsyncWaterfallHook<{
29
+ shareScope: ShareScopeMap[string];
30
+ initScope: InitScope;
31
+ remoteEntryInitOptions: RemoteEntryInitOptions;
32
+ remoteInfo: RemoteInfo;
33
+ remoteEntryExports: RemoteEntryExports;
34
+ origin: FederationHost;
35
+ id: string;
36
+ remoteSnapshot?: ModuleInfo;
37
+ }>;
38
+ }>;
39
+ version: string;
40
+ name: string;
41
+ moduleCache: Map<string, Module>;
42
+ snapshotHandler: SnapshotHandler;
43
+ sharedHandler: SharedHandler;
44
+ remoteHandler: RemoteHandler;
45
+ shareScopeMap: ShareScopeMap;
46
+ loaderHook: PluginSystem<{
47
+ getModuleInfo: SyncHook<[{
48
+ target: Record<string, any>;
49
+ key: any;
50
+ }], void | {
51
+ value: any | undefined;
52
+ key: string;
53
+ }>;
54
+ createScript: SyncHook<[{
55
+ url: string;
56
+ attrs?: Record<string, any>;
57
+ }], CreateScriptHookReturn>;
58
+ createLink: SyncHook<[{
59
+ url: string;
60
+ attrs?: Record<string, any>;
61
+ }], void | HTMLLinkElement>;
62
+ fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
63
+ getModuleFactory: AsyncHook<[{
64
+ remoteEntryExports: RemoteEntryExports;
65
+ expose: string;
66
+ moduleInfo: RemoteInfo;
67
+ }], Promise<(() => Promise<Module>) | undefined>>;
68
+ }>;
69
+ bridgeHook: PluginSystem<{
70
+ beforeBridgeRender: SyncHook<[Record<string, any>], void | Record<string, any>>;
71
+ afterBridgeRender: SyncHook<[Record<string, any>], void | Record<string, any>>;
72
+ beforeBridgeDestroy: SyncHook<[Record<string, any>], void | Record<string, any>>;
73
+ afterBridgeDestroy: SyncHook<[Record<string, any>], void | Record<string, any>>;
74
+ }>;
75
+ constructor(userOptions: UserOptions);
76
+ initOptions(userOptions: UserOptions): Options;
77
+ loadShare<T>(pkgName: string, extraOptions?: {
78
+ customShareInfo?: Partial<Shared>;
79
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
80
+ }): Promise<false | (() => T | undefined)>;
81
+ loadShareSync<T>(pkgName: string, extraOptions?: {
82
+ customShareInfo?: Partial<Shared>;
83
+ from?: 'build' | 'runtime';
84
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
85
+ }): () => T | never;
86
+ initializeSharing(shareScopeName?: string, extraOptions?: {
87
+ initScope?: InitScope;
88
+ from?: CallFrom;
89
+ strategy?: Shared['strategy'];
90
+ }): Array<Promise<void>>;
91
+ initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
92
+ loadRemote<T>(id: string, options?: {
93
+ loadFactory?: boolean;
94
+ from: CallFrom;
95
+ }): Promise<T | null>;
96
+ preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
97
+ initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
98
+ hostShareScopeMap?: ShareScopeMap;
99
+ }): void;
100
+ formatOptions(globalOptions: Options, userOptions: UserOptions): Options;
101
+ registerPlugins(plugins: UserOptions['plugins']): void;
102
+ registerRemotes(remotes: Remote[], options?: {
103
+ force?: boolean;
104
+ }): void;
105
+ }
@@ -0,0 +1,42 @@
1
+ import { FederationHost } from './core';
2
+ import { RemoteEntryExports, GlobalShareScopeMap, Remote, Optional } from './type';
3
+ import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
4
+ import { FederationRuntimePlugin } from './type/plugin';
5
+ export interface Federation {
6
+ __GLOBAL_PLUGIN__: Array<FederationRuntimePlugin>;
7
+ __DEBUG_CONSTRUCTOR_VERSION__?: string;
8
+ moduleInfo: GlobalModuleInfo;
9
+ __DEBUG_CONSTRUCTOR__?: typeof FederationHost;
10
+ __INSTANCES__: Array<FederationHost>;
11
+ __SHARE__: GlobalShareScopeMap;
12
+ __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
13
+ __PRELOADED_MAP__: Map<string, boolean>;
14
+ }
15
+ export declare const CurrentGlobal: typeof globalThis;
16
+ export declare const nativeGlobal: typeof global;
17
+ export declare const Global: typeof globalThis;
18
+ declare global {
19
+ var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
20
+ }
21
+ export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
22
+ export declare function resetFederationGlobalInfo(): void;
23
+ export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
24
+ export declare function getGlobalFederationConstructor(): typeof FederationHost | undefined;
25
+ export declare function setGlobalFederationConstructor(FederationConstructor: typeof FederationHost | undefined, isDebug?: boolean): void;
26
+ export declare function getInfoWithoutType<T extends object>(target: T, key: keyof T): {
27
+ value: T[keyof T] | undefined;
28
+ key: string;
29
+ };
30
+ export declare const getGlobalSnapshot: () => GlobalModuleInfo;
31
+ export declare const getTargetSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, "alias">, snapshot: GlobalModuleInfo) => GlobalModuleInfo[string] | undefined;
32
+ export declare const getGlobalSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, "alias">) => GlobalModuleInfo[string] | undefined;
33
+ export declare const setGlobalSnapshotInfoByModuleInfo: (remoteInfo: Remote, moduleDetailInfo: GlobalModuleInfo[string]) => GlobalModuleInfo;
34
+ export declare const addGlobalSnapshot: (moduleInfos: GlobalModuleInfo) => (() => void);
35
+ export declare const getRemoteEntryExports: (name: string, globalName: string | undefined) => {
36
+ remoteEntryKey: string;
37
+ entryExports: RemoteEntryExports | undefined;
38
+ };
39
+ export declare const registerGlobalPlugins: (plugins: Array<FederationRuntimePlugin>) => void;
40
+ export declare const getGlobalHostPlugins: () => Array<FederationRuntimePlugin>;
41
+ export declare const getPreloaded: (id: string) => boolean | undefined;
42
+ export declare const setPreloaded: (id: string) => Map<string, boolean>;
@@ -0,0 +1,31 @@
1
+ import { resetFederationGlobalInfo, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global';
2
+ import { getRegisteredShare, getGlobalShareScope } from './utils/share';
3
+ interface IShareUtils {
4
+ getRegisteredShare: typeof getRegisteredShare;
5
+ getGlobalShareScope: typeof getGlobalShareScope;
6
+ }
7
+ interface IGlobalUtils {
8
+ Global: typeof Global;
9
+ nativeGlobal: typeof global;
10
+ resetFederationGlobalInfo: typeof resetFederationGlobalInfo;
11
+ setGlobalFederationInstance: typeof setGlobalFederationInstance;
12
+ getGlobalFederationConstructor: typeof getGlobalFederationConstructor;
13
+ setGlobalFederationConstructor: typeof setGlobalFederationConstructor;
14
+ getInfoWithoutType: typeof getInfoWithoutType;
15
+ getGlobalSnapshot: typeof getGlobalSnapshot;
16
+ getTargetSnapshotInfoByModuleInfo: typeof getTargetSnapshotInfoByModuleInfo;
17
+ getGlobalSnapshotInfoByModuleInfo: typeof getGlobalSnapshotInfoByModuleInfo;
18
+ setGlobalSnapshotInfoByModuleInfo: typeof setGlobalSnapshotInfoByModuleInfo;
19
+ addGlobalSnapshot: typeof addGlobalSnapshot;
20
+ getRemoteEntryExports: typeof getRemoteEntryExports;
21
+ registerGlobalPlugins: typeof registerGlobalPlugins;
22
+ getGlobalHostPlugins: typeof getGlobalHostPlugins;
23
+ getPreloaded: typeof getPreloaded;
24
+ setPreloaded: typeof setPreloaded;
25
+ }
26
+ declare const _default: {
27
+ global: IGlobalUtils;
28
+ share: IShareUtils;
29
+ };
30
+ export default _default;
31
+ export type { IGlobalUtils, IShareUtils };
@@ -0,0 +1,14 @@
1
+ import helpers, { type IGlobalUtils, type IShareUtils } from './helpers';
2
+ export { FederationHost } from './core';
3
+ export { type Federation, CurrentGlobal, Global, getGlobalFederationConstructor, setGlobalFederationInstance, setGlobalFederationConstructor, resetFederationGlobalInfo, addGlobalSnapshot, getGlobalSnapshot, getInfoWithoutType, } from './global';
4
+ export type { UserOptions, FederationRuntimePlugin } from './type';
5
+ export { assert } from './utils/logger';
6
+ export { registerGlobalPlugins } from './global';
7
+ export { getRemoteEntry, getRemoteInfo, isStaticResourcesEqual, matchRemoteWithNameAndExpose, safeWrapper, } from './utils';
8
+ export { getRegisteredShare } from '../src/utils/share';
9
+ export { loadScript, loadScriptNode } from '@module-federation/sdk';
10
+ export { Module } from './module';
11
+ export * as types from './type';
12
+ export { helpers };
13
+ export { satisfy } from '../src/utils/semver';
14
+ export type { IGlobalUtils, IShareUtils };
@@ -0,0 +1,21 @@
1
+ import { ModuleInfo } from '@module-federation/sdk';
2
+ import { FederationHost } from '../core';
3
+ import { RemoteEntryExports, RemoteInfo } from '../type';
4
+ export type ModuleOptions = ConstructorParameters<typeof Module>[0];
5
+ declare class Module {
6
+ remoteInfo: RemoteInfo;
7
+ inited: boolean;
8
+ remoteEntryExports?: RemoteEntryExports;
9
+ lib: RemoteEntryExports | undefined;
10
+ host: FederationHost;
11
+ constructor({ remoteInfo, host, }: {
12
+ remoteInfo: RemoteInfo;
13
+ host: FederationHost;
14
+ });
15
+ getEntry(): Promise<RemoteEntryExports>;
16
+ get(id: string, expose: string, options?: {
17
+ loadFactory?: boolean;
18
+ }, remoteSnapshot?: ModuleInfo): Promise<any>;
19
+ private wraperFactory;
20
+ }
21
+ export { Module };
@@ -0,0 +1,8 @@
1
+ import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
2
+ import { FederationRuntimePlugin, PreloadAssets, PreloadOptions, RemoteInfoOptionalVersion } from '../type';
3
+ import { FederationHost } from '../core';
4
+ declare global {
5
+ var __INIT_VMOK_DEPLOY_GLOBAL_DATA__: boolean | undefined;
6
+ }
7
+ export declare function generatePreloadAssets(origin: FederationHost, preloadOptions: PreloadOptions[number], remote: RemoteInfoOptionalVersion, globalSnapshot: GlobalModuleInfo, remoteSnapshot: ModuleInfo): PreloadAssets;
8
+ export declare const generatePreloadAssetsPlugin: () => FederationRuntimePlugin;
@@ -0,0 +1,58 @@
1
+ import { GlobalModuleInfo, Manifest, ModuleInfo } from '@module-federation/sdk';
2
+ import { Options, Remote } from '../../type';
3
+ import { getGlobalSnapshot } from '../../global';
4
+ import { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';
5
+ import { FederationHost } from '../../core';
6
+ export declare function getGlobalRemoteInfo(moduleInfo: Remote, origin: FederationHost): {
7
+ hostGlobalSnapshot: ModuleInfo | undefined;
8
+ globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
9
+ remoteSnapshot: GlobalModuleInfo[string] | undefined;
10
+ };
11
+ export declare class SnapshotHandler {
12
+ loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null;
13
+ HostInstance: FederationHost;
14
+ manifestCache: Map<string, Manifest>;
15
+ hooks: PluginSystem<{
16
+ beforeLoadRemoteSnapshot: AsyncHook<[{
17
+ options: Options;
18
+ moduleInfo: Remote;
19
+ }], void>;
20
+ loadSnapshot: AsyncWaterfallHook<{
21
+ options: Options;
22
+ moduleInfo: Remote;
23
+ hostGlobalSnapshot: GlobalModuleInfo[string] | undefined;
24
+ globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
25
+ remoteSnapshot?: GlobalModuleInfo[string] | undefined;
26
+ }>;
27
+ loadRemoteSnapshot: AsyncWaterfallHook<{
28
+ options: Options;
29
+ moduleInfo: Remote;
30
+ manifestJson?: Manifest;
31
+ manifestUrl?: string;
32
+ remoteSnapshot: ModuleInfo;
33
+ from: "global" | "manifest";
34
+ }>;
35
+ afterLoadSnapshot: AsyncWaterfallHook<{
36
+ options: Options;
37
+ moduleInfo: Remote;
38
+ remoteSnapshot: ModuleInfo;
39
+ }>;
40
+ }>;
41
+ loaderHook: FederationHost['loaderHook'];
42
+ manifestLoading: Record<string, Promise<ModuleInfo>>;
43
+ constructor(HostInstance: FederationHost);
44
+ loadSnapshot(moduleInfo: Remote): Promise<{
45
+ remoteSnapshot: GlobalModuleInfo[string] | undefined;
46
+ globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
47
+ }>;
48
+ loadRemoteSnapshotInfo(moduleInfo: Remote): Promise<{
49
+ remoteSnapshot: ModuleInfo;
50
+ globalSnapshot: GlobalModuleInfo;
51
+ }> | never;
52
+ getGlobalRemoteInfo(moduleInfo: Remote): {
53
+ hostGlobalSnapshot: ModuleInfo | undefined;
54
+ globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
55
+ remoteSnapshot: GlobalModuleInfo[string] | undefined;
56
+ };
57
+ private getManifestJson;
58
+ }
@@ -0,0 +1,5 @@
1
+ import { ModuleInfo } from '@module-federation/sdk';
2
+ import { FederationRuntimePlugin } from '../../type/plugin';
3
+ import { RemoteInfo } from '../../type';
4
+ export declare function assignRemoteInfo(remoteInfo: RemoteInfo, remoteSnapshot: ModuleInfo): void;
5
+ export declare function snapshotPlugin(): FederationRuntimePlugin;
@@ -0,0 +1,109 @@
1
+ import { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
2
+ import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports, CallFrom } from '../type';
3
+ import { FederationHost } from '../core';
4
+ import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
5
+ import { Module, ModuleOptions } from '../module';
6
+ export interface LoadRemoteMatch {
7
+ id: string;
8
+ pkgNameOrAlias: string;
9
+ expose: string;
10
+ remote: Remote;
11
+ options: Options;
12
+ origin: FederationHost;
13
+ remoteInfo: RemoteInfo;
14
+ remoteSnapshot?: ModuleInfo;
15
+ }
16
+ export declare class RemoteHandler {
17
+ host: FederationHost;
18
+ idToRemoteMap: Record<string, {
19
+ name: string;
20
+ expose: string;
21
+ }>;
22
+ hooks: PluginSystem<{
23
+ beforeRegisterRemote: SyncWaterfallHook<{
24
+ remote: Remote;
25
+ origin: FederationHost;
26
+ }>;
27
+ registerRemote: SyncWaterfallHook<{
28
+ remote: Remote;
29
+ origin: FederationHost;
30
+ }>;
31
+ beforeRequest: AsyncWaterfallHook<{
32
+ id: string;
33
+ options: Options;
34
+ origin: FederationHost;
35
+ }>;
36
+ onLoad: AsyncHook<[{
37
+ id: string;
38
+ expose: string;
39
+ pkgNameOrAlias: string;
40
+ remote: Remote;
41
+ options: ModuleOptions;
42
+ origin: FederationHost;
43
+ exposeModule: any;
44
+ exposeModuleFactory: any;
45
+ moduleInstance: Module;
46
+ }], void>;
47
+ handlePreloadModule: SyncHook<[{
48
+ id: string;
49
+ name: string;
50
+ remote: Remote;
51
+ remoteSnapshot: ModuleInfo;
52
+ preloadConfig: PreloadRemoteArgs;
53
+ origin: FederationHost;
54
+ }], void>;
55
+ errorLoadRemote: AsyncHook<[{
56
+ id: string;
57
+ error: unknown;
58
+ options?: any;
59
+ from: CallFrom;
60
+ lifecycle: "onLoad" | "beforeRequest" | "beforeLoadShare";
61
+ origin: FederationHost;
62
+ }], unknown>;
63
+ beforePreloadRemote: AsyncHook<[{
64
+ preloadOps: Array<PreloadRemoteArgs>;
65
+ options: Options;
66
+ origin: FederationHost;
67
+ }], false | void | Promise<false | void>>;
68
+ generatePreloadAssets: AsyncHook<[{
69
+ origin: FederationHost;
70
+ preloadOptions: PreloadOptions[number];
71
+ remote: Remote;
72
+ remoteInfo: RemoteInfo;
73
+ remoteSnapshot: ModuleInfo;
74
+ globalSnapshot: GlobalModuleInfo;
75
+ }], Promise<PreloadAssets>>;
76
+ afterPreloadRemote: AsyncHook<{
77
+ preloadOps: Array<PreloadRemoteArgs>;
78
+ options: Options;
79
+ origin: FederationHost;
80
+ }, false | void | Promise<false | void>>;
81
+ loadEntry: AsyncHook<[{
82
+ loaderHook: FederationHost["loaderHook"];
83
+ remoteInfo: RemoteInfo;
84
+ remoteEntryExports?: RemoteEntryExports;
85
+ }], Promise<RemoteEntryExports>>;
86
+ }>;
87
+ constructor(host: FederationHost);
88
+ formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions): Remote[];
89
+ setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch): void;
90
+ loadRemote<T>(id: string, options?: {
91
+ loadFactory?: boolean;
92
+ from: CallFrom;
93
+ }): Promise<T | null>;
94
+ preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
95
+ registerRemotes(remotes: Remote[], options?: {
96
+ force?: boolean;
97
+ }): void;
98
+ getRemoteModuleAndOptions(options: {
99
+ id: string;
100
+ }): Promise<{
101
+ module: Module;
102
+ moduleOptions: ModuleOptions;
103
+ remoteMatchInfo: LoadRemoteMatch;
104
+ }>;
105
+ registerRemote(remote: Remote, targetRemotes: Remote[], options?: {
106
+ force?: boolean;
107
+ }): void;
108
+ private removeRemote;
109
+ }
@@ -0,0 +1,66 @@
1
+ import { Federation } from '../global';
2
+ import { Options, ShareScopeMap, ShareInfos, Shared, UserOptions, ShareStrategy, InitScope, InitTokens, CallFrom } from '../type';
3
+ import { FederationHost } from '../core';
4
+ import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncWaterfallHook } from '../utils/hooks';
5
+ import { LoadRemoteMatch } from '../remote';
6
+ export declare class SharedHandler {
7
+ host: FederationHost;
8
+ shareScopeMap: ShareScopeMap;
9
+ hooks: PluginSystem<{
10
+ afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
11
+ beforeLoadShare: AsyncWaterfallHook<{
12
+ pkgName: string;
13
+ shareInfo?: Shared;
14
+ shared: Options["shared"];
15
+ origin: FederationHost;
16
+ }>;
17
+ loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
18
+ resolveShare: SyncWaterfallHook<{
19
+ shareScopeMap: ShareScopeMap;
20
+ scope: string;
21
+ pkgName: string;
22
+ version: string;
23
+ GlobalFederation: Federation;
24
+ resolver: () => Shared | undefined;
25
+ }>;
26
+ initContainerShareScopeMap: SyncWaterfallHook<{
27
+ shareScope: ShareScopeMap[string];
28
+ options: Options;
29
+ origin: FederationHost;
30
+ scopeName: string;
31
+ hostShareScopeMap?: ShareScopeMap;
32
+ }>;
33
+ }>;
34
+ initTokens: InitTokens;
35
+ constructor(host: FederationHost);
36
+ registerShared(globalOptions: Options, userOptions: UserOptions): {
37
+ shareInfos: ShareInfos;
38
+ shared: {
39
+ [x: string]: Shared[];
40
+ };
41
+ };
42
+ loadShare<T>(pkgName: string, extraOptions?: {
43
+ customShareInfo?: Partial<Shared>;
44
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
45
+ }): Promise<false | (() => T | undefined)>;
46
+ /**
47
+ * This function initializes the sharing sequence (executed only once per share scope).
48
+ * It accepts one argument, the name of the share scope.
49
+ * If the share scope does not exist, it creates one.
50
+ */
51
+ initializeSharing(shareScopeName?: string, extraOptions?: {
52
+ initScope?: InitScope;
53
+ from?: CallFrom;
54
+ strategy?: ShareStrategy;
55
+ }): Array<Promise<void>>;
56
+ loadShareSync<T>(pkgName: string, extraOptions?: {
57
+ from?: 'build' | 'runtime';
58
+ customShareInfo?: Partial<Shared>;
59
+ resolver?: (sharedOptions: ShareInfos[string]) => Shared;
60
+ }): () => T | never;
61
+ initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
62
+ hostShareScopeMap?: ShareScopeMap;
63
+ }): void;
64
+ private setShared;
65
+ private _setGlobalShareScopeMap;
66
+ }