@module-federation/webpack-bundler-runtime 2.0.1 → 2.1.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.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/attachShareScopeMap.cjs +11 -0
- package/dist/attachShareScopeMap.cjs.map +1 -0
- package/dist/attachShareScopeMap.d.ts +7 -0
- package/dist/attachShareScopeMap.js +10 -0
- package/dist/attachShareScopeMap.js.map +1 -0
- package/dist/constant.cjs +8 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.d.ts +5 -1
- package/dist/constant.js +6 -0
- package/dist/constant.js.map +1 -0
- package/dist/consumes.cjs +55 -0
- package/dist/consumes.cjs.map +1 -0
- package/dist/consumes.js +55 -0
- package/dist/consumes.js.map +1 -0
- package/dist/getSharedFallbackGetter.cjs +27 -0
- package/dist/getSharedFallbackGetter.cjs.map +1 -0
- package/dist/getSharedFallbackGetter.js +26 -0
- package/dist/getSharedFallbackGetter.js.map +1 -0
- package/dist/getUsedExports.cjs +11 -0
- package/dist/getUsedExports.cjs.map +1 -0
- package/dist/getUsedExports.js +10 -0
- package/dist/getUsedExports.js.map +1 -0
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +48 -2
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/init.cjs +82 -0
- package/dist/init.cjs.map +1 -0
- package/dist/init.js +80 -0
- package/dist/init.js.map +1 -0
- package/dist/initContainerEntry.cjs +43 -0
- package/dist/initContainerEntry.cjs.map +1 -0
- package/dist/initContainerEntry.d.ts +7 -0
- package/dist/initContainerEntry.js +42 -0
- package/dist/initContainerEntry.js.map +1 -0
- package/dist/initializeSharing.cjs +61 -0
- package/dist/initializeSharing.cjs.map +1 -0
- package/dist/initializeSharing.d.ts +13 -0
- package/dist/initializeSharing.js +61 -0
- package/dist/initializeSharing.js.map +1 -0
- package/dist/installInitialConsumes.cjs +63 -0
- package/dist/installInitialConsumes.cjs.map +1 -0
- package/dist/installInitialConsumes.js +63 -0
- package/dist/installInitialConsumes.js.map +1 -0
- package/dist/remotes.cjs +74 -0
- package/dist/remotes.cjs.map +1 -0
- package/dist/remotes.js +73 -0
- package/dist/remotes.js.map +1 -0
- package/dist/runtime-core/dist/core.d.ts +132 -0
- package/dist/runtime-core/dist/global.d.ts +25 -0
- package/dist/runtime-core/dist/helpers.d.ts +4 -0
- package/dist/runtime-core/dist/index.d.ts +15 -0
- package/dist/runtime-core/dist/module/index.d.ts +33 -0
- package/dist/runtime-core/dist/plugins/snapshot/SnapshotHandler.d.ts +68 -0
- package/dist/runtime-core/dist/remote/index.d.ts +121 -0
- package/dist/runtime-core/dist/shared/index.d.ts +85 -0
- package/dist/runtime-core/dist/type/config.d.ts +117 -0
- package/dist/runtime-core/dist/type/index.d.ts +3 -0
- package/dist/runtime-core/dist/type/plugin.d.ts +28 -0
- package/dist/runtime-core/dist/type/preload.d.ts +32 -0
- package/dist/runtime-core/dist/types.d.ts +4 -0
- package/dist/runtime-core/dist/utils/env.d.ts +1 -0
- package/dist/runtime-core/dist/utils/hooks/asyncHook.d.ts +11 -0
- package/dist/runtime-core/dist/utils/hooks/asyncWaterfallHooks.d.ts +13 -0
- package/dist/runtime-core/dist/utils/hooks/pluginSystem.d.ts +20 -0
- package/dist/runtime-core/dist/utils/hooks/syncHook.d.ts +17 -0
- package/dist/runtime-core/dist/utils/hooks/syncWaterfallHook.d.ts +12 -0
- package/dist/runtime-core/dist/utils/index.d.ts +2 -0
- package/dist/runtime-core/dist/utils/load.d.ts +16 -0
- package/dist/runtime-core/dist/utils/logger.d.ts +1 -0
- package/dist/runtime-core/dist/utils/manifest.d.ts +2 -0
- package/dist/runtime-core/dist/utils/plugin.d.ts +2 -0
- package/dist/runtime-core/dist/utils/preload.d.ts +4 -0
- package/dist/runtime-core/dist/utils/share.d.ts +3 -0
- package/dist/runtime-core/dist/utils/tool.d.ts +1 -0
- package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +13 -0
- package/dist/types.d.ts +201 -0
- package/dist/updateOptions.cjs +112 -0
- package/dist/updateOptions.cjs.map +1 -0
- package/dist/updateOptions.js +110 -0
- package/dist/updateOptions.js.map +1 -0
- package/package.json +9 -9
- package/dist/constant.cjs.cjs +0 -6
- package/dist/constant.cjs.cjs.map +0 -1
- package/dist/constant.cjs.d.ts +0 -1
- package/dist/constant.esm.js +0 -4
- package/dist/constant.esm.js.map +0 -1
- package/dist/index.cjs.cjs +0 -793
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -2
- package/dist/index.esm.js +0 -772
- package/dist/index.esm.js.map +0 -1
- package/dist/src/attachShareScopeMap.d.ts +0 -2
- package/dist/src/constant.d.ts +0 -1
- package/dist/src/consumes.d.ts +0 -2
- package/dist/src/getSharedFallbackGetter.d.ts +0 -2
- package/dist/src/getUsedExports.d.ts +0 -2
- package/dist/src/index.d.ts +0 -39
- package/dist/src/init.d.ts +0 -4
- package/dist/src/initContainerEntry.d.ts +0 -2
- package/dist/src/initializeSharing.d.ts +0 -2
- package/dist/src/installInitialConsumes.d.ts +0 -2
- package/dist/src/remotes.d.ts +0 -2
- package/dist/src/types.d.ts +0 -194
- package/dist/src/updateOptions.d.ts +0 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ModuleFederationRuntimePlugin } from "./plugin.js";
|
|
2
|
+
import { Module, RemoteEntryType, RemoteWithEntry, RemoteWithVersion, TreeShakingStatus } from "@module-federation/sdk";
|
|
3
|
+
|
|
4
|
+
//#region ../runtime-core/dist/type/config.d.ts
|
|
5
|
+
//#region src/type/config.d.ts
|
|
6
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
7
|
+
interface RemoteInfoCommon {
|
|
8
|
+
alias?: string;
|
|
9
|
+
shareScope?: string | string[];
|
|
10
|
+
type?: RemoteEntryType;
|
|
11
|
+
entryGlobalName?: string;
|
|
12
|
+
}
|
|
13
|
+
type Remote = (RemoteWithEntry | RemoteWithVersion) & RemoteInfoCommon;
|
|
14
|
+
interface RemoteInfo {
|
|
15
|
+
alias?: string;
|
|
16
|
+
name: string;
|
|
17
|
+
version?: string;
|
|
18
|
+
buildVersion?: string;
|
|
19
|
+
entry: string;
|
|
20
|
+
type: RemoteEntryType;
|
|
21
|
+
entryGlobalName: string;
|
|
22
|
+
shareScope: string | string[];
|
|
23
|
+
}
|
|
24
|
+
interface SharedConfig {
|
|
25
|
+
singleton?: boolean;
|
|
26
|
+
requiredVersion: false | string;
|
|
27
|
+
eager?: boolean;
|
|
28
|
+
strictVersion?: boolean;
|
|
29
|
+
layer?: string | null;
|
|
30
|
+
}
|
|
31
|
+
type TreeShakingArgs = {
|
|
32
|
+
usedExports?: string[];
|
|
33
|
+
get?: SharedGetter;
|
|
34
|
+
lib?: () => Module;
|
|
35
|
+
status?: TreeShakingStatus;
|
|
36
|
+
mode?: 'server-calc' | 'runtime-infer';
|
|
37
|
+
loading?: null | Promise<any>;
|
|
38
|
+
loaded?: boolean;
|
|
39
|
+
useIn?: Array<string>;
|
|
40
|
+
};
|
|
41
|
+
type SharedBaseArgs = {
|
|
42
|
+
version?: string;
|
|
43
|
+
shareConfig?: SharedConfig;
|
|
44
|
+
scope?: string | Array<string>;
|
|
45
|
+
deps?: Array<string>;
|
|
46
|
+
strategy?: 'version-first' | 'loaded-first';
|
|
47
|
+
loaded?: boolean;
|
|
48
|
+
treeShaking?: TreeShakingArgs;
|
|
49
|
+
};
|
|
50
|
+
type SharedGetter = (() => () => Module) | (() => Promise<() => Module>);
|
|
51
|
+
type ShareArgs = (SharedBaseArgs & {
|
|
52
|
+
get: SharedGetter;
|
|
53
|
+
}) | (SharedBaseArgs & {
|
|
54
|
+
lib: () => Module;
|
|
55
|
+
}) | SharedBaseArgs;
|
|
56
|
+
type ShareStrategy = 'version-first' | 'loaded-first';
|
|
57
|
+
type Shared = {
|
|
58
|
+
version: string;
|
|
59
|
+
get: SharedGetter;
|
|
60
|
+
shareConfig: SharedConfig;
|
|
61
|
+
scope: Array<string>;
|
|
62
|
+
useIn: Array<string>;
|
|
63
|
+
from: string;
|
|
64
|
+
deps: Array<string>;
|
|
65
|
+
lib?: () => Module;
|
|
66
|
+
loaded?: boolean;
|
|
67
|
+
loading?: null | Promise<any>;
|
|
68
|
+
eager?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated set in initOptions.shareStrategy instead
|
|
71
|
+
*/
|
|
72
|
+
strategy: ShareStrategy;
|
|
73
|
+
treeShaking?: TreeShakingArgs;
|
|
74
|
+
};
|
|
75
|
+
type ShareScopeMap = {
|
|
76
|
+
[scope: string]: {
|
|
77
|
+
[pkgName: string]: {
|
|
78
|
+
[sharedVersion: string]: Shared;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
type GlobalShareScopeMap = {
|
|
83
|
+
[instanceName: string]: ShareScopeMap;
|
|
84
|
+
};
|
|
85
|
+
type ShareInfos = {
|
|
86
|
+
[pkgName: string]: Shared[];
|
|
87
|
+
};
|
|
88
|
+
interface Options {
|
|
89
|
+
id?: string;
|
|
90
|
+
name: string;
|
|
91
|
+
version?: string;
|
|
92
|
+
remotes: Array<Remote>;
|
|
93
|
+
shared: ShareInfos;
|
|
94
|
+
plugins: Array<ModuleFederationRuntimePlugin>;
|
|
95
|
+
inBrowser: boolean;
|
|
96
|
+
shareStrategy?: ShareStrategy;
|
|
97
|
+
}
|
|
98
|
+
type UserOptions = Omit<Optional<Options, 'plugins'>, 'shared' | 'inBrowser'> & {
|
|
99
|
+
shared?: {
|
|
100
|
+
[pkgName: string]: ShareArgs | ShareArgs[];
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
type RemoteEntryInitOptions = {
|
|
104
|
+
version: string;
|
|
105
|
+
shareScopeMap?: ShareScopeMap;
|
|
106
|
+
shareScopeKeys: string | string[];
|
|
107
|
+
};
|
|
108
|
+
type InitTokens = Record<string, Record<string, any>>;
|
|
109
|
+
type InitScope = InitTokens[];
|
|
110
|
+
type CallFrom = 'build' | 'runtime';
|
|
111
|
+
type RemoteEntryExports = {
|
|
112
|
+
get: (id: string) => () => Promise<Module>;
|
|
113
|
+
init: (shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void | Promise<void>;
|
|
114
|
+
}; //#endregion
|
|
115
|
+
//#endregion
|
|
116
|
+
export { CallFrom, GlobalShareScopeMap, InitScope, InitTokens, Optional, Options, Remote, RemoteEntryExports, RemoteEntryInitOptions, RemoteInfo, RemoteInfoCommon, ShareArgs, ShareInfos, ShareScopeMap, ShareStrategy, Shared, SharedConfig, SharedGetter, TreeShakingArgs, UserOptions };
|
|
117
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RemoteHandler } from "../remote/index.js";
|
|
2
|
+
import { SharedHandler } from "../shared/index.js";
|
|
3
|
+
import { SnapshotHandler } from "../plugins/snapshot/SnapshotHandler.js";
|
|
4
|
+
import { ModuleFederation } from "../core.js";
|
|
5
|
+
import { Module$1 } from "../module/index.js";
|
|
6
|
+
|
|
7
|
+
//#region ../runtime-core/dist/type/plugin.d.ts
|
|
8
|
+
//#region src/type/plugin.d.ts
|
|
9
|
+
type CoreLifeCycle = ModuleFederation['hooks']['lifecycle'];
|
|
10
|
+
type CoreLifeCyclePartial = Partial<{ [k in keyof CoreLifeCycle]: Parameters<CoreLifeCycle[k]['on']>[0] }>;
|
|
11
|
+
type SnapshotLifeCycle = SnapshotHandler['hooks']['lifecycle'];
|
|
12
|
+
type SnapshotLifeCycleCyclePartial = Partial<{ [k in keyof SnapshotLifeCycle]: Parameters<SnapshotLifeCycle[k]['on']>[0] }>;
|
|
13
|
+
type ModuleLifeCycle = Module$1['host']['loaderHook']['lifecycle'];
|
|
14
|
+
type ModuleLifeCycleCyclePartial = Partial<{ [k in keyof ModuleLifeCycle]: Parameters<ModuleLifeCycle[k]['on']>[0] }>;
|
|
15
|
+
type ModuleBridgeLifeCycle = Module$1['host']['bridgeHook']['lifecycle'];
|
|
16
|
+
type ModuleBridgeLifeCycleCyclePartial = Partial<{ [k in keyof ModuleBridgeLifeCycle]: Parameters<ModuleBridgeLifeCycle[k]['on']>[0] }>;
|
|
17
|
+
type SharedLifeCycle = SharedHandler['hooks']['lifecycle'];
|
|
18
|
+
type SharedLifeCycleCyclePartial = Partial<{ [k in keyof SharedLifeCycle]: Parameters<SharedLifeCycle[k]['on']>[0] }>;
|
|
19
|
+
type RemoteLifeCycle = RemoteHandler['hooks']['lifecycle'];
|
|
20
|
+
type RemoteLifeCycleCyclePartial = Partial<{ [k in keyof RemoteLifeCycle]: Parameters<RemoteLifeCycle[k]['on']>[0] }>;
|
|
21
|
+
type ModuleFederationRuntimePlugin = CoreLifeCyclePartial & SnapshotLifeCycleCyclePartial & SharedLifeCycleCyclePartial & RemoteLifeCycleCyclePartial & ModuleLifeCycleCyclePartial & ModuleBridgeLifeCycleCyclePartial & {
|
|
22
|
+
name: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
apply?: (instance: ModuleFederation) => void;
|
|
25
|
+
}; //#endregion
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ModuleFederationRuntimePlugin };
|
|
28
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Remote, RemoteInfo } from "./config.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime-core/dist/type/preload.d.ts
|
|
4
|
+
//#region src/type/preload.d.ts
|
|
5
|
+
type depsPreloadArg = Omit<PreloadRemoteArgs, 'depsRemote'>;
|
|
6
|
+
interface PreloadRemoteArgs {
|
|
7
|
+
nameOrAlias: string;
|
|
8
|
+
exposes?: Array<string>;
|
|
9
|
+
resourceCategory?: 'all' | 'sync';
|
|
10
|
+
share?: boolean;
|
|
11
|
+
depsRemote?: boolean | Array<depsPreloadArg>;
|
|
12
|
+
filter?: (assetUrl: string) => boolean;
|
|
13
|
+
prefetchInterface?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type PreloadConfig = PreloadRemoteArgs;
|
|
16
|
+
type PreloadOptions = Array<{
|
|
17
|
+
remote: Remote;
|
|
18
|
+
preloadConfig: PreloadConfig;
|
|
19
|
+
}>;
|
|
20
|
+
type EntryAssets = {
|
|
21
|
+
name: string;
|
|
22
|
+
url: string;
|
|
23
|
+
moduleInfo: RemoteInfo;
|
|
24
|
+
};
|
|
25
|
+
interface PreloadAssets {
|
|
26
|
+
cssAssets: Array<string>;
|
|
27
|
+
jsAssetsWithoutEntry: Array<string>;
|
|
28
|
+
entryAssets: Array<EntryAssets>;
|
|
29
|
+
} //#endregion
|
|
30
|
+
//#endregion
|
|
31
|
+
export { EntryAssets, PreloadAssets, PreloadConfig, PreloadOptions, PreloadRemoteArgs, depsPreloadArg };
|
|
32
|
+
//# sourceMappingURL=preload.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CallFrom, GlobalShareScopeMap, InitScope, InitTokens, Optional, Options, Remote, RemoteEntryExports, RemoteEntryInitOptions, RemoteInfo, RemoteInfoCommon, ShareArgs, ShareInfos, ShareScopeMap, ShareStrategy, Shared, SharedConfig, SharedGetter, TreeShakingArgs, UserOptions } from "./type/config.js";
|
|
2
|
+
import { EntryAssets, PreloadAssets, PreloadConfig, PreloadOptions, PreloadRemoteArgs, depsPreloadArg } from "./type/preload.js";
|
|
3
|
+
import "./type/index.js";
|
|
4
|
+
import { ModuleFederationRuntimePlugin } from "./type/plugin.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@module-federation/sdk";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ArgsType, SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime-core/dist/utils/hooks/asyncHook.d.ts
|
|
4
|
+
//#region src/utils/hooks/asyncHook.d.ts
|
|
5
|
+
type CallbackReturnType = void | false | Promise<void | false>;
|
|
6
|
+
declare class AsyncHook<T, ExternalEmitReturnType = CallbackReturnType> extends SyncHook<T, ExternalEmitReturnType> {
|
|
7
|
+
emit(...data: ArgsType<T>): Promise<void | false | ExternalEmitReturnType>;
|
|
8
|
+
} //#endregion
|
|
9
|
+
//#endregion
|
|
10
|
+
export { AsyncHook };
|
|
11
|
+
//# sourceMappingURL=asyncHook.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime-core/dist/utils/hooks/asyncWaterfallHooks.d.ts
|
|
4
|
+
//#region src/utils/hooks/asyncWaterfallHooks.d.ts
|
|
5
|
+
type CallbackReturnType<T> = T | Promise<T>;
|
|
6
|
+
declare class AsyncWaterfallHook<T extends Record<string, any>> extends SyncHook<[T], CallbackReturnType<T>> {
|
|
7
|
+
onerror: (errMsg: string | Error | unknown) => void;
|
|
8
|
+
constructor(type: string);
|
|
9
|
+
emit(data: T): Promise<T>;
|
|
10
|
+
} //#endregion
|
|
11
|
+
//#endregion
|
|
12
|
+
export { AsyncWaterfallHook };
|
|
13
|
+
//# sourceMappingURL=asyncWaterfallHooks.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ModuleFederation } from "../../core.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime-core/dist/utils/hooks/pluginSystem.d.ts
|
|
4
|
+
//#region src/utils/hooks/pluginSystem.d.ts
|
|
5
|
+
type Plugin<T extends Record<string, any>> = { [k in keyof T]?: Parameters<T[k]['on']>[0] } & {
|
|
6
|
+
name: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
apply?: (instance: ModuleFederation) => void;
|
|
9
|
+
};
|
|
10
|
+
declare class PluginSystem<T extends Record<string, any>> {
|
|
11
|
+
lifecycle: T;
|
|
12
|
+
lifecycleKeys: Array<keyof T>;
|
|
13
|
+
registerPlugins: Record<string, Plugin<T>>;
|
|
14
|
+
constructor(lifecycle: T);
|
|
15
|
+
applyPlugin(plugin: Plugin<T>, instance: ModuleFederation): void;
|
|
16
|
+
removePlugin(pluginName: string): void;
|
|
17
|
+
} //#endregion
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PluginSystem };
|
|
20
|
+
//# sourceMappingURL=pluginSystem.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region ../runtime-core/dist/utils/hooks/syncHook.d.ts
|
|
2
|
+
//#region src/utils/hooks/syncHook.d.ts
|
|
3
|
+
type Callback<T, K> = (...args: ArgsType<T>) => K;
|
|
4
|
+
type ArgsType<T> = T extends Array<any> ? T : Array<any>;
|
|
5
|
+
declare class SyncHook<T, K> {
|
|
6
|
+
type: string;
|
|
7
|
+
listeners: Set<Callback<T, K>>;
|
|
8
|
+
constructor(type?: string);
|
|
9
|
+
on(fn: Callback<T, K>): void;
|
|
10
|
+
once(fn: Callback<T, K>): void;
|
|
11
|
+
emit(...data: ArgsType<T>): void | K | Promise<any>;
|
|
12
|
+
remove(fn: Callback<T, K>): void;
|
|
13
|
+
removeAll(): void;
|
|
14
|
+
} //#endregion
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ArgsType, SyncHook };
|
|
17
|
+
//# sourceMappingURL=syncHook.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SyncHook } from "./syncHook.js";
|
|
2
|
+
|
|
3
|
+
//#region ../runtime-core/dist/utils/hooks/syncWaterfallHook.d.ts
|
|
4
|
+
//#region src/utils/hooks/syncWaterfallHook.d.ts
|
|
5
|
+
declare class SyncWaterfallHook<T extends Record<string, any>> extends SyncHook<[T], T> {
|
|
6
|
+
onerror: (errMsg: string | Error | unknown) => void;
|
|
7
|
+
constructor(type: string);
|
|
8
|
+
emit(data: T): T;
|
|
9
|
+
} //#endregion
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SyncWaterfallHook };
|
|
12
|
+
//# sourceMappingURL=syncWaterfallHook.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RemoteEntryExports, RemoteInfo } from "../type/config.js";
|
|
2
|
+
import "../type/index.js";
|
|
3
|
+
import { ModuleFederation } from "../core.js";
|
|
4
|
+
|
|
5
|
+
//#region ../runtime-core/dist/utils/load.d.ts
|
|
6
|
+
//#region src/utils/load.d.ts
|
|
7
|
+
declare function getRemoteEntry(params: {
|
|
8
|
+
origin: ModuleFederation;
|
|
9
|
+
remoteInfo: RemoteInfo;
|
|
10
|
+
remoteEntryExports?: RemoteEntryExports | undefined;
|
|
11
|
+
getEntryUrl?: (url: string) => string;
|
|
12
|
+
_inErrorHandling?: boolean;
|
|
13
|
+
}): Promise<RemoteEntryExports | false | void>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getRemoteEntry };
|
|
16
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@module-federation/sdk";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../type/index.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "webpack";
|
|
2
|
+
|
|
3
|
+
//#region ../sdk/dist/types/plugins/ModuleFederationPlugin.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).
|
|
6
|
+
*/
|
|
7
|
+
type ExternalsType = 'var' | 'module' | 'assign' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system' | 'promise' | 'import' | 'script' | 'module-import' | 'node-commonjs';
|
|
8
|
+
/**
|
|
9
|
+
* Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.
|
|
10
|
+
*/
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ExternalsType };
|
|
13
|
+
//# sourceMappingURL=ModuleFederationPlugin.d.ts.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { initializeSharing } from "./initializeSharing.js";
|
|
2
|
+
import { attachShareScopeMap } from "./attachShareScopeMap.js";
|
|
3
|
+
import { initContainerEntry } from "./initContainerEntry.js";
|
|
4
|
+
import * as runtime from "@module-federation/runtime";
|
|
5
|
+
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
6
|
+
import { Remote, RemoteEntryInitOptions, SharedConfig, SharedGetter, TreeShakingArgs } from "@module-federation/runtime/types";
|
|
7
|
+
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
type ExcludeUndefined<T> = T extends undefined ? never : T;
|
|
10
|
+
type Shared = InitOptions['shared'];
|
|
11
|
+
type NonUndefined<T = Shared> = ExcludeUndefined<T>;
|
|
12
|
+
type InitOptions = Omit<Parameters<typeof runtime.init>[0], 'remotes'> & {
|
|
13
|
+
remotes: Array<Remote & {
|
|
14
|
+
externalType: moduleFederationPlugin.ExternalsType;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
type ModuleCache = runtime.ModuleFederation['moduleCache'];
|
|
18
|
+
type InferModule<T> = T extends Map<string, infer U> ? U : never;
|
|
19
|
+
type InferredModule = InferModule<ModuleCache>;
|
|
20
|
+
type ShareScopeMap = runtime.ModuleFederation['shareScopeMap'];
|
|
21
|
+
type InitToken = Record<string, Record<string, any>>;
|
|
22
|
+
interface InitializeSharingOptions {
|
|
23
|
+
shareScopeName: string | string[];
|
|
24
|
+
webpackRequire: WebpackRequire;
|
|
25
|
+
initPromises: Record<string, Promise<boolean> | boolean>;
|
|
26
|
+
initTokens: InitToken;
|
|
27
|
+
initScope: InitToken[];
|
|
28
|
+
}
|
|
29
|
+
type RemoteEntryExports = NonUndefined<InferredModule['remoteEntryExports']>;
|
|
30
|
+
type ExtractInitParameters<T> = T extends {
|
|
31
|
+
init: (shareScope: infer U, ...args: any[]) => void;
|
|
32
|
+
} ? U : never;
|
|
33
|
+
type InferredShareScope = ExtractInitParameters<RemoteEntryExports>;
|
|
34
|
+
type InferredGlobalShareScope = {
|
|
35
|
+
[scope: string]: InferredShareScope;
|
|
36
|
+
};
|
|
37
|
+
type IdToExternalAndNameMappingItem = [string | string[], string, string | number];
|
|
38
|
+
interface IdToExternalAndNameMappingItemWithPromise extends IdToExternalAndNameMappingItem {
|
|
39
|
+
p?: Promise<any> | number;
|
|
40
|
+
}
|
|
41
|
+
type IdToExternalAndNameMapping = Record<string, IdToExternalAndNameMappingItemWithPromise>;
|
|
42
|
+
type ModuleId = string | number;
|
|
43
|
+
type RemoteDataItem = {
|
|
44
|
+
shareScope: string | string[];
|
|
45
|
+
name: string;
|
|
46
|
+
externalModuleId: ModuleId;
|
|
47
|
+
remoteName: string;
|
|
48
|
+
};
|
|
49
|
+
type ModuleIdToRemoteDataMapping = Record<ModuleId, RemoteDataItem>;
|
|
50
|
+
type ModuleIdToConsumeDataMapping = {
|
|
51
|
+
fallback: () => Promise<any>;
|
|
52
|
+
shareKey: string;
|
|
53
|
+
shareScope: string | string[];
|
|
54
|
+
treeShakingMode?: 'server-calc' | 'runtime-infer';
|
|
55
|
+
} & SharedConfig;
|
|
56
|
+
type WithStatus<T> = T & {
|
|
57
|
+
_updated: number;
|
|
58
|
+
};
|
|
59
|
+
type ConsumesLoadingData = WithStatus<{
|
|
60
|
+
chunkMapping?: Record<string, Array<string | number>>;
|
|
61
|
+
moduleIdToConsumeDataMapping?: Record<string, ModuleIdToConsumeDataMapping>;
|
|
62
|
+
initialConsumes?: Array<ModuleId>;
|
|
63
|
+
}>;
|
|
64
|
+
type RemotesLoadingData = WithStatus<{
|
|
65
|
+
chunkMapping?: Record<string, Array<ModuleId>>;
|
|
66
|
+
moduleIdToRemoteDataMapping?: ModuleIdToRemoteDataMapping;
|
|
67
|
+
}>;
|
|
68
|
+
type InitializeSharingData = WithStatus<{
|
|
69
|
+
scopeToSharingDataMapping: {
|
|
70
|
+
[shareScope: string]: Array<{
|
|
71
|
+
name: string;
|
|
72
|
+
version: string;
|
|
73
|
+
factory: SharedGetter;
|
|
74
|
+
eager?: boolean;
|
|
75
|
+
singleton?: boolean;
|
|
76
|
+
requiredVersion?: string;
|
|
77
|
+
strictVersion?: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
uniqueName: string;
|
|
81
|
+
}>;
|
|
82
|
+
interface WebpackRequire {
|
|
83
|
+
(moduleId: string | number): any;
|
|
84
|
+
p: string;
|
|
85
|
+
o: (obj: Record<string, any>, key: string | number) => boolean;
|
|
86
|
+
R: Array<string | number>;
|
|
87
|
+
m: Record<string, (mod: any) => any>;
|
|
88
|
+
j?: string;
|
|
89
|
+
c: Record<string, any>;
|
|
90
|
+
I: (scopeName: string | string[], initScope?: InitializeSharingOptions['initScope']) => ReturnType<typeof initializeSharing>;
|
|
91
|
+
S?: InferredGlobalShareScope;
|
|
92
|
+
federation: Federation;
|
|
93
|
+
consumesLoadingData?: ConsumesLoadingData;
|
|
94
|
+
remotesLoadingData?: RemotesLoadingData;
|
|
95
|
+
initializeSharingData?: InitializeSharingData;
|
|
96
|
+
}
|
|
97
|
+
interface ShareInfo {
|
|
98
|
+
shareConfig: SharedConfig;
|
|
99
|
+
scope: Array<string>;
|
|
100
|
+
treeShaking?: TreeShakingArgs;
|
|
101
|
+
}
|
|
102
|
+
interface ModuleToHandlerMappingItem {
|
|
103
|
+
getter: () => Promise<any>;
|
|
104
|
+
shareInfo: ShareInfo;
|
|
105
|
+
shareKey: string;
|
|
106
|
+
treeShakingGetter?: () => Promise<any>;
|
|
107
|
+
}
|
|
108
|
+
interface IdToRemoteMapItem {
|
|
109
|
+
externalType: string;
|
|
110
|
+
name: string;
|
|
111
|
+
}
|
|
112
|
+
type IdToRemoteMap = Record<string, IdToRemoteMapItem[]>;
|
|
113
|
+
type RemoteInfos = Record<string, Array<IdToRemoteMapItem & {
|
|
114
|
+
alias: string;
|
|
115
|
+
entry?: string;
|
|
116
|
+
shareScope: string;
|
|
117
|
+
}>>;
|
|
118
|
+
type RemoteChunkMapping = Record<string, Array<ModuleId>>;
|
|
119
|
+
type CoreRemotesOptions = {
|
|
120
|
+
idToRemoteMap: IdToRemoteMap;
|
|
121
|
+
chunkMapping: RemoteChunkMapping;
|
|
122
|
+
idToExternalAndNameMapping: IdToExternalAndNameMapping;
|
|
123
|
+
};
|
|
124
|
+
type RemotesOptions = {
|
|
125
|
+
chunkId: string | number;
|
|
126
|
+
promises: Promise<any>[];
|
|
127
|
+
webpackRequire: WebpackRequire;
|
|
128
|
+
} & CoreRemotesOptions;
|
|
129
|
+
interface HandleInitialConsumesOptions {
|
|
130
|
+
moduleId: string | number;
|
|
131
|
+
moduleToHandlerMapping: Record<string, ModuleToHandlerMappingItem>;
|
|
132
|
+
webpackRequire: WebpackRequire;
|
|
133
|
+
asyncLoad?: boolean;
|
|
134
|
+
}
|
|
135
|
+
interface InstallInitialConsumesOptions {
|
|
136
|
+
moduleToHandlerMapping: Record<string, ModuleToHandlerMappingItem>;
|
|
137
|
+
webpackRequire: WebpackRequire;
|
|
138
|
+
installedModules: Record<string, Promise<any> | 0>;
|
|
139
|
+
initialConsumes: Array<string | number>;
|
|
140
|
+
asyncLoad?: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface ConsumesOptions {
|
|
143
|
+
chunkId: string | number;
|
|
144
|
+
promises: Promise<any>[];
|
|
145
|
+
chunkMapping: Record<string, Array<string | number>>;
|
|
146
|
+
installedModules: Record<string, Promise<any> | 0>;
|
|
147
|
+
moduleToHandlerMapping: Record<string, ModuleToHandlerMappingItem>;
|
|
148
|
+
webpackRequire: WebpackRequire;
|
|
149
|
+
}
|
|
150
|
+
interface InitContainerEntryOptions {
|
|
151
|
+
shareScope: ShareScopeMap[string];
|
|
152
|
+
shareScopeKey: string | string[];
|
|
153
|
+
webpackRequire: WebpackRequire;
|
|
154
|
+
remoteEntryInitOptions?: RemoteEntryInitOptions;
|
|
155
|
+
initScope?: InitializeSharingOptions['initScope'];
|
|
156
|
+
}
|
|
157
|
+
interface GetSharedFallbackGetterOptions {
|
|
158
|
+
shareKey: string;
|
|
159
|
+
factory: SharedGetter;
|
|
160
|
+
version?: string;
|
|
161
|
+
webpackRequire: WebpackRequire;
|
|
162
|
+
libraryType?: string;
|
|
163
|
+
}
|
|
164
|
+
interface Federation {
|
|
165
|
+
runtime?: typeof runtime;
|
|
166
|
+
instance?: runtime.ModuleFederation;
|
|
167
|
+
initOptions?: InitOptions;
|
|
168
|
+
installInitialConsumes?: (options: InstallInitialConsumesOptions) => any;
|
|
169
|
+
bundlerRuntime?: {
|
|
170
|
+
remotes: (options: RemotesOptions) => void;
|
|
171
|
+
consumes: (options: ConsumesOptions) => void;
|
|
172
|
+
I: typeof initializeSharing;
|
|
173
|
+
S: InferredGlobalShareScope;
|
|
174
|
+
installInitialConsumes: (options: InstallInitialConsumesOptions) => any;
|
|
175
|
+
initContainerEntry: typeof initContainerEntry;
|
|
176
|
+
init: ({
|
|
177
|
+
webpackRequire,
|
|
178
|
+
libraryType
|
|
179
|
+
}: {
|
|
180
|
+
webpackRequire: WebpackRequire;
|
|
181
|
+
libraryType: string;
|
|
182
|
+
}) => void;
|
|
183
|
+
getSharedFallbackGetter: (options: GetSharedFallbackGetterOptions) => SharedGetter;
|
|
184
|
+
};
|
|
185
|
+
bundlerRuntimeOptions: {
|
|
186
|
+
remotes?: Exclude<RemotesOptions, 'chunkId' | 'promises'> & {
|
|
187
|
+
remoteInfos?: RemoteInfos;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
attachShareScopeMap?: typeof attachShareScopeMap;
|
|
191
|
+
hasAttachShareScopeMap?: boolean;
|
|
192
|
+
prefetch?: () => void;
|
|
193
|
+
usedExports?: {
|
|
194
|
+
[sharedName: string]: string[];
|
|
195
|
+
};
|
|
196
|
+
libraryType?: string;
|
|
197
|
+
sharedFallback?: Record<string, Array<[string, string, string]>>;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
export { ConsumesLoadingData, ConsumesOptions, CoreRemotesOptions, Federation, GetSharedFallbackGetterOptions, HandleInitialConsumesOptions, IdToExternalAndNameMapping, IdToRemoteMap, IdToRemoteMapItem, InitContainerEntryOptions, InitializeSharingData, InitializeSharingOptions, InstallInitialConsumesOptions, ModuleId, ModuleIdToRemoteDataMapping, RemoteChunkMapping, RemoteDataItem, RemoteEntryExports, RemoteInfos, RemotesLoadingData, RemotesOptions, ShareScopeMap, WebpackRequire };
|
|
201
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/updateOptions.ts
|
|
3
|
+
function updateConsumeOptions(options) {
|
|
4
|
+
const { webpackRequire, moduleToHandlerMapping } = options;
|
|
5
|
+
const { consumesLoadingData, initializeSharingData } = webpackRequire;
|
|
6
|
+
const { sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
7
|
+
if (consumesLoadingData && !consumesLoadingData._updated) {
|
|
8
|
+
const { moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {}, initialConsumes: updatedInitialConsumes = [], chunkMapping: updatedChunkMapping = {} } = consumesLoadingData;
|
|
9
|
+
Object.entries(updatedModuleIdToConsumeDataMapping).forEach(([id, data]) => {
|
|
10
|
+
if (!moduleToHandlerMapping[id]) moduleToHandlerMapping[id] = {
|
|
11
|
+
getter: sharedFallback ? bundlerRuntime?.getSharedFallbackGetter({
|
|
12
|
+
shareKey: data.shareKey,
|
|
13
|
+
factory: data.fallback,
|
|
14
|
+
webpackRequire,
|
|
15
|
+
libraryType
|
|
16
|
+
}) : data.fallback,
|
|
17
|
+
treeShakingGetter: sharedFallback ? data.fallback : void 0,
|
|
18
|
+
shareInfo: {
|
|
19
|
+
shareConfig: {
|
|
20
|
+
requiredVersion: data.requiredVersion,
|
|
21
|
+
strictVersion: data.strictVersion,
|
|
22
|
+
singleton: data.singleton,
|
|
23
|
+
eager: data.eager,
|
|
24
|
+
layer: data.layer
|
|
25
|
+
},
|
|
26
|
+
scope: Array.isArray(data.shareScope) ? data.shareScope : [data.shareScope || "default"],
|
|
27
|
+
treeShaking: sharedFallback ? {
|
|
28
|
+
get: data.fallback,
|
|
29
|
+
mode: data.treeShakingMode
|
|
30
|
+
} : void 0
|
|
31
|
+
},
|
|
32
|
+
shareKey: data.shareKey
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
if ("initialConsumes" in options) {
|
|
36
|
+
const { initialConsumes = [] } = options;
|
|
37
|
+
updatedInitialConsumes.forEach((id) => {
|
|
38
|
+
if (!initialConsumes.includes(id)) initialConsumes.push(id);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if ("chunkMapping" in options) {
|
|
42
|
+
const { chunkMapping = {} } = options;
|
|
43
|
+
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
44
|
+
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
45
|
+
chunkModules.forEach((moduleId) => {
|
|
46
|
+
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
consumesLoadingData._updated = 1;
|
|
51
|
+
}
|
|
52
|
+
if (initializeSharingData && !initializeSharingData._updated) {
|
|
53
|
+
const { federation } = webpackRequire;
|
|
54
|
+
if (!federation.instance || !initializeSharingData.scopeToSharingDataMapping) return;
|
|
55
|
+
const shared = {};
|
|
56
|
+
for (let [scope, stages] of Object.entries(initializeSharingData.scopeToSharingDataMapping)) for (let stage of stages) if (typeof stage === "object" && stage !== null) {
|
|
57
|
+
const { name, version, factory, eager, singleton, requiredVersion, strictVersion } = stage;
|
|
58
|
+
const shareConfig = { requiredVersion: `^${version}` };
|
|
59
|
+
const isValidValue = function(val) {
|
|
60
|
+
return typeof val !== "undefined";
|
|
61
|
+
};
|
|
62
|
+
if (isValidValue(singleton)) shareConfig.singleton = singleton;
|
|
63
|
+
if (isValidValue(requiredVersion)) shareConfig.requiredVersion = requiredVersion;
|
|
64
|
+
if (isValidValue(eager)) shareConfig.eager = eager;
|
|
65
|
+
if (isValidValue(strictVersion)) shareConfig.strictVersion = strictVersion;
|
|
66
|
+
const options = {
|
|
67
|
+
version,
|
|
68
|
+
scope: [scope],
|
|
69
|
+
shareConfig,
|
|
70
|
+
get: factory
|
|
71
|
+
};
|
|
72
|
+
if (shared[name]) shared[name].push(options);
|
|
73
|
+
else shared[name] = [options];
|
|
74
|
+
}
|
|
75
|
+
federation.instance.registerShared(shared);
|
|
76
|
+
initializeSharingData._updated = 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function updateRemoteOptions(options) {
|
|
80
|
+
const { webpackRequire, idToExternalAndNameMapping = {}, idToRemoteMap = {}, chunkMapping = {} } = options;
|
|
81
|
+
const { remotesLoadingData } = webpackRequire;
|
|
82
|
+
const remoteInfos = webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;
|
|
83
|
+
if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) return;
|
|
84
|
+
const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } = remotesLoadingData;
|
|
85
|
+
if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) return;
|
|
86
|
+
for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {
|
|
87
|
+
if (!idToExternalAndNameMapping[moduleId]) idToExternalAndNameMapping[moduleId] = [
|
|
88
|
+
data.shareScope,
|
|
89
|
+
data.name,
|
|
90
|
+
data.externalModuleId
|
|
91
|
+
];
|
|
92
|
+
if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {
|
|
93
|
+
const items = remoteInfos[data.remoteName];
|
|
94
|
+
idToRemoteMap[moduleId] ||= [];
|
|
95
|
+
items.forEach((item) => {
|
|
96
|
+
if (!idToRemoteMap[moduleId].includes(item)) idToRemoteMap[moduleId].push(item);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (chunkMapping) Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
101
|
+
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
102
|
+
chunkModules.forEach((moduleId) => {
|
|
103
|
+
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
remotesLoadingData._updated = 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
exports.updateConsumeOptions = updateConsumeOptions;
|
|
111
|
+
exports.updateRemoteOptions = updateRemoteOptions;
|
|
112
|
+
//# sourceMappingURL=updateOptions.cjs.map
|