@module-federation/bridge-react 0.0.0-perf-devtools-20260108034446 → 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/dist/base.cjs.js +4 -4
- package/dist/base.d.ts +8 -311
- package/dist/base.es.js +11 -11
- package/dist/{bridge-base-CPSTBjEp.mjs → bridge-base-CHnL6Q9P.mjs} +63 -103
- package/dist/{bridge-base-RStDxH71.js → bridge-base-DSYKAGGD.js} +63 -102
- package/dist/{createHelpers-Ui5pt7je.mjs → createHelpers-D3Sg5lKp.mjs} +32 -17
- package/dist/{createHelpers-B_L612IN.js → createHelpers-D6thyyLv.js} +30 -15
- package/dist/data-fetch-server-middleware.cjs.js +4 -4
- package/dist/data-fetch-server-middleware.d.ts +1 -15
- package/dist/data-fetch-server-middleware.es.js +2 -2
- package/dist/data-fetch-utils.cjs.js +2 -2
- package/dist/data-fetch-utils.d.ts +1 -81
- package/dist/data-fetch-utils.es.js +7 -7
- package/dist/data-fetch.cjs.js +22 -0
- package/dist/data-fetch.d.ts +4 -0
- package/dist/data-fetch.es.js +22 -0
- package/dist/error-boundary.d.ts +17 -0
- package/dist/error-boundary.spec.d.ts +1 -0
- package/dist/{index-DyQNwY2M.mjs → index-Bs2NxD2z.mjs} +1 -1
- package/dist/{index-DRSBaSu3.js → index-DbjGCKOr.js} +2 -2
- package/dist/index.cjs.js +27 -6
- package/dist/index.d.ts +12 -299
- package/dist/index.es.js +34 -13
- package/dist/lazy/AwaitDataFetch.d.ts +24 -0
- package/dist/lazy/HydratedStylesheetAssets.d.ts +4 -0
- package/dist/lazy/constant.d.ts +26 -0
- package/dist/lazy/createLazyComponent.d.ts +28 -0
- package/dist/lazy/data-fetch/cache.d.ts +34 -0
- package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
- package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
- package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
- package/{src/lazy/data-fetch/index.ts → dist/lazy/data-fetch/index.d.ts} +1 -11
- package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
- package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
- package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
- package/dist/lazy/index.d.ts +9 -0
- package/dist/lazy/logger.d.ts +2 -0
- package/dist/lazy/types.d.ts +60 -0
- package/dist/lazy/utils.d.ts +48 -0
- package/dist/lazy/wrapNoSSR.d.ts +9 -0
- package/dist/{lazy-load-component-plugin-BvnyaA6i.js → lazy-load-component-plugin-DSURjnZ0.js} +170 -44
- package/dist/{lazy-load-component-plugin-CVcFMRce.mjs → lazy-load-component-plugin-NZphPG7_.mjs} +174 -48
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.d.ts +2 -16
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.cjs.js +2 -2
- package/dist/lazy-utils.d.ts +1 -149
- package/dist/lazy-utils.es.js +19 -19
- package/dist/logger-DwWkXsWl.mjs +139 -0
- package/dist/logger-Dxblx6P-.js +138 -0
- package/dist/plugin.d.ts +2 -22
- package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
- package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
- package/dist/prefetch-Bxf6DSx_.js +1477 -0
- package/dist/prefetch-TKq_EK_q.mjs +1478 -0
- package/dist/provider/context.d.ts +3 -0
- package/dist/provider/plugin.d.ts +7 -0
- package/dist/provider/versions/bridge-base.d.ts +5 -0
- package/dist/provider/versions/legacy.d.ts +26 -0
- package/dist/provider/versions/v18.d.ts +19 -0
- package/dist/provider/versions/v19.d.ts +21 -0
- package/dist/remote/RemoteAppWrapper.d.ts +7 -0
- package/dist/remote/base-component/create.d.ts +9 -0
- package/dist/remote/base-component/index.d.ts +5 -0
- package/dist/remote/createHelpers.d.ts +17 -0
- package/dist/remote/router-component/component.d.ts +8 -0
- package/dist/remote/router-component/create.d.ts +9 -0
- package/dist/remote/router-component/index.d.ts +5 -0
- package/dist/router/default.d.ts +7 -0
- package/dist/router/v5.d.ts +4 -0
- package/dist/router/v6.d.ts +7 -0
- package/dist/router/v7.d.ts +6 -0
- package/dist/router-v5.cjs.js +5 -3
- package/dist/router-v5.d.ts +1 -18
- package/dist/router-v5.es.js +5 -3
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.d.ts +1 -20
- package/dist/router-v6.es.js +1 -1
- package/dist/router-v7.cjs.js +5 -3
- package/dist/router-v7.d.ts +1 -20
- package/dist/router-v7.es.js +5 -3
- package/dist/router.cjs.js +1 -1
- package/dist/router.d.ts +1 -20
- package/dist/router.es.js +1 -1
- package/dist/shared/size-limited-cache.d.ts +29 -0
- package/dist/shared/size-limited-cache.spec.d.ts +1 -0
- package/dist/size-limited-cache.cjs.js +82 -0
- package/dist/size-limited-cache.d.ts +1 -0
- package/dist/size-limited-cache.es.js +82 -0
- package/dist/types.d.ts +137 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils-5dGErM3C.js +588 -0
- package/dist/utils-BBP3hEeV.mjs +589 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.d.ts +3 -114
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.d.ts +3 -115
- package/dist/v19.es.js +1 -1
- package/package.json +35 -14
- package/CHANGELOG.md +0 -735
- package/__tests__/bridge.spec.tsx +0 -160
- package/__tests__/createLazyComponent.spec.tsx +0 -209
- package/__tests__/prefetch.spec.ts +0 -156
- package/__tests__/router.spec.tsx +0 -82
- package/__tests__/setupTests.ts +0 -8
- package/__tests__/util.ts +0 -36
- package/dist/index.esm-BWaKho-8.js +0 -491
- package/dist/index.esm-CPwSeCvw.mjs +0 -492
- package/dist/prefetch-CK3EZdY4.mjs +0 -1273
- package/dist/prefetch-MiXeF8KH.js +0 -1272
- package/dist/utils-dUgb9Jkm.mjs +0 -2016
- package/dist/utils-tM9yE73c.js +0 -2015
- package/jest.config.ts +0 -21
- package/project.json +0 -23
- package/src/base.ts +0 -50
- package/src/index.ts +0 -50
- package/src/lazy/AwaitDataFetch.tsx +0 -215
- package/src/lazy/constant.ts +0 -30
- package/src/lazy/createLazyComponent.tsx +0 -411
- package/src/lazy/data-fetch/cache.ts +0 -291
- package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
- package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
- package/src/lazy/data-fetch/prefetch.ts +0 -112
- package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
- package/src/lazy/index.ts +0 -35
- package/src/lazy/logger.ts +0 -6
- package/src/lazy/types.ts +0 -75
- package/src/lazy/utils.ts +0 -372
- package/src/lazy/wrapNoSSR.tsx +0 -10
- package/src/modern-app-env.d.ts +0 -2
- package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
- package/src/plugins/lazy-load-component-plugin.ts +0 -57
- package/src/provider/context.tsx +0 -4
- package/src/provider/plugin.ts +0 -22
- package/src/provider/versions/bridge-base.tsx +0 -150
- package/src/provider/versions/legacy.ts +0 -87
- package/src/provider/versions/v18.ts +0 -47
- package/src/provider/versions/v19.ts +0 -48
- package/src/remote/RemoteAppWrapper.tsx +0 -108
- package/src/remote/base-component/create.tsx +0 -23
- package/src/remote/base-component/index.tsx +0 -10
- package/src/remote/createHelpers.tsx +0 -130
- package/src/remote/router-component/component.tsx +0 -104
- package/src/remote/router-component/create.tsx +0 -23
- package/src/remote/router-component/index.tsx +0 -10
- package/src/router/default.tsx +0 -73
- package/src/router/v5.tsx +0 -43
- package/src/router/v6.tsx +0 -74
- package/src/router/v7.tsx +0 -75
- package/src/types.ts +0 -147
- package/src/utils/index.ts +0 -44
- package/src/v18.ts +0 -9
- package/src/v19.ts +0 -9
- package/tsconfig.json +0 -42
- package/tsconfig.node.json +0 -11
- package/tsconfig.spec.json +0 -26
- package/vite.config.ts +0 -112
- package/vitest.config.ts +0 -27
- /package/{src/remote/base-component/component.tsx → dist/remote/base-component/component.d.ts} +0 -0
|
@@ -0,0 +1,1477 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const lazyUtils = require("./utils-5dGErM3C.js");
|
|
3
|
+
const logger = require("./logger-Dxblx6P-.js");
|
|
4
|
+
async function safeWrapper(callback, disableWarn) {
|
|
5
|
+
try {
|
|
6
|
+
return await callback();
|
|
7
|
+
} catch (e) {
|
|
8
|
+
lazyUtils.warn(e);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function isStaticResourcesEqual(url1, url2) {
|
|
13
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
14
|
+
return url1.replace(REG_EXP, "").replace(/\/$/, "") === url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
15
|
+
}
|
|
16
|
+
function createScript(info) {
|
|
17
|
+
let script = null;
|
|
18
|
+
let needAttach = true;
|
|
19
|
+
let timeout = 2e4;
|
|
20
|
+
let timeoutId;
|
|
21
|
+
const scripts = document.getElementsByTagName("script");
|
|
22
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
23
|
+
const s = scripts[i];
|
|
24
|
+
const scriptSrc = s.getAttribute("src");
|
|
25
|
+
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
26
|
+
script = s;
|
|
27
|
+
needAttach = false;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!script) {
|
|
32
|
+
const attrs = info.attrs;
|
|
33
|
+
script = document.createElement("script");
|
|
34
|
+
script.type = (attrs == null ? void 0 : attrs["type"]) === "module" ? "module" : "text/javascript";
|
|
35
|
+
let createScriptRes = void 0;
|
|
36
|
+
if (info.createScriptHook) {
|
|
37
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
38
|
+
if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
|
|
39
|
+
else if (typeof createScriptRes === "object") {
|
|
40
|
+
if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
|
|
41
|
+
if ("timeout" in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!script.src) script.src = info.url;
|
|
45
|
+
if (attrs && !createScriptRes) Object.keys(attrs).forEach((name) => {
|
|
46
|
+
if (script) {
|
|
47
|
+
if (name === "async" || name === "defer") script[name] = attrs[name];
|
|
48
|
+
else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
let executionError = null;
|
|
53
|
+
const executionErrorHandler = typeof window !== "undefined" ? (evt) => {
|
|
54
|
+
if (evt.filename && isStaticResourcesEqual(evt.filename, info.url)) {
|
|
55
|
+
const err = /* @__PURE__ */ new Error(`ScriptExecutionError: Script "${info.url}" loaded but threw a runtime error during execution: ${evt.message} (${evt.filename}:${evt.lineno}:${evt.colno})`);
|
|
56
|
+
err.name = "ScriptExecutionError";
|
|
57
|
+
executionError = err;
|
|
58
|
+
}
|
|
59
|
+
} : null;
|
|
60
|
+
if (executionErrorHandler) window.addEventListener("error", executionErrorHandler);
|
|
61
|
+
const onScriptComplete = async (prev, event) => {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
if (executionErrorHandler) window.removeEventListener("error", executionErrorHandler);
|
|
64
|
+
const onScriptCompleteCallback = () => {
|
|
65
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
66
|
+
const networkError = /* @__PURE__ */ new Error((event == null ? void 0 : event.isTimeout) ? `ScriptNetworkError: Script "${info.url}" timed out.` : `ScriptNetworkError: Failed to load script "${info.url}" - the script URL is unreachable or the server returned an error (network failure, 404, CORS, etc.)`);
|
|
67
|
+
networkError.name = "ScriptNetworkError";
|
|
68
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(networkError));
|
|
69
|
+
} else if (executionError) (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(executionError));
|
|
70
|
+
else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
71
|
+
};
|
|
72
|
+
if (script) {
|
|
73
|
+
script.onerror = null;
|
|
74
|
+
script.onload = null;
|
|
75
|
+
safeWrapper(() => {
|
|
76
|
+
const { needDeleteScript = true } = info;
|
|
77
|
+
if (needDeleteScript) (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
|
|
78
|
+
});
|
|
79
|
+
if (prev && typeof prev === "function") {
|
|
80
|
+
const result = prev(event);
|
|
81
|
+
if (result instanceof Promise) {
|
|
82
|
+
const res = await result;
|
|
83
|
+
onScriptCompleteCallback();
|
|
84
|
+
return res;
|
|
85
|
+
}
|
|
86
|
+
onScriptCompleteCallback();
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
onScriptCompleteCallback();
|
|
91
|
+
};
|
|
92
|
+
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
93
|
+
script.onload = onScriptComplete.bind(null, script.onload);
|
|
94
|
+
timeoutId = setTimeout(() => {
|
|
95
|
+
onScriptComplete(null, {
|
|
96
|
+
type: "error",
|
|
97
|
+
isTimeout: true
|
|
98
|
+
});
|
|
99
|
+
}, timeout);
|
|
100
|
+
return {
|
|
101
|
+
script,
|
|
102
|
+
needAttach
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function createLink(info) {
|
|
106
|
+
let link = null;
|
|
107
|
+
let needAttach = true;
|
|
108
|
+
let timeout = 2e4;
|
|
109
|
+
let timeoutId;
|
|
110
|
+
const links = document.getElementsByTagName("link");
|
|
111
|
+
for (let i = 0; i < links.length; i++) {
|
|
112
|
+
const l = links[i];
|
|
113
|
+
const linkHref = l.getAttribute("href");
|
|
114
|
+
const linkRel = l.getAttribute("rel");
|
|
115
|
+
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
116
|
+
link = l;
|
|
117
|
+
needAttach = false;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!link) {
|
|
122
|
+
link = document.createElement("link");
|
|
123
|
+
link.setAttribute("href", info.url);
|
|
124
|
+
let createLinkRes = void 0;
|
|
125
|
+
let shouldApplyAttrs = true;
|
|
126
|
+
const attrs = info.attrs;
|
|
127
|
+
if (info.createLinkHook) {
|
|
128
|
+
createLinkRes = info.createLinkHook(info.url, attrs);
|
|
129
|
+
if (createLinkRes instanceof HTMLLinkElement) {
|
|
130
|
+
link = createLinkRes;
|
|
131
|
+
shouldApplyAttrs = false;
|
|
132
|
+
} else if (typeof createLinkRes === "object") {
|
|
133
|
+
if ("link" in createLinkRes && createLinkRes.link) {
|
|
134
|
+
link = createLinkRes.link;
|
|
135
|
+
shouldApplyAttrs = false;
|
|
136
|
+
}
|
|
137
|
+
if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
|
|
141
|
+
if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (!needAttach) {
|
|
145
|
+
Promise.resolve().then(() => {
|
|
146
|
+
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
link,
|
|
150
|
+
needAttach
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const onLinkComplete = (prev, event) => {
|
|
154
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
155
|
+
const onLinkCompleteCallback = () => {
|
|
156
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
157
|
+
const linkError = /* @__PURE__ */ new Error((event == null ? void 0 : event.isTimeout) ? `LinkNetworkError: Link "${info.url}" timed out.` : `LinkNetworkError: Failed to load link "${info.url}" - the URL is unreachable or the server returned an error.`);
|
|
158
|
+
linkError.name = "LinkNetworkError";
|
|
159
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(linkError));
|
|
160
|
+
} else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
161
|
+
};
|
|
162
|
+
if (link) {
|
|
163
|
+
link.onerror = null;
|
|
164
|
+
link.onload = null;
|
|
165
|
+
safeWrapper(() => {
|
|
166
|
+
const { needDeleteLink = true } = info;
|
|
167
|
+
if (needDeleteLink) (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
168
|
+
});
|
|
169
|
+
if (prev) {
|
|
170
|
+
const res = prev(event);
|
|
171
|
+
onLinkCompleteCallback();
|
|
172
|
+
return res;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
onLinkCompleteCallback();
|
|
176
|
+
};
|
|
177
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
178
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
179
|
+
timeoutId = setTimeout(() => {
|
|
180
|
+
onLinkComplete(null, {
|
|
181
|
+
type: "error",
|
|
182
|
+
isTimeout: true
|
|
183
|
+
});
|
|
184
|
+
}, timeout);
|
|
185
|
+
return {
|
|
186
|
+
link,
|
|
187
|
+
needAttach
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function loadScript(url, info) {
|
|
191
|
+
const { attrs = {}, createScriptHook } = info;
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
|
+
const { script, needAttach } = createScript({
|
|
194
|
+
url,
|
|
195
|
+
cb: resolve,
|
|
196
|
+
onErrorCallback: reject,
|
|
197
|
+
attrs: {
|
|
198
|
+
fetchpriority: "high",
|
|
199
|
+
...attrs
|
|
200
|
+
},
|
|
201
|
+
createScriptHook,
|
|
202
|
+
needDeleteScript: true
|
|
203
|
+
});
|
|
204
|
+
needAttach && document.head.appendChild(script);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const sdkImportCache = /* @__PURE__ */ new Map();
|
|
208
|
+
function importNodeModule(name) {
|
|
209
|
+
if (!name) throw new Error("import specifier is required");
|
|
210
|
+
if (sdkImportCache.has(name)) return sdkImportCache.get(name);
|
|
211
|
+
const promise = new Function("name", `return import(name)`)(name).then((res) => res).catch((error2) => {
|
|
212
|
+
console.error(`Error importing module ${name}:`, error2);
|
|
213
|
+
sdkImportCache.delete(name);
|
|
214
|
+
throw error2;
|
|
215
|
+
});
|
|
216
|
+
sdkImportCache.set(name, promise);
|
|
217
|
+
return promise;
|
|
218
|
+
}
|
|
219
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook) => {
|
|
220
|
+
const hook = (url, init2) => {
|
|
221
|
+
return loaderHook.lifecycle.fetch.emit(url, init2);
|
|
222
|
+
};
|
|
223
|
+
const res = await hook(input, init || {});
|
|
224
|
+
if (!res || !(res instanceof Response)) return fetch(input, init || {});
|
|
225
|
+
return res;
|
|
226
|
+
};
|
|
227
|
+
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
228
|
+
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
229
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
230
|
+
if (hookResult && typeof hookResult === "object" && "url" in hookResult) url = hookResult.url;
|
|
231
|
+
}
|
|
232
|
+
let urlObj;
|
|
233
|
+
try {
|
|
234
|
+
urlObj = new URL(url);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
console.error("Error constructing URL:", e);
|
|
237
|
+
cb(/* @__PURE__ */ new Error(`Invalid URL: ${e}`));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const getFetch = async () => {
|
|
241
|
+
if (loaderHook == null ? void 0 : loaderHook.fetch) return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
242
|
+
return fetch;
|
|
243
|
+
};
|
|
244
|
+
const handleScriptFetch = async (f, urlObj2) => {
|
|
245
|
+
var _a;
|
|
246
|
+
try {
|
|
247
|
+
const res = await f(urlObj2.href);
|
|
248
|
+
const data = await res.text();
|
|
249
|
+
const [path, vm] = await Promise.all([importNodeModule("path"), importNodeModule("vm")]);
|
|
250
|
+
const scriptContext = {
|
|
251
|
+
exports: {},
|
|
252
|
+
module: { exports: {} }
|
|
253
|
+
};
|
|
254
|
+
const urlDirname = urlObj2.pathname.split("/").slice(0, -1).join("/");
|
|
255
|
+
const filename = path.basename(urlObj2.pathname);
|
|
256
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
257
|
+
})`, {
|
|
258
|
+
filename,
|
|
259
|
+
importModuleDynamically: ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
|
|
260
|
+
});
|
|
261
|
+
let requireFn;
|
|
262
|
+
requireFn = (await importNodeModule("node:module")).createRequire(urlObj2.protocol === "file:" || urlObj2.protocol === "node:" ? urlObj2.href : path.join(process.cwd(), "__mf_require_base__.js"));
|
|
263
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, requireFn, urlDirname, filename);
|
|
264
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
265
|
+
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
266
|
+
cb(void 0, exportedInterface[attrs["globalName"]] || exportedInterface);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
cb(void 0, exportedInterface);
|
|
270
|
+
} catch (e) {
|
|
271
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
getFetch().then(async (f) => {
|
|
275
|
+
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") return loadModule(urlObj.href, {
|
|
276
|
+
fetch: f,
|
|
277
|
+
vm: await importNodeModule("vm")
|
|
278
|
+
}).then(async (module2) => {
|
|
279
|
+
await module2.evaluate();
|
|
280
|
+
cb(void 0, module2.namespace);
|
|
281
|
+
}).catch((e) => {
|
|
282
|
+
cb(e instanceof Error ? e : /* @__PURE__ */ new Error(`Script execution error: ${e}`));
|
|
283
|
+
});
|
|
284
|
+
handleScriptFetch(f, urlObj);
|
|
285
|
+
}).catch((err) => {
|
|
286
|
+
cb(err);
|
|
287
|
+
});
|
|
288
|
+
} : (url, cb, attrs, loaderHook) => {
|
|
289
|
+
cb(/* @__PURE__ */ new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
290
|
+
};
|
|
291
|
+
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, info) => {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
createScriptNode(url, (error2, scriptContext) => {
|
|
294
|
+
var _a, _b;
|
|
295
|
+
if (error2) reject(error2);
|
|
296
|
+
else {
|
|
297
|
+
const remoteEntryKey = ((_a = info == null ? void 0 : info.attrs) == null ? void 0 : _a["globalName"]) || `__FEDERATION_${(_b = info == null ? void 0 : info.attrs) == null ? void 0 : _b["name"]}:custom__`;
|
|
298
|
+
resolve(globalThis[remoteEntryKey] = scriptContext);
|
|
299
|
+
}
|
|
300
|
+
}, info.attrs, info.loaderHook);
|
|
301
|
+
});
|
|
302
|
+
} : (url, info) => {
|
|
303
|
+
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
304
|
+
};
|
|
305
|
+
const esmModuleCache = /* @__PURE__ */ new Map();
|
|
306
|
+
const isFetchableRemoteModuleUrl = (url) => url.startsWith("http:") || url.startsWith("https:");
|
|
307
|
+
const isBareModuleSpecifier = (specifier) => !specifier.startsWith("./") && !specifier.startsWith("../") && !specifier.startsWith("/") && !specifier.includes(":");
|
|
308
|
+
function encodeRemoteModulePath(url) {
|
|
309
|
+
const remoteUrl = new URL(url);
|
|
310
|
+
const encodedProtocol = encodeURIComponent(remoteUrl.protocol.slice(0, -1));
|
|
311
|
+
const encodedHost = encodeURIComponent(remoteUrl.host);
|
|
312
|
+
const encodedPathname = remoteUrl.pathname.split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
313
|
+
const encodedSearchHash = encodeURIComponent(`${remoteUrl.search}${remoteUrl.hash}`);
|
|
314
|
+
return `/${encodedProtocol}/${encodedHost}${encodedPathname}${encodedSearchHash ? `/${encodedSearchHash}` : ""}`;
|
|
315
|
+
}
|
|
316
|
+
function createImportMetaUrl(url, baseFileUrl) {
|
|
317
|
+
const baseUrl = baseFileUrl.endsWith("/") ? baseFileUrl : `${baseFileUrl}/`;
|
|
318
|
+
return new URL(`__module_federation_remote__${encodeRemoteModulePath(url)}`, baseUrl).href;
|
|
319
|
+
}
|
|
320
|
+
async function isNodeBuiltinSpecifier(specifier) {
|
|
321
|
+
if (specifier.startsWith("node:")) return true;
|
|
322
|
+
if (!isBareModuleSpecifier(specifier)) return false;
|
|
323
|
+
return (await importNodeModule("node:module")).builtinModules.includes(specifier);
|
|
324
|
+
}
|
|
325
|
+
function getSyntheticModuleExports(moduleExports) {
|
|
326
|
+
const namespaceObject = moduleExports && (typeof moduleExports === "object" || typeof moduleExports === "function") ? moduleExports : { default: moduleExports };
|
|
327
|
+
const effectiveExports = { ...namespaceObject };
|
|
328
|
+
if (!Object.prototype.hasOwnProperty.call(effectiveExports, "default")) effectiveExports.default = namespaceObject;
|
|
329
|
+
return effectiveExports;
|
|
330
|
+
}
|
|
331
|
+
async function createSyntheticModuleFromExports(identifier, moduleExports, vm) {
|
|
332
|
+
if (typeof vm.SyntheticModule !== "function") throw new Error("vm.SyntheticModule is required to load Node.js built-in modules in ESM remote entries.");
|
|
333
|
+
const effectiveExports = getSyntheticModuleExports(moduleExports);
|
|
334
|
+
const exportNames = Object.keys(effectiveExports);
|
|
335
|
+
const syntheticModule = new vm.SyntheticModule(exportNames, function setSyntheticModuleExports() {
|
|
336
|
+
for (const name of exportNames) this.setExport(name, effectiveExports[name]);
|
|
337
|
+
}, { identifier });
|
|
338
|
+
esmModuleCache.set(identifier, syntheticModule);
|
|
339
|
+
await syntheticModule.link(async () => {
|
|
340
|
+
throw new Error(`Node.js built-in module "${identifier}" should not request child modules.`);
|
|
341
|
+
});
|
|
342
|
+
await syntheticModule.evaluate();
|
|
343
|
+
return syntheticModule;
|
|
344
|
+
}
|
|
345
|
+
async function loadNodeBuiltinModule(specifier, vm) {
|
|
346
|
+
const cacheKey = `node-builtin:${specifier}`;
|
|
347
|
+
if (esmModuleCache.has(cacheKey)) return esmModuleCache.get(cacheKey);
|
|
348
|
+
return createSyntheticModuleFromExports(cacheKey, await importNodeModule(specifier), vm);
|
|
349
|
+
}
|
|
350
|
+
async function loadResolvedModule(specifier, parentUrl, options) {
|
|
351
|
+
if (await isNodeBuiltinSpecifier(specifier)) return loadNodeBuiltinModule(specifier, options.vm);
|
|
352
|
+
if (isBareModuleSpecifier(specifier)) throw new Error(`Unsupported ESM module specifier "${specifier}". Only relative or absolute http(s) remote modules and Node.js built-in modules are supported.`);
|
|
353
|
+
const resolvedUrl = new URL(specifier, parentUrl).href;
|
|
354
|
+
if (!isFetchableRemoteModuleUrl(resolvedUrl)) throw new Error(`Unsupported ESM module specifier "${specifier}" resolved to "${resolvedUrl}". Only http(s) remote modules and Node.js built-in modules are supported.`);
|
|
355
|
+
return loadModule(resolvedUrl, options);
|
|
356
|
+
}
|
|
357
|
+
async function evaluateDynamicModule(module2) {
|
|
358
|
+
if (module2.status === "linked") await module2.evaluate();
|
|
359
|
+
if (module2.status === "errored") throw module2.error;
|
|
360
|
+
return module2;
|
|
361
|
+
}
|
|
362
|
+
async function loadModule(url, options) {
|
|
363
|
+
if (esmModuleCache.has(url)) return esmModuleCache.get(url);
|
|
364
|
+
const { fetch: fetch2, vm } = options;
|
|
365
|
+
if (!isFetchableRemoteModuleUrl(url)) throw new Error(`Unsupported ESM module URL "${url}". Only http(s) remote modules and Node.js built-in modules are supported.`);
|
|
366
|
+
const code = await (await fetch2(url)).text();
|
|
367
|
+
const cwdFileUrl = (await importNodeModule("node:url")).pathToFileURL(process.cwd()).href;
|
|
368
|
+
const sourceTextModule = new vm.SourceTextModule(code, {
|
|
369
|
+
identifier: url,
|
|
370
|
+
initializeImportMeta: (meta) => {
|
|
371
|
+
meta.url = createImportMetaUrl(url, cwdFileUrl);
|
|
372
|
+
},
|
|
373
|
+
importModuleDynamically: async (specifier) => {
|
|
374
|
+
return evaluateDynamicModule(await loadResolvedModule(specifier, url, options));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
esmModuleCache.set(url, sourceTextModule);
|
|
378
|
+
await sourceTextModule.link(async (specifier) => {
|
|
379
|
+
return loadResolvedModule(specifier, url, options);
|
|
380
|
+
});
|
|
381
|
+
return sourceTextModule;
|
|
382
|
+
}
|
|
383
|
+
const dataFetchFunction = async function(options) {
|
|
384
|
+
var _a, _b;
|
|
385
|
+
const [id, data, downgrade] = options;
|
|
386
|
+
lazyUtils.logger.debug("==========call data fetch function!");
|
|
387
|
+
if (data) {
|
|
388
|
+
if (!id) {
|
|
389
|
+
throw new Error("id is required!");
|
|
390
|
+
}
|
|
391
|
+
if (!lazyUtils.getDataFetchMap()) {
|
|
392
|
+
lazyUtils.initDataFetchMap();
|
|
393
|
+
}
|
|
394
|
+
const dataFetchItem = lazyUtils.getDataFetchItem(id);
|
|
395
|
+
if (dataFetchItem) {
|
|
396
|
+
(_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
|
|
397
|
+
dataFetchItem[2] = lazyUtils.MF_DATA_FETCH_STATUS.LOADED;
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!dataFetchItem) {
|
|
401
|
+
const dataFetchMap = lazyUtils.getDataFetchMap();
|
|
402
|
+
let res;
|
|
403
|
+
let rej;
|
|
404
|
+
const p = new Promise((resolve, reject) => {
|
|
405
|
+
res = resolve;
|
|
406
|
+
rej = reject;
|
|
407
|
+
});
|
|
408
|
+
dataFetchMap[id] = [
|
|
409
|
+
[
|
|
410
|
+
async () => async () => {
|
|
411
|
+
return "";
|
|
412
|
+
},
|
|
413
|
+
lazyUtils.MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
414
|
+
],
|
|
415
|
+
[p, res, rej],
|
|
416
|
+
lazyUtils.MF_DATA_FETCH_STATUS.LOADED
|
|
417
|
+
];
|
|
418
|
+
res && res(data);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (downgrade) {
|
|
423
|
+
const mfDowngrade2 = lazyUtils.getDowngradeTag();
|
|
424
|
+
if (!mfDowngrade2) {
|
|
425
|
+
globalThis[lazyUtils.DOWNGRADE_KEY] = id ? [id] : true;
|
|
426
|
+
} else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
|
|
427
|
+
mfDowngrade2.push(id);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const mfDowngrade = lazyUtils.getDowngradeTag();
|
|
431
|
+
if (typeof mfDowngrade === "boolean") {
|
|
432
|
+
return lazyUtils.callAllDowngrade();
|
|
433
|
+
}
|
|
434
|
+
if (Array.isArray(mfDowngrade)) {
|
|
435
|
+
if (!id) {
|
|
436
|
+
globalThis[lazyUtils.DOWNGRADE_KEY] = true;
|
|
437
|
+
return lazyUtils.callAllDowngrade();
|
|
438
|
+
}
|
|
439
|
+
if (!mfDowngrade.includes(id)) {
|
|
440
|
+
mfDowngrade.push(id);
|
|
441
|
+
}
|
|
442
|
+
return lazyUtils.callDowngrade(id);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
function injectDataFetch() {
|
|
446
|
+
var _a;
|
|
447
|
+
globalThis[_a = lazyUtils.DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
|
|
448
|
+
const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
|
|
449
|
+
if (dataFetch.push === dataFetchFunction) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (typeof window === "undefined") {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
globalThis[lazyUtils.FS_HREF] = window.location.href;
|
|
456
|
+
dataFetch.push = dataFetchFunction;
|
|
457
|
+
}
|
|
458
|
+
const getDocsUrl = (errorCode) => {
|
|
459
|
+
return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
|
|
460
|
+
};
|
|
461
|
+
const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
|
|
462
|
+
const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
|
|
463
|
+
args && msg.push(`args: ${JSON.stringify(args)}`);
|
|
464
|
+
msg.push(getDocsUrl(errorCode));
|
|
465
|
+
originalErrorMsg && msg.push(`Original Error Message:
|
|
466
|
+
${originalErrorMsg}`);
|
|
467
|
+
return msg.join("\n");
|
|
468
|
+
};
|
|
469
|
+
function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
|
|
470
|
+
return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
|
|
471
|
+
}
|
|
472
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
473
|
+
function assert(condition, msgOrCode, descMap, args, context) {
|
|
474
|
+
if (!condition) error(msgOrCode);
|
|
475
|
+
}
|
|
476
|
+
function error(msgOrCode, descMap, args, originalErrorMsg, context) {
|
|
477
|
+
if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
|
|
478
|
+
throw new Error(`${LOG_CATEGORY}: ${msg2}`);
|
|
479
|
+
}, originalErrorMsg);
|
|
480
|
+
const msg = msgOrCode;
|
|
481
|
+
if (msg instanceof Error) {
|
|
482
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
483
|
+
throw msg;
|
|
484
|
+
}
|
|
485
|
+
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
486
|
+
}
|
|
487
|
+
const processModuleAlias = (name, subPath) => {
|
|
488
|
+
let moduleName;
|
|
489
|
+
if (name.endsWith("/")) moduleName = name.slice(0, -1);
|
|
490
|
+
else moduleName = name;
|
|
491
|
+
if (subPath.startsWith(".")) subPath = subPath.slice(1);
|
|
492
|
+
moduleName = moduleName + subPath;
|
|
493
|
+
return moduleName;
|
|
494
|
+
};
|
|
495
|
+
const MAX_PRELOADED_ASSETS = 2e3;
|
|
496
|
+
const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
|
|
497
|
+
const nativeGlobal = (() => {
|
|
498
|
+
try {
|
|
499
|
+
return document.defaultView;
|
|
500
|
+
} catch {
|
|
501
|
+
return CurrentGlobal;
|
|
502
|
+
}
|
|
503
|
+
})();
|
|
504
|
+
function definePropertyGlobalVal(target, key, val) {
|
|
505
|
+
Object.defineProperty(target, key, {
|
|
506
|
+
value: val,
|
|
507
|
+
configurable: false,
|
|
508
|
+
writable: true
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
function includeOwnProperty(target, key) {
|
|
512
|
+
return Object.hasOwnProperty.call(target, key);
|
|
513
|
+
}
|
|
514
|
+
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
515
|
+
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
516
|
+
function setGlobalDefaultVal(target) {
|
|
517
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
518
|
+
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
519
|
+
if (!includeOwnProperty(target, "__FEDERATION__")) {
|
|
520
|
+
definePropertyGlobalVal(target, "__FEDERATION__", {
|
|
521
|
+
__GLOBAL_PLUGIN__: [],
|
|
522
|
+
__INSTANCES__: [],
|
|
523
|
+
moduleInfo: {},
|
|
524
|
+
__SHARE__: {},
|
|
525
|
+
__MANIFEST_LOADING__: {},
|
|
526
|
+
__PRELOADED_MAP__: /* @__PURE__ */ new Map(),
|
|
527
|
+
__PRELOADED_ASSETS__: /* @__PURE__ */ new Set()
|
|
528
|
+
});
|
|
529
|
+
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
|
|
530
|
+
}
|
|
531
|
+
(_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
|
|
532
|
+
(_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
|
|
533
|
+
(_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
|
|
534
|
+
(_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
|
|
535
|
+
(_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
|
|
536
|
+
(_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
|
|
537
|
+
(_g = target.__FEDERATION__).__PRELOADED_ASSETS__ ?? (_g.__PRELOADED_ASSETS__ = /* @__PURE__ */ new Set());
|
|
538
|
+
}
|
|
539
|
+
setGlobalDefaultVal(CurrentGlobal);
|
|
540
|
+
setGlobalDefaultVal(nativeGlobal);
|
|
541
|
+
const getRemoteEntryExports = (name, globalName) => {
|
|
542
|
+
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
|
|
543
|
+
return {
|
|
544
|
+
remoteEntryKey,
|
|
545
|
+
entryExports: CurrentGlobal[remoteEntryKey]
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
const getPreloadedAsset = (url) => CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__.has(url);
|
|
549
|
+
const setPreloadedAsset = (url) => {
|
|
550
|
+
const preloadedAssets = CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__;
|
|
551
|
+
preloadedAssets.add(url);
|
|
552
|
+
if (preloadedAssets.size > MAX_PRELOADED_ASSETS) {
|
|
553
|
+
const oldestUrl = preloadedAssets.values().next().value;
|
|
554
|
+
if (oldestUrl !== void 0) preloadedAssets.delete(oldestUrl);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const DEFAULT_SCOPE = "default";
|
|
558
|
+
const DEFAULT_REMOTE_TYPE = "global";
|
|
559
|
+
function composeRemoteRequestId(remoteName, expose) {
|
|
560
|
+
if (!expose || expose === ".") return remoteName;
|
|
561
|
+
return `${remoteName}/${expose.replace(/^\.\//, "")}`;
|
|
562
|
+
}
|
|
563
|
+
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
564
|
+
for (const remote of remotes) {
|
|
565
|
+
const isNameMatched = id.startsWith(remote.name);
|
|
566
|
+
let expose = id.replace(remote.name, "");
|
|
567
|
+
if (isNameMatched) {
|
|
568
|
+
if (expose.startsWith("/")) {
|
|
569
|
+
const pkgNameOrAlias = remote.name;
|
|
570
|
+
expose = `.${expose}`;
|
|
571
|
+
return {
|
|
572
|
+
pkgNameOrAlias,
|
|
573
|
+
expose,
|
|
574
|
+
remote
|
|
575
|
+
};
|
|
576
|
+
} else if (expose === "") return {
|
|
577
|
+
pkgNameOrAlias: remote.name,
|
|
578
|
+
expose: ".",
|
|
579
|
+
remote
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
const isAliasMatched = remote.alias && id.startsWith(remote.alias);
|
|
583
|
+
let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
|
|
584
|
+
if (remote.alias && isAliasMatched) {
|
|
585
|
+
if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
|
|
586
|
+
const pkgNameOrAlias = remote.alias;
|
|
587
|
+
exposeWithAlias = `.${exposeWithAlias}`;
|
|
588
|
+
return {
|
|
589
|
+
pkgNameOrAlias,
|
|
590
|
+
expose: exposeWithAlias,
|
|
591
|
+
remote
|
|
592
|
+
};
|
|
593
|
+
} else if (exposeWithAlias === "") return {
|
|
594
|
+
pkgNameOrAlias: remote.alias,
|
|
595
|
+
expose: ".",
|
|
596
|
+
remote
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const RUNTIME_001 = "RUNTIME-001";
|
|
602
|
+
const RUNTIME_002 = "RUNTIME-002";
|
|
603
|
+
const RUNTIME_003 = "RUNTIME-003";
|
|
604
|
+
const RUNTIME_004 = "RUNTIME-004";
|
|
605
|
+
const RUNTIME_005 = "RUNTIME-005";
|
|
606
|
+
const RUNTIME_006 = "RUNTIME-006";
|
|
607
|
+
const RUNTIME_007 = "RUNTIME-007";
|
|
608
|
+
const RUNTIME_008 = "RUNTIME-008";
|
|
609
|
+
const RUNTIME_009 = "RUNTIME-009";
|
|
610
|
+
const RUNTIME_010 = "RUNTIME-010";
|
|
611
|
+
const RUNTIME_011 = "RUNTIME-011";
|
|
612
|
+
const RUNTIME_012 = "RUNTIME-012";
|
|
613
|
+
const RUNTIME_013 = "RUNTIME-013";
|
|
614
|
+
const RUNTIME_014 = "RUNTIME-014";
|
|
615
|
+
const RUNTIME_015 = "RUNTIME-015";
|
|
616
|
+
const runtimeDescMap = {
|
|
617
|
+
[RUNTIME_001]: "Failed to get remoteEntry exports.",
|
|
618
|
+
[RUNTIME_002]: 'The remote entry interface does not contain "init"',
|
|
619
|
+
[RUNTIME_003]: "Failed to get manifest.",
|
|
620
|
+
[RUNTIME_004]: "Failed to locate remote.",
|
|
621
|
+
[RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
|
|
622
|
+
[RUNTIME_006]: "Invalid loadShareSync function call from runtime",
|
|
623
|
+
[RUNTIME_007]: "Failed to get remote snapshot.",
|
|
624
|
+
[RUNTIME_008]: "Failed to load script resources.",
|
|
625
|
+
[RUNTIME_009]: "Please call createInstance first.",
|
|
626
|
+
[RUNTIME_010]: 'The name option cannot be changed after initialization. If you want to create a new instance with a different name, please use "createInstance" api.',
|
|
627
|
+
[RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot.",
|
|
628
|
+
[RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.',
|
|
629
|
+
[RUNTIME_013]: "The manifest is not a valid Module Federation manifest.",
|
|
630
|
+
[RUNTIME_014]: "The remote does not expose the requested module.",
|
|
631
|
+
[RUNTIME_015]: "Remote container initialization failed."
|
|
632
|
+
};
|
|
633
|
+
({
|
|
634
|
+
...runtimeDescMap
|
|
635
|
+
});
|
|
636
|
+
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
637
|
+
const remoteEntryLoadingOrigins = /* @__PURE__ */ new WeakMap();
|
|
638
|
+
const esmRemoteEntryLoadErrorMessages = [
|
|
639
|
+
"Failed to fetch dynamically imported module",
|
|
640
|
+
"Importing a module script failed",
|
|
641
|
+
"error loading dynamically imported module"
|
|
642
|
+
];
|
|
643
|
+
function isEsmRemoteEntryLoadError(err) {
|
|
644
|
+
if (!(err instanceof TypeError)) return false;
|
|
645
|
+
return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
|
|
646
|
+
}
|
|
647
|
+
function isEsmRemoteType(type) {
|
|
648
|
+
return type === "esm" || type === "module";
|
|
649
|
+
}
|
|
650
|
+
async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
|
|
651
|
+
return new Promise((resolve, reject) => {
|
|
652
|
+
const rejectEntry = (loadError) => {
|
|
653
|
+
if (isEsmRemoteEntryLoadError(loadError)) {
|
|
654
|
+
const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
|
|
655
|
+
try {
|
|
656
|
+
error(RUNTIME_008, runtimeDescMap, {
|
|
657
|
+
remoteName: name,
|
|
658
|
+
resourceUrl: url
|
|
659
|
+
}, originalMsg);
|
|
660
|
+
} catch (runtimeError) {
|
|
661
|
+
reject(runtimeError);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
reject(loadError);
|
|
666
|
+
};
|
|
667
|
+
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
668
|
+
try {
|
|
669
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
|
|
670
|
+
else import(
|
|
671
|
+
/* webpackIgnore: true */
|
|
672
|
+
/* @vite-ignore */
|
|
673
|
+
url
|
|
674
|
+
).then(resolve).catch(rejectEntry);
|
|
675
|
+
else resolve(remoteEntryExports);
|
|
676
|
+
} catch (e) {
|
|
677
|
+
error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
682
|
+
return new Promise((resolve, reject) => {
|
|
683
|
+
try {
|
|
684
|
+
if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
|
|
685
|
+
else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
686
|
+
else resolve(remoteEntryExports);
|
|
687
|
+
} catch (e) {
|
|
688
|
+
error(`Failed to load SystemJS entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
693
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
694
|
+
if (!entryExports) error(RUNTIME_001, runtimeDescMap, {
|
|
695
|
+
remoteName: name,
|
|
696
|
+
remoteEntryUrl: entry,
|
|
697
|
+
remoteEntryKey
|
|
698
|
+
});
|
|
699
|
+
return entryExports;
|
|
700
|
+
}
|
|
701
|
+
async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
|
|
702
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
703
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
704
|
+
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
705
|
+
return loadScript(url, {
|
|
706
|
+
attrs: {},
|
|
707
|
+
createScriptHook: (url2, attrs) => {
|
|
708
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
709
|
+
url: url2,
|
|
710
|
+
attrs,
|
|
711
|
+
remoteInfo,
|
|
712
|
+
resourceContext: resourceContext ? {
|
|
713
|
+
...resourceContext,
|
|
714
|
+
url: url2
|
|
715
|
+
} : void 0
|
|
716
|
+
});
|
|
717
|
+
if (!res) return;
|
|
718
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
719
|
+
if ("script" in res || "timeout" in res) return res;
|
|
720
|
+
}
|
|
721
|
+
}).then(() => {
|
|
722
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
723
|
+
}, (loadError) => {
|
|
724
|
+
const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
|
|
725
|
+
error(RUNTIME_008, runtimeDescMap, {
|
|
726
|
+
remoteName: name,
|
|
727
|
+
resourceUrl: url
|
|
728
|
+
}, originalMsg);
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
|
|
732
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
733
|
+
if (isEsmRemoteType(type)) return loadEsmEntry({
|
|
734
|
+
entry,
|
|
735
|
+
remoteEntryExports,
|
|
736
|
+
name,
|
|
737
|
+
getEntryUrl
|
|
738
|
+
});
|
|
739
|
+
if (type === "system") return loadSystemJsEntry({
|
|
740
|
+
entry,
|
|
741
|
+
remoteEntryExports
|
|
742
|
+
});
|
|
743
|
+
return loadEntryScript({
|
|
744
|
+
entry,
|
|
745
|
+
globalName,
|
|
746
|
+
name,
|
|
747
|
+
remoteInfo,
|
|
748
|
+
loaderHook,
|
|
749
|
+
getEntryUrl,
|
|
750
|
+
resourceContext
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
|
|
754
|
+
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
755
|
+
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
756
|
+
if (remoteEntryExports) return remoteEntryExports;
|
|
757
|
+
return loadScriptNode(entry, {
|
|
758
|
+
attrs: {
|
|
759
|
+
name,
|
|
760
|
+
globalName,
|
|
761
|
+
type
|
|
762
|
+
},
|
|
763
|
+
loaderHook: { createScriptHook: (url, attrs = {}) => {
|
|
764
|
+
const res = loaderHook.lifecycle.createScript.emit({
|
|
765
|
+
url,
|
|
766
|
+
attrs,
|
|
767
|
+
remoteInfo,
|
|
768
|
+
resourceContext: resourceContext ? {
|
|
769
|
+
...resourceContext,
|
|
770
|
+
url
|
|
771
|
+
} : void 0
|
|
772
|
+
});
|
|
773
|
+
if (!res) return;
|
|
774
|
+
if ("url" in res) return res;
|
|
775
|
+
} }
|
|
776
|
+
}).then(() => {
|
|
777
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
778
|
+
}).catch((e) => {
|
|
779
|
+
error(`Failed to load Node.js entry for remote "${name}" from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
783
|
+
const { entry, name } = remoteInfo;
|
|
784
|
+
return lazyUtils.composeKeyWithSeparator(name, entry);
|
|
785
|
+
}
|
|
786
|
+
async function getRemoteEntry(params) {
|
|
787
|
+
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
|
|
788
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
789
|
+
if (remoteEntryExports) {
|
|
790
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
791
|
+
origin,
|
|
792
|
+
remoteInfo,
|
|
793
|
+
remoteEntryExports,
|
|
794
|
+
resourceContext,
|
|
795
|
+
cached: true
|
|
796
|
+
});
|
|
797
|
+
return remoteEntryExports;
|
|
798
|
+
}
|
|
799
|
+
if (!globalLoading[uniqueKey]) {
|
|
800
|
+
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
801
|
+
const loaderHook = origin.loaderHook;
|
|
802
|
+
const loading = loadEntryHook.emit({
|
|
803
|
+
origin,
|
|
804
|
+
loaderHook,
|
|
805
|
+
remoteInfo,
|
|
806
|
+
remoteEntryExports,
|
|
807
|
+
resourceContext
|
|
808
|
+
}).then((res) => {
|
|
809
|
+
if (res) return res;
|
|
810
|
+
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : logger.isBrowserEnvValue) ? loadEntryDom({
|
|
811
|
+
remoteInfo,
|
|
812
|
+
remoteEntryExports,
|
|
813
|
+
loaderHook,
|
|
814
|
+
getEntryUrl,
|
|
815
|
+
resourceContext
|
|
816
|
+
}) : loadEntryNode({
|
|
817
|
+
remoteInfo,
|
|
818
|
+
loaderHook,
|
|
819
|
+
resourceContext
|
|
820
|
+
});
|
|
821
|
+
}).then(async (res) => {
|
|
822
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
823
|
+
origin,
|
|
824
|
+
remoteInfo,
|
|
825
|
+
remoteEntryExports: res,
|
|
826
|
+
resourceContext
|
|
827
|
+
});
|
|
828
|
+
return res;
|
|
829
|
+
}).catch(async (loadError) => {
|
|
830
|
+
const isScriptExecutionError = loadError instanceof Error && loadError.message.includes("ScriptExecutionError");
|
|
831
|
+
if (loadError instanceof Error && loadError.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
832
|
+
const wrappedGetRemoteEntry = (params2) => {
|
|
833
|
+
return getRemoteEntry({
|
|
834
|
+
...params2,
|
|
835
|
+
_inErrorHandling: true
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
const recoveredRemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
839
|
+
getRemoteEntry: wrappedGetRemoteEntry,
|
|
840
|
+
origin,
|
|
841
|
+
remoteInfo,
|
|
842
|
+
remoteEntryExports,
|
|
843
|
+
globalLoading,
|
|
844
|
+
uniqueKey
|
|
845
|
+
});
|
|
846
|
+
if (recoveredRemoteEntryExports) {
|
|
847
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
848
|
+
origin,
|
|
849
|
+
remoteInfo,
|
|
850
|
+
remoteEntryExports: recoveredRemoteEntryExports,
|
|
851
|
+
resourceContext,
|
|
852
|
+
error: loadError,
|
|
853
|
+
recovered: true
|
|
854
|
+
});
|
|
855
|
+
return recoveredRemoteEntryExports;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
859
|
+
origin,
|
|
860
|
+
remoteInfo,
|
|
861
|
+
resourceContext,
|
|
862
|
+
error: loadError
|
|
863
|
+
});
|
|
864
|
+
throw loadError;
|
|
865
|
+
});
|
|
866
|
+
globalLoading[uniqueKey] = loading;
|
|
867
|
+
loading.then(void 0, () => {
|
|
868
|
+
if (globalLoading[uniqueKey] === loading) delete globalLoading[uniqueKey];
|
|
869
|
+
});
|
|
870
|
+
remoteEntryLoadingOrigins.set(loading, origin);
|
|
871
|
+
}
|
|
872
|
+
const remoteEntryLoading = globalLoading[uniqueKey];
|
|
873
|
+
if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) try {
|
|
874
|
+
const result = await remoteEntryLoading;
|
|
875
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
876
|
+
origin,
|
|
877
|
+
remoteInfo,
|
|
878
|
+
remoteEntryExports: result,
|
|
879
|
+
resourceContext
|
|
880
|
+
});
|
|
881
|
+
return result;
|
|
882
|
+
} catch (loadError) {
|
|
883
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
884
|
+
origin,
|
|
885
|
+
remoteInfo,
|
|
886
|
+
resourceContext,
|
|
887
|
+
error: loadError
|
|
888
|
+
});
|
|
889
|
+
throw loadError;
|
|
890
|
+
}
|
|
891
|
+
return remoteEntryLoading;
|
|
892
|
+
}
|
|
893
|
+
function getRemoteInfo(remote) {
|
|
894
|
+
return {
|
|
895
|
+
...remote,
|
|
896
|
+
entry: "entry" in remote ? remote.entry : "",
|
|
897
|
+
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
898
|
+
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
899
|
+
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
function remoteToEntry(r) {
|
|
903
|
+
return {
|
|
904
|
+
name: r.name,
|
|
905
|
+
alias: r.alias,
|
|
906
|
+
entry: "entry" in r ? r.entry : void 0,
|
|
907
|
+
version: "version" in r ? r.version : void 0,
|
|
908
|
+
type: r.type,
|
|
909
|
+
entryGlobalName: r.entryGlobalName,
|
|
910
|
+
shareScope: r.shareScope
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
function optionsToMFContext(options) {
|
|
914
|
+
var _a, _b, _c, _d, _e, _f;
|
|
915
|
+
const shared = {};
|
|
916
|
+
for (const [pkgName, versions] of Object.entries(options.shared)) {
|
|
917
|
+
const first = versions[0];
|
|
918
|
+
if (first) shared[pkgName] = {
|
|
919
|
+
version: first.version,
|
|
920
|
+
singleton: (_a = first.shareConfig) == null ? void 0 : _a.singleton,
|
|
921
|
+
requiredVersion: ((_b = first.shareConfig) == null ? void 0 : _b.requiredVersion) === false ? false : (_c = first.shareConfig) == null ? void 0 : _c.requiredVersion,
|
|
922
|
+
eager: first.eager,
|
|
923
|
+
strictVersion: (_d = first.shareConfig) == null ? void 0 : _d.strictVersion
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
return {
|
|
927
|
+
project: {
|
|
928
|
+
name: options.name,
|
|
929
|
+
mfRole: ((_e = options.remotes) == null ? void 0 : _e.length) > 0 ? "host" : "unknown"
|
|
930
|
+
},
|
|
931
|
+
mfConfig: {
|
|
932
|
+
name: options.name,
|
|
933
|
+
remotes: ((_f = options.remotes) == null ? void 0 : _f.map(remoteToEntry)) ?? [],
|
|
934
|
+
shared
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function isTimeoutError(error2) {
|
|
939
|
+
if (!(error2 instanceof Error)) return false;
|
|
940
|
+
return error2.message.includes("timed out") || error2.name.includes("Timeout");
|
|
941
|
+
}
|
|
942
|
+
function createAssetResult(context, url, status, error2) {
|
|
943
|
+
return {
|
|
944
|
+
url,
|
|
945
|
+
status,
|
|
946
|
+
resourceType: context.resourceType,
|
|
947
|
+
initiator: context.initiator,
|
|
948
|
+
id: context.id,
|
|
949
|
+
error: error2
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function preloadAssetOnce(context, url, recordPreloadedAssets, preload) {
|
|
953
|
+
if (!recordPreloadedAssets) return preload();
|
|
954
|
+
if (getPreloadedAsset(url)) return Promise.resolve(createAssetResult(context, url, "cached"));
|
|
955
|
+
setPreloadedAsset(url);
|
|
956
|
+
return preload();
|
|
957
|
+
}
|
|
958
|
+
async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
|
|
959
|
+
const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
|
|
960
|
+
const url = entryRemoteInfo.entry;
|
|
961
|
+
if (cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports) return createAssetResult(context, url, "cached");
|
|
962
|
+
try {
|
|
963
|
+
if (!await getRemoteEntry({
|
|
964
|
+
origin: host,
|
|
965
|
+
remoteInfo: entryRemoteInfo,
|
|
966
|
+
remoteEntryExports: cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports,
|
|
967
|
+
resourceContext: {
|
|
968
|
+
...context,
|
|
969
|
+
url
|
|
970
|
+
}
|
|
971
|
+
})) throw new Error(`Failed to load remoteEntry "${url}".`);
|
|
972
|
+
return createAssetResult(context, url, "success");
|
|
973
|
+
} catch (error2) {
|
|
974
|
+
return createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function waitForLinkPreload({ host, remoteInfo, url, attrs, context, needDeleteLink }) {
|
|
978
|
+
return new Promise((resolve) => {
|
|
979
|
+
const { link, needAttach } = createLink({
|
|
980
|
+
url,
|
|
981
|
+
cb: () => {
|
|
982
|
+
resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
|
|
983
|
+
},
|
|
984
|
+
onErrorCallback: (error2) => {
|
|
985
|
+
resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
|
|
986
|
+
},
|
|
987
|
+
attrs,
|
|
988
|
+
createLinkHook: (hookUrl, hookAttrs) => {
|
|
989
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
990
|
+
url: hookUrl,
|
|
991
|
+
attrs: hookAttrs,
|
|
992
|
+
remoteInfo,
|
|
993
|
+
resourceContext: {
|
|
994
|
+
...context,
|
|
995
|
+
url: hookUrl
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
if (res instanceof HTMLLinkElement) return res;
|
|
999
|
+
return res;
|
|
1000
|
+
},
|
|
1001
|
+
needDeleteLink
|
|
1002
|
+
});
|
|
1003
|
+
needAttach && document.head.appendChild(link);
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
function waitForScriptPreload({ host, remoteInfo, url, attrs, context }) {
|
|
1007
|
+
return new Promise((resolve) => {
|
|
1008
|
+
const { script, needAttach } = createScript({
|
|
1009
|
+
url,
|
|
1010
|
+
cb: () => {
|
|
1011
|
+
resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
|
|
1012
|
+
},
|
|
1013
|
+
onErrorCallback: (error2) => {
|
|
1014
|
+
resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
|
|
1015
|
+
},
|
|
1016
|
+
attrs,
|
|
1017
|
+
createScriptHook: (hookUrl, hookAttrs) => {
|
|
1018
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
1019
|
+
url: hookUrl,
|
|
1020
|
+
attrs: hookAttrs,
|
|
1021
|
+
remoteInfo,
|
|
1022
|
+
resourceContext: {
|
|
1023
|
+
...context,
|
|
1024
|
+
url: hookUrl
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
if (res instanceof HTMLScriptElement) return res;
|
|
1028
|
+
return res;
|
|
1029
|
+
},
|
|
1030
|
+
needDeleteScript: true
|
|
1031
|
+
});
|
|
1032
|
+
needAttach && document.head.appendChild(script);
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
function createResourceContext(baseContext, resourceType) {
|
|
1036
|
+
return {
|
|
1037
|
+
...baseContext,
|
|
1038
|
+
resourceType
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
|
|
1042
|
+
initiator: "preloadRemote",
|
|
1043
|
+
id: remoteInfo.name
|
|
1044
|
+
}, recordPreloadedAssets = true) {
|
|
1045
|
+
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
1046
|
+
const results = [];
|
|
1047
|
+
if (host.options.inBrowser) {
|
|
1048
|
+
entryAssets.forEach((asset) => {
|
|
1049
|
+
const { moduleInfo: entryRemoteInfo } = asset;
|
|
1050
|
+
results.push(waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, createResourceContext(baseContext, "remoteEntry")));
|
|
1051
|
+
});
|
|
1052
|
+
if (useLinkPreload) {
|
|
1053
|
+
const defaultAttrs2 = {
|
|
1054
|
+
rel: "preload",
|
|
1055
|
+
as: "style"
|
|
1056
|
+
};
|
|
1057
|
+
cssAssets.forEach((cssUrl) => {
|
|
1058
|
+
const context = createResourceContext(baseContext, "css");
|
|
1059
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
1060
|
+
host,
|
|
1061
|
+
remoteInfo,
|
|
1062
|
+
url: cssUrl,
|
|
1063
|
+
attrs: defaultAttrs2,
|
|
1064
|
+
context
|
|
1065
|
+
})));
|
|
1066
|
+
});
|
|
1067
|
+
} else {
|
|
1068
|
+
const defaultAttrs2 = {
|
|
1069
|
+
rel: "stylesheet",
|
|
1070
|
+
type: "text/css"
|
|
1071
|
+
};
|
|
1072
|
+
cssAssets.forEach((cssUrl) => {
|
|
1073
|
+
const context = createResourceContext(baseContext, "css");
|
|
1074
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
1075
|
+
host,
|
|
1076
|
+
remoteInfo,
|
|
1077
|
+
url: cssUrl,
|
|
1078
|
+
attrs: defaultAttrs2,
|
|
1079
|
+
needDeleteLink: false,
|
|
1080
|
+
context
|
|
1081
|
+
})));
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
let preloadJsAsset = waitForScriptPreload;
|
|
1085
|
+
let defaultAttrs = {
|
|
1086
|
+
fetchpriority: "high",
|
|
1087
|
+
type: "text/javascript"
|
|
1088
|
+
};
|
|
1089
|
+
if (useLinkPreload) {
|
|
1090
|
+
preloadJsAsset = waitForLinkPreload;
|
|
1091
|
+
defaultAttrs = {
|
|
1092
|
+
rel: "preload",
|
|
1093
|
+
as: "script"
|
|
1094
|
+
};
|
|
1095
|
+
} else if (isEsmRemoteType(remoteInfo.type)) {
|
|
1096
|
+
preloadJsAsset = waitForLinkPreload;
|
|
1097
|
+
defaultAttrs = {
|
|
1098
|
+
rel: "modulepreload",
|
|
1099
|
+
fetchpriority: "high"
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1103
|
+
const context = createResourceContext(baseContext, "js");
|
|
1104
|
+
results.push(preloadAssetOnce(context, jsUrl, recordPreloadedAssets, () => preloadJsAsset({
|
|
1105
|
+
host,
|
|
1106
|
+
remoteInfo,
|
|
1107
|
+
url: jsUrl,
|
|
1108
|
+
attrs: defaultAttrs,
|
|
1109
|
+
context
|
|
1110
|
+
})));
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
return Promise.all(results);
|
|
1114
|
+
}
|
|
1115
|
+
var helpers_default = {
|
|
1116
|
+
utils: {
|
|
1117
|
+
matchRemoteWithNameAndExpose,
|
|
1118
|
+
preloadAssets,
|
|
1119
|
+
getRemoteInfo
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
function getAvailableExposeNames(remoteSnapshot) {
|
|
1123
|
+
if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
|
|
1124
|
+
const exposes = remoteSnapshot.modules.map((module2) => module2.moduleName).filter(Boolean);
|
|
1125
|
+
return exposes.length ? exposes.join(",") : void 0;
|
|
1126
|
+
}
|
|
1127
|
+
function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
|
|
1128
|
+
const localShareScopeMap = hostShareScopeMap;
|
|
1129
|
+
const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
|
|
1130
|
+
if (!shareScopeKeys.length) shareScopeKeys.push("default");
|
|
1131
|
+
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1132
|
+
if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
|
|
1133
|
+
});
|
|
1134
|
+
const remoteEntryInitOptions = {
|
|
1135
|
+
version: remoteInfo.version || "",
|
|
1136
|
+
shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
|
|
1137
|
+
};
|
|
1138
|
+
Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
|
|
1139
|
+
value: localShareScopeMap,
|
|
1140
|
+
enumerable: false
|
|
1141
|
+
});
|
|
1142
|
+
return {
|
|
1143
|
+
remoteEntryInitOptions,
|
|
1144
|
+
shareScope: localShareScopeMap[shareScopeKeys[0]],
|
|
1145
|
+
initScope: rawInitScope ?? []
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
var Module$1 = class {
|
|
1149
|
+
constructor({ remoteInfo, host }) {
|
|
1150
|
+
this.inited = false;
|
|
1151
|
+
this.initing = false;
|
|
1152
|
+
this.lib = void 0;
|
|
1153
|
+
this.remoteInfo = remoteInfo;
|
|
1154
|
+
this.host = host;
|
|
1155
|
+
}
|
|
1156
|
+
async getEntry(expose, resourceContext) {
|
|
1157
|
+
const effectiveResourceContext = resourceContext || {
|
|
1158
|
+
initiator: "loadRemote",
|
|
1159
|
+
id: composeRemoteRequestId(this.remoteInfo.name, expose),
|
|
1160
|
+
resourceType: "remoteEntry",
|
|
1161
|
+
url: this.remoteInfo.entry,
|
|
1162
|
+
expose
|
|
1163
|
+
};
|
|
1164
|
+
const remoteEntryExports = await getRemoteEntry({
|
|
1165
|
+
origin: this.host,
|
|
1166
|
+
remoteInfo: this.remoteInfo,
|
|
1167
|
+
remoteEntryExports: this.remoteEntryExports,
|
|
1168
|
+
resourceContext: effectiveResourceContext
|
|
1169
|
+
});
|
|
1170
|
+
assert(remoteEntryExports, `remoteEntryExports is undefined
|
|
1171
|
+
${lazyUtils.safeToString(this.remoteInfo)}`);
|
|
1172
|
+
this.remoteEntryExports = remoteEntryExports;
|
|
1173
|
+
return this.remoteEntryExports;
|
|
1174
|
+
}
|
|
1175
|
+
async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
|
|
1176
|
+
const remoteEntryExports = await this.getEntry(expose, resourceContext);
|
|
1177
|
+
if (this.inited) {
|
|
1178
|
+
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1179
|
+
id,
|
|
1180
|
+
remoteInfo: this.remoteInfo,
|
|
1181
|
+
remoteSnapshot,
|
|
1182
|
+
remoteEntryExports,
|
|
1183
|
+
cached: true,
|
|
1184
|
+
origin: this.host
|
|
1185
|
+
});
|
|
1186
|
+
return remoteEntryExports;
|
|
1187
|
+
}
|
|
1188
|
+
if (this.initPromise) {
|
|
1189
|
+
try {
|
|
1190
|
+
await this.initPromise;
|
|
1191
|
+
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1192
|
+
id,
|
|
1193
|
+
remoteInfo: this.remoteInfo,
|
|
1194
|
+
remoteSnapshot,
|
|
1195
|
+
remoteEntryExports,
|
|
1196
|
+
cached: true,
|
|
1197
|
+
origin: this.host
|
|
1198
|
+
});
|
|
1199
|
+
} catch (initError) {
|
|
1200
|
+
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1201
|
+
id,
|
|
1202
|
+
remoteInfo: this.remoteInfo,
|
|
1203
|
+
remoteSnapshot,
|
|
1204
|
+
remoteEntryExports,
|
|
1205
|
+
error: initError,
|
|
1206
|
+
cached: true,
|
|
1207
|
+
origin: this.host
|
|
1208
|
+
});
|
|
1209
|
+
throw initError;
|
|
1210
|
+
}
|
|
1211
|
+
return remoteEntryExports;
|
|
1212
|
+
}
|
|
1213
|
+
this.initing = true;
|
|
1214
|
+
this.initPromise = (async () => {
|
|
1215
|
+
await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
|
|
1216
|
+
id,
|
|
1217
|
+
remoteInfo: this.remoteInfo,
|
|
1218
|
+
remoteSnapshot,
|
|
1219
|
+
origin: this.host
|
|
1220
|
+
});
|
|
1221
|
+
const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
|
|
1222
|
+
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
1223
|
+
shareScope,
|
|
1224
|
+
remoteEntryInitOptions,
|
|
1225
|
+
initScope,
|
|
1226
|
+
remoteInfo: this.remoteInfo,
|
|
1227
|
+
origin: this.host
|
|
1228
|
+
});
|
|
1229
|
+
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === "undefined") error(RUNTIME_002, runtimeDescMap, {
|
|
1230
|
+
hostName: this.host.name,
|
|
1231
|
+
remoteName: this.remoteInfo.name,
|
|
1232
|
+
remoteEntryUrl: this.remoteInfo.entry,
|
|
1233
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
1234
|
+
}, void 0, optionsToMFContext(this.host.options));
|
|
1235
|
+
try {
|
|
1236
|
+
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
1237
|
+
} catch (initError) {
|
|
1238
|
+
error(RUNTIME_015, runtimeDescMap, {
|
|
1239
|
+
hostName: this.host.name,
|
|
1240
|
+
remoteName: this.remoteInfo.name,
|
|
1241
|
+
remoteEntryUrl: this.remoteInfo.entry,
|
|
1242
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName,
|
|
1243
|
+
shareScope: this.remoteInfo.shareScope
|
|
1244
|
+
}, `${initError}`, optionsToMFContext(this.host.options));
|
|
1245
|
+
}
|
|
1246
|
+
await this.host.hooks.lifecycle.initContainer.emit({
|
|
1247
|
+
...initContainerOptions,
|
|
1248
|
+
id,
|
|
1249
|
+
remoteSnapshot,
|
|
1250
|
+
remoteEntryExports
|
|
1251
|
+
});
|
|
1252
|
+
this.inited = true;
|
|
1253
|
+
})();
|
|
1254
|
+
try {
|
|
1255
|
+
await this.initPromise;
|
|
1256
|
+
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1257
|
+
id,
|
|
1258
|
+
remoteInfo: this.remoteInfo,
|
|
1259
|
+
remoteSnapshot,
|
|
1260
|
+
remoteEntryExports,
|
|
1261
|
+
origin: this.host
|
|
1262
|
+
});
|
|
1263
|
+
} catch (initError) {
|
|
1264
|
+
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1265
|
+
id,
|
|
1266
|
+
remoteInfo: this.remoteInfo,
|
|
1267
|
+
remoteSnapshot,
|
|
1268
|
+
remoteEntryExports,
|
|
1269
|
+
error: initError,
|
|
1270
|
+
origin: this.host
|
|
1271
|
+
});
|
|
1272
|
+
throw initError;
|
|
1273
|
+
} finally {
|
|
1274
|
+
this.initing = false;
|
|
1275
|
+
this.initPromise = void 0;
|
|
1276
|
+
}
|
|
1277
|
+
return remoteEntryExports;
|
|
1278
|
+
}
|
|
1279
|
+
async get(id, expose, options, remoteSnapshot) {
|
|
1280
|
+
const { loadFactory = true } = options || { loadFactory: true };
|
|
1281
|
+
const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
|
|
1282
|
+
this.lib = remoteEntryExports;
|
|
1283
|
+
await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
|
|
1284
|
+
id,
|
|
1285
|
+
expose,
|
|
1286
|
+
moduleInfo: this.remoteInfo,
|
|
1287
|
+
remoteEntryExports,
|
|
1288
|
+
origin: this.host
|
|
1289
|
+
});
|
|
1290
|
+
let moduleFactory;
|
|
1291
|
+
try {
|
|
1292
|
+
const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
1293
|
+
remoteEntryExports,
|
|
1294
|
+
expose,
|
|
1295
|
+
moduleInfo: this.remoteInfo
|
|
1296
|
+
});
|
|
1297
|
+
moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
|
|
1298
|
+
if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
|
|
1299
|
+
if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
|
|
1300
|
+
hostName: this.host.name,
|
|
1301
|
+
remoteName: this.remoteInfo.name,
|
|
1302
|
+
remoteEntryUrl: this.remoteInfo.entry,
|
|
1303
|
+
expose,
|
|
1304
|
+
requestId: id,
|
|
1305
|
+
availableExposes: getAvailableExposeNames(remoteSnapshot)
|
|
1306
|
+
}, void 0, optionsToMFContext(this.host.options));
|
|
1307
|
+
await this.host.loaderHook.lifecycle.afterGetExpose.emit({
|
|
1308
|
+
id,
|
|
1309
|
+
expose,
|
|
1310
|
+
moduleInfo: this.remoteInfo,
|
|
1311
|
+
remoteEntryExports,
|
|
1312
|
+
moduleFactory,
|
|
1313
|
+
origin: this.host
|
|
1314
|
+
});
|
|
1315
|
+
} catch (getExposeError) {
|
|
1316
|
+
await this.host.loaderHook.lifecycle.afterGetExpose.emit({
|
|
1317
|
+
id,
|
|
1318
|
+
expose,
|
|
1319
|
+
moduleInfo: this.remoteInfo,
|
|
1320
|
+
remoteEntryExports,
|
|
1321
|
+
error: getExposeError,
|
|
1322
|
+
origin: this.host
|
|
1323
|
+
});
|
|
1324
|
+
throw getExposeError;
|
|
1325
|
+
}
|
|
1326
|
+
const symbolName = processModuleAlias(this.remoteInfo.name, expose);
|
|
1327
|
+
const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
|
|
1328
|
+
if (!loadFactory) return wrapModuleFactory;
|
|
1329
|
+
await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
|
|
1330
|
+
id,
|
|
1331
|
+
expose,
|
|
1332
|
+
moduleInfo: this.remoteInfo,
|
|
1333
|
+
loadFactory,
|
|
1334
|
+
origin: this.host
|
|
1335
|
+
});
|
|
1336
|
+
try {
|
|
1337
|
+
const exposeContent = await wrapModuleFactory();
|
|
1338
|
+
await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
|
|
1339
|
+
id,
|
|
1340
|
+
expose,
|
|
1341
|
+
moduleInfo: this.remoteInfo,
|
|
1342
|
+
loadFactory,
|
|
1343
|
+
exposeModule: exposeContent,
|
|
1344
|
+
origin: this.host
|
|
1345
|
+
});
|
|
1346
|
+
return exposeContent;
|
|
1347
|
+
} catch (executeFactoryError) {
|
|
1348
|
+
await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
|
|
1349
|
+
id,
|
|
1350
|
+
expose,
|
|
1351
|
+
moduleInfo: this.remoteInfo,
|
|
1352
|
+
loadFactory,
|
|
1353
|
+
error: executeFactoryError,
|
|
1354
|
+
origin: this.host
|
|
1355
|
+
});
|
|
1356
|
+
throw executeFactoryError;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
wraperFactory(moduleFactory, id) {
|
|
1360
|
+
function defineModuleId(res, id2) {
|
|
1361
|
+
if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
|
|
1362
|
+
value: id2,
|
|
1363
|
+
enumerable: false
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
return () => {
|
|
1367
|
+
const res = moduleFactory();
|
|
1368
|
+
if (res instanceof Promise) return res.then((asyncRes) => {
|
|
1369
|
+
defineModuleId(asyncRes, id);
|
|
1370
|
+
return asyncRes;
|
|
1371
|
+
});
|
|
1372
|
+
defineModuleId(res, id);
|
|
1373
|
+
return res;
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const REMOTE_DISABLED_MESSAGE = "Remote loading is disabled by experiments.optimization.disableRemote.";
|
|
1378
|
+
var UnavailableRemoteModule = class {
|
|
1379
|
+
constructor() {
|
|
1380
|
+
throw new Error(REMOTE_DISABLED_MESSAGE);
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
|
|
1384
|
+
typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
|
|
1385
|
+
typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
|
|
1386
|
+
const helpers = helpers_default;
|
|
1387
|
+
typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" && FEDERATION_OPTIMIZE_NO_REMOTE ? UnavailableRemoteModule : Module$1;
|
|
1388
|
+
const utils = helpers.utils;
|
|
1389
|
+
const runtimeHelpers = {
|
|
1390
|
+
utils
|
|
1391
|
+
};
|
|
1392
|
+
async function prefetch(options) {
|
|
1393
|
+
const { instance, id, dataFetchParams, preloadComponentResource } = options;
|
|
1394
|
+
if (!id) {
|
|
1395
|
+
lazyUtils.logger.error("id is required for prefetch!");
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
if (!instance) {
|
|
1399
|
+
lazyUtils.logger.error("instance is required for prefetch!");
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
const matchedRemoteInfo = runtimeHelpers.utils.matchRemoteWithNameAndExpose(
|
|
1403
|
+
instance.options.remotes,
|
|
1404
|
+
id
|
|
1405
|
+
);
|
|
1406
|
+
if (!matchedRemoteInfo) {
|
|
1407
|
+
lazyUtils.logger.error(`Can not found '${id}' in instance.options.remotes!`);
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
const { remote, expose } = matchedRemoteInfo;
|
|
1411
|
+
const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
|
|
1412
|
+
moduleInfo: remote,
|
|
1413
|
+
id
|
|
1414
|
+
});
|
|
1415
|
+
if (preloadComponentResource) {
|
|
1416
|
+
const remoteInfo = runtimeHelpers.utils.getRemoteInfo(remote);
|
|
1417
|
+
Promise.resolve(
|
|
1418
|
+
instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
|
|
1419
|
+
origin: instance,
|
|
1420
|
+
preloadOptions: {
|
|
1421
|
+
remote,
|
|
1422
|
+
preloadConfig: {
|
|
1423
|
+
nameOrAlias: remote.name,
|
|
1424
|
+
exposes: [expose]
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
remote,
|
|
1428
|
+
remoteInfo,
|
|
1429
|
+
globalSnapshot,
|
|
1430
|
+
remoteSnapshot
|
|
1431
|
+
})
|
|
1432
|
+
).then((assets) => {
|
|
1433
|
+
if (assets) {
|
|
1434
|
+
runtimeHelpers.utils.preloadAssets(remoteInfo, instance, assets);
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
const dataFetchMap = lazyUtils.getDataFetchMap();
|
|
1439
|
+
if (!dataFetchMap) {
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
const dataFetchInfo = lazyUtils.getDataFetchInfo({
|
|
1443
|
+
name: remote.name,
|
|
1444
|
+
alias: remote.alias,
|
|
1445
|
+
id,
|
|
1446
|
+
remoteSnapshot
|
|
1447
|
+
});
|
|
1448
|
+
const dataFetchMapKey = lazyUtils.getDataFetchMapKey(dataFetchInfo, {
|
|
1449
|
+
name: instance.name,
|
|
1450
|
+
version: instance.options.version
|
|
1451
|
+
});
|
|
1452
|
+
if (!dataFetchMapKey) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
const dataFetchItem = dataFetchMap[dataFetchMapKey];
|
|
1456
|
+
if (!dataFetchItem) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
|
|
1460
|
+
let _getDataFetchPromise = getDataFetchPromise;
|
|
1461
|
+
if (!getDataFetchPromise) {
|
|
1462
|
+
if (!getDataFetchGetter) {
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
_getDataFetchPromise = getDataFetchGetter();
|
|
1466
|
+
}
|
|
1467
|
+
_getDataFetchPromise.then((dataFetchFn) => {
|
|
1468
|
+
return dataFetchFn({
|
|
1469
|
+
...dataFetchParams,
|
|
1470
|
+
_id: dataFetchMapKey,
|
|
1471
|
+
isDowngrade: false
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
exports.dataFetchFunction = dataFetchFunction;
|
|
1476
|
+
exports.injectDataFetch = injectDataFetch;
|
|
1477
|
+
exports.prefetch = prefetch;
|