@module-federation/webpack-bundler-runtime 2.0.1 → 2.2.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/bundler.cjs +18 -0
- package/dist/bundler.d.ts +4 -0
- package/dist/bundler.js +4 -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 +46 -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 +130 -0
- package/dist/runtime-core/dist/global.d.ts +24 -0
- package/dist/runtime-core/dist/helpers.d.ts +1 -0
- package/dist/runtime-core/dist/index.d.ts +6 -0
- package/dist/runtime-core/dist/module/index.d.ts +32 -0
- package/dist/runtime-core/dist/plugins/snapshot/SnapshotHandler.d.ts +67 -0
- package/dist/runtime-core/dist/remote/index.d.ts +120 -0
- package/dist/runtime-core/dist/shared/index.d.ts +84 -0
- package/dist/runtime-core/dist/type/config.d.ts +117 -0
- package/dist/runtime-core/dist/type/index.d.ts +1 -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 +3 -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/load.d.ts +15 -0
- package/dist/runtime-core/dist/utils/manifest.d.ts +1 -0
- package/dist/runtime-core/dist/utils/preload.d.ts +1 -0
- package/dist/runtime-core/dist/utils/share.d.ts +1 -0
- package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +11 -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 +20 -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,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,3 @@
|
|
|
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 { ModuleFederationRuntimePlugin } from "./type/plugin.js";
|
|
@@ -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,15 @@
|
|
|
1
|
+
import { RemoteEntryExports, RemoteInfo } from "../type/config.js";
|
|
2
|
+
import { ModuleFederation } from "../core.js";
|
|
3
|
+
|
|
4
|
+
//#region ../runtime-core/dist/utils/load.d.ts
|
|
5
|
+
//#region src/utils/load.d.ts
|
|
6
|
+
declare function getRemoteEntry(params: {
|
|
7
|
+
origin: ModuleFederation;
|
|
8
|
+
remoteInfo: RemoteInfo;
|
|
9
|
+
remoteEntryExports?: RemoteEntryExports | undefined;
|
|
10
|
+
getEntryUrl?: (url: string) => string;
|
|
11
|
+
_inErrorHandling?: boolean;
|
|
12
|
+
}): Promise<RemoteEntryExports | false | void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { getRemoteEntry };
|
|
15
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../sdk/dist/types/plugins/ModuleFederationPlugin.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).
|
|
4
|
+
*/
|
|
5
|
+
type ExternalsType = 'var' | 'module' | 'assign' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system' | 'promise' | 'import' | 'module-import' | 'script' | 'node-commonjs';
|
|
6
|
+
/**
|
|
7
|
+
* Container location from which modules should be resolved and loaded at runtime.
|
|
8
|
+
*/
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ExternalsType };
|
|
11
|
+
//# 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 { moduleFederationPlugin } from "@module-federation/sdk";
|
|
5
|
+
import * as runtime from "@module-federation/runtime";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateOptions.cjs","names":[],"sources":["../src/updateOptions.ts"],"sourcesContent":["import type {\n IdToRemoteMapItem,\n RemotesOptions,\n InstallInitialConsumesOptions,\n ConsumesOptions,\n} from './types';\nimport type {\n UserOptions,\n ShareArgs,\n SharedConfig,\n} from '@module-federation/runtime/types';\n\nexport function updateConsumeOptions(\n options: InstallInitialConsumesOptions | ConsumesOptions,\n) {\n const { webpackRequire, moduleToHandlerMapping } = options;\n const { consumesLoadingData, initializeSharingData } = webpackRequire;\n const { sharedFallback, bundlerRuntime, libraryType } =\n webpackRequire.federation;\n if (consumesLoadingData && !consumesLoadingData._updated) {\n const {\n moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {},\n initialConsumes: updatedInitialConsumes = [],\n chunkMapping: updatedChunkMapping = {},\n } = consumesLoadingData;\n\n Object.entries(updatedModuleIdToConsumeDataMapping).forEach(\n ([id, data]) => {\n if (!moduleToHandlerMapping[id]) {\n moduleToHandlerMapping[id] = {\n // @ts-ignore\n getter: sharedFallback\n ? bundlerRuntime?.getSharedFallbackGetter({\n shareKey: data.shareKey,\n factory: data.fallback,\n webpackRequire,\n libraryType,\n })\n : data.fallback,\n treeShakingGetter: sharedFallback ? data.fallback : undefined,\n shareInfo: {\n shareConfig: {\n requiredVersion: data.requiredVersion,\n strictVersion: data.strictVersion,\n singleton: data.singleton,\n eager: data.eager,\n layer: data.layer,\n },\n scope: Array.isArray(data.shareScope)\n ? data.shareScope\n : [data.shareScope || 'default'],\n treeShaking: sharedFallback\n ? {\n get: data.fallback,\n mode: data.treeShakingMode,\n }\n : undefined,\n },\n shareKey: data.shareKey,\n };\n }\n },\n );\n\n if ('initialConsumes' in options) {\n const { initialConsumes = [] } = options;\n updatedInitialConsumes.forEach((id) => {\n if (!initialConsumes.includes(id)) {\n initialConsumes.push(id);\n }\n });\n }\n\n if ('chunkMapping' in options) {\n const { chunkMapping = {} } = options;\n Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {\n if (!chunkMapping[id]) {\n chunkMapping[id] = [];\n }\n chunkModules.forEach((moduleId) => {\n if (!chunkMapping[id].includes(moduleId)) {\n chunkMapping[id].push(moduleId);\n }\n });\n });\n }\n consumesLoadingData._updated = 1;\n }\n\n if (initializeSharingData && !initializeSharingData._updated) {\n const { federation } = webpackRequire;\n if (\n !federation.instance ||\n !initializeSharingData.scopeToSharingDataMapping\n ) {\n return;\n }\n const shared: Record<string, Array<ShareArgs>> = {};\n for (let [scope, stages] of Object.entries(\n initializeSharingData.scopeToSharingDataMapping,\n )) {\n for (let stage of stages) {\n if (typeof stage === 'object' && stage !== null) {\n const {\n name,\n version,\n factory,\n eager,\n singleton,\n requiredVersion,\n strictVersion,\n } = stage;\n const shareConfig: SharedConfig = {\n requiredVersion: `^${version}`,\n };\n const isValidValue = function (\n val: unknown,\n ): val is NonNullable<unknown> {\n return typeof val !== 'undefined';\n };\n if (isValidValue(singleton)) {\n shareConfig.singleton = singleton;\n }\n if (isValidValue(requiredVersion)) {\n shareConfig.requiredVersion = requiredVersion;\n }\n if (isValidValue(eager)) {\n shareConfig.eager = eager;\n }\n if (isValidValue(strictVersion)) {\n shareConfig.strictVersion = strictVersion;\n }\n const options = {\n version,\n scope: [scope],\n shareConfig,\n get: factory,\n };\n if (shared[name]) {\n shared[name].push(options);\n } else {\n shared[name] = [options];\n }\n }\n }\n }\n federation.instance.registerShared(shared);\n initializeSharingData._updated = 1;\n }\n}\n\nexport function updateRemoteOptions(options: RemotesOptions) {\n const {\n webpackRequire,\n idToExternalAndNameMapping = {},\n idToRemoteMap = {},\n chunkMapping = {},\n } = options;\n const { remotesLoadingData } = webpackRequire;\n const remoteInfos =\n webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;\n if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) {\n return;\n }\n const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } =\n remotesLoadingData;\n if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) {\n return;\n }\n for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {\n if (!idToExternalAndNameMapping[moduleId]) {\n idToExternalAndNameMapping[moduleId] = [\n data.shareScope,\n data.name,\n data.externalModuleId,\n ];\n }\n if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {\n const items = remoteInfos[data.remoteName];\n idToRemoteMap[moduleId] ||= [];\n items.forEach((item) => {\n if (!idToRemoteMap[moduleId].includes(item)) {\n idToRemoteMap[moduleId].push(item);\n }\n });\n }\n }\n\n if (chunkMapping) {\n Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {\n if (!chunkMapping[id]) {\n chunkMapping[id] = [];\n }\n chunkModules.forEach((moduleId) => {\n if (!chunkMapping[id].includes(moduleId)) {\n chunkMapping[id].push(moduleId);\n }\n });\n });\n }\n remotesLoadingData._updated = 1;\n}\n"],"mappings":";;AAYA,SAAgB,qBACd,SACA;CACA,MAAM,EAAE,gBAAgB,2BAA2B;CACnD,MAAM,EAAE,qBAAqB,0BAA0B;CACvD,MAAM,EAAE,gBAAgB,gBAAgB,gBACtC,eAAe;AACjB,KAAI,uBAAuB,CAAC,oBAAoB,UAAU;EACxD,MAAM,EACJ,8BAA8B,sCA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AAc,cAAc,EAAE;AAC9B,SAAM,SAAS,SAAS;AACtB,QAAI,CAAC,cAAc,UAAU,SAAS,KAAK,CACzC,eAAc,UAAU,KAAK,KAAK;KAEpC;;;AAIN,KAAI,aACF,QAAO,QAAQ,oBAAoB,CAAC,SAAS,CAAC,IAAI,kBAAkB;AAClE,MAAI,CAAC,aAAa,IAChB,cAAa,MAAM,EAAE;AAEvB,eAAa,SAAS,aAAa;AACjC,OAAI,CAAC,aAAa,IAAI,SAAS,SAAS,CACtC,cAAa,IAAI,KAAK,SAAS;IAEjC;GACF;AAEJ,oBAAmB,WAAW"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/updateOptions.ts
|
|
2
|
+
function updateConsumeOptions(options) {
|
|
3
|
+
const { webpackRequire, moduleToHandlerMapping } = options;
|
|
4
|
+
const { consumesLoadingData, initializeSharingData } = webpackRequire;
|
|
5
|
+
const { sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
6
|
+
if (consumesLoadingData && !consumesLoadingData._updated) {
|
|
7
|
+
const { moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {}, initialConsumes: updatedInitialConsumes = [], chunkMapping: updatedChunkMapping = {} } = consumesLoadingData;
|
|
8
|
+
Object.entries(updatedModuleIdToConsumeDataMapping).forEach(([id, data]) => {
|
|
9
|
+
if (!moduleToHandlerMapping[id]) moduleToHandlerMapping[id] = {
|
|
10
|
+
getter: sharedFallback ? bundlerRuntime?.getSharedFallbackGetter({
|
|
11
|
+
shareKey: data.shareKey,
|
|
12
|
+
factory: data.fallback,
|
|
13
|
+
webpackRequire,
|
|
14
|
+
libraryType
|
|
15
|
+
}) : data.fallback,
|
|
16
|
+
treeShakingGetter: sharedFallback ? data.fallback : void 0,
|
|
17
|
+
shareInfo: {
|
|
18
|
+
shareConfig: {
|
|
19
|
+
requiredVersion: data.requiredVersion,
|
|
20
|
+
strictVersion: data.strictVersion,
|
|
21
|
+
singleton: data.singleton,
|
|
22
|
+
eager: data.eager,
|
|
23
|
+
layer: data.layer
|
|
24
|
+
},
|
|
25
|
+
scope: Array.isArray(data.shareScope) ? data.shareScope : [data.shareScope || "default"],
|
|
26
|
+
treeShaking: sharedFallback ? {
|
|
27
|
+
get: data.fallback,
|
|
28
|
+
mode: data.treeShakingMode
|
|
29
|
+
} : void 0
|
|
30
|
+
},
|
|
31
|
+
shareKey: data.shareKey
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
if ("initialConsumes" in options) {
|
|
35
|
+
const { initialConsumes = [] } = options;
|
|
36
|
+
updatedInitialConsumes.forEach((id) => {
|
|
37
|
+
if (!initialConsumes.includes(id)) initialConsumes.push(id);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if ("chunkMapping" in options) {
|
|
41
|
+
const { chunkMapping = {} } = options;
|
|
42
|
+
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
43
|
+
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
44
|
+
chunkModules.forEach((moduleId) => {
|
|
45
|
+
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
consumesLoadingData._updated = 1;
|
|
50
|
+
}
|
|
51
|
+
if (initializeSharingData && !initializeSharingData._updated) {
|
|
52
|
+
const { federation } = webpackRequire;
|
|
53
|
+
if (!federation.instance || !initializeSharingData.scopeToSharingDataMapping) return;
|
|
54
|
+
const shared = {};
|
|
55
|
+
for (let [scope, stages] of Object.entries(initializeSharingData.scopeToSharingDataMapping)) for (let stage of stages) if (typeof stage === "object" && stage !== null) {
|
|
56
|
+
const { name, version, factory, eager, singleton, requiredVersion, strictVersion } = stage;
|
|
57
|
+
const shareConfig = { requiredVersion: `^${version}` };
|
|
58
|
+
const isValidValue = function(val) {
|
|
59
|
+
return typeof val !== "undefined";
|
|
60
|
+
};
|
|
61
|
+
if (isValidValue(singleton)) shareConfig.singleton = singleton;
|
|
62
|
+
if (isValidValue(requiredVersion)) shareConfig.requiredVersion = requiredVersion;
|
|
63
|
+
if (isValidValue(eager)) shareConfig.eager = eager;
|
|
64
|
+
if (isValidValue(strictVersion)) shareConfig.strictVersion = strictVersion;
|
|
65
|
+
const options = {
|
|
66
|
+
version,
|
|
67
|
+
scope: [scope],
|
|
68
|
+
shareConfig,
|
|
69
|
+
get: factory
|
|
70
|
+
};
|
|
71
|
+
if (shared[name]) shared[name].push(options);
|
|
72
|
+
else shared[name] = [options];
|
|
73
|
+
}
|
|
74
|
+
federation.instance.registerShared(shared);
|
|
75
|
+
initializeSharingData._updated = 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function updateRemoteOptions(options) {
|
|
79
|
+
const { webpackRequire, idToExternalAndNameMapping = {}, idToRemoteMap = {}, chunkMapping = {} } = options;
|
|
80
|
+
const { remotesLoadingData } = webpackRequire;
|
|
81
|
+
const remoteInfos = webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;
|
|
82
|
+
if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) return;
|
|
83
|
+
const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } = remotesLoadingData;
|
|
84
|
+
if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) return;
|
|
85
|
+
for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {
|
|
86
|
+
if (!idToExternalAndNameMapping[moduleId]) idToExternalAndNameMapping[moduleId] = [
|
|
87
|
+
data.shareScope,
|
|
88
|
+
data.name,
|
|
89
|
+
data.externalModuleId
|
|
90
|
+
];
|
|
91
|
+
if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {
|
|
92
|
+
const items = remoteInfos[data.remoteName];
|
|
93
|
+
idToRemoteMap[moduleId] ||= [];
|
|
94
|
+
items.forEach((item) => {
|
|
95
|
+
if (!idToRemoteMap[moduleId].includes(item)) idToRemoteMap[moduleId].push(item);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (chunkMapping) Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
100
|
+
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
101
|
+
chunkModules.forEach((moduleId) => {
|
|
102
|
+
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
remotesLoadingData._updated = 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { updateConsumeOptions, updateRemoteOptions };
|
|
110
|
+
//# sourceMappingURL=updateOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateOptions.js","names":[],"sources":["../src/updateOptions.ts"],"sourcesContent":["import type {\n IdToRemoteMapItem,\n RemotesOptions,\n InstallInitialConsumesOptions,\n ConsumesOptions,\n} from './types';\nimport type {\n UserOptions,\n ShareArgs,\n SharedConfig,\n} from '@module-federation/runtime/types';\n\nexport function updateConsumeOptions(\n options: InstallInitialConsumesOptions | ConsumesOptions,\n) {\n const { webpackRequire, moduleToHandlerMapping } = options;\n const { consumesLoadingData, initializeSharingData } = webpackRequire;\n const { sharedFallback, bundlerRuntime, libraryType } =\n webpackRequire.federation;\n if (consumesLoadingData && !consumesLoadingData._updated) {\n const {\n moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {},\n initialConsumes: updatedInitialConsumes = [],\n chunkMapping: updatedChunkMapping = {},\n } = consumesLoadingData;\n\n Object.entries(updatedModuleIdToConsumeDataMapping).forEach(\n ([id, data]) => {\n if (!moduleToHandlerMapping[id]) {\n moduleToHandlerMapping[id] = {\n // @ts-ignore\n getter: sharedFallback\n ? bundlerRuntime?.getSharedFallbackGetter({\n shareKey: data.shareKey,\n factory: data.fallback,\n webpackRequire,\n libraryType,\n })\n : data.fallback,\n treeShakingGetter: sharedFallback ? data.fallback : undefined,\n shareInfo: {\n shareConfig: {\n requiredVersion: data.requiredVersion,\n strictVersion: data.strictVersion,\n singleton: data.singleton,\n eager: data.eager,\n layer: data.layer,\n },\n scope: Array.isArray(data.shareScope)\n ? data.shareScope\n : [data.shareScope || 'default'],\n treeShaking: sharedFallback\n ? {\n get: data.fallback,\n mode: data.treeShakingMode,\n }\n : undefined,\n },\n shareKey: data.shareKey,\n };\n }\n },\n );\n\n if ('initialConsumes' in options) {\n const { initialConsumes = [] } = options;\n updatedInitialConsumes.forEach((id) => {\n if (!initialConsumes.includes(id)) {\n initialConsumes.push(id);\n }\n });\n }\n\n if ('chunkMapping' in options) {\n const { chunkMapping = {} } = options;\n Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {\n if (!chunkMapping[id]) {\n chunkMapping[id] = [];\n }\n chunkModules.forEach((moduleId) => {\n if (!chunkMapping[id].includes(moduleId)) {\n chunkMapping[id].push(moduleId);\n }\n });\n });\n }\n consumesLoadingData._updated = 1;\n }\n\n if (initializeSharingData && !initializeSharingData._updated) {\n const { federation } = webpackRequire;\n if (\n !federation.instance ||\n !initializeSharingData.scopeToSharingDataMapping\n ) {\n return;\n }\n const shared: Record<string, Array<ShareArgs>> = {};\n for (let [scope, stages] of Object.entries(\n initializeSharingData.scopeToSharingDataMapping,\n )) {\n for (let stage of stages) {\n if (typeof stage === 'object' && stage !== null) {\n const {\n name,\n version,\n factory,\n eager,\n singleton,\n requiredVersion,\n strictVersion,\n } = stage;\n const shareConfig: SharedConfig = {\n requiredVersion: `^${version}`,\n };\n const isValidValue = function (\n val: unknown,\n ): val is NonNullable<unknown> {\n return typeof val !== 'undefined';\n };\n if (isValidValue(singleton)) {\n shareConfig.singleton = singleton;\n }\n if (isValidValue(requiredVersion)) {\n shareConfig.requiredVersion = requiredVersion;\n }\n if (isValidValue(eager)) {\n shareConfig.eager = eager;\n }\n if (isValidValue(strictVersion)) {\n shareConfig.strictVersion = strictVersion;\n }\n const options = {\n version,\n scope: [scope],\n shareConfig,\n get: factory,\n };\n if (shared[name]) {\n shared[name].push(options);\n } else {\n shared[name] = [options];\n }\n }\n }\n }\n federation.instance.registerShared(shared);\n initializeSharingData._updated = 1;\n }\n}\n\nexport function updateRemoteOptions(options: RemotesOptions) {\n const {\n webpackRequire,\n idToExternalAndNameMapping = {},\n idToRemoteMap = {},\n chunkMapping = {},\n } = options;\n const { remotesLoadingData } = webpackRequire;\n const remoteInfos =\n webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;\n if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) {\n return;\n }\n const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } =\n remotesLoadingData;\n if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) {\n return;\n }\n for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {\n if (!idToExternalAndNameMapping[moduleId]) {\n idToExternalAndNameMapping[moduleId] = [\n data.shareScope,\n data.name,\n data.externalModuleId,\n ];\n }\n if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {\n const items = remoteInfos[data.remoteName];\n idToRemoteMap[moduleId] ||= [];\n items.forEach((item) => {\n if (!idToRemoteMap[moduleId].includes(item)) {\n idToRemoteMap[moduleId].push(item);\n }\n });\n }\n }\n\n if (chunkMapping) {\n Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {\n if (!chunkMapping[id]) {\n chunkMapping[id] = [];\n }\n chunkModules.forEach((moduleId) => {\n if (!chunkMapping[id].includes(moduleId)) {\n chunkMapping[id].push(moduleId);\n }\n });\n });\n }\n remotesLoadingData._updated = 1;\n}\n"],"mappings":";AAYA,SAAgB,qBACd,SACA;CACA,MAAM,EAAE,gBAAgB,2BAA2B;CACnD,MAAM,EAAE,qBAAqB,0BAA0B;CACvD,MAAM,EAAE,gBAAgB,gBAAgB,gBACtC,eAAe;AACjB,KAAI,uBAAuB,CAAC,oBAAoB,UAAU;EACxD,MAAM,EACJ,8BAA8B,sCAAsC,EAAE,EACtE,iBAAiB,yBAAyB,E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