@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,258 @@
|
|
|
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_load = require('../../utils/load.cjs');
|
|
5
|
+
const require_context = require('../../utils/context.cjs');
|
|
6
|
+
require('../../utils/index.cjs');
|
|
7
|
+
const require_asyncHook = require('../../utils/hooks/asyncHook.cjs');
|
|
8
|
+
const require_asyncWaterfallHooks = require('../../utils/hooks/asyncWaterfallHooks.cjs');
|
|
9
|
+
const require_pluginSystem = require('../../utils/hooks/pluginSystem.cjs');
|
|
10
|
+
require('../../utils/hooks/index.cjs');
|
|
11
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
12
|
+
let _module_federation_error_codes = require("@module-federation/error-codes");
|
|
13
|
+
|
|
14
|
+
//#region src/plugins/snapshot/SnapshotHandler.ts
|
|
15
|
+
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
16
|
+
const hostGlobalSnapshot = require_global.getGlobalSnapshotInfoByModuleInfo({
|
|
17
|
+
name: origin.name,
|
|
18
|
+
version: origin.options.version
|
|
19
|
+
});
|
|
20
|
+
const globalRemoteInfo = hostGlobalSnapshot && "remotesInfo" in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && require_global.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
21
|
+
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) return {
|
|
22
|
+
hostGlobalSnapshot,
|
|
23
|
+
globalSnapshot: require_global.getGlobalSnapshot(),
|
|
24
|
+
remoteSnapshot: require_global.getGlobalSnapshotInfoByModuleInfo({
|
|
25
|
+
name: moduleInfo.name,
|
|
26
|
+
version: globalRemoteInfo.matchedVersion
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
hostGlobalSnapshot: void 0,
|
|
31
|
+
globalSnapshot: require_global.getGlobalSnapshot(),
|
|
32
|
+
remoteSnapshot: require_global.getGlobalSnapshotInfoByModuleInfo({
|
|
33
|
+
name: moduleInfo.name,
|
|
34
|
+
version: "version" in moduleInfo ? moduleInfo.version : void 0
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var SnapshotHandler = class {
|
|
39
|
+
constructor(HostInstance) {
|
|
40
|
+
this.loadingHostSnapshot = null;
|
|
41
|
+
this.manifestCache = /* @__PURE__ */ new Map();
|
|
42
|
+
this.hooks = new require_pluginSystem.PluginSystem({
|
|
43
|
+
beforeLoadRemoteSnapshot: new require_asyncHook.AsyncHook("beforeLoadRemoteSnapshot"),
|
|
44
|
+
loadSnapshot: new require_asyncWaterfallHooks.AsyncWaterfallHook("loadGlobalSnapshot"),
|
|
45
|
+
loadRemoteSnapshot: new require_asyncWaterfallHooks.AsyncWaterfallHook("loadRemoteSnapshot"),
|
|
46
|
+
afterLoadSnapshot: new require_asyncWaterfallHooks.AsyncWaterfallHook("afterLoadSnapshot"),
|
|
47
|
+
beforeLoadManifest: new require_asyncHook.AsyncHook("beforeLoadManifest"),
|
|
48
|
+
afterLoadManifest: new require_asyncHook.AsyncHook("afterLoadManifest")
|
|
49
|
+
});
|
|
50
|
+
this.manifestLoading = require_global.Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
51
|
+
this.HostInstance = HostInstance;
|
|
52
|
+
this.loaderHook = HostInstance.loaderHook;
|
|
53
|
+
}
|
|
54
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, initiator = "loadRemote" }) {
|
|
55
|
+
const { options } = this.HostInstance;
|
|
56
|
+
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
57
|
+
options,
|
|
58
|
+
moduleInfo,
|
|
59
|
+
origin: this.HostInstance
|
|
60
|
+
});
|
|
61
|
+
let hostSnapshot = require_global.getGlobalSnapshotInfoByModuleInfo({
|
|
62
|
+
name: this.HostInstance.options.name,
|
|
63
|
+
version: this.HostInstance.options.version
|
|
64
|
+
});
|
|
65
|
+
if (!hostSnapshot) {
|
|
66
|
+
hostSnapshot = {
|
|
67
|
+
version: this.HostInstance.options.version || "",
|
|
68
|
+
remoteEntry: "",
|
|
69
|
+
remotesInfo: {}
|
|
70
|
+
};
|
|
71
|
+
require_global.addGlobalSnapshot({ [this.HostInstance.options.name]: hostSnapshot });
|
|
72
|
+
}
|
|
73
|
+
if (hostSnapshot && "remotesInfo" in hostSnapshot && !require_global.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
74
|
+
if ("version" in moduleInfo || "entry" in moduleInfo) hostSnapshot.remotesInfo = {
|
|
75
|
+
...hostSnapshot?.remotesInfo,
|
|
76
|
+
[moduleInfo.name]: { matchedVersion: "version" in moduleInfo ? moduleInfo.version : moduleInfo.entry }
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
80
|
+
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
81
|
+
options,
|
|
82
|
+
moduleInfo,
|
|
83
|
+
hostGlobalSnapshot,
|
|
84
|
+
remoteSnapshot,
|
|
85
|
+
globalSnapshot
|
|
86
|
+
});
|
|
87
|
+
let mSnapshot;
|
|
88
|
+
let gSnapshot;
|
|
89
|
+
if (globalRemoteSnapshot) if ((0, _module_federation_sdk.isManifestProvider)(globalRemoteSnapshot)) {
|
|
90
|
+
const remoteEntry = _module_federation_sdk.isBrowserEnvValue ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || "";
|
|
91
|
+
const moduleSnapshot = await this.loadManifestSnapshot(remoteEntry, moduleInfo, {}, {
|
|
92
|
+
initiator,
|
|
93
|
+
id: id || moduleInfo.name
|
|
94
|
+
});
|
|
95
|
+
const globalSnapshotRes = require_global.setGlobalSnapshotInfoByModuleInfo({
|
|
96
|
+
...moduleInfo,
|
|
97
|
+
entry: remoteEntry
|
|
98
|
+
}, moduleSnapshot);
|
|
99
|
+
mSnapshot = moduleSnapshot;
|
|
100
|
+
gSnapshot = globalSnapshotRes;
|
|
101
|
+
} else {
|
|
102
|
+
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
103
|
+
options: this.HostInstance.options,
|
|
104
|
+
moduleInfo,
|
|
105
|
+
remoteSnapshot: globalRemoteSnapshot,
|
|
106
|
+
from: "global"
|
|
107
|
+
});
|
|
108
|
+
mSnapshot = remoteSnapshotRes;
|
|
109
|
+
gSnapshot = globalSnapshotRes;
|
|
110
|
+
}
|
|
111
|
+
else if (require_tool.isRemoteInfoWithEntry(moduleInfo)) {
|
|
112
|
+
const moduleSnapshot = await this.loadManifestSnapshot(moduleInfo.entry, moduleInfo, {}, {
|
|
113
|
+
initiator,
|
|
114
|
+
id: id || moduleInfo.name
|
|
115
|
+
});
|
|
116
|
+
const globalSnapshotRes = require_global.setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
|
|
117
|
+
mSnapshot = moduleSnapshot;
|
|
118
|
+
gSnapshot = globalSnapshotRes;
|
|
119
|
+
} else require_logger.error(_module_federation_error_codes.RUNTIME_007, _module_federation_error_codes.runtimeDescMap, {
|
|
120
|
+
remoteName: moduleInfo.name,
|
|
121
|
+
remoteVersion: moduleInfo.version,
|
|
122
|
+
hostName: this.HostInstance.options.name,
|
|
123
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
124
|
+
}, void 0, require_context.optionsToMFContext(this.HostInstance.options));
|
|
125
|
+
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
126
|
+
id,
|
|
127
|
+
host: this.HostInstance,
|
|
128
|
+
options,
|
|
129
|
+
moduleInfo,
|
|
130
|
+
remoteSnapshot: mSnapshot
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
remoteSnapshot: mSnapshot,
|
|
134
|
+
globalSnapshot: gSnapshot
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
getGlobalRemoteInfo(moduleInfo) {
|
|
138
|
+
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
139
|
+
}
|
|
140
|
+
async getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
|
|
141
|
+
const getManifest = async () => {
|
|
142
|
+
const remoteInfo = require_load.getRemoteInfo(moduleInfo);
|
|
143
|
+
let manifestJson = this.manifestCache.get(manifestUrl);
|
|
144
|
+
if (manifestJson) {
|
|
145
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
146
|
+
manifestUrl,
|
|
147
|
+
moduleInfo,
|
|
148
|
+
resourceOptions,
|
|
149
|
+
manifestJson,
|
|
150
|
+
cached: true,
|
|
151
|
+
origin: this.HostInstance
|
|
152
|
+
});
|
|
153
|
+
return manifestJson;
|
|
154
|
+
}
|
|
155
|
+
await this.hooks.lifecycle.beforeLoadManifest.emit({
|
|
156
|
+
manifestUrl,
|
|
157
|
+
moduleInfo,
|
|
158
|
+
resourceOptions,
|
|
159
|
+
origin: this.HostInstance
|
|
160
|
+
});
|
|
161
|
+
let response;
|
|
162
|
+
let loadError;
|
|
163
|
+
let recovered = false;
|
|
164
|
+
try {
|
|
165
|
+
let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, remoteInfo, resourceOptions ? {
|
|
166
|
+
...resourceOptions,
|
|
167
|
+
url: manifestUrl,
|
|
168
|
+
resourceType: "manifest"
|
|
169
|
+
} : void 0);
|
|
170
|
+
if (!res || !(res instanceof Response)) res = await fetch(manifestUrl, {});
|
|
171
|
+
response = res;
|
|
172
|
+
manifestJson = await res.json();
|
|
173
|
+
} catch (err) {
|
|
174
|
+
loadError = err;
|
|
175
|
+
manifestJson = await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
176
|
+
id: manifestUrl,
|
|
177
|
+
error: err,
|
|
178
|
+
from: "runtime",
|
|
179
|
+
lifecycle: "afterResolve",
|
|
180
|
+
remote: remoteInfo,
|
|
181
|
+
origin: this.HostInstance
|
|
182
|
+
});
|
|
183
|
+
if (!manifestJson) {
|
|
184
|
+
delete this.manifestLoading[manifestUrl];
|
|
185
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
186
|
+
manifestUrl,
|
|
187
|
+
moduleInfo,
|
|
188
|
+
resourceOptions,
|
|
189
|
+
response,
|
|
190
|
+
error: err,
|
|
191
|
+
origin: this.HostInstance
|
|
192
|
+
});
|
|
193
|
+
require_logger.error(_module_federation_error_codes.RUNTIME_003, _module_federation_error_codes.runtimeDescMap, {
|
|
194
|
+
manifestUrl,
|
|
195
|
+
moduleName: moduleInfo.name,
|
|
196
|
+
hostName: this.HostInstance.options.name
|
|
197
|
+
}, `${err}`, require_context.optionsToMFContext(this.HostInstance.options));
|
|
198
|
+
}
|
|
199
|
+
recovered = true;
|
|
200
|
+
}
|
|
201
|
+
const missingRequiredFields = [
|
|
202
|
+
!manifestJson.metaData && "metaData",
|
|
203
|
+
!manifestJson.exposes && "exposes",
|
|
204
|
+
!manifestJson.shared && "shared"
|
|
205
|
+
].filter(Boolean);
|
|
206
|
+
const validationError = missingRequiredFields.length > 0 ? /* @__PURE__ */ new Error(`"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${missingRequiredFields.join(", ")}.`) : void 0;
|
|
207
|
+
if (validationError) await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
208
|
+
id: manifestUrl,
|
|
209
|
+
error: validationError,
|
|
210
|
+
from: "runtime",
|
|
211
|
+
lifecycle: "afterResolve",
|
|
212
|
+
remote: remoteInfo,
|
|
213
|
+
origin: this.HostInstance
|
|
214
|
+
});
|
|
215
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
216
|
+
manifestUrl,
|
|
217
|
+
moduleInfo,
|
|
218
|
+
resourceOptions,
|
|
219
|
+
manifestJson,
|
|
220
|
+
response,
|
|
221
|
+
error: validationError || loadError,
|
|
222
|
+
recovered: validationError ? void 0 : recovered || void 0,
|
|
223
|
+
origin: this.HostInstance
|
|
224
|
+
});
|
|
225
|
+
if (validationError) require_logger.error(_module_federation_error_codes.RUNTIME_013, _module_federation_error_codes.runtimeDescMap, {
|
|
226
|
+
manifestUrl,
|
|
227
|
+
moduleName: moduleInfo.name,
|
|
228
|
+
hostName: this.HostInstance.options.name,
|
|
229
|
+
missingFields: missingRequiredFields.join(",")
|
|
230
|
+
}, void 0, require_context.optionsToMFContext(this.HostInstance.options));
|
|
231
|
+
this.manifestCache.set(manifestUrl, manifestJson);
|
|
232
|
+
return manifestJson;
|
|
233
|
+
};
|
|
234
|
+
return getManifest();
|
|
235
|
+
}
|
|
236
|
+
async loadManifestSnapshot(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
|
|
237
|
+
const asyncLoadProcess = async () => {
|
|
238
|
+
const manifestJson = await this.getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions);
|
|
239
|
+
const remoteSnapshot = (0, _module_federation_sdk.generateSnapshotFromManifest)(manifestJson, { version: manifestUrl });
|
|
240
|
+
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
241
|
+
options: this.HostInstance.options,
|
|
242
|
+
moduleInfo,
|
|
243
|
+
manifestJson,
|
|
244
|
+
remoteSnapshot,
|
|
245
|
+
manifestUrl,
|
|
246
|
+
from: "manifest"
|
|
247
|
+
});
|
|
248
|
+
return remoteSnapshotRes;
|
|
249
|
+
};
|
|
250
|
+
if (!this.manifestLoading[manifestUrl]) this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
|
|
251
|
+
return this.manifestLoading[manifestUrl];
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
exports.SnapshotHandler = SnapshotHandler;
|
|
257
|
+
exports.getGlobalRemoteInfo = getGlobalRemoteInfo;
|
|
258
|
+
//# sourceMappingURL=SnapshotHandler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapshotHandler.cjs","names":["getGlobalSnapshotInfoByModuleInfo","getInfoWithoutType","getGlobalSnapshot","PluginSystem","AsyncHook","AsyncWaterfallHook","Global","isBrowserEnvValue","setGlobalSnapshotInfoByModuleInfo","isRemoteInfoWithEntry","RUNTIME_007","runtimeDescMap","optionsToMFContext","getRemoteInfo","RUNTIME_003","RUNTIME_013"],"sources":["../../../src/plugins/snapshot/SnapshotHandler.ts"],"sourcesContent":["import {\n GlobalModuleInfo,\n Manifest,\n ModuleInfo,\n generateSnapshotFromManifest,\n isManifestProvider,\n isBrowserEnvValue,\n} from '@module-federation/sdk';\nimport {\n RUNTIME_003,\n RUNTIME_007,\n RUNTIME_013,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Options, Remote, ResourceLoadInitiator } from '../../type';\nimport {\n isRemoteInfoWithEntry,\n error,\n optionsToMFContext,\n getRemoteInfo,\n} from '../../utils';\nimport {\n getGlobalSnapshot,\n setGlobalSnapshotInfoByModuleInfo,\n Global,\n addGlobalSnapshot,\n getGlobalSnapshotInfoByModuleInfo,\n getInfoWithoutType,\n} from '../../global';\nimport { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';\nimport { ModuleFederation } from '../../core';\n\nexport function getGlobalRemoteInfo(\n moduleInfo: Remote,\n origin: ModuleFederation,\n): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n} {\n const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: origin.name,\n version: origin.options.version,\n });\n\n // get remote detail info from global\n const globalRemoteInfo =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;\n\n if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {\n return {\n hostGlobalSnapshot,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: globalRemoteInfo.matchedVersion,\n }),\n };\n }\n\n return {\n hostGlobalSnapshot: undefined,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: 'version' in moduleInfo ? moduleInfo.version : undefined,\n }),\n };\n}\n\nexport class SnapshotHandler {\n loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null = null;\n HostInstance: ModuleFederation;\n manifestCache: Map<string, Manifest> = new Map();\n hooks = new PluginSystem({\n beforeLoadRemoteSnapshot: new AsyncHook<\n [\n {\n options: Options;\n moduleInfo: Remote;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeLoadRemoteSnapshot'),\n loadSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n hostGlobalSnapshot: GlobalModuleInfo[string] | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot?: GlobalModuleInfo[string] | undefined;\n }>('loadGlobalSnapshot'),\n loadRemoteSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n manifestJson?: Manifest;\n manifestUrl?: string;\n remoteSnapshot: ModuleInfo;\n from: 'global' | 'manifest';\n }>('loadRemoteSnapshot'),\n afterLoadSnapshot: new AsyncWaterfallHook<{\n id?: string;\n host: ModuleFederation;\n options: Options;\n moduleInfo: Remote;\n remoteSnapshot: ModuleInfo;\n }>('afterLoadSnapshot'),\n beforeLoadManifest: new AsyncHook<\n [\n {\n manifestUrl: string;\n moduleInfo: Remote;\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n };\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeLoadManifest'),\n afterLoadManifest: new AsyncHook<\n [\n {\n manifestUrl: string;\n moduleInfo: Remote;\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n };\n manifestJson?: Manifest;\n response?: Response;\n error?: unknown;\n cached?: boolean;\n recovered?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterLoadManifest'),\n });\n loaderHook: ModuleFederation['loaderHook'];\n manifestLoading: Record<string, Promise<ModuleInfo>> =\n Global.__FEDERATION__.__MANIFEST_LOADING__;\n\n constructor(HostInstance: ModuleFederation) {\n this.HostInstance = HostInstance;\n this.loaderHook = HostInstance.loaderHook;\n }\n\n // eslint-disable-next-line max-lines-per-function\n async loadRemoteSnapshotInfo({\n moduleInfo,\n id,\n initiator = 'loadRemote',\n }: {\n moduleInfo: Remote;\n id?: string;\n initiator?: ResourceLoadInitiator;\n }):\n | Promise<{\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n }>\n | never {\n const { options } = this.HostInstance;\n\n await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({\n options,\n moduleInfo,\n origin: this.HostInstance,\n });\n\n let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: this.HostInstance.options.name,\n version: this.HostInstance.options.version,\n });\n\n if (!hostSnapshot) {\n hostSnapshot = {\n version: this.HostInstance.options.version || '',\n remoteEntry: '',\n remotesInfo: {},\n };\n addGlobalSnapshot({\n [this.HostInstance.options.name]: hostSnapshot,\n });\n }\n\n // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.\n // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.\n if (\n hostSnapshot &&\n 'remotesInfo' in hostSnapshot &&\n !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value\n ) {\n if ('version' in moduleInfo || 'entry' in moduleInfo) {\n hostSnapshot.remotesInfo = {\n ...hostSnapshot?.remotesInfo,\n [moduleInfo.name]: {\n matchedVersion:\n 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,\n },\n };\n }\n }\n\n const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } =\n this.getGlobalRemoteInfo(moduleInfo);\n const {\n remoteSnapshot: globalRemoteSnapshot,\n globalSnapshot: globalSnapshotRes,\n } = await this.hooks.lifecycle.loadSnapshot.emit({\n options,\n moduleInfo,\n hostGlobalSnapshot,\n remoteSnapshot,\n globalSnapshot,\n });\n\n let mSnapshot;\n let gSnapshot;\n // global snapshot includes manifest or module info includes manifest\n if (globalRemoteSnapshot) {\n if (isManifestProvider(globalRemoteSnapshot)) {\n const remoteEntry = isBrowserEnvValue\n ? globalRemoteSnapshot.remoteEntry\n : globalRemoteSnapshot.ssrRemoteEntry ||\n globalRemoteSnapshot.remoteEntry ||\n '';\n const moduleSnapshot = await this.loadManifestSnapshot(\n remoteEntry,\n moduleInfo,\n {},\n {\n initiator,\n id: id || moduleInfo.name,\n },\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n {\n ...moduleInfo,\n // The global remote may be overridden\n // Therefore, set the snapshot key to the global address of the actual request\n entry: remoteEntry,\n },\n moduleSnapshot,\n );\n mSnapshot = moduleSnapshot;\n gSnapshot = globalSnapshotRes;\n } else {\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n remoteSnapshot: globalRemoteSnapshot,\n from: 'global',\n });\n mSnapshot = remoteSnapshotRes;\n gSnapshot = globalSnapshotRes;\n }\n } else {\n if (isRemoteInfoWithEntry(moduleInfo)) {\n // get from manifest.json and merge remote info from remote server\n const moduleSnapshot = await this.loadManifestSnapshot(\n moduleInfo.entry,\n moduleInfo,\n {},\n {\n initiator,\n id: id || moduleInfo.name,\n },\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n moduleInfo,\n moduleSnapshot,\n );\n mSnapshot = moduleSnapshot;\n gSnapshot = globalSnapshotRes;\n } else {\n error(\n RUNTIME_007,\n runtimeDescMap,\n {\n remoteName: moduleInfo.name,\n remoteVersion: moduleInfo.version,\n hostName: this.HostInstance.options.name,\n globalSnapshot: JSON.stringify(globalSnapshotRes),\n },\n undefined,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n }\n\n await this.hooks.lifecycle.afterLoadSnapshot.emit({\n id,\n host: this.HostInstance,\n options,\n moduleInfo,\n remoteSnapshot: mSnapshot,\n });\n\n return {\n remoteSnapshot: mSnapshot,\n globalSnapshot: gSnapshot,\n };\n }\n\n getGlobalRemoteInfo(moduleInfo: Remote): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n } {\n return getGlobalRemoteInfo(moduleInfo, this.HostInstance);\n }\n\n private async getManifestJson(\n manifestUrl: string,\n moduleInfo: Remote,\n extraOptions: Record<string, any>,\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n },\n ): Promise<Manifest> {\n const getManifest = async (): Promise<Manifest> => {\n const remoteInfo = getRemoteInfo(moduleInfo);\n let manifestJson: Manifest | undefined =\n this.manifestCache.get(manifestUrl);\n if (manifestJson) {\n await this.hooks.lifecycle.afterLoadManifest.emit({\n manifestUrl,\n moduleInfo,\n resourceOptions,\n manifestJson,\n cached: true,\n origin: this.HostInstance,\n });\n return manifestJson;\n }\n\n await this.hooks.lifecycle.beforeLoadManifest.emit({\n manifestUrl,\n moduleInfo,\n resourceOptions,\n origin: this.HostInstance,\n });\n\n let response: Response | undefined;\n let loadError: unknown;\n let recovered = false;\n\n try {\n let res = await this.loaderHook.lifecycle.fetch.emit(\n manifestUrl,\n {},\n remoteInfo,\n resourceOptions\n ? {\n ...resourceOptions,\n url: manifestUrl,\n resourceType: 'manifest',\n }\n : undefined,\n );\n if (!res || !(res instanceof Response)) {\n res = await fetch(manifestUrl, {});\n }\n response = res;\n manifestJson = (await res.json()) as Manifest;\n } catch (err) {\n loadError = err;\n manifestJson =\n (await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit(\n {\n id: manifestUrl,\n error: err,\n from: 'runtime',\n lifecycle: 'afterResolve',\n remote: remoteInfo,\n origin: this.HostInstance,\n },\n )) as Manifest | undefined;\n\n if (!manifestJson) {\n delete this.manifestLoading[manifestUrl];\n await this.hooks.lifecycle.afterLoadManifest.emit({\n manifestUrl,\n moduleInfo,\n resourceOptions,\n response,\n error: err,\n origin: this.HostInstance,\n });\n error(\n RUNTIME_003,\n runtimeDescMap,\n {\n manifestUrl,\n moduleName: moduleInfo.name,\n hostName: this.HostInstance.options.name,\n },\n `${err}`,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n recovered = true;\n }\n\n const missingRequiredFields = [\n !manifestJson.metaData && 'metaData',\n !manifestJson.exposes && 'exposes',\n !manifestJson.shared && 'shared',\n ].filter(Boolean);\n const validationError =\n missingRequiredFields.length > 0\n ? new Error(\n `\"${manifestUrl}\" is not a valid federation manifest for remote \"${moduleInfo.name}\". Missing required fields: ${missingRequiredFields.join(', ')}.`,\n )\n : undefined;\n if (validationError) {\n await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit(\n {\n id: manifestUrl,\n error: validationError,\n from: 'runtime',\n lifecycle: 'afterResolve',\n remote: remoteInfo,\n origin: this.HostInstance,\n },\n );\n }\n\n await this.hooks.lifecycle.afterLoadManifest.emit({\n manifestUrl,\n moduleInfo,\n resourceOptions,\n manifestJson,\n response,\n error: validationError || loadError,\n recovered: validationError ? undefined : recovered || undefined,\n origin: this.HostInstance,\n });\n\n if (validationError) {\n error(\n RUNTIME_013,\n runtimeDescMap,\n {\n manifestUrl,\n moduleName: moduleInfo.name,\n hostName: this.HostInstance.options.name,\n missingFields: missingRequiredFields.join(','),\n },\n undefined,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n\n this.manifestCache.set(manifestUrl, manifestJson);\n return manifestJson;\n };\n\n return getManifest();\n }\n\n private async loadManifestSnapshot(\n manifestUrl: string,\n moduleInfo: Remote,\n extraOptions: Record<string, any>,\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n },\n ): Promise<ModuleInfo> {\n const asyncLoadProcess = async () => {\n const manifestJson = await this.getManifestJson(\n manifestUrl,\n moduleInfo,\n extraOptions,\n resourceOptions,\n );\n const remoteSnapshot = generateSnapshotFromManifest(manifestJson, {\n version: manifestUrl,\n });\n\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n manifestJson,\n remoteSnapshot,\n manifestUrl,\n from: 'manifest',\n });\n return remoteSnapshotRes;\n };\n\n if (!this.manifestLoading[manifestUrl]) {\n this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);\n }\n return this.manifestLoading[manifestUrl];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,oBACd,YACA,QAKA;CACA,MAAM,qBAAqBA,iDAAkC;EAC3D,MAAM,OAAO;EACb,SAAS,OAAO,QAAQ;EACzB,CAAC;CAGF,MAAM,mBACJ,sBACA,iBAAiB,sBACjB,mBAAmB,eACnBC,kCAAmB,mBAAmB,aAAa,WAAW,KAAK,CAAC;AAEtE,KAAI,oBAAoB,iBAAiB,eACvC,QAAO;EACL;EACA,gBAAgBC,kCAAmB;EACnC,gBAAgBF,iDAAkC;GAChD,MAAM,WAAW;GACjB,SAAS,iBAAiB;GAC3B,CAAC;EACH;AAGH,QAAO;EACL,oBAAoB;EACpB,gBAAgBE,kCAAmB;EACnC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ils/hooks/asyncWaterfallHooks.js";
|
|
3
|
+
import { PluginSystem } from "../../utils/hooks/pluginSystem.js";
|
|
4
|
+
import { getGlobalSnapshot } from "../../global.js";
|
|
5
|
+
import { ModuleFederation } from "../../core.js";
|
|
6
|
+
import { Options, Remote } from "../../type/config.js";
|
|
7
|
+
import { ResourceLoadInitiator } from "../../type/preload.js";
|
|
8
|
+
import { GlobalModuleInfo, Manifest, ModuleInfo } from "@module-federation/sdk";
|
|
9
|
+
|
|
10
|
+
//#region src/plugins/snapshot/SnapshotHandler.d.ts
|
|
11
|
+
declare class SnapshotHandler {
|
|
12
|
+
loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null;
|
|
13
|
+
HostInstance: ModuleFederation;
|
|
14
|
+
manifestCache: Map<string, Manifest>;
|
|
15
|
+
hooks: PluginSystem<{
|
|
16
|
+
beforeLoadRemoteSnapshot: AsyncHook<[{
|
|
17
|
+
options: Options;
|
|
18
|
+
moduleInfo: Remote;
|
|
19
|
+
origin: ModuleFederation;
|
|
20
|
+
}], void>;
|
|
21
|
+
loadSnapshot: AsyncWaterfallHook<{
|
|
22
|
+
options: Options;
|
|
23
|
+
moduleInfo: Remote;
|
|
24
|
+
hostGlobalSnapshot: GlobalModuleInfo[string] | undefined;
|
|
25
|
+
globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
|
|
26
|
+
remoteSnapshot?: GlobalModuleInfo[string] | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
loadRemoteSnapshot: AsyncWaterfallHook<{
|
|
29
|
+
options: Options;
|
|
30
|
+
moduleInfo: Remote;
|
|
31
|
+
manifestJson?: Manifest;
|
|
32
|
+
manifestUrl?: string;
|
|
33
|
+
remoteSnapshot: ModuleInfo;
|
|
34
|
+
from: "global" | "manifest";
|
|
35
|
+
}>;
|
|
36
|
+
afterLoadSnapshot: AsyncWaterfallHook<{
|
|
37
|
+
id?: string;
|
|
38
|
+
host: ModuleFederation;
|
|
39
|
+
options: Options;
|
|
40
|
+
moduleInfo: Remote;
|
|
41
|
+
remoteSnapshot: ModuleInfo;
|
|
42
|
+
}>;
|
|
43
|
+
beforeLoadManifest: AsyncHook<[{
|
|
44
|
+
manifestUrl: string;
|
|
45
|
+
moduleInfo: Remote;
|
|
46
|
+
resourceOptions?: {
|
|
47
|
+
initiator: ResourceLoadInitiator;
|
|
48
|
+
id: string;
|
|
49
|
+
};
|
|
50
|
+
origin: ModuleFederation;
|
|
51
|
+
}], void>;
|
|
52
|
+
afterLoadManifest: AsyncHook<[{
|
|
53
|
+
manifestUrl: string;
|
|
54
|
+
moduleInfo: Remote;
|
|
55
|
+
resourceOptions?: {
|
|
56
|
+
initiator: ResourceLoadInitiator;
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
manifestJson?: Manifest;
|
|
60
|
+
response?: Response;
|
|
61
|
+
error?: unknown;
|
|
62
|
+
cached?: boolean;
|
|
63
|
+
recovered?: boolean;
|
|
64
|
+
origin: ModuleFederation;
|
|
65
|
+
}], void>;
|
|
66
|
+
}>;
|
|
67
|
+
loaderHook: ModuleFederation['loaderHook'];
|
|
68
|
+
manifestLoading: Record<string, Promise<ModuleInfo>>;
|
|
69
|
+
constructor(HostInstance: ModuleFederation);
|
|
70
|
+
loadRemoteSnapshotInfo({
|
|
71
|
+
moduleInfo,
|
|
72
|
+
id,
|
|
73
|
+
initiator
|
|
74
|
+
}: {
|
|
75
|
+
moduleInfo: Remote;
|
|
76
|
+
id?: string;
|
|
77
|
+
initiator?: ResourceLoadInitiator;
|
|
78
|
+
}): Promise<{
|
|
79
|
+
remoteSnapshot: ModuleInfo;
|
|
80
|
+
globalSnapshot: GlobalModuleInfo;
|
|
81
|
+
}> | never;
|
|
82
|
+
getGlobalRemoteInfo(moduleInfo: Remote): {
|
|
83
|
+
hostGlobalSnapshot: ModuleInfo | undefined;
|
|
84
|
+
globalSnapshot: ReturnType<typeof getGlobalSnapshot>;
|
|
85
|
+
remoteSnapshot: GlobalModuleInfo[string] | undefined;
|
|
86
|
+
};
|
|
87
|
+
private getManifestJson;
|
|
88
|
+
private loadManifestSnapshot;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { SnapshotHandler };
|
|
92
|
+
//# sourceMappingURL=SnapshotHandler.d.ts.map
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { error } from "../../utils/logger.js";
|
|
2
|
+
import { isRemoteInfoWithEntry } from "../../utils/tool.js";
|
|
3
|
+
import { Global, addGlobalSnapshot, getGlobalSnapshot, getGlobalSnapshotInfoByModuleInfo, getInfoWithoutType, setGlobalSnapshotInfoByModuleInfo } from "../../global.js";
|
|
4
|
+
import { getRemoteInfo } from "../../utils/load.js";
|
|
5
|
+
import { optionsToMFContext } from "../../utils/context.js";
|
|
6
|
+
import "../../utils/index.js";
|
|
7
|
+
import { AsyncHook } from "../../utils/hooks/asyncHook.js";
|
|
8
|
+
import { AsyncWaterfallHook } from "../../utils/hooks/asyncWaterfallHooks.js";
|
|
9
|
+
import { PluginSystem } from "../../utils/hooks/pluginSystem.js";
|
|
10
|
+
import "../../utils/hooks/index.js";
|
|
11
|
+
import { generateSnapshotFromManifest, isBrowserEnvValue, isManifestProvider } from "@module-federation/sdk";
|
|
12
|
+
import { RUNTIME_003, RUNTIME_007, RUNTIME_013, runtimeDescMap } from "@module-federation/error-codes";
|
|
13
|
+
|
|
14
|
+
//#region src/plugins/snapshot/SnapshotHandler.ts
|
|
15
|
+
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
16
|
+
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
17
|
+
name: origin.name,
|
|
18
|
+
version: origin.options.version
|
|
19
|
+
});
|
|
20
|
+
const globalRemoteInfo = hostGlobalSnapshot && "remotesInfo" in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
21
|
+
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) return {
|
|
22
|
+
hostGlobalSnapshot,
|
|
23
|
+
globalSnapshot: getGlobalSnapshot(),
|
|
24
|
+
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
25
|
+
name: moduleInfo.name,
|
|
26
|
+
version: globalRemoteInfo.matchedVersion
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
hostGlobalSnapshot: void 0,
|
|
31
|
+
globalSnapshot: getGlobalSnapshot(),
|
|
32
|
+
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
33
|
+
name: moduleInfo.name,
|
|
34
|
+
version: "version" in moduleInfo ? moduleInfo.version : void 0
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var SnapshotHandler = class {
|
|
39
|
+
constructor(HostInstance) {
|
|
40
|
+
this.loadingHostSnapshot = null;
|
|
41
|
+
this.manifestCache = /* @__PURE__ */ new Map();
|
|
42
|
+
this.hooks = new PluginSystem({
|
|
43
|
+
beforeLoadRemoteSnapshot: new AsyncHook("beforeLoadRemoteSnapshot"),
|
|
44
|
+
loadSnapshot: new AsyncWaterfallHook("loadGlobalSnapshot"),
|
|
45
|
+
loadRemoteSnapshot: new AsyncWaterfallHook("loadRemoteSnapshot"),
|
|
46
|
+
afterLoadSnapshot: new AsyncWaterfallHook("afterLoadSnapshot"),
|
|
47
|
+
beforeLoadManifest: new AsyncHook("beforeLoadManifest"),
|
|
48
|
+
afterLoadManifest: new AsyncHook("afterLoadManifest")
|
|
49
|
+
});
|
|
50
|
+
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
51
|
+
this.HostInstance = HostInstance;
|
|
52
|
+
this.loaderHook = HostInstance.loaderHook;
|
|
53
|
+
}
|
|
54
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, initiator = "loadRemote" }) {
|
|
55
|
+
const { options } = this.HostInstance;
|
|
56
|
+
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
57
|
+
options,
|
|
58
|
+
moduleInfo,
|
|
59
|
+
origin: this.HostInstance
|
|
60
|
+
});
|
|
61
|
+
let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
62
|
+
name: this.HostInstance.options.name,
|
|
63
|
+
version: this.HostInstance.options.version
|
|
64
|
+
});
|
|
65
|
+
if (!hostSnapshot) {
|
|
66
|
+
hostSnapshot = {
|
|
67
|
+
version: this.HostInstance.options.version || "",
|
|
68
|
+
remoteEntry: "",
|
|
69
|
+
remotesInfo: {}
|
|
70
|
+
};
|
|
71
|
+
addGlobalSnapshot({ [this.HostInstance.options.name]: hostSnapshot });
|
|
72
|
+
}
|
|
73
|
+
if (hostSnapshot && "remotesInfo" in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
74
|
+
if ("version" in moduleInfo || "entry" in moduleInfo) hostSnapshot.remotesInfo = {
|
|
75
|
+
...hostSnapshot?.remotesInfo,
|
|
76
|
+
[moduleInfo.name]: { matchedVersion: "version" in moduleInfo ? moduleInfo.version : moduleInfo.entry }
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
80
|
+
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
81
|
+
options,
|
|
82
|
+
moduleInfo,
|
|
83
|
+
hostGlobalSnapshot,
|
|
84
|
+
remoteSnapshot,
|
|
85
|
+
globalSnapshot
|
|
86
|
+
});
|
|
87
|
+
let mSnapshot;
|
|
88
|
+
let gSnapshot;
|
|
89
|
+
if (globalRemoteSnapshot) if (isManifestProvider(globalRemoteSnapshot)) {
|
|
90
|
+
const remoteEntry = isBrowserEnvValue ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || "";
|
|
91
|
+
const moduleSnapshot = await this.loadManifestSnapshot(remoteEntry, moduleInfo, {}, {
|
|
92
|
+
initiator,
|
|
93
|
+
id: id || moduleInfo.name
|
|
94
|
+
});
|
|
95
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo({
|
|
96
|
+
...moduleInfo,
|
|
97
|
+
entry: remoteEntry
|
|
98
|
+
}, moduleSnapshot);
|
|
99
|
+
mSnapshot = moduleSnapshot;
|
|
100
|
+
gSnapshot = globalSnapshotRes;
|
|
101
|
+
} else {
|
|
102
|
+
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
103
|
+
options: this.HostInstance.options,
|
|
104
|
+
moduleInfo,
|
|
105
|
+
remoteSnapshot: globalRemoteSnapshot,
|
|
106
|
+
from: "global"
|
|
107
|
+
});
|
|
108
|
+
mSnapshot = remoteSnapshotRes;
|
|
109
|
+
gSnapshot = globalSnapshotRes;
|
|
110
|
+
}
|
|
111
|
+
else if (isRemoteInfoWithEntry(moduleInfo)) {
|
|
112
|
+
const moduleSnapshot = await this.loadManifestSnapshot(moduleInfo.entry, moduleInfo, {}, {
|
|
113
|
+
initiator,
|
|
114
|
+
id: id || moduleInfo.name
|
|
115
|
+
});
|
|
116
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
|
|
117
|
+
mSnapshot = moduleSnapshot;
|
|
118
|
+
gSnapshot = globalSnapshotRes;
|
|
119
|
+
} else error(RUNTIME_007, runtimeDescMap, {
|
|
120
|
+
remoteName: moduleInfo.name,
|
|
121
|
+
remoteVersion: moduleInfo.version,
|
|
122
|
+
hostName: this.HostInstance.options.name,
|
|
123
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
124
|
+
}, void 0, optionsToMFContext(this.HostInstance.options));
|
|
125
|
+
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
126
|
+
id,
|
|
127
|
+
host: this.HostInstance,
|
|
128
|
+
options,
|
|
129
|
+
moduleInfo,
|
|
130
|
+
remoteSnapshot: mSnapshot
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
remoteSnapshot: mSnapshot,
|
|
134
|
+
globalSnapshot: gSnapshot
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
getGlobalRemoteInfo(moduleInfo) {
|
|
138
|
+
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
139
|
+
}
|
|
140
|
+
async getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
|
|
141
|
+
const getManifest = async () => {
|
|
142
|
+
const remoteInfo = getRemoteInfo(moduleInfo);
|
|
143
|
+
let manifestJson = this.manifestCache.get(manifestUrl);
|
|
144
|
+
if (manifestJson) {
|
|
145
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
146
|
+
manifestUrl,
|
|
147
|
+
moduleInfo,
|
|
148
|
+
resourceOptions,
|
|
149
|
+
manifestJson,
|
|
150
|
+
cached: true,
|
|
151
|
+
origin: this.HostInstance
|
|
152
|
+
});
|
|
153
|
+
return manifestJson;
|
|
154
|
+
}
|
|
155
|
+
await this.hooks.lifecycle.beforeLoadManifest.emit({
|
|
156
|
+
manifestUrl,
|
|
157
|
+
moduleInfo,
|
|
158
|
+
resourceOptions,
|
|
159
|
+
origin: this.HostInstance
|
|
160
|
+
});
|
|
161
|
+
let response;
|
|
162
|
+
let loadError;
|
|
163
|
+
let recovered = false;
|
|
164
|
+
try {
|
|
165
|
+
let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, remoteInfo, resourceOptions ? {
|
|
166
|
+
...resourceOptions,
|
|
167
|
+
url: manifestUrl,
|
|
168
|
+
resourceType: "manifest"
|
|
169
|
+
} : void 0);
|
|
170
|
+
if (!res || !(res instanceof Response)) res = await fetch(manifestUrl, {});
|
|
171
|
+
response = res;
|
|
172
|
+
manifestJson = await res.json();
|
|
173
|
+
} catch (err) {
|
|
174
|
+
loadError = err;
|
|
175
|
+
manifestJson = await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
176
|
+
id: manifestUrl,
|
|
177
|
+
error: err,
|
|
178
|
+
from: "runtime",
|
|
179
|
+
lifecycle: "afterResolve",
|
|
180
|
+
remote: remoteInfo,
|
|
181
|
+
origin: this.HostInstance
|
|
182
|
+
});
|
|
183
|
+
if (!manifestJson) {
|
|
184
|
+
delete this.manifestLoading[manifestUrl];
|
|
185
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
186
|
+
manifestUrl,
|
|
187
|
+
moduleInfo,
|
|
188
|
+
resourceOptions,
|
|
189
|
+
response,
|
|
190
|
+
error: err,
|
|
191
|
+
origin: this.HostInstance
|
|
192
|
+
});
|
|
193
|
+
error(RUNTIME_003, runtimeDescMap, {
|
|
194
|
+
manifestUrl,
|
|
195
|
+
moduleName: moduleInfo.name,
|
|
196
|
+
hostName: this.HostInstance.options.name
|
|
197
|
+
}, `${err}`, optionsToMFContext(this.HostInstance.options));
|
|
198
|
+
}
|
|
199
|
+
recovered = true;
|
|
200
|
+
}
|
|
201
|
+
const missingRequiredFields = [
|
|
202
|
+
!manifestJson.metaData && "metaData",
|
|
203
|
+
!manifestJson.exposes && "exposes",
|
|
204
|
+
!manifestJson.shared && "shared"
|
|
205
|
+
].filter(Boolean);
|
|
206
|
+
const validationError = missingRequiredFields.length > 0 ? /* @__PURE__ */ new Error(`"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${missingRequiredFields.join(", ")}.`) : void 0;
|
|
207
|
+
if (validationError) await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
208
|
+
id: manifestUrl,
|
|
209
|
+
error: validationError,
|
|
210
|
+
from: "runtime",
|
|
211
|
+
lifecycle: "afterResolve",
|
|
212
|
+
remote: remoteInfo,
|
|
213
|
+
origin: this.HostInstance
|
|
214
|
+
});
|
|
215
|
+
await this.hooks.lifecycle.afterLoadManifest.emit({
|
|
216
|
+
manifestUrl,
|
|
217
|
+
moduleInfo,
|
|
218
|
+
resourceOptions,
|
|
219
|
+
manifestJson,
|
|
220
|
+
response,
|
|
221
|
+
error: validationError || loadError,
|
|
222
|
+
recovered: validationError ? void 0 : recovered || void 0,
|
|
223
|
+
origin: this.HostInstance
|
|
224
|
+
});
|
|
225
|
+
if (validationError) error(RUNTIME_013, runtimeDescMap, {
|
|
226
|
+
manifestUrl,
|
|
227
|
+
moduleName: moduleInfo.name,
|
|
228
|
+
hostName: this.HostInstance.options.name,
|
|
229
|
+
missingFields: missingRequiredFields.join(",")
|
|
230
|
+
}, void 0, optionsToMFContext(this.HostInstance.options));
|
|
231
|
+
this.manifestCache.set(manifestUrl, manifestJson);
|
|
232
|
+
return manifestJson;
|
|
233
|
+
};
|
|
234
|
+
return getManifest();
|
|
235
|
+
}
|
|
236
|
+
async loadManifestSnapshot(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
|
|
237
|
+
const asyncLoadProcess = async () => {
|
|
238
|
+
const manifestJson = await this.getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions);
|
|
239
|
+
const remoteSnapshot = generateSnapshotFromManifest(manifestJson, { version: manifestUrl });
|
|
240
|
+
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
241
|
+
options: this.HostInstance.options,
|
|
242
|
+
moduleInfo,
|
|
243
|
+
manifestJson,
|
|
244
|
+
remoteSnapshot,
|
|
245
|
+
manifestUrl,
|
|
246
|
+
from: "manifest"
|
|
247
|
+
});
|
|
248
|
+
return remoteSnapshotRes;
|
|
249
|
+
};
|
|
250
|
+
if (!this.manifestLoading[manifestUrl]) this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
|
|
251
|
+
return this.manifestLoading[manifestUrl];
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
export { SnapshotHandler, getGlobalRemoteInfo };
|
|
257
|
+
//# sourceMappingURL=SnapshotHandler.js.map
|