@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
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-
|
|
1
|
+
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-BoshEggF.mjs";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import React__default, { forwardRef, useRef, useState, useEffect, useContext } from "react";
|
|
4
|
-
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin } from "./index-
|
|
4
|
+
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin } from "./index-CqxytsLY.mjs";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
6
|
import { federationRuntime } from "./plugin.es.js";
|
|
7
|
+
import { b, a, c, l } from "./lazy-load-component-plugin-PERjiaFJ.mjs";
|
|
8
|
+
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-Cy-amYU5.mjs";
|
|
9
|
+
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
10
|
+
import { p } from "./prefetch-Dux8GUpr.mjs";
|
|
7
11
|
function createReact16Or17Root(container) {
|
|
8
12
|
return {
|
|
9
13
|
render(children) {
|
|
@@ -34,7 +38,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
34
38
|
};
|
|
35
39
|
return createBaseBridgeComponent(fullBridgeInfo);
|
|
36
40
|
}
|
|
37
|
-
function
|
|
41
|
+
function e2() {
|
|
38
42
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
39
43
|
window.dispatchEvent(t);
|
|
40
44
|
}
|
|
@@ -64,7 +68,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
64
68
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
65
69
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
66
70
|
LoggerInstance.debug(
|
|
67
|
-
`
|
|
71
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
68
72
|
{ moduleName, basename, dom: renderDom.current }
|
|
69
73
|
);
|
|
70
74
|
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
@@ -152,7 +156,7 @@ function withRouterData(WrappedComponent) {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
|
-
LoggerInstance.debug(`
|
|
159
|
+
LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
156
160
|
...props,
|
|
157
161
|
basename,
|
|
158
162
|
routerContextVal,
|
|
@@ -164,13 +168,13 @@ function withRouterData(WrappedComponent) {
|
|
|
164
168
|
useEffect(() => {
|
|
165
169
|
if (pathname !== "" && pathname !== location.pathname) {
|
|
166
170
|
LoggerInstance.debug(
|
|
167
|
-
`
|
|
171
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
168
172
|
{
|
|
169
173
|
name: props.name,
|
|
170
174
|
pathname: location.pathname
|
|
171
175
|
}
|
|
172
176
|
);
|
|
173
|
-
|
|
177
|
+
e2();
|
|
174
178
|
}
|
|
175
179
|
setPathname(location.pathname);
|
|
176
180
|
}, [location]);
|
|
@@ -185,7 +189,7 @@ const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
|
185
189
|
function createLazyRemoteComponent(info) {
|
|
186
190
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
187
191
|
return React__default.lazy(async () => {
|
|
188
|
-
LoggerInstance.debug(`
|
|
192
|
+
LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
|
|
189
193
|
lazyComponent: info.loader,
|
|
190
194
|
exportName
|
|
191
195
|
});
|
|
@@ -193,7 +197,7 @@ function createLazyRemoteComponent(info) {
|
|
|
193
197
|
const m = await info.loader();
|
|
194
198
|
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
195
199
|
LoggerInstance.debug(
|
|
196
|
-
`
|
|
200
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
197
201
|
{ name: moduleName, module: m, exportName }
|
|
198
202
|
);
|
|
199
203
|
const exportFn = m[exportName];
|
|
@@ -216,7 +220,7 @@ function createLazyRemoteComponent(info) {
|
|
|
216
220
|
};
|
|
217
221
|
} else {
|
|
218
222
|
LoggerInstance.debug(
|
|
219
|
-
`
|
|
223
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
220
224
|
{ name: moduleName, module: m, exportName }
|
|
221
225
|
);
|
|
222
226
|
throw Error(
|
|
@@ -230,7 +234,7 @@ function createLazyRemoteComponent(info) {
|
|
|
230
234
|
}
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
|
-
function
|
|
237
|
+
function createRemoteAppComponent(info) {
|
|
234
238
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
235
239
|
return forwardRef((props, ref) => {
|
|
236
240
|
return /* @__PURE__ */ React__default.createElement(
|
|
@@ -242,7 +246,29 @@ function createRemoteComponent(info) {
|
|
|
242
246
|
);
|
|
243
247
|
});
|
|
244
248
|
}
|
|
249
|
+
function createRemoteComponent(info) {
|
|
250
|
+
LoggerInstance.warn(
|
|
251
|
+
`createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
252
|
+
);
|
|
253
|
+
return createRemoteAppComponent(info);
|
|
254
|
+
}
|
|
245
255
|
export {
|
|
256
|
+
C as CacheSize,
|
|
257
|
+
b2 as CacheTime,
|
|
258
|
+
E as ERROR_TYPE,
|
|
259
|
+
b as autoFetchDataPlugin,
|
|
260
|
+
e as cache,
|
|
261
|
+
callDataFetch,
|
|
262
|
+
h as clearStore,
|
|
263
|
+
a as collectSSRAssets,
|
|
264
|
+
c2 as configureCache,
|
|
246
265
|
createBridgeComponent,
|
|
247
|
-
|
|
266
|
+
c as createLazyComponent,
|
|
267
|
+
createRemoteAppComponent,
|
|
268
|
+
createRemoteComponent,
|
|
269
|
+
d as generateKey,
|
|
270
|
+
l as lazyLoadComponentPlugin,
|
|
271
|
+
p as prefetch,
|
|
272
|
+
r as revalidateTag,
|
|
273
|
+
s as setSSREnv
|
|
248
274
|
};
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
return target;
|
|
8
|
+
};
|
|
9
|
+
return _extends.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
const MANIFEST_EXT = ".json";
|
|
12
|
+
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
13
|
+
const SEPARATOR = ":";
|
|
14
|
+
function isBrowserEnv() {
|
|
15
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
16
|
+
}
|
|
17
|
+
function isBrowserDebug() {
|
|
18
|
+
try {
|
|
19
|
+
if (isBrowserEnv() && window.localStorage) {
|
|
20
|
+
return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function isDebugMode() {
|
|
28
|
+
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
|
|
29
|
+
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
30
|
+
}
|
|
31
|
+
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return isBrowserDebug();
|
|
35
|
+
}
|
|
36
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
37
|
+
const composeKeyWithSeparator = function(...args) {
|
|
38
|
+
if (!args.length) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
return args.reduce((sum, cur) => {
|
|
42
|
+
if (!cur) {
|
|
43
|
+
return sum;
|
|
44
|
+
}
|
|
45
|
+
if (!sum) {
|
|
46
|
+
return cur;
|
|
47
|
+
}
|
|
48
|
+
return `${sum}${SEPARATOR}${cur}`;
|
|
49
|
+
}, "");
|
|
50
|
+
};
|
|
51
|
+
const warn = (msg) => {
|
|
52
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
53
|
+
};
|
|
54
|
+
let Logger = class Logger2 {
|
|
55
|
+
setPrefix(prefix) {
|
|
56
|
+
this.prefix = prefix;
|
|
57
|
+
}
|
|
58
|
+
log(...args) {
|
|
59
|
+
console.log(this.prefix, ...args);
|
|
60
|
+
}
|
|
61
|
+
warn(...args) {
|
|
62
|
+
console.log(this.prefix, ...args);
|
|
63
|
+
}
|
|
64
|
+
error(...args) {
|
|
65
|
+
console.log(this.prefix, ...args);
|
|
66
|
+
}
|
|
67
|
+
success(...args) {
|
|
68
|
+
console.log(this.prefix, ...args);
|
|
69
|
+
}
|
|
70
|
+
info(...args) {
|
|
71
|
+
console.log(this.prefix, ...args);
|
|
72
|
+
}
|
|
73
|
+
ready(...args) {
|
|
74
|
+
console.log(this.prefix, ...args);
|
|
75
|
+
}
|
|
76
|
+
debug(...args) {
|
|
77
|
+
if (isDebugMode()) {
|
|
78
|
+
console.log(this.prefix, ...args);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
constructor(prefix) {
|
|
82
|
+
this.prefix = prefix;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function createLogger(prefix) {
|
|
86
|
+
return new Logger(prefix);
|
|
87
|
+
}
|
|
88
|
+
async function safeWrapper(callback, disableWarn) {
|
|
89
|
+
try {
|
|
90
|
+
const res2 = await callback();
|
|
91
|
+
return res2;
|
|
92
|
+
} catch (e) {
|
|
93
|
+
warn(e);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isStaticResourcesEqual(url1, url2) {
|
|
98
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
99
|
+
const relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
|
|
100
|
+
const relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
101
|
+
return relativeUrl1 === relativeUrl2;
|
|
102
|
+
}
|
|
103
|
+
function createScript(info) {
|
|
104
|
+
let script2 = null;
|
|
105
|
+
let needAttach = true;
|
|
106
|
+
let timeout = 2e4;
|
|
107
|
+
let timeoutId;
|
|
108
|
+
const scripts = document.getElementsByTagName("script");
|
|
109
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
110
|
+
const s = scripts[i];
|
|
111
|
+
const scriptSrc = s.getAttribute("src");
|
|
112
|
+
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
113
|
+
script2 = s;
|
|
114
|
+
needAttach = false;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!script2) {
|
|
119
|
+
const attrs2 = info.attrs;
|
|
120
|
+
script2 = document.createElement("script");
|
|
121
|
+
script2.type = (attrs2 == null ? void 0 : attrs2["type"]) === "module" ? "module" : "text/javascript";
|
|
122
|
+
let createScriptRes = void 0;
|
|
123
|
+
if (info.createScriptHook) {
|
|
124
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
125
|
+
if (createScriptRes instanceof HTMLScriptElement) {
|
|
126
|
+
script2 = createScriptRes;
|
|
127
|
+
} else if (typeof createScriptRes === "object") {
|
|
128
|
+
if ("script" in createScriptRes && createScriptRes.script) {
|
|
129
|
+
script2 = createScriptRes.script;
|
|
130
|
+
}
|
|
131
|
+
if ("timeout" in createScriptRes && createScriptRes.timeout) {
|
|
132
|
+
timeout = createScriptRes.timeout;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!script2.src) {
|
|
137
|
+
script2.src = info.url;
|
|
138
|
+
}
|
|
139
|
+
if (attrs2 && !createScriptRes) {
|
|
140
|
+
Object.keys(attrs2).forEach((name) => {
|
|
141
|
+
if (script2) {
|
|
142
|
+
if (name === "async" || name === "defer") {
|
|
143
|
+
script2[name] = attrs2[name];
|
|
144
|
+
} else if (!script2.getAttribute(name)) {
|
|
145
|
+
script2.setAttribute(name, attrs2[name]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const onScriptComplete = async (prev, event) => {
|
|
152
|
+
clearTimeout(timeoutId);
|
|
153
|
+
const onScriptCompleteCallback = () => {
|
|
154
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
155
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
156
|
+
} else {
|
|
157
|
+
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
if (script2) {
|
|
161
|
+
script2.onerror = null;
|
|
162
|
+
script2.onload = null;
|
|
163
|
+
safeWrapper(() => {
|
|
164
|
+
const { needDeleteScript = true } = info;
|
|
165
|
+
if (needDeleteScript) {
|
|
166
|
+
(script2 == null ? void 0 : script2.parentNode) && script2.parentNode.removeChild(script2);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (prev && typeof prev === "function") {
|
|
170
|
+
const result = prev(event);
|
|
171
|
+
if (result instanceof Promise) {
|
|
172
|
+
const res2 = await result;
|
|
173
|
+
onScriptCompleteCallback();
|
|
174
|
+
return res2;
|
|
175
|
+
}
|
|
176
|
+
onScriptCompleteCallback();
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
onScriptCompleteCallback();
|
|
181
|
+
};
|
|
182
|
+
script2.onerror = onScriptComplete.bind(null, script2.onerror);
|
|
183
|
+
script2.onload = onScriptComplete.bind(null, script2.onload);
|
|
184
|
+
timeoutId = setTimeout(() => {
|
|
185
|
+
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
186
|
+
}, timeout);
|
|
187
|
+
return {
|
|
188
|
+
script: script2,
|
|
189
|
+
needAttach
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function createLink(info) {
|
|
193
|
+
let link = null;
|
|
194
|
+
let needAttach = true;
|
|
195
|
+
const links = document.getElementsByTagName("link");
|
|
196
|
+
for (let i = 0; i < links.length; i++) {
|
|
197
|
+
const l = links[i];
|
|
198
|
+
const linkHref = l.getAttribute("href");
|
|
199
|
+
const linkRel = l.getAttribute("rel");
|
|
200
|
+
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
|
|
201
|
+
link = l;
|
|
202
|
+
needAttach = false;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (!link) {
|
|
207
|
+
link = document.createElement("link");
|
|
208
|
+
link.setAttribute("href", info.url);
|
|
209
|
+
let createLinkRes = void 0;
|
|
210
|
+
const attrs2 = info.attrs;
|
|
211
|
+
if (info.createLinkHook) {
|
|
212
|
+
createLinkRes = info.createLinkHook(info.url, attrs2);
|
|
213
|
+
if (createLinkRes instanceof HTMLLinkElement) {
|
|
214
|
+
link = createLinkRes;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (attrs2 && !createLinkRes) {
|
|
218
|
+
Object.keys(attrs2).forEach((name) => {
|
|
219
|
+
if (link && !link.getAttribute(name)) {
|
|
220
|
+
link.setAttribute(name, attrs2[name]);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const onLinkComplete = (prev, event) => {
|
|
226
|
+
const onLinkCompleteCallback = () => {
|
|
227
|
+
if ((event == null ? void 0 : event.type) === "error") {
|
|
228
|
+
(info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
|
|
229
|
+
} else {
|
|
230
|
+
(info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
if (link) {
|
|
234
|
+
link.onerror = null;
|
|
235
|
+
link.onload = null;
|
|
236
|
+
safeWrapper(() => {
|
|
237
|
+
const { needDeleteLink = true } = info;
|
|
238
|
+
if (needDeleteLink) {
|
|
239
|
+
(link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
if (prev) {
|
|
243
|
+
const res2 = prev(event);
|
|
244
|
+
onLinkCompleteCallback();
|
|
245
|
+
return res2;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
onLinkCompleteCallback();
|
|
249
|
+
};
|
|
250
|
+
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
251
|
+
link.onload = onLinkComplete.bind(null, link.onload);
|
|
252
|
+
return {
|
|
253
|
+
link,
|
|
254
|
+
needAttach
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function loadScript(url2, info) {
|
|
258
|
+
const { attrs: attrs2 = {}, createScriptHook } = info;
|
|
259
|
+
return new Promise((resolve, reject) => {
|
|
260
|
+
const { script: script2, needAttach } = createScript({
|
|
261
|
+
url: url2,
|
|
262
|
+
cb: resolve,
|
|
263
|
+
onErrorCallback: reject,
|
|
264
|
+
attrs: _extends({
|
|
265
|
+
fetchpriority: "high"
|
|
266
|
+
}, attrs2),
|
|
267
|
+
createScriptHook,
|
|
268
|
+
needDeleteScript: true
|
|
269
|
+
});
|
|
270
|
+
needAttach && document.head.appendChild(script2);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function importNodeModule(name) {
|
|
274
|
+
if (!name) {
|
|
275
|
+
throw new Error("import specifier is required");
|
|
276
|
+
}
|
|
277
|
+
const importModule = new Function("name", `return import(name)`);
|
|
278
|
+
return importModule(name).then((res2) => res2).catch((error) => {
|
|
279
|
+
console.error(`Error importing module ${name}:`, error);
|
|
280
|
+
throw error;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const loadNodeFetch = async () => {
|
|
284
|
+
const fetchModule = await importNodeModule("node-fetch");
|
|
285
|
+
return fetchModule.default || fetchModule;
|
|
286
|
+
};
|
|
287
|
+
const lazyLoaderHookFetch = async (input, init, loaderHook2) => {
|
|
288
|
+
const hook = (url2, init2) => {
|
|
289
|
+
return loaderHook2.lifecycle.fetch.emit(url2, init2);
|
|
290
|
+
};
|
|
291
|
+
const res2 = await hook(input, init || {});
|
|
292
|
+
if (!res2 || !(res2 instanceof Response)) {
|
|
293
|
+
const fetchFunction = typeof fetch === "undefined" ? await loadNodeFetch() : fetch;
|
|
294
|
+
return fetchFunction(input, init || {});
|
|
295
|
+
}
|
|
296
|
+
return res2;
|
|
297
|
+
};
|
|
298
|
+
const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
|
|
299
|
+
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
300
|
+
const hookResult = loaderHook.createScriptHook(url);
|
|
301
|
+
if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
|
|
302
|
+
url = hookResult.url;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let urlObj;
|
|
306
|
+
try {
|
|
307
|
+
urlObj = new URL(url);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
console.error("Error constructing URL:", e);
|
|
310
|
+
cb(new Error(`Invalid URL: ${e}`));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const getFetch = async () => {
|
|
314
|
+
if (loaderHook == null ? void 0 : loaderHook.fetch) {
|
|
315
|
+
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
316
|
+
}
|
|
317
|
+
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
318
|
+
};
|
|
319
|
+
const handleScriptFetch = async (f, urlObj) => {
|
|
320
|
+
try {
|
|
321
|
+
var _vm_constants;
|
|
322
|
+
const res = await f(urlObj.href);
|
|
323
|
+
const data = await res.text();
|
|
324
|
+
const [path, vm] = await Promise.all([
|
|
325
|
+
importNodeModule("path"),
|
|
326
|
+
importNodeModule("vm")
|
|
327
|
+
]);
|
|
328
|
+
const scriptContext = {
|
|
329
|
+
exports: {},
|
|
330
|
+
module: {
|
|
331
|
+
exports: {}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
|
|
335
|
+
const filename = path.basename(urlObj.pathname);
|
|
336
|
+
var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
337
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
338
|
+
})`, {
|
|
339
|
+
filename,
|
|
340
|
+
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
|
|
341
|
+
});
|
|
342
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
343
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
344
|
+
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
345
|
+
const container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
346
|
+
cb(void 0, container);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
cb(void 0, exportedInterface);
|
|
350
|
+
} catch (e) {
|
|
351
|
+
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
getFetch().then(async (f2) => {
|
|
355
|
+
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") {
|
|
356
|
+
return loadModule(urlObj.href, {
|
|
357
|
+
fetch: f2,
|
|
358
|
+
vm: await importNodeModule("vm")
|
|
359
|
+
}).then(async (module) => {
|
|
360
|
+
await module.evaluate();
|
|
361
|
+
cb(void 0, module.namespace);
|
|
362
|
+
}).catch((e) => {
|
|
363
|
+
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
handleScriptFetch(f2, urlObj);
|
|
367
|
+
}).catch((err) => {
|
|
368
|
+
cb(err);
|
|
369
|
+
});
|
|
370
|
+
} : (url2, cb2, attrs2, loaderHook2) => {
|
|
371
|
+
cb2(new Error("createScriptNode is disabled in non-Node.js environment"));
|
|
372
|
+
};
|
|
373
|
+
const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
|
|
374
|
+
return new Promise((resolve, reject) => {
|
|
375
|
+
createScriptNode(url2, (error, scriptContext2) => {
|
|
376
|
+
if (error) {
|
|
377
|
+
reject(error);
|
|
378
|
+
} else {
|
|
379
|
+
var _info_attrs, _info_attrs1;
|
|
380
|
+
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__`;
|
|
381
|
+
const entryExports = globalThis[remoteEntryKey] = scriptContext2;
|
|
382
|
+
resolve(entryExports);
|
|
383
|
+
}
|
|
384
|
+
}, info.attrs, info.loaderHook);
|
|
385
|
+
});
|
|
386
|
+
} : (url2, info) => {
|
|
387
|
+
throw new Error("loadScriptNode is disabled in non-Node.js environment");
|
|
388
|
+
};
|
|
389
|
+
async function loadModule(url2, options) {
|
|
390
|
+
const { fetch: fetch1, vm: vm2 } = options;
|
|
391
|
+
const response = await fetch1(url2);
|
|
392
|
+
const code = await response.text();
|
|
393
|
+
const module = new vm2.SourceTextModule(code, {
|
|
394
|
+
// @ts-ignore
|
|
395
|
+
importModuleDynamically: async (specifier, script2) => {
|
|
396
|
+
const resolvedUrl = new URL(specifier, url2).href;
|
|
397
|
+
return loadModule(resolvedUrl, options);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
await module.link(async (specifier) => {
|
|
401
|
+
const resolvedUrl = new URL(specifier, url2).href;
|
|
402
|
+
const module2 = await loadModule(resolvedUrl, options);
|
|
403
|
+
return module2;
|
|
404
|
+
});
|
|
405
|
+
return module;
|
|
406
|
+
}
|
|
407
|
+
export {
|
|
408
|
+
MANIFEST_EXT as M,
|
|
409
|
+
SEPARATOR as S,
|
|
410
|
+
composeKeyWithSeparator as a,
|
|
411
|
+
isDebugMode as b,
|
|
412
|
+
createLogger as c,
|
|
413
|
+
createLink as d,
|
|
414
|
+
createScript as e,
|
|
415
|
+
loadScript as f,
|
|
416
|
+
isBrowserEnv as i,
|
|
417
|
+
loadScriptNode as l
|
|
418
|
+
};
|