@module-federation/runtime-core 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703
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/README.md +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +19 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/constant.cjs +9 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.js +7 -0
- package/dist/constant.js.map +1 -0
- package/dist/core.cjs +150 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +199 -0
- package/dist/core.js +150 -0
- package/dist/core.js.map +1 -0
- package/dist/global.cjs +175 -0
- package/dist/global.cjs.map +1 -0
- package/dist/global.d.ts +46 -0
- package/dist/global.js +155 -0
- package/dist/global.js.map +1 -0
- package/dist/helpers.cjs +44 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.ts +30 -0
- package/dist/helpers.js +44 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +62 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/module/index.cjs +268 -0
- package/dist/module/index.cjs.map +1 -0
- package/dist/module/index.d.ts +33 -0
- package/dist/module/index.js +268 -0
- package/dist/module/index.js.map +1 -0
- package/dist/plugins/generate-preload-assets.cjs +182 -0
- package/dist/plugins/generate-preload-assets.cjs.map +1 -0
- package/dist/plugins/generate-preload-assets.js +182 -0
- package/dist/plugins/generate-preload-assets.js.map +1 -0
- package/dist/plugins/snapshot/SnapshotHandler.cjs +258 -0
- package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -0
- package/dist/plugins/snapshot/SnapshotHandler.d.ts +92 -0
- package/dist/plugins/snapshot/SnapshotHandler.js +257 -0
- package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -0
- package/dist/plugins/snapshot/disabled.cjs +13 -0
- package/dist/plugins/snapshot/disabled.cjs.map +1 -0
- package/dist/plugins/snapshot/disabled.js +13 -0
- package/dist/plugins/snapshot/disabled.js.map +1 -0
- package/dist/plugins/snapshot/index.cjs +77 -0
- package/dist/plugins/snapshot/index.cjs.map +1 -0
- package/dist/plugins/snapshot/index.js +76 -0
- package/dist/plugins/snapshot/index.js.map +1 -0
- package/dist/remote/disabled.cjs +38 -0
- package/dist/remote/disabled.cjs.map +1 -0
- package/dist/remote/disabled.js +37 -0
- package/dist/remote/disabled.js.map +1 -0
- package/dist/remote/index.cjs +458 -0
- package/dist/remote/index.cjs.map +1 -0
- package/dist/remote/index.d.ts +147 -0
- package/dist/remote/index.js +458 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/shared/disabled.cjs +33 -0
- package/dist/shared/disabled.cjs.map +1 -0
- package/dist/shared/disabled.js +33 -0
- package/dist/shared/disabled.js.map +1 -0
- package/dist/shared/index.cjs +477 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.ts +113 -0
- package/dist/shared/index.js +477 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/type/config.d.ts +138 -0
- package/dist/type/index.cjs +13 -0
- package/dist/type/index.cjs.map +1 -0
- package/dist/type/index.d.ts +11 -0
- package/dist/type/index.js +8 -0
- package/dist/type/index.js.map +1 -0
- package/dist/type/plugin.d.ts +28 -0
- package/dist/type/preload.d.ts +60 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +4 -1
- package/dist/types.js +1 -0
- package/dist/utils/context.cjs +45 -0
- package/dist/utils/context.cjs.map +1 -0
- package/dist/utils/context.d.ts +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/env.cjs +10 -0
- package/dist/utils/env.cjs.map +1 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +10 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/hooks/asyncHook.cjs +26 -0
- package/dist/utils/hooks/asyncHook.cjs.map +1 -0
- package/dist/utils/hooks/asyncHook.d.ts +10 -0
- package/dist/utils/hooks/asyncHook.js +26 -0
- package/dist/utils/hooks/asyncHook.js.map +1 -0
- package/dist/utils/hooks/asyncWaterfallHooks.cjs +44 -0
- package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -0
- package/dist/utils/hooks/asyncWaterfallHooks.d.ts +12 -0
- package/dist/utils/hooks/asyncWaterfallHooks.js +44 -0
- package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -0
- package/dist/utils/hooks/index.cjs +5 -0
- package/dist/utils/hooks/index.js +7 -0
- package/dist/utils/hooks/pluginSystem.cjs +38 -0
- package/dist/utils/hooks/pluginSystem.cjs.map +1 -0
- package/dist/utils/hooks/pluginSystem.d.ts +16 -0
- package/dist/utils/hooks/pluginSystem.js +38 -0
- package/dist/utils/hooks/pluginSystem.js.map +1 -0
- package/dist/utils/hooks/syncHook.cjs +37 -0
- package/dist/utils/hooks/syncHook.cjs.map +1 -0
- package/dist/utils/hooks/syncHook.d.ts +16 -0
- package/dist/utils/hooks/syncHook.js +36 -0
- package/dist/utils/hooks/syncHook.js.map +1 -0
- package/dist/utils/hooks/syncWaterfallHook.cjs +40 -0
- package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -0
- package/dist/utils/hooks/syncWaterfallHook.d.ts +11 -0
- package/dist/utils/hooks/syncWaterfallHook.js +39 -0
- package/dist/utils/hooks/syncWaterfallHook.js.map +1 -0
- package/dist/utils/index.cjs +8 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/load.cjs +280 -0
- package/dist/utils/load.cjs.map +1 -0
- package/dist/utils/load.d.ts +16 -0
- package/dist/utils/load.js +277 -0
- package/dist/utils/load.js.map +1 -0
- package/dist/utils/logger.cjs +34 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +31 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/manifest.cjs +56 -0
- package/dist/utils/manifest.cjs.map +1 -0
- package/dist/utils/manifest.d.ts +10 -0
- package/dist/utils/manifest.js +53 -0
- package/dist/utils/manifest.js.map +1 -0
- package/dist/utils/plugin.cjs +50 -0
- package/dist/utils/plugin.cjs.map +1 -0
- package/dist/utils/plugin.d.ts +1 -0
- package/dist/utils/plugin.js +50 -0
- package/dist/utils/plugin.js.map +1 -0
- package/dist/utils/preload.cjs +221 -0
- package/dist/utils/preload.cjs.map +1 -0
- package/dist/utils/preload.d.ts +8 -0
- package/dist/utils/preload.js +218 -0
- package/dist/utils/preload.js.map +1 -0
- package/dist/utils/semver/compare.cjs +48 -0
- package/dist/utils/semver/compare.cjs.map +1 -0
- package/dist/utils/semver/compare.js +47 -0
- package/dist/utils/semver/compare.js.map +1 -0
- package/dist/utils/semver/constants.cjs +41 -0
- package/dist/utils/semver/constants.cjs.map +1 -0
- package/dist/utils/semver/constants.js +31 -0
- package/dist/utils/semver/constants.js.map +1 -0
- package/dist/utils/semver/index.cjs +68 -0
- package/dist/utils/semver/index.cjs.map +1 -0
- package/dist/utils/semver/index.d.ts +5 -0
- package/dist/utils/semver/index.js +68 -0
- package/dist/utils/semver/index.js.map +1 -0
- package/dist/utils/semver/parser.cjs +104 -0
- package/dist/utils/semver/parser.cjs.map +1 -0
- package/dist/utils/semver/parser.js +96 -0
- package/dist/utils/semver/parser.js.map +1 -0
- package/dist/utils/semver/utils.cjs +28 -0
- package/dist/utils/semver/utils.cjs.map +1 -0
- package/dist/utils/semver/utils.js +24 -0
- package/dist/utils/semver/utils.js.map +1 -0
- package/dist/utils/share.cjs +285 -0
- package/dist/utils/share.cjs.map +1 -0
- package/dist/utils/share.d.ts +24 -0
- package/dist/utils/share.js +279 -0
- package/dist/utils/share.js.map +1 -0
- package/dist/utils/tool.cjs +82 -0
- package/dist/utils/tool.cjs.map +1 -0
- package/dist/utils/tool.d.ts +8 -0
- package/dist/utils/tool.js +71 -0
- package/dist/utils/tool.js.map +1 -0
- package/package.json +16 -9
- package/dist/index.cjs.cjs +0 -3226
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.esm.js +0 -3202
- package/dist/index.esm.js.map +0 -1
- package/dist/src/constant.d.ts +0 -2
- package/dist/src/core.d.ts +0 -115
- package/dist/src/global.d.ts +0 -42
- package/dist/src/helpers.d.ts +0 -38
- package/dist/src/index.d.ts +0 -14
- package/dist/src/module/index.d.ts +0 -22
- package/dist/src/plugins/generate-preload-assets.d.ts +0 -8
- package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +0 -60
- package/dist/src/plugins/snapshot/index.d.ts +0 -5
- package/dist/src/remote/index.d.ts +0 -109
- package/dist/src/shared/index.d.ts +0 -66
- package/dist/src/type/config.d.ts +0 -115
- package/dist/src/type/index.d.ts +0 -3
- package/dist/src/type/plugin.d.ts +0 -35
- package/dist/src/type/preload.d.ts +0 -26
- package/dist/src/types.d.ts +0 -1
- package/dist/src/utils/env.d.ts +0 -3
- package/dist/src/utils/hooks/asyncHook.d.ts +0 -6
- package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +0 -10
- package/dist/src/utils/hooks/index.d.ts +0 -6
- package/dist/src/utils/hooks/pluginSystem.d.ts +0 -16
- package/dist/src/utils/hooks/syncHook.d.ts +0 -12
- package/dist/src/utils/hooks/syncWaterfallHook.d.ts +0 -9
- package/dist/src/utils/index.d.ts +0 -6
- package/dist/src/utils/load.d.ts +0 -11
- package/dist/src/utils/logger.d.ts +0 -6
- package/dist/src/utils/manifest.d.ts +0 -7
- package/dist/src/utils/plugin.d.ts +0 -3
- package/dist/src/utils/preload.d.ts +0 -6
- package/dist/src/utils/semver/compare.d.ts +0 -9
- package/dist/src/utils/semver/constants.d.ts +0 -10
- package/dist/src/utils/semver/index.d.ts +0 -2
- package/dist/src/utils/semver/parser.d.ts +0 -9
- package/dist/src/utils/semver/utils.d.ts +0 -11
- package/dist/src/utils/share.d.ts +0 -27
- package/dist/src/utils/tool.d.ts +0 -18
- package/dist/types.cjs.cjs +0 -3
- package/dist/types.cjs.cjs.map +0 -1
- package/dist/types.cjs.d.ts +0 -1
- package/dist/types.esm.js +0 -2
- package/dist/types.esm.js.map +0 -1
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
const require_logger = require('../utils/logger.cjs');
|
|
2
|
+
const require_tool = require('../utils/tool.cjs');
|
|
3
|
+
const require_global = require('../global.cjs');
|
|
4
|
+
const require_constant = require('../constant.cjs');
|
|
5
|
+
const require_share = require('../utils/share.cjs');
|
|
6
|
+
const require_manifest = require('../utils/manifest.cjs');
|
|
7
|
+
const require_load = require('../utils/load.cjs');
|
|
8
|
+
const require_context = require('../utils/context.cjs');
|
|
9
|
+
require('../utils/index.cjs');
|
|
10
|
+
const require_preload = require('../utils/preload.cjs');
|
|
11
|
+
const require_index$1 = require('../module/index.cjs');
|
|
12
|
+
const require_syncHook = require('../utils/hooks/syncHook.cjs');
|
|
13
|
+
const require_asyncHook = require('../utils/hooks/asyncHook.cjs');
|
|
14
|
+
const require_syncWaterfallHook = require('../utils/hooks/syncWaterfallHook.cjs');
|
|
15
|
+
const require_asyncWaterfallHooks = require('../utils/hooks/asyncWaterfallHooks.cjs');
|
|
16
|
+
const require_pluginSystem = require('../utils/hooks/pluginSystem.cjs');
|
|
17
|
+
require('../utils/hooks/index.cjs');
|
|
18
|
+
const require_SnapshotHandler = require('../plugins/snapshot/SnapshotHandler.cjs');
|
|
19
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
20
|
+
let _module_federation_error_codes = require("@module-federation/error-codes");
|
|
21
|
+
|
|
22
|
+
//#region src/remote/index.ts
|
|
23
|
+
var RemoteHandler = class {
|
|
24
|
+
constructor(host) {
|
|
25
|
+
this.hooks = new require_pluginSystem.PluginSystem({
|
|
26
|
+
beforeRegisterRemote: new require_syncWaterfallHook.SyncWaterfallHook("beforeRegisterRemote"),
|
|
27
|
+
registerRemote: new require_syncWaterfallHook.SyncWaterfallHook("registerRemote"),
|
|
28
|
+
beforeRequest: new require_asyncWaterfallHooks.AsyncWaterfallHook("beforeRequest"),
|
|
29
|
+
afterMatchRemote: new require_asyncHook.AsyncHook("afterMatchRemote"),
|
|
30
|
+
onLoad: new require_asyncHook.AsyncHook("onLoad"),
|
|
31
|
+
afterLoadRemote: new require_asyncHook.AsyncHook("afterLoadRemote"),
|
|
32
|
+
handlePreloadModule: new require_syncHook.SyncHook("handlePreloadModule"),
|
|
33
|
+
errorLoadRemote: new require_asyncHook.AsyncHook("errorLoadRemote"),
|
|
34
|
+
beforePreloadRemote: new require_asyncHook.AsyncHook("beforePreloadRemote"),
|
|
35
|
+
generatePreloadAssets: new require_asyncHook.AsyncHook("generatePreloadAssets"),
|
|
36
|
+
afterPreloadRemote: new require_asyncHook.AsyncHook("afterPreloadRemote"),
|
|
37
|
+
loadEntry: new require_asyncHook.AsyncHook()
|
|
38
|
+
});
|
|
39
|
+
this.host = host;
|
|
40
|
+
this.idToRemoteMap = {};
|
|
41
|
+
}
|
|
42
|
+
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
43
|
+
return (userOptions.remotes || []).reduce((res, remote) => {
|
|
44
|
+
this.registerRemote(remote, res, { force: false });
|
|
45
|
+
return res;
|
|
46
|
+
}, globalOptions.remotes);
|
|
47
|
+
}
|
|
48
|
+
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
49
|
+
const { remote, expose } = remoteMatchInfo;
|
|
50
|
+
const { name, alias } = remote;
|
|
51
|
+
this.idToRemoteMap[id] = {
|
|
52
|
+
name: remote.name,
|
|
53
|
+
expose
|
|
54
|
+
};
|
|
55
|
+
if (alias && id.startsWith(name)) {
|
|
56
|
+
const idWithAlias = id.replace(name, alias);
|
|
57
|
+
this.idToRemoteMap[idWithAlias] = {
|
|
58
|
+
name: remote.name,
|
|
59
|
+
expose
|
|
60
|
+
};
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (alias && id.startsWith(alias)) {
|
|
64
|
+
const idWithName = id.replace(alias, name);
|
|
65
|
+
this.idToRemoteMap[idWithName] = {
|
|
66
|
+
name: remote.name,
|
|
67
|
+
expose
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async loadRemote(id, options) {
|
|
72
|
+
const { host } = this;
|
|
73
|
+
const startMatchInfo = require_manifest.matchRemoteWithNameAndExpose(host.options.remotes, id);
|
|
74
|
+
let completeRequestId = id;
|
|
75
|
+
let completeExpose = startMatchInfo?.expose;
|
|
76
|
+
let completeRemote = startMatchInfo ? require_load.getRemoteInfo(startMatchInfo.remote) : void 0;
|
|
77
|
+
let afterLoadRemoteArgs;
|
|
78
|
+
try {
|
|
79
|
+
const { loadFactory = true } = options || { loadFactory: true };
|
|
80
|
+
const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({ id });
|
|
81
|
+
const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
|
|
82
|
+
completeRequestId = idRes;
|
|
83
|
+
completeExpose = expose;
|
|
84
|
+
completeRemote = require_load.getRemoteInfo(remote);
|
|
85
|
+
const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
|
|
86
|
+
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
87
|
+
id: idRes,
|
|
88
|
+
pkgNameOrAlias,
|
|
89
|
+
expose,
|
|
90
|
+
exposeModule: loadFactory ? moduleOrFactory : void 0,
|
|
91
|
+
exposeModuleFactory: loadFactory ? void 0 : moduleOrFactory,
|
|
92
|
+
remote,
|
|
93
|
+
options: moduleOptions,
|
|
94
|
+
moduleInstance: module,
|
|
95
|
+
origin: host
|
|
96
|
+
});
|
|
97
|
+
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
98
|
+
afterLoadRemoteArgs = {
|
|
99
|
+
id: completeRequestId,
|
|
100
|
+
expose: completeExpose,
|
|
101
|
+
remote: completeRemote,
|
|
102
|
+
options,
|
|
103
|
+
origin: host
|
|
104
|
+
};
|
|
105
|
+
if (typeof moduleWrapper === "function") return moduleWrapper;
|
|
106
|
+
return moduleOrFactory;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const { from = "runtime" } = options || { from: "runtime" };
|
|
109
|
+
let failOver;
|
|
110
|
+
try {
|
|
111
|
+
failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
112
|
+
id,
|
|
113
|
+
error,
|
|
114
|
+
from,
|
|
115
|
+
lifecycle: "onLoad",
|
|
116
|
+
expose: completeExpose,
|
|
117
|
+
remote: completeRemote,
|
|
118
|
+
origin: host
|
|
119
|
+
});
|
|
120
|
+
} catch (hookError) {
|
|
121
|
+
afterLoadRemoteArgs = {
|
|
122
|
+
id: completeRequestId,
|
|
123
|
+
expose: completeExpose,
|
|
124
|
+
remote: completeRemote,
|
|
125
|
+
options,
|
|
126
|
+
error: hookError,
|
|
127
|
+
origin: host
|
|
128
|
+
};
|
|
129
|
+
throw hookError;
|
|
130
|
+
}
|
|
131
|
+
if (!failOver) {
|
|
132
|
+
afterLoadRemoteArgs = {
|
|
133
|
+
id: completeRequestId,
|
|
134
|
+
expose: completeExpose,
|
|
135
|
+
remote: completeRemote,
|
|
136
|
+
options,
|
|
137
|
+
error,
|
|
138
|
+
origin: host
|
|
139
|
+
};
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
afterLoadRemoteArgs = {
|
|
143
|
+
id: completeRequestId,
|
|
144
|
+
expose: completeExpose,
|
|
145
|
+
remote: completeRemote,
|
|
146
|
+
options,
|
|
147
|
+
error,
|
|
148
|
+
origin: host,
|
|
149
|
+
recovered: true
|
|
150
|
+
};
|
|
151
|
+
return failOver;
|
|
152
|
+
} finally {
|
|
153
|
+
if (afterLoadRemoteArgs) await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async preloadRemote(preloadOptions) {
|
|
157
|
+
const { host } = this;
|
|
158
|
+
const preloadResults = [];
|
|
159
|
+
await this.hooks.lifecycle.beforePreloadRemote.emit({
|
|
160
|
+
preloadOps: preloadOptions,
|
|
161
|
+
options: host.options,
|
|
162
|
+
origin: host
|
|
163
|
+
});
|
|
164
|
+
const preloadOps = require_preload.formatPreloadArgs(host.options.remotes, preloadOptions);
|
|
165
|
+
const createPreloadAssetOps = (ops) => {
|
|
166
|
+
const { preloadConfig, remote } = ops;
|
|
167
|
+
const exposes = preloadConfig.exposes || [];
|
|
168
|
+
if (!exposes.length) return [{
|
|
169
|
+
ops,
|
|
170
|
+
id: `${remote.name}/*`
|
|
171
|
+
}];
|
|
172
|
+
return exposes.map((expose) => ({
|
|
173
|
+
ops: {
|
|
174
|
+
...ops,
|
|
175
|
+
preloadConfig: {
|
|
176
|
+
...preloadConfig,
|
|
177
|
+
exposes: [expose]
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
id: require_manifest.composeRemoteRequestId(remote.name, expose)
|
|
181
|
+
}));
|
|
182
|
+
};
|
|
183
|
+
let preloadError;
|
|
184
|
+
await Promise.all(preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {
|
|
185
|
+
const { ops, id: preloadId } = assetOps;
|
|
186
|
+
const { remote, preloadConfig } = ops;
|
|
187
|
+
const remoteInfo = require_load.getRemoteInfo(remote);
|
|
188
|
+
try {
|
|
189
|
+
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
190
|
+
moduleInfo: remote,
|
|
191
|
+
id: preloadId,
|
|
192
|
+
initiator: "preloadRemote"
|
|
193
|
+
});
|
|
194
|
+
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
195
|
+
origin: host,
|
|
196
|
+
preloadOptions: ops,
|
|
197
|
+
remote,
|
|
198
|
+
remoteInfo,
|
|
199
|
+
globalSnapshot,
|
|
200
|
+
remoteSnapshot
|
|
201
|
+
});
|
|
202
|
+
if (!assets) return;
|
|
203
|
+
const results = await require_preload.preloadAssets(remoteInfo, host, assets, true, {
|
|
204
|
+
initiator: "preloadRemote",
|
|
205
|
+
id: preloadId
|
|
206
|
+
}, preloadConfig.recordPreloadedAssets);
|
|
207
|
+
preloadResults.push({
|
|
208
|
+
remote,
|
|
209
|
+
remoteInfo,
|
|
210
|
+
preloadConfig,
|
|
211
|
+
id: preloadId,
|
|
212
|
+
results
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
preloadResults.push({
|
|
216
|
+
remote,
|
|
217
|
+
remoteInfo,
|
|
218
|
+
preloadConfig,
|
|
219
|
+
id: preloadId,
|
|
220
|
+
results: [{
|
|
221
|
+
url: remoteInfo.entry,
|
|
222
|
+
status: "error",
|
|
223
|
+
resourceType: /\.json(?:$|[?#])/i.test(remoteInfo.entry) ? "manifest" : "remoteEntry",
|
|
224
|
+
initiator: "preloadRemote",
|
|
225
|
+
id: preloadId,
|
|
226
|
+
error
|
|
227
|
+
}]
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
231
|
+
const failedResults = preloadResults.flatMap((preloadResult) => preloadResult.results.filter((result) => result.status === "error" || result.status === "timeout"));
|
|
232
|
+
if (failedResults.length > 0) {
|
|
233
|
+
preloadError = /* @__PURE__ */ new Error(`preloadRemote failed to load ${failedResults.length} resource(s).`);
|
|
234
|
+
Object.assign(preloadError, {
|
|
235
|
+
results: preloadResults,
|
|
236
|
+
failedResults
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
await this.hooks.lifecycle.afterPreloadRemote.emit({
|
|
240
|
+
preloadOps: preloadOptions,
|
|
241
|
+
options: host.options,
|
|
242
|
+
origin: host,
|
|
243
|
+
results: preloadResults,
|
|
244
|
+
error: preloadError
|
|
245
|
+
});
|
|
246
|
+
if (preloadError) throw preloadError;
|
|
247
|
+
}
|
|
248
|
+
registerRemotes(remotes, options) {
|
|
249
|
+
const { host } = this;
|
|
250
|
+
remotes.forEach((remote) => {
|
|
251
|
+
this.registerRemote(remote, host.options.remotes, { force: options?.force });
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
initRawContainer(name, url, container) {
|
|
255
|
+
const { host } = this;
|
|
256
|
+
const module = new require_index$1.Module({
|
|
257
|
+
host,
|
|
258
|
+
remoteInfo: require_load.getRemoteInfo({
|
|
259
|
+
name,
|
|
260
|
+
entry: url
|
|
261
|
+
})
|
|
262
|
+
});
|
|
263
|
+
module.remoteEntryExports = container;
|
|
264
|
+
host.moduleCache.set(name, module);
|
|
265
|
+
return module;
|
|
266
|
+
}
|
|
267
|
+
async getRemoteModuleAndOptions(options) {
|
|
268
|
+
const { host } = this;
|
|
269
|
+
const { id } = options;
|
|
270
|
+
let loadRemoteArgs;
|
|
271
|
+
try {
|
|
272
|
+
loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
273
|
+
id,
|
|
274
|
+
options: host.options,
|
|
275
|
+
origin: host
|
|
276
|
+
});
|
|
277
|
+
} catch (error) {
|
|
278
|
+
loadRemoteArgs = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
279
|
+
id,
|
|
280
|
+
options: host.options,
|
|
281
|
+
origin: host,
|
|
282
|
+
from: "runtime",
|
|
283
|
+
error,
|
|
284
|
+
lifecycle: "beforeRequest"
|
|
285
|
+
});
|
|
286
|
+
if (!loadRemoteArgs) throw error;
|
|
287
|
+
}
|
|
288
|
+
const { id: idRes } = loadRemoteArgs;
|
|
289
|
+
const remoteSplitInfo = require_manifest.matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
290
|
+
if (!remoteSplitInfo) try {
|
|
291
|
+
require_logger.error(_module_federation_error_codes.RUNTIME_004, _module_federation_error_codes.runtimeDescMap, {
|
|
292
|
+
hostName: host.options.name,
|
|
293
|
+
requestId: idRes
|
|
294
|
+
}, void 0, require_context.optionsToMFContext(host.options));
|
|
295
|
+
} catch (matchError) {
|
|
296
|
+
await this.hooks.lifecycle.afterMatchRemote.emit({
|
|
297
|
+
id: idRes,
|
|
298
|
+
options: host.options,
|
|
299
|
+
error: matchError,
|
|
300
|
+
origin: host
|
|
301
|
+
});
|
|
302
|
+
throw matchError;
|
|
303
|
+
}
|
|
304
|
+
const { remote: rawRemote } = remoteSplitInfo;
|
|
305
|
+
const remoteInfo = require_load.getRemoteInfo(rawRemote);
|
|
306
|
+
await this.hooks.lifecycle.afterMatchRemote.emit({
|
|
307
|
+
id: idRes,
|
|
308
|
+
...remoteSplitInfo,
|
|
309
|
+
options: host.options,
|
|
310
|
+
remoteInfo,
|
|
311
|
+
origin: host
|
|
312
|
+
});
|
|
313
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
|
|
314
|
+
id: idRes,
|
|
315
|
+
...remoteSplitInfo,
|
|
316
|
+
options: host.options,
|
|
317
|
+
origin: host,
|
|
318
|
+
remoteInfo
|
|
319
|
+
});
|
|
320
|
+
const { remote, expose } = matchInfo;
|
|
321
|
+
require_logger.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
322
|
+
let module = host.moduleCache.get(remote.name);
|
|
323
|
+
const moduleOptions = {
|
|
324
|
+
host,
|
|
325
|
+
remoteInfo
|
|
326
|
+
};
|
|
327
|
+
if (!module) {
|
|
328
|
+
module = new require_index$1.Module(moduleOptions);
|
|
329
|
+
host.moduleCache.set(remote.name, module);
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
module,
|
|
333
|
+
moduleOptions,
|
|
334
|
+
remoteMatchInfo: matchInfo
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
registerRemote(remote, targetRemotes, options) {
|
|
338
|
+
const { host } = this;
|
|
339
|
+
const normalizeRemote = () => {
|
|
340
|
+
if (remote.alias) {
|
|
341
|
+
const findEqual = targetRemotes.find((item) => remote.alias && (item.name.startsWith(remote.alias) || item.alias?.startsWith(remote.alias)));
|
|
342
|
+
require_logger.assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
343
|
+
}
|
|
344
|
+
if ("entry" in remote) {
|
|
345
|
+
if (_module_federation_sdk.isBrowserEnvValue && typeof window !== "undefined" && !remote.entry.startsWith("http")) remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
346
|
+
}
|
|
347
|
+
if (!remote.shareScope) remote.shareScope = require_constant.DEFAULT_SCOPE;
|
|
348
|
+
if (!remote.type) remote.type = require_constant.DEFAULT_REMOTE_TYPE;
|
|
349
|
+
};
|
|
350
|
+
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
351
|
+
remote,
|
|
352
|
+
origin: host
|
|
353
|
+
});
|
|
354
|
+
const registeredRemote = targetRemotes.find((item) => item.name === remote.name);
|
|
355
|
+
if (!registeredRemote) {
|
|
356
|
+
normalizeRemote();
|
|
357
|
+
targetRemotes.push(remote);
|
|
358
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
359
|
+
remote,
|
|
360
|
+
origin: host
|
|
361
|
+
});
|
|
362
|
+
} else {
|
|
363
|
+
const messages = [`The remote "${remote.name}" is already registered.`, "Please note that overriding it may cause unexpected errors."];
|
|
364
|
+
if (options?.force) {
|
|
365
|
+
this.removeRemote(registeredRemote);
|
|
366
|
+
normalizeRemote();
|
|
367
|
+
targetRemotes.push(remote);
|
|
368
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
369
|
+
remote,
|
|
370
|
+
origin: host
|
|
371
|
+
});
|
|
372
|
+
(0, _module_federation_sdk.warn)(messages.join(" "));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
removeRemote(remote) {
|
|
377
|
+
try {
|
|
378
|
+
const { host } = this;
|
|
379
|
+
const { name } = remote;
|
|
380
|
+
const remoteIndex = host.options.remotes.findIndex((item) => item.name === name);
|
|
381
|
+
if (remoteIndex !== -1) host.options.remotes.splice(remoteIndex, 1);
|
|
382
|
+
const globalSnapshotKey = require_global.getInfoWithoutType(require_global.CurrentGlobal.__FEDERATION__.moduleInfo, require_tool.getFMId(remote)).key;
|
|
383
|
+
delete require_global.CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];
|
|
384
|
+
if ("entry" in remote) {
|
|
385
|
+
host.snapshotHandler.manifestCache.delete(remote.entry);
|
|
386
|
+
delete require_global.Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];
|
|
387
|
+
}
|
|
388
|
+
const { hostGlobalSnapshot } = require_SnapshotHandler.getGlobalRemoteInfo(remote, host);
|
|
389
|
+
if (hostGlobalSnapshot) {
|
|
390
|
+
const remoteKey = hostGlobalSnapshot && "remotesInfo" in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && require_global.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
391
|
+
if (remoteKey) delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
392
|
+
}
|
|
393
|
+
const loadedModule = host.moduleCache.get(remote.name);
|
|
394
|
+
if (loadedModule) {
|
|
395
|
+
const remoteInfo = loadedModule.remoteInfo;
|
|
396
|
+
const key = remoteInfo.entryGlobalName;
|
|
397
|
+
if (require_global.CurrentGlobal[key]) if (Object.getOwnPropertyDescriptor(require_global.CurrentGlobal, key)?.configurable) delete require_global.CurrentGlobal[key];
|
|
398
|
+
else require_global.CurrentGlobal[key] = void 0;
|
|
399
|
+
const remoteEntryUniqueKey = require_load.getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
400
|
+
if (require_global.globalLoading[remoteEntryUniqueKey]) delete require_global.globalLoading[remoteEntryUniqueKey];
|
|
401
|
+
let remoteInsId = remoteInfo.buildVersion ? (0, _module_federation_sdk.composeKeyWithSeparator)(remoteInfo.name, remoteInfo.buildVersion) : remoteInfo.name;
|
|
402
|
+
const remoteInsIndex = require_global.CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {
|
|
403
|
+
if (remoteInfo.buildVersion) return ins.options.id === remoteInsId;
|
|
404
|
+
else return ins.name === remoteInsId;
|
|
405
|
+
});
|
|
406
|
+
if (remoteInsIndex !== -1) {
|
|
407
|
+
const remoteIns = require_global.CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];
|
|
408
|
+
remoteInsId = remoteIns.options.id || remoteInsId;
|
|
409
|
+
const globalShareScopeMap = require_share.getGlobalShareScope();
|
|
410
|
+
let isAllSharedNotUsed = true;
|
|
411
|
+
const needDeleteKeys = [];
|
|
412
|
+
Object.keys(globalShareScopeMap).forEach((instId) => {
|
|
413
|
+
const shareScopeMap = globalShareScopeMap[instId];
|
|
414
|
+
shareScopeMap && Object.keys(shareScopeMap).forEach((shareScope) => {
|
|
415
|
+
const shareScopeVal = shareScopeMap[shareScope];
|
|
416
|
+
shareScopeVal && Object.keys(shareScopeVal).forEach((shareName) => {
|
|
417
|
+
const sharedPkgs = shareScopeVal[shareName];
|
|
418
|
+
sharedPkgs && Object.keys(sharedPkgs).forEach((shareVersion) => {
|
|
419
|
+
const shared = sharedPkgs[shareVersion];
|
|
420
|
+
if (shared && typeof shared === "object" && shared.from === remoteInfo.name) if (shared.loaded || shared.loading) {
|
|
421
|
+
shared.useIn = shared.useIn.filter((usedHostName) => usedHostName !== remoteInfo.name);
|
|
422
|
+
if (shared.useIn.length) isAllSharedNotUsed = false;
|
|
423
|
+
else needDeleteKeys.push([
|
|
424
|
+
instId,
|
|
425
|
+
shareScope,
|
|
426
|
+
shareName,
|
|
427
|
+
shareVersion
|
|
428
|
+
]);
|
|
429
|
+
} else needDeleteKeys.push([
|
|
430
|
+
instId,
|
|
431
|
+
shareScope,
|
|
432
|
+
shareName,
|
|
433
|
+
shareVersion
|
|
434
|
+
]);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
if (isAllSharedNotUsed) {
|
|
440
|
+
remoteIns.shareScopeMap = {};
|
|
441
|
+
delete globalShareScopeMap[remoteInsId];
|
|
442
|
+
}
|
|
443
|
+
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion]) => {
|
|
444
|
+
delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[shareVersion];
|
|
445
|
+
});
|
|
446
|
+
require_global.CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
447
|
+
}
|
|
448
|
+
host.moduleCache.delete(remote.name);
|
|
449
|
+
}
|
|
450
|
+
} catch (err) {
|
|
451
|
+
require_logger.logger.error(`removeRemote failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
//#endregion
|
|
457
|
+
exports.RemoteHandler = RemoteHandler;
|
|
458
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PluginSystem","SyncWaterfallHook","AsyncWaterfallHook","AsyncHook","SyncHook","matchRemoteWithNameAndExpose","getRemoteInfo","formatPreloadArgs","composeRemoteRequestId","preloadAssets","Module","RUNTIME_004","runtimeDescMap","optionsToMFContext","isBrowserEnvValue","DEFAULT_SCOPE","DEFAULT_REMOTE_TYPE","getInfoWithoutType","CurrentGlobal","getFMId","Global","getGlobalRemoteInfo","getRemoteEntryUniqueKey","globalLoading","getGlobalShareScope"],"sources":["../../src/remote/index.ts"],"sourcesContent":["import {\n isBrowserEnvValue,\n warn,\n composeKeyWithSeparator,\n ModuleInfo,\n GlobalModuleInfo,\n} from '@module-federation/sdk';\nimport { RUNTIME_004, runtimeDescMap } from '@module-federation/error-codes';\nimport {\n Global,\n getInfoWithoutType,\n globalLoading,\n CurrentGlobal,\n} from '../global';\nimport {\n Options,\n UserOptions,\n PreloadAssets,\n PreloadOptions,\n PreloadRemoteArgs,\n PreloadRemoteResult,\n Remote,\n RemoteInfo,\n RemoteEntryExports,\n CallFrom,\n} from '../type';\nimport { ModuleFederation } from '../core';\nimport {\n PluginSystem,\n AsyncHook,\n AsyncWaterfallHook,\n SyncHook,\n SyncWaterfallHook,\n} from '../utils/hooks';\nimport {\n assert,\n error,\n getRemoteInfo,\n getRemoteEntryUniqueKey,\n getFMId,\n composeRemoteRequestId,\n matchRemoteWithNameAndExpose,\n optionsToMFContext,\n logger,\n} from '../utils';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { Module, ModuleOptions } from '../module';\nimport { formatPreloadArgs, preloadAssets } from '../utils/preload';\nimport { getGlobalShareScope } from '../utils/share';\nimport { getGlobalRemoteInfo } from '../plugins/snapshot/SnapshotHandler';\n\nexport interface LoadRemoteMatch {\n id: string;\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n options: Options;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n}\n\nexport class RemoteHandler {\n host: ModuleFederation;\n idToRemoteMap: Record<string, { name: string; expose: string }>;\n\n hooks = new PluginSystem({\n beforeRegisterRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('beforeRegisterRemote'),\n registerRemote: new SyncWaterfallHook<{\n remote: Remote;\n origin: ModuleFederation;\n }>('registerRemote'),\n beforeRequest: new AsyncWaterfallHook<{\n id: string;\n options: Options;\n origin: ModuleFederation;\n }>('beforeRequest'),\n afterMatchRemote: new AsyncHook<\n [\n {\n id: string;\n options: Options;\n remote?: Remote;\n expose?: string;\n remoteInfo?: RemoteInfo;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterMatchRemote'),\n onLoad: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n pkgNameOrAlias: string;\n remote: Remote;\n options: ModuleOptions;\n origin: ModuleFederation;\n exposeModule: any;\n exposeModuleFactory: any;\n moduleInstance: Module;\n },\n ],\n unknown\n >('onLoad'),\n afterLoadRemote: new AsyncHook<\n [\n {\n id: string;\n expose?: string;\n remote?: RemoteInfo;\n options?: {\n loadFactory?: boolean;\n from?: CallFrom;\n };\n error?: unknown;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadRemote'),\n handlePreloadModule: new SyncHook<\n [\n {\n id: string;\n name: string;\n remote: Remote;\n remoteSnapshot: ModuleInfo;\n preloadConfig: PreloadRemoteArgs;\n origin: ModuleFederation;\n },\n ],\n void\n >('handlePreloadModule'),\n errorLoadRemote: new AsyncHook<\n [\n {\n id: string;\n error: unknown;\n options?: any;\n from: CallFrom;\n lifecycle:\n | 'beforeRequest'\n | 'beforeLoadShare'\n | 'afterResolve'\n | 'onLoad';\n remote?: RemoteInfo;\n expose?: string;\n origin: ModuleFederation;\n },\n ],\n void | unknown\n >('errorLoadRemote'),\n beforePreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n },\n ]\n >('beforePreloadRemote'),\n generatePreloadAssets: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n preloadOptions: PreloadOptions[number];\n remote: Remote;\n remoteInfo: RemoteInfo;\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n },\n ],\n Promise<PreloadAssets>\n >('generatePreloadAssets'),\n afterPreloadRemote: new AsyncHook<\n [\n {\n preloadOps: Array<PreloadRemoteArgs>;\n options: Options;\n origin: ModuleFederation;\n results: PreloadRemoteResult[];\n error?: unknown;\n },\n ]\n >('afterPreloadRemote'),\n // TODO: Move to loaderHook\n loadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n loaderHook: ModuleFederation['loaderHook'];\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n resourceContext?: ResourceLoadContext;\n },\n ],\n Promise<RemoteEntryExports | void> | RemoteEntryExports | void\n >(),\n });\n\n constructor(host: ModuleFederation) {\n this.host = host;\n this.idToRemoteMap = {};\n }\n\n formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions) {\n const userRemotes = userOptions.remotes || [];\n\n return userRemotes.reduce((res, remote) => {\n this.registerRemote(remote, res, { force: false });\n return res;\n }, globalOptions.remotes);\n }\n\n setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch) {\n const { remote, expose } = remoteMatchInfo;\n const { name, alias } = remote;\n this.idToRemoteMap[id] = { name: remote.name, expose };\n if (alias && id.startsWith(name)) {\n const idWithAlias = id.replace(name, alias);\n this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };\n return;\n }\n\n if (alias && id.startsWith(alias)) {\n const idWithName = id.replace(alias, name);\n this.idToRemoteMap[idWithName] = { name: remote.name, expose };\n }\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n const { host } = this;\n const startMatchInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n id,\n );\n let completeRequestId = id;\n let completeExpose = startMatchInfo?.expose;\n let completeRemote = startMatchInfo\n ? getRemoteInfo(startMatchInfo.remote)\n : undefined;\n let afterLoadRemoteArgs:\n | Parameters<\n RemoteHandler['hooks']['lifecycle']['afterLoadRemote']['emit']\n >[0]\n | undefined;\n\n try {\n const { loadFactory = true } = options || {\n loadFactory: true,\n };\n // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.\n // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.\n // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)\n // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get\n // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n // id: alias(app1) + expose(button) = app1/button\n // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\n const { module, moduleOptions, remoteMatchInfo } =\n await this.getRemoteModuleAndOptions({\n id,\n });\n const {\n pkgNameOrAlias,\n remote,\n expose,\n id: idRes,\n remoteSnapshot,\n } = remoteMatchInfo;\n completeRequestId = idRes;\n completeExpose = expose;\n completeRemote = getRemoteInfo(remote);\n\n const moduleOrFactory = (await module.get(\n idRes,\n expose,\n options,\n remoteSnapshot,\n )) as T;\n\n const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({\n id: idRes,\n pkgNameOrAlias,\n expose,\n exposeModule: loadFactory ? moduleOrFactory : undefined,\n exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,\n remote,\n options: moduleOptions,\n moduleInstance: module,\n origin: host,\n });\n\n this.setIdToRemoteMap(id, remoteMatchInfo);\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n origin: host,\n };\n\n if (typeof moduleWrapper === 'function') {\n return moduleWrapper as T;\n }\n\n return moduleOrFactory;\n } catch (error) {\n const { from = 'runtime' } = options || { from: 'runtime' };\n\n let failOver;\n try {\n failOver = await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n error,\n from,\n lifecycle: 'onLoad',\n expose: completeExpose,\n remote: completeRemote,\n origin: host,\n });\n } catch (hookError) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error: hookError,\n origin: host,\n };\n throw hookError;\n }\n\n if (!failOver) {\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n };\n throw error;\n }\n\n afterLoadRemoteArgs = {\n id: completeRequestId,\n expose: completeExpose,\n remote: completeRemote,\n options,\n error,\n origin: host,\n recovered: true,\n };\n\n return failOver as T;\n } finally {\n if (afterLoadRemoteArgs) {\n await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);\n }\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n const { host } = this;\n const preloadResults: PreloadRemoteResult[] = [];\n\n await this.hooks.lifecycle.beforePreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n });\n\n const preloadOps: PreloadOptions = formatPreloadArgs(\n host.options.remotes,\n preloadOptions,\n );\n\n const createPreloadAssetOps = (ops: PreloadOptions[number]) => {\n const { preloadConfig, remote } = ops;\n const exposes = preloadConfig.exposes || [];\n\n if (!exposes.length) {\n return [\n {\n ops,\n id: `${remote.name}/*`,\n },\n ];\n }\n\n return exposes.map((expose) => ({\n ops: {\n ...ops,\n preloadConfig: {\n ...preloadConfig,\n exposes: [expose],\n },\n },\n id: composeRemoteRequestId(remote.name, expose),\n }));\n };\n\n let preloadError: Error | undefined;\n\n await Promise.all(\n preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {\n const { ops, id: preloadId } = assetOps;\n const { remote, preloadConfig } = ops;\n const remoteInfo = getRemoteInfo(remote);\n try {\n const { globalSnapshot, remoteSnapshot } =\n await host.snapshotHandler.loadRemoteSnapshotInfo({\n moduleInfo: remote,\n id: preloadId,\n initiator: 'preloadRemote',\n });\n\n const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({\n origin: host,\n preloadOptions: ops,\n remote,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n });\n if (!assets) {\n return;\n }\n const results = await preloadAssets(\n remoteInfo,\n host,\n assets,\n true,\n {\n initiator: 'preloadRemote',\n id: preloadId,\n },\n preloadConfig.recordPreloadedAssets,\n );\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results,\n });\n } catch (error) {\n preloadResults.push({\n remote,\n remoteInfo,\n preloadConfig,\n id: preloadId,\n results: [\n {\n url: remoteInfo.entry,\n status: 'error',\n resourceType: /\\.json(?:$|[?#])/i.test(remoteInfo.entry)\n ? 'manifest'\n : 'remoteEntry',\n initiator: 'preloadRemote',\n id: preloadId,\n error,\n },\n ],\n });\n }\n }),\n );\n\n const failedResults = preloadResults.flatMap((preloadResult) =>\n preloadResult.results.filter(\n (result) => result.status === 'error' || result.status === 'timeout',\n ),\n );\n if (failedResults.length > 0) {\n preloadError = new Error(\n `preloadRemote failed to load ${failedResults.length} resource(s).`,\n );\n Object.assign(preloadError, {\n results: preloadResults,\n failedResults,\n });\n }\n\n await this.hooks.lifecycle.afterPreloadRemote.emit({\n preloadOps: preloadOptions,\n options: host.options,\n origin: host,\n results: preloadResults,\n error: preloadError,\n });\n\n if (preloadError) {\n throw preloadError;\n }\n }\n\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n const { host } = this;\n remotes.forEach((remote) => {\n this.registerRemote(remote, host.options.remotes, {\n force: options?.force,\n });\n });\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const { host } = this;\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host, remoteInfo });\n\n module.remoteEntryExports = container;\n host.moduleCache.set(name, module);\n\n return module;\n }\n\n async getRemoteModuleAndOptions(options: { id: string }): Promise<{\n module: Module;\n moduleOptions: ModuleOptions;\n remoteMatchInfo: LoadRemoteMatch;\n }> {\n const { host } = this;\n const { id } = options;\n let loadRemoteArgs;\n\n try {\n loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({\n id,\n options: host.options,\n origin: host,\n });\n } catch (error) {\n loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({\n id,\n options: host.options,\n origin: host,\n from: 'runtime',\n error,\n lifecycle: 'beforeRequest',\n })) as {\n id: string;\n options: Options;\n origin: ModuleFederation;\n };\n\n if (!loadRemoteArgs) {\n throw error;\n }\n }\n\n const { id: idRes } = loadRemoteArgs;\n\n const remoteSplitInfo = matchRemoteWithNameAndExpose(\n host.options.remotes,\n idRes,\n );\n if (!remoteSplitInfo) {\n try {\n error(\n RUNTIME_004,\n runtimeDescMap,\n {\n hostName: host.options.name,\n requestId: idRes,\n },\n undefined,\n optionsToMFContext(host.options),\n );\n } catch (matchError) {\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n options: host.options,\n error: matchError,\n origin: host,\n });\n throw matchError;\n }\n }\n\n const { remote: rawRemote } = remoteSplitInfo;\n const remoteInfo = getRemoteInfo(rawRemote);\n await this.hooks.lifecycle.afterMatchRemote.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n remoteInfo,\n origin: host,\n });\n const matchInfo =\n await host.sharedHandler.hooks.lifecycle.afterResolve.emit({\n id: idRes,\n ...remoteSplitInfo,\n options: host.options,\n origin: host,\n remoteInfo,\n });\n\n const { remote, expose } = matchInfo;\n assert(\n remote && expose,\n `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`,\n );\n let module: Module | undefined = host.moduleCache.get(remote.name);\n\n const moduleOptions: ModuleOptions = {\n host: host,\n remoteInfo,\n };\n\n if (!module) {\n module = new Module(moduleOptions);\n host.moduleCache.set(remote.name, module);\n }\n return {\n module,\n moduleOptions,\n remoteMatchInfo: matchInfo,\n };\n }\n\n registerRemote(\n remote: Remote,\n targetRemotes: Remote[],\n options?: { force?: boolean },\n ): void {\n const { host } = this;\n const normalizeRemote = () => {\n if (remote.alias) {\n // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error\n // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported\n const findEqual = targetRemotes.find(\n (item) =>\n remote.alias &&\n (item.name.startsWith(remote.alias) ||\n item.alias?.startsWith(remote.alias)),\n );\n assert(\n !findEqual,\n `The alias ${remote.alias} of remote ${\n remote.name\n } is not allowed to be the prefix of ${\n findEqual && findEqual.name\n } name or alias`,\n );\n }\n // Set the remote entry to a complete path\n if ('entry' in remote) {\n if (\n isBrowserEnvValue &&\n typeof window !== 'undefined' &&\n !remote.entry.startsWith('http')\n ) {\n remote.entry = new URL(remote.entry, window.location.origin).href;\n }\n }\n if (!remote.shareScope) {\n remote.shareScope = DEFAULT_SCOPE;\n }\n if (!remote.type) {\n remote.type = DEFAULT_REMOTE_TYPE;\n }\n };\n this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });\n const registeredRemote = targetRemotes.find(\n (item) => item.name === remote.name,\n );\n if (!registeredRemote) {\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n } else {\n const messages = [\n `The remote \"${remote.name}\" is already registered.`,\n 'Please note that overriding it may cause unexpected errors.',\n ];\n if (options?.force) {\n // remove registered remote\n this.removeRemote(registeredRemote);\n normalizeRemote();\n targetRemotes.push(remote);\n this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });\n warn(messages.join(' '));\n }\n }\n }\n\n private removeRemote(remote: Remote): void {\n try {\n const { host } = this;\n const { name } = remote;\n const remoteIndex = host.options.remotes.findIndex(\n (item) => item.name === name,\n );\n if (remoteIndex !== -1) {\n host.options.remotes.splice(remoteIndex, 1);\n }\n const globalSnapshotKey = getInfoWithoutType(\n CurrentGlobal.__FEDERATION__.moduleInfo,\n getFMId(remote),\n ).key;\n delete CurrentGlobal.__FEDERATION__.moduleInfo[globalSnapshotKey];\n\n if ('entry' in remote) {\n host.snapshotHandler.manifestCache.delete(remote.entry);\n delete Global.__FEDERATION__.__MANIFEST_LOADING__[remote.entry];\n }\n\n const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);\n if (hostGlobalSnapshot) {\n const remoteKey =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;\n if (remoteKey) {\n delete hostGlobalSnapshot.remotesInfo[remoteKey];\n }\n }\n\n const loadedModule = host.moduleCache.get(remote.name);\n if (loadedModule) {\n const remoteInfo = loadedModule.remoteInfo;\n const key = remoteInfo.entryGlobalName as keyof typeof CurrentGlobal;\n\n if (CurrentGlobal[key]) {\n if (\n Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable\n ) {\n delete CurrentGlobal[key];\n } else {\n // @ts-ignore\n CurrentGlobal[key] = undefined;\n }\n }\n const remoteEntryUniqueKey = getRemoteEntryUniqueKey(\n loadedModule.remoteInfo,\n );\n\n if (globalLoading[remoteEntryUniqueKey]) {\n delete globalLoading[remoteEntryUniqueKey];\n }\n\n // delete unloaded shared and instance\n let remoteInsId = remoteInfo.buildVersion\n ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)\n : remoteInfo.name;\n const remoteInsIndex =\n CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {\n if (remoteInfo.buildVersion) {\n return ins.options.id === remoteInsId;\n } else {\n return ins.name === remoteInsId;\n }\n });\n if (remoteInsIndex !== -1) {\n const remoteIns =\n CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex];\n remoteInsId = remoteIns.options.id || remoteInsId;\n const globalShareScopeMap = getGlobalShareScope();\n\n let isAllSharedNotUsed = true;\n const needDeleteKeys: Array<[string, string, string, string]> = [];\n Object.keys(globalShareScopeMap).forEach((instId) => {\n const shareScopeMap = globalShareScopeMap[instId];\n shareScopeMap &&\n Object.keys(shareScopeMap).forEach((shareScope) => {\n const shareScopeVal = shareScopeMap[shareScope];\n shareScopeVal &&\n Object.keys(shareScopeVal).forEach((shareName) => {\n const sharedPkgs = shareScopeVal[shareName];\n sharedPkgs &&\n Object.keys(sharedPkgs).forEach((shareVersion) => {\n const shared = sharedPkgs[shareVersion];\n if (\n shared &&\n typeof shared === 'object' &&\n shared.from === remoteInfo.name\n ) {\n if (shared.loaded || shared.loading) {\n shared.useIn = shared.useIn.filter(\n (usedHostName) =>\n usedHostName !== remoteInfo.name,\n );\n if (shared.useIn.length) {\n isAllSharedNotUsed = false;\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n } else {\n needDeleteKeys.push([\n instId,\n shareScope,\n shareName,\n shareVersion,\n ]);\n }\n }\n });\n });\n });\n });\n\n if (isAllSharedNotUsed) {\n remoteIns.shareScopeMap = {};\n delete globalShareScopeMap[remoteInsId];\n }\n needDeleteKeys.forEach(\n ([insId, shareScope, shareName, shareVersion]) => {\n delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[\n shareVersion\n ];\n },\n );\n CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);\n }\n\n host.moduleCache.delete(remote.name);\n }\n } catch (err) {\n logger.error(\n `removeRemote failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAa,gBAAb,MAA2B;CAiJzB,YAAY,MAAwB;eA7I5B,IAAIA,kCAAa;GACvB,sBAAsB,IAAIC,4CAGvB,uBAAuB;GAC1B,gBAAgB,IAAIA,4CAGjB,iBAAiB;GACpB,eAAe,IAAIC,+CAIhB,gBAAgB;GACnB,kBAAkB,IAAIC,4BAapB,mBAAmB;GACrB,QAAQ,IAAIA,4BAeV,SAAS;GACX,iBAAiB,IAAIA,4BAgBnB,kBAAkB;GACpB,qBAAqB,IAAIC,0BAYvB,sBAAsB;GACxB,iBAAiB,IAAID,4BAkBnB,kBAAkB;GACpB,qBAAqB,IAAIA,4BAQvB,sBAAsB;GACxB,uBAAuB,IAAIA,4BAYzB,wBAAwB;GAC1B,oBAAoB,IAAIA,4BAUtB,qBAAqB;GAEvB,WAAW,IAAIA,6BAWZ;GACJ,CAAC;AAGA,OAAK,OAAO;AACZ,OAAK,gBAAgB,EAAE;;CAGzB,wBAAwB,eAAwB,aAA0B;AAGxE,UAFoB,YAAY,WAAW,EAAE,EAE1B,QAAQ,KAAK,WAAW;AACzC,QAAK,eAAe,QAAQ,KAAK,EAAE,OAAO,OAAO,CAAC;AAClD,UAAO;KACN,cAAc,QAAQ;;CAG3B,iBAAiB,IAAY,iBAAkC;EAC7D,MAAM,EAAE,QAAQ,WAAW;EAC3B,MAAM,EAAE,MAAM,UAAU;AACxB,OAAK,cAAc,MAAM;GAAE,MAAM,OAAO;GAAM;GAAQ;AACtD,MAAI,SAAS,GAAG,WAAW,KAAK,EAAE;GAChC,MAAM,cAAc,GAAG,QAAQ,MAAM,MAAM;AAC3C,QAAK,cAAc,eAAe;IA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B,IAAI;KACzB,MAAM,YACJA,6BAAc,eAAe,cAAc;AAC7C,mBAAc,UAAU,QAAQ,MAAM;KACtC,MAAM,sBAAsBM,mCAAqB;KAEjD,IAAI,qBAAqB;KACzB,MAAM,iBAA0D,EAAE;AAClE,YAAO,KAAK,oBAAoB,CAAC,SAAS,WAAW;MACnD,MAAM,gBAAgB,oBAAoB;AAC1C,uBACE,OAAO,KAAK,cAAc,CAAC,SAAS,eAAe;OACjD,MAAM,gBAAgB,cAAc;AACpC,wBACE,OAAO,KAAK,cAAc,CAAC,SAAS,cAAc;QAChD,MAAM,aAAa,cAAc;AACjC,sBACE,OAAO,KAAK,WAAW,CAAC,SAAS,iBAAiB;SAChD,MAAM,SAAS,WAAW;AAC1B,aACE,UACA,OAAO,WAAW,YAClB,OAAO,SAAS,WAAW,KAE3B,KAAI,OAAO,UAAU,OAAO,SAAS;AACnC,iBAAO,QAAQ,OAAO,MAAM,QACzB,iBACC,iBAAiB,WAAW,KAC/B;AACD,cAAI,OAAO,MAAM,OACf,sBAAqB;cAErB,gBAAe,KAAK;WAClB;WACA;WACA;WACA;WACD,CAAC;eAGJ,gBAAe,KAAK;UAClB;UACA;UACA;UACA;UACD,CAAC;UAGN;SACJ;QACJ;OACJ;AAEF,SAAI,oBAAoB;AACtB,gBAAU,gBAAgB,EAAE;AAC5B,aAAO,oBAAoB;;AAE7B,oBAAe,SACZ,CAAC,OAAO,YAAY,WAAW,kBAAkB;AAChD,aAAO,oBAAoB,SAAS,cAAc,aAChD;OAGL;AACD,kCAAc,eAAe,cAAc,OAAO,gBAAgB,EAAE;;AAGtE,SAAK,YAAY,OAAO,OAAO,KAAK;;WAE/B,KAAK;AACZ,yBAAO,MACL,wBAAwB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACzE"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Module as Module$1, ModuleOptions } from "../module/index.js";
|
|
2
|
+
import { SyncHook } from "../utils/hooks/syncHook.js";
|
|
3
|
+
import { AsyncHook } from "../utils/hooks/asyncHook.js";
|
|
4
|
+
import { SyncWaterfallHook } from "../utils/hooks/syncWaterfallHook.js";
|
|
5
|
+
import { AsyncWaterfallHook } from "../utils/hooks/asyncWaterfallHooks.js";
|
|
6
|
+
import { PluginSystem } from "../utils/hooks/pluginSystem.js";
|
|
7
|
+
import { ModuleFederation } from "../core.js";
|
|
8
|
+
import { CallFrom, Options, Remote, RemoteEntryExports, RemoteInfo, UserOptions } from "../type/config.js";
|
|
9
|
+
import { PreloadAssets, PreloadOptions, PreloadRemoteArgs, PreloadRemoteResult } from "../type/preload.js";
|
|
10
|
+
import { GlobalModuleInfo, ModuleInfo } from "@module-federation/sdk";
|
|
11
|
+
|
|
12
|
+
//#region src/remote/index.d.ts
|
|
13
|
+
interface LoadRemoteMatch {
|
|
14
|
+
id: string;
|
|
15
|
+
pkgNameOrAlias: string;
|
|
16
|
+
expose: string;
|
|
17
|
+
remote: Remote;
|
|
18
|
+
options: Options;
|
|
19
|
+
origin: ModuleFederation;
|
|
20
|
+
remoteInfo: RemoteInfo;
|
|
21
|
+
remoteSnapshot?: ModuleInfo;
|
|
22
|
+
}
|
|
23
|
+
declare class RemoteHandler {
|
|
24
|
+
host: ModuleFederation;
|
|
25
|
+
idToRemoteMap: Record<string, {
|
|
26
|
+
name: string;
|
|
27
|
+
expose: string;
|
|
28
|
+
}>;
|
|
29
|
+
hooks: PluginSystem<{
|
|
30
|
+
beforeRegisterRemote: SyncWaterfallHook<{
|
|
31
|
+
remote: Remote;
|
|
32
|
+
origin: ModuleFederation;
|
|
33
|
+
}>;
|
|
34
|
+
registerRemote: SyncWaterfallHook<{
|
|
35
|
+
remote: Remote;
|
|
36
|
+
origin: ModuleFederation;
|
|
37
|
+
}>;
|
|
38
|
+
beforeRequest: AsyncWaterfallHook<{
|
|
39
|
+
id: string;
|
|
40
|
+
options: Options;
|
|
41
|
+
origin: ModuleFederation;
|
|
42
|
+
}>;
|
|
43
|
+
afterMatchRemote: AsyncHook<[{
|
|
44
|
+
id: string;
|
|
45
|
+
options: Options;
|
|
46
|
+
remote?: Remote;
|
|
47
|
+
expose?: string;
|
|
48
|
+
remoteInfo?: RemoteInfo;
|
|
49
|
+
error?: unknown;
|
|
50
|
+
origin: ModuleFederation;
|
|
51
|
+
}], void>;
|
|
52
|
+
onLoad: AsyncHook<[{
|
|
53
|
+
id: string;
|
|
54
|
+
expose: string;
|
|
55
|
+
pkgNameOrAlias: string;
|
|
56
|
+
remote: Remote;
|
|
57
|
+
options: ModuleOptions;
|
|
58
|
+
origin: ModuleFederation;
|
|
59
|
+
exposeModule: any;
|
|
60
|
+
exposeModuleFactory: any;
|
|
61
|
+
moduleInstance: Module$1;
|
|
62
|
+
}], unknown>;
|
|
63
|
+
afterLoadRemote: AsyncHook<[{
|
|
64
|
+
id: string;
|
|
65
|
+
expose?: string;
|
|
66
|
+
remote?: RemoteInfo;
|
|
67
|
+
options?: {
|
|
68
|
+
loadFactory?: boolean;
|
|
69
|
+
from?: CallFrom;
|
|
70
|
+
};
|
|
71
|
+
error?: unknown;
|
|
72
|
+
recovered?: boolean;
|
|
73
|
+
origin: ModuleFederation;
|
|
74
|
+
}], void>;
|
|
75
|
+
handlePreloadModule: SyncHook<[{
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
remote: Remote;
|
|
79
|
+
remoteSnapshot: ModuleInfo;
|
|
80
|
+
preloadConfig: PreloadRemoteArgs;
|
|
81
|
+
origin: ModuleFederation;
|
|
82
|
+
}], void>;
|
|
83
|
+
errorLoadRemote: AsyncHook<[{
|
|
84
|
+
id: string;
|
|
85
|
+
error: unknown;
|
|
86
|
+
options?: any;
|
|
87
|
+
from: CallFrom;
|
|
88
|
+
lifecycle: "beforeRequest" | "beforeLoadShare" | "afterResolve" | "onLoad";
|
|
89
|
+
remote?: RemoteInfo;
|
|
90
|
+
expose?: string;
|
|
91
|
+
origin: ModuleFederation;
|
|
92
|
+
}], unknown>;
|
|
93
|
+
beforePreloadRemote: AsyncHook<[{
|
|
94
|
+
preloadOps: Array<PreloadRemoteArgs>;
|
|
95
|
+
options: Options;
|
|
96
|
+
origin: ModuleFederation;
|
|
97
|
+
}], false | void | Promise<false | void>>;
|
|
98
|
+
generatePreloadAssets: AsyncHook<[{
|
|
99
|
+
origin: ModuleFederation;
|
|
100
|
+
preloadOptions: PreloadOptions[number];
|
|
101
|
+
remote: Remote;
|
|
102
|
+
remoteInfo: RemoteInfo;
|
|
103
|
+
remoteSnapshot: ModuleInfo;
|
|
104
|
+
globalSnapshot: GlobalModuleInfo;
|
|
105
|
+
}], Promise<PreloadAssets>>;
|
|
106
|
+
afterPreloadRemote: AsyncHook<[{
|
|
107
|
+
preloadOps: Array<PreloadRemoteArgs>;
|
|
108
|
+
options: Options;
|
|
109
|
+
origin: ModuleFederation;
|
|
110
|
+
results: PreloadRemoteResult[];
|
|
111
|
+
error?: unknown;
|
|
112
|
+
}], false | void | Promise<false | void>>;
|
|
113
|
+
loadEntry: AsyncHook<[{
|
|
114
|
+
origin: ModuleFederation;
|
|
115
|
+
loaderHook: ModuleFederation["loaderHook"];
|
|
116
|
+
remoteInfo: RemoteInfo;
|
|
117
|
+
remoteEntryExports?: RemoteEntryExports;
|
|
118
|
+
resourceContext?: ResourceLoadContext;
|
|
119
|
+
}], void | RemoteEntryExports | Promise<void | RemoteEntryExports>>;
|
|
120
|
+
}>;
|
|
121
|
+
constructor(host: ModuleFederation);
|
|
122
|
+
formatAndRegisterRemote(globalOptions: Options, userOptions: UserOptions): Remote[];
|
|
123
|
+
setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch): void;
|
|
124
|
+
loadRemote<T>(id: string, options?: {
|
|
125
|
+
loadFactory?: boolean;
|
|
126
|
+
from: CallFrom;
|
|
127
|
+
}): Promise<T | null>;
|
|
128
|
+
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
129
|
+
registerRemotes(remotes: Remote[], options?: {
|
|
130
|
+
force?: boolean;
|
|
131
|
+
}): void;
|
|
132
|
+
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module$1;
|
|
133
|
+
getRemoteModuleAndOptions(options: {
|
|
134
|
+
id: string;
|
|
135
|
+
}): Promise<{
|
|
136
|
+
module: Module$1;
|
|
137
|
+
moduleOptions: ModuleOptions;
|
|
138
|
+
remoteMatchInfo: LoadRemoteMatch;
|
|
139
|
+
}>;
|
|
140
|
+
registerRemote(remote: Remote, targetRemotes: Remote[], options?: {
|
|
141
|
+
force?: boolean;
|
|
142
|
+
}): void;
|
|
143
|
+
private removeRemote;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { LoadRemoteMatch, RemoteHandler };
|
|
147
|
+
//# sourceMappingURL=index.d.ts.map
|