@module-federation/bridge-react 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/__tests__/bridge.spec.tsx +7 -7
- package/__tests__/createLazyComponent.spec.tsx +210 -0
- package/__tests__/prefetch.spec.ts +153 -0
- package/__tests__/setupTests.ts +3 -0
- package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
- package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-C0fDZB5b.js +45 -0
- package/dist/index-CqxytsLY.mjs +46 -0
- package/dist/index.cjs.js +35 -9
- package/dist/index.d.ts +140 -0
- package/dist/index.es.js +38 -12
- package/dist/index.esm-BCeUd-x9.mjs +418 -0
- package/dist/index.esm-j_1sIRzg.js +417 -0
- package/dist/lazy-load-component-plugin-C1tVve-W.js +521 -0
- package/dist/lazy-load-component-plugin-PERjiaFJ.mjs +522 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.d.ts +13 -4
- package/dist/prefetch-CZvoIftg.js +1334 -0
- package/dist/prefetch-Dux8GUpr.mjs +1335 -0
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.d.ts +9 -0
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.d.ts +9 -0
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.d.ts +9 -0
- package/dist/router.es.js +1 -1
- package/dist/utils-Cy-amYU5.mjs +2016 -0
- package/dist/utils-iEVlDmyk.js +2015 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.d.ts +9 -0
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.d.ts +9 -0
- package/dist/v19.es.js +1 -1
- package/package.json +47 -5
- package/src/index.ts +32 -1
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +106 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/plugin.ts +4 -4
- package/src/remote/component.tsx +3 -3
- package/src/remote/create.tsx +17 -4
- package/tsconfig.json +1 -1
- package/vite.config.ts +13 -0
- package/vitest.config.ts +6 -1
- package/dist/index-Cv3p6r66.cjs +0 -235
- package/dist/index-D4yt7Udv.js +0 -236
- package/src/.eslintrc.js +0 -9
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _extends() {
|
|
3
|
+
_extends = Object.assign || function assign(target) {
|
|
4
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
5
|
+
var source = arguments[i];
|
|
6
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
7
|
+
}
|
|
8
|
+
return target;
|
|
9
|
+
};
|
|
10
|
+
return _extends.apply(this, arguments);
|
|
11
|
+
}
|
|
12
|
+
const MANIFEST_EXT = ".json";
|
|
13
|
+
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
14
|
+
const SEPARATOR = ":";
|
|
15
|
+
function isBrowserEnv() {
|
|
16
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
17
|
+
}
|
|
18
|
+
function isBrowserDebug() {
|
|
19
|
+
try {
|
|
20
|
+
if (isBrowserEnv() && window.localStorage) {
|
|
21
|
+
return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function isDebugMode() {
|
|
29
|
+
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
|
|
30
|
+
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
31
|
+
}
|
|
32
|
+
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return isBrowserDebug();
|
|
36
|
+
}
|
|
37
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
38
|
+
const composeKeyWithSeparator = function(...args) {
|
|
39
|
+
if (!args.length) {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
return args.reduce((sum, cur) => {
|
|
43
|
+
if (!cur) {
|
|
44
|
+
return sum;
|
|
45
|
+
}
|
|
46
|
+
if (!sum) {
|
|
47
|
+
return cur;
|
|
48
|
+
}
|
|
49
|
+
return `${sum}${SEPARATOR}${cur}`;
|
|
50
|
+
}, "");
|
|
51
|
+
};
|
|
52
|
+
const warn = (msg) => {
|
|
53
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
54
|
+
};
|
|
55
|
+
let Logger = class Logger2 {
|
|
56
|
+
setPrefix(prefix) {
|
|
57
|
+
this.prefix = prefix;
|
|
58
|
+
}
|
|
59
|
+
log(...args) {
|
|
60
|
+
console.log(this.prefix, ...args);
|
|
61
|
+
}
|
|
62
|
+
warn(...args) {
|
|
63
|
+
console.log(this.prefix, ...args);
|
|
64
|
+
}
|
|
65
|
+
error(...args) {
|
|
66
|
+
console.log(this.prefix, ...args);
|
|
67
|
+
}
|
|
68
|
+
success(...args) {
|
|
69
|
+
console.log(this.prefix, ...args);
|
|
70
|
+
}
|
|
71
|
+
info(...args) {
|
|
72
|
+
console.log(this.prefix, ...args);
|
|
73
|
+
}
|
|
74
|
+
ready(...args) {
|
|
75
|
+
console.log(this.prefix, ...args);
|
|
76
|
+
}
|
|
77
|
+
debug(...args) {
|
|
78
|
+
if (isDebugMode()) {
|
|
79
|
+
console.log(this.prefix, ...args);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
constructor(prefix) {
|
|
83
|
+
this.prefix = prefix;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function createLogger(prefix) {
|
|
87
|
+
return new Logger(prefix);
|
|
88
|
+
}
|
|
89
|
+
async function safeWrapper(callback, disableWarn) {
|
|
90
|
+
try {
|
|
91
|
+
const res2 = await callback();
|
|
92
|
+
return res2;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
warn(e);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function isStaticResourcesEqual(url1, url2) {
|
|
99
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
100
|
+
const relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
|
|
101
|
+
const relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
102
|
+
return relativeUrl1 === relativeUrl2;
|
|
103
|
+
}
|
|
104
|
+
function createScript(info) {
|
|
105
|
+
let script2 = null;
|
|
106
|
+
let needAttach = true;
|
|
107
|
+
let timeout = 2e4;
|
|
108
|
+
let timeoutId;
|
|
109
|
+
const scripts = document.getElementsByTagName("script");
|
|
110
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
111
|
+
const s = scripts[i];
|
|
112
|
+
const scriptSrc = s.getAttribute("src");
|
|
113
|
+
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
114
|
+
script2 = s;
|
|
115
|
+
needAttach = false;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!script2) {
|
|
120
|
+
const attrs2 = info.attrs;
|
|
121
|
+
script2 = document.createElement("script");
|
|
122
|
+
script2.type = (attrs2 == null ? void 0 : attrs2["type"]) === "module" ? "module" : "text/javascript";
|
|
123
|
+
let createScriptRes = void 0;
|
|
124
|
+
if (info.createScriptHook) {
|
|
125
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
126
|
+
if (createScriptRes instanceof HTMLScriptElement) {
|
|
127
|
+
script2 = createScriptRes;
|
|
128
|
+
} else if (typeof createScriptRes === "object") {
|
|
129
|
+
if ("script" in createScriptRes && createScriptRes.script) {
|
|
130
|
+
script2 = createScriptRes.script;
|
|
131
|
+
}
|
|
132
|
+
if ("timeout" in createScriptRes && createScriptRes.timeout) {
|
|
133
|
+
timeout = createScriptRes.timeout;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!script2.src) {
|
|
138
|
+
script2.src = info.url;
|
|
139
|
+
}
|
|
140
|
+
if (attrs2 && !createScriptRes) {
|
|
141
|
+
Object.keys(attrs2).forEach((name) => {
|
|
142
|
+
if (script2) {
|
|
143
|
+
if (name === "async" || name === "defer") {
|
|
144
|
+
script2[name] = attrs2[name];
|
|
145
|
+
} else if (!script2.getAttribute(name)) {
|
|
146
|
+
script2.setAttribute(name, attrs2[name]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const onScriptComplete = async (prev, event) => {
|
|
153
|
+
clearTimeout(timeoutId);
|
|
154
|
+
const onScriptCompleteCallback = () => {
|
|
155
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
156
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
157
|
+
} else {
|
|
158
|
+
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
if (script2) {
|
|
162
|
+
script2.onerror = null;
|
|
163
|
+
script2.onload = null;
|
|
164
|
+
safeWrapper(() => {
|
|
165
|
+
const { needDeleteScript = true } = info;
|
|
166
|
+
if (needDeleteScript) {
|
|
167
|
+
(script2 == null ? void 0 : script2.parentNode) && script2.parentNode.removeChild(script2);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
if (prev && typeof prev === "function") {
|
|
171
|
+
const result = prev(event);
|
|
172
|
+
if (result instanceof Promise) {
|
|
173
|
+
const res2 = await result;
|
|
174
|
+
onScriptCompleteCallback();
|
|
175
|
+
return res2;
|
|
176
|
+
}
|
|
177
|
+
onScriptCompleteCallback();
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
onScriptCompleteCallback();
|
|
182
|
+
};
|
|
183
|
+
script2.onerror = onScriptComplete.bind(null, script2.onerror);
|
|
184
|
+
script2.onload = onScriptComplete.bind(null, script2.onload);
|
|
185
|
+
timeoutId = setTimeout(() => {
|
|
186
|
+
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
187
|
+
}, timeout);
|
|
188
|
+
return {
|
|
189
|
+
script: script2,
|
|
190
|
+
needAttach
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createLink(info) {
|
|
194
|
+
let link = null;
|
|
195
|
+
let needAttach = true;
|
|
196
|
+
const links = document.getElementsByTagName("link");
|
|
197
|
+
for (let i = 0; i < links.length; i++) {
|
|
198
|
+
const l = links[i];
|
|
199
|
+
const linkHref = l.getAttribute("href");
|
|
200
|
+
const linkRel = l.getAttribute("rel");
|
|
201
|
+
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
202
|
+
link = l;
|
|
203
|
+
needAttach = false;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!link) {
|
|
208
|
+
link = document.createElement("link");
|
|
209
|
+
link.setAttribute("href", info.url);
|
|
210
|
+
let createLinkRes = void 0;
|
|
211
|
+
const attrs2 = info.attrs;
|
|
212
|
+
if (info.createLinkHook) {
|
|
213
|
+
createLinkRes = info.createLinkHook(info.url, attrs2);
|
|
214
|
+
if (createLinkRes instanceof HTMLLinkElement) {
|
|
215
|
+
link = createLinkRes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (attrs2 && !createLinkRes) {
|
|
219
|
+
Object.keys(attrs2).forEach((name) => {
|
|
220
|
+
if (link && !link.getAttribute(name)) {
|
|
221
|
+
link.setAttribute(name, attrs2[name]);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const onLinkComplete = (prev, event) => {
|
|
227
|
+
const onLinkCompleteCallback = () => {
|
|
228
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
229
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
230
|
+
} else {
|
|
231
|
+
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
if (link) {
|
|
235
|
+
link.onerror = null;
|
|
236
|
+
link.onload = null;
|
|
237
|
+
safeWrapper(() => {
|
|
238
|
+
const { needDeleteLink = true } = info;
|
|
239
|
+
if (needDeleteLink) {
|
|
240
|
+
(link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
if (prev) {
|
|
244
|
+
const res2 = prev(event);
|
|
245
|
+
onLinkCompleteCallback();
|
|
246
|
+
return res2;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
onLinkCompleteCallback();
|
|
250
|
+
};
|
|
251
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
252
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
253
|
+
return {
|
|
254
|
+
link,
|
|
255
|
+
needAttach
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function loadScript(url2, info) {
|
|
259
|
+
const { attrs: attrs2 = {}, createScriptHook } = info;
|
|
260
|
+
return new Promise((resolve, reject) => {
|
|
261
|
+
const { script: script2, needAttach } = createScript({
|
|
262
|
+
url: url2,
|
|
263
|
+
cb: resolve,
|
|
264
|
+
onErrorCallback: reject,
|
|
265
|
+
attrs: _extends({
|
|
266
|
+
fetchpriority: "high"
|
|
267
|
+
}, attrs2),
|
|
268
|
+
createScriptHook,
|
|
269
|
+
needDeleteScript: true
|
|
270
|
+
});
|
|
271
|
+
needAttach && document.head.appendChild(script2);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function importNodeModule(name) {
|
|
275
|
+
if (!name) {
|
|
276
|
+
throw new Error("import specifier is required");
|
|
277
|
+
}
|
|
278
|
+
const importModule = new Function("name", `return import(name)`);
|
|
279
|
+
return importModule(name).then((res2) => res2).catch((error) => {
|
|
280
|
+
console.error(`Error importing module ${name}:`, error);
|
|
281
|
+
throw error;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const loadNodeFetch = async () => {
|
|
285
|
+
const fetchModule = await importNodeModule("node-fetch");
|
|
286
|
+
return fetchModule.default || fetchModule;
|
|
287
|
+
};
|
|
288
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook2) => {
|
|
289
|
+
const hook = (url2, init2) => {
|
|
290
|
+
return loaderHook2.lifecycle.fetch.emit(url2, init2);
|
|
291
|
+
};
|
|
292
|
+
const res2 = await hook(input, init || {});
|
|
293
|
+
if (!res2 || !(res2 instanceof Response)) {
|
|
294
|
+
const fetchFunction = typeof fetch === "undefined" ? await loadNodeFetch() : fetch;
|
|
295
|
+
return fetchFunction(input, init || {});
|
|
296
|
+
}
|
|
297
|
+
return res2;
|
|
298
|
+
};
|
|
299
|
+
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
300
|
+
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
301
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
302
|
+
if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
|
|
303
|
+
url = hookResult.url;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let urlObj;
|
|
307
|
+
try {
|
|
308
|
+
urlObj = new URL(url);
|
|
309
|
+
} catch (e) {
|
|
310
|
+
console.error("Error constructing URL:", e);
|
|
311
|
+
cb(new Error(`Invalid URL: ${e}`));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const getFetch = async () => {
|
|
315
|
+
if (loaderHook == null ? void 0 : loaderHook.fetch) {
|
|
316
|
+
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
317
|
+
}
|
|
318
|
+
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
319
|
+
};
|
|
320
|
+
const handleScriptFetch = async (f, urlObj) => {
|
|
321
|
+
try {
|
|
322
|
+
var _vm_constants;
|
|
323
|
+
const res = await f(urlObj.href);
|
|
324
|
+
const data = await res.text();
|
|
325
|
+
const [path, vm] = await Promise.all([
|
|
326
|
+
importNodeModule("path"),
|
|
327
|
+
importNodeModule("vm")
|
|
328
|
+
]);
|
|
329
|
+
const scriptContext = {
|
|
330
|
+
exports: {},
|
|
331
|
+
module: {
|
|
332
|
+
exports: {}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
|
|
336
|
+
const filename = path.basename(urlObj.pathname);
|
|
337
|
+
var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
338
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
339
|
+
})`, {
|
|
340
|
+
filename,
|
|
341
|
+
importModuleDynamically: (_vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER = (_vm_constants = vm.constants) == null ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) != null ? _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER : importNodeModule
|
|
342
|
+
});
|
|
343
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
344
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
345
|
+
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
346
|
+
const container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
347
|
+
cb(void 0, container);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
cb(void 0, exportedInterface);
|
|
351
|
+
} catch (e) {
|
|
352
|
+
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
getFetch().then(async (f2) => {
|
|
356
|
+
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") {
|
|
357
|
+
return loadModule(urlObj.href, {
|
|
358
|
+
fetch: f2,
|
|
359
|
+
vm: await importNodeModule("vm")
|
|
360
|
+
}).then(async (module2) => {
|
|
361
|
+
await module2.evaluate();
|
|
362
|
+
cb(void 0, module2.namespace);
|
|
363
|
+
}).catch((e) => {
|
|
364
|
+
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
handleScriptFetch(f2, urlObj);
|
|
368
|
+
}).catch((err) => {
|
|
369
|
+
cb(err);
|
|
370
|
+
});
|
|
371
|
+
} : (url2, cb2, attrs2, loaderHook2) => {
|
|
372
|
+
cb2(new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
373
|
+
};
|
|
374
|
+
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
|
|
375
|
+
return new Promise((resolve, reject) => {
|
|
376
|
+
createScriptNode(url2, (error, scriptContext2) => {
|
|
377
|
+
if (error) {
|
|
378
|
+
reject(error);
|
|
379
|
+
} else {
|
|
380
|
+
var _info_attrs, _info_attrs1;
|
|
381
|
+
const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs["globalName"]) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1["name"]}:custom__`;
|
|
382
|
+
const entryExports = globalThis[remoteEntryKey] = scriptContext2;
|
|
383
|
+
resolve(entryExports);
|
|
384
|
+
}
|
|
385
|
+
}, info.attrs, info.loaderHook);
|
|
386
|
+
});
|
|
387
|
+
} : (url2, info) => {
|
|
388
|
+
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
389
|
+
};
|
|
390
|
+
async function loadModule(url2, options) {
|
|
391
|
+
const { fetch: fetch1, vm: vm2 } = options;
|
|
392
|
+
const response = await fetch1(url2);
|
|
393
|
+
const code = await response.text();
|
|
394
|
+
const module2 = new vm2.SourceTextModule(code, {
|
|
395
|
+
// @ts-ignore
|
|
396
|
+
importModuleDynamically: async (specifier, script2) => {
|
|
397
|
+
const resolvedUrl = new URL(specifier, url2).href;
|
|
398
|
+
return loadModule(resolvedUrl, options);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
await module2.link(async (specifier) => {
|
|
402
|
+
const resolvedUrl = new URL(specifier, url2).href;
|
|
403
|
+
const module3 = await loadModule(resolvedUrl, options);
|
|
404
|
+
return module3;
|
|
405
|
+
});
|
|
406
|
+
return module2;
|
|
407
|
+
}
|
|
408
|
+
exports.MANIFEST_EXT = MANIFEST_EXT;
|
|
409
|
+
exports.SEPARATOR = SEPARATOR;
|
|
410
|
+
exports.composeKeyWithSeparator = composeKeyWithSeparator;
|
|
411
|
+
exports.createLink = createLink;
|
|
412
|
+
exports.createLogger = createLogger;
|
|
413
|
+
exports.createScript = createScript;
|
|
414
|
+
exports.isBrowserEnv = isBrowserEnv;
|
|
415
|
+
exports.isDebugMode = isDebugMode;
|
|
416
|
+
exports.loadScript = loadScript;
|
|
417
|
+
exports.loadScriptNode = loadScriptNode;
|