@module-federation/bridge-vue3 0.0.0-next-20240903075658 → 0.0.0-next-20240904030559

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/index.es.js CHANGED
@@ -1,2465 +1,69 @@
1
- import * as Vue from "vue";
2
- import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createVNode, defineAsyncComponent, h } from "vue";
3
- import * as VueRouter from "vue-router";
4
- import { useRoute } from "vue-router";
5
- var a = Object.defineProperty, c = (t, e, n) => e in t ? a(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, i = (t, e, n) => (c(t, typeof e != "symbol" ? e + "" : e, n), n);
6
- class g {
7
- constructor(e) {
8
- i(this, "name"), i(this, "isDebugEnabled"), i(this, "color"), this.name = e, this.isDebugEnabled = !1, this.color = this.stringToColor(e), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
9
- }
10
- log(...e) {
11
- var n, o;
1
+ import * as h from "vue";
2
+ import { defineComponent as y, ref as l, watch as b, onMounted as v, onBeforeUnmount as R, createVNode as f, defineAsyncComponent as C, h as w } from "vue";
3
+ import * as d from "vue-router";
4
+ import { useRoute as g } from "vue-router";
5
+ var E = Object.defineProperty, _ = (t, o, e) => o in t ? E(t, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[o] = e, p = (t, o, e) => (_(t, typeof o != "symbol" ? o + "" : o, e), e);
6
+ class S {
7
+ constructor(o) {
8
+ p(this, "name"), p(this, "isDebugEnabled"), p(this, "color"), this.name = o, this.isDebugEnabled = !1, this.color = this.stringToColor(o), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
9
+ }
10
+ log(...o) {
11
+ var e, n;
12
12
  if (this.isDebugEnabled) {
13
- const r = `color: ${this.color}; font-weight: bold`, s = `%c[${this.name}]`, u = ((o = (n = new Error().stack) == null ? void 0 : n.split(`
14
- `)[2]) == null ? void 0 : o.trim()) || "Stack information not available";
15
- typeof console < "u" && console.debug && console.debug(s, r, ...e, `
16
- (${u})`);
13
+ const r = `color: ${this.color}; font-weight: bold`, a = `%c[${this.name}]`, s = ((n = (e = new Error().stack) == null ? void 0 : e.split(`
14
+ `)[2]) == null ? void 0 : n.trim()) || "Stack information not available";
15
+ typeof console < "u" && console.debug && console.debug(a, r, ...o, `
16
+ (${s})`);
17
17
  }
18
18
  }
19
- stringToColor(e) {
20
- let n = 0;
21
- for (let r = 0; r < e.length; r++)
22
- n = e.charCodeAt(r) + ((n << 5) - n);
23
- let o = "#";
19
+ stringToColor(o) {
20
+ let e = 0;
21
+ for (let r = 0; r < o.length; r++)
22
+ e = o.charCodeAt(r) + ((e << 5) - e);
23
+ let n = "#";
24
24
  for (let r = 0; r < 3; r++) {
25
- const s = n >> r * 8 & 255;
26
- o += ("00" + s.toString(16)).substr(-2);
25
+ const a = e >> r * 8 & 255;
26
+ n += ("00" + a.toString(16)).substr(-2);
27
27
  }
28
- return o;
28
+ return n;
29
29
  }
30
30
  }
31
- function f() {
31
+ function I() {
32
32
  const t = new PopStateEvent("popstate", { state: window.history.state });
33
33
  window.dispatchEvent(t);
34
34
  }
35
- const LoggerInstance = new g("vue3-bridge");
36
- function createBridgeComponent(t) {
37
- const e = /* @__PURE__ */ new Map();
35
+ const u = new S("vue3-bridge");
36
+ function B(t) {
37
+ const o = /* @__PURE__ */ new Map();
38
38
  return () => ({
39
39
  __APP_VERSION__: "0.6.0",
40
- render(n) {
41
- var l;
42
- LoggerInstance.log("createBridgeComponent render Info", n);
43
- const o = Vue.createApp(t.rootComponent);
44
- e.set(n.dom, o), (l = t == null ? void 0 : t.renderLifecycle) == null || l.call(t, n);
40
+ render(e) {
41
+ u.log("createBridgeComponent render Info", e);
42
+ const n = h.createApp(t.rootComponent);
43
+ o.set(e.dom, n);
45
44
  const r = t.appOptions({
46
- basename: n.basename,
47
- memoryRoute: n.memoryRoute
48
- }), s = n.memoryRoute ? VueRouter.createMemoryHistory(n.basename) : VueRouter.createWebHistory(n.basename), u = VueRouter.createRouter({
45
+ basename: e.basename,
46
+ memoryRoute: e.memoryRoute
47
+ }), a = e.memoryRoute ? d.createMemoryHistory(e.basename) : d.createWebHistory(e.basename), s = d.createRouter({
49
48
  ...r.router.options,
50
- history: s,
49
+ history: a,
51
50
  routes: r.router.getRoutes()
52
51
  });
53
- LoggerInstance.log("createBridgeComponent render router info>>>", {
54
- name: n.moduleName,
55
- router: u
56
- }), n.memoryRoute ? u.push(n.memoryRoute.entryPath).then(() => {
57
- o.use(u), o.mount(n.dom);
58
- }) : (o.use(u), o.mount(n.dom));
59
- },
60
- destroy(n) {
61
- var r;
62
- LoggerInstance.log("createBridgeComponent destroy Info", n);
63
- const o = e.get(n == null ? void 0 : n.dom);
64
- (r = t == null ? void 0 : t.destroyLifecycle) == null || r.call(t, n), o == null || o.unmount();
65
- }
66
- });
67
- }
68
- const MANIFEST_EXT = ".json", BROWSER_LOG_KEY = "FEDERATION_DEBUG", BROWSER_LOG_VALUE = "1", SEPARATOR = ":";
69
- function isBrowserEnv() {
70
- return typeof window < "u";
71
- }
72
- function isDebugMode() {
73
- return typeof process < "u" && process.env && process.env.FEDERATION_DEBUG ? !!process.env.FEDERATION_DEBUG : typeof FEDERATION_DEBUG < "u" && !!FEDERATION_DEBUG;
74
- }
75
- const DEBUG_LOG = "[ FEDERATION DEBUG ]";
76
- function safeGetLocalStorageItem() {
77
- try {
78
- if (typeof window < "u" && window.localStorage)
79
- return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
80
- } catch {
81
- return typeof document < "u";
82
- }
83
- return !1;
84
- }
85
- let Logger = class {
86
- info(e, n) {
87
- if (this.enable) {
88
- const o = safeToString(n) || "";
89
- isBrowserEnv() ? console.info(`%c ${this.identifier}: ${e} ${o}`, "color:#3300CC") : console.info("\x1B[34m%s", `${this.identifier}: ${e} ${o ? `
90
- ${o}` : ""}`);
91
- }
92
- }
93
- logOriginalInfo(...e) {
94
- this.enable && (isBrowserEnv() ? (console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC"), console.log(...e)) : (console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC"), console.log(...e)));
95
- }
96
- constructor(e) {
97
- this.enable = !1, this.identifier = e || DEBUG_LOG, isBrowserEnv() && safeGetLocalStorageItem() ? this.enable = !0 : isDebugMode() && (this.enable = !0);
98
- }
99
- };
100
- const LOG_CATEGORY$1 = "[ Federation Runtime ]";
101
- new Logger();
102
- const composeKeyWithSeparator = function(...t) {
103
- return t.length ? t.reduce((e, n) => n ? e ? `${e}${SEPARATOR}${n}` : n : e, "") : "";
104
- }, getResourceUrl = (t, e) => {
105
- if ("getPublicPath" in t) {
106
- let n;
107
- return t.getPublicPath.startsWith("function") ? n = new Function("return " + t.getPublicPath)()() : n = new Function(t.getPublicPath)(), `${n}${e}`;
108
- } else
109
- return "publicPath" in t ? `${t.publicPath}${e}` : (console.warn("Cannot get resource URL. If in debug mode, please ignore.", t, e), "");
110
- }, warn$1 = (t) => {
111
- console.warn(`${LOG_CATEGORY$1}: ${t}`);
112
- };
113
- function safeToString(t) {
114
- try {
115
- return JSON.stringify(t, null, 2);
116
- } catch {
117
- return "";
118
- }
119
- }
120
- function _extends$9() {
121
- return _extends$9 = Object.assign || function(e) {
122
- for (var n = 1; n < arguments.length; n++) {
123
- var o = arguments[n];
124
- for (var r in o)
125
- Object.prototype.hasOwnProperty.call(o, r) && (e[r] = o[r]);
126
- }
127
- return e;
128
- }, _extends$9.apply(this, arguments);
129
- }
130
- const simpleJoinRemoteEntry = (t, e) => {
131
- if (!t)
132
- return e;
133
- const o = ((r) => {
134
- if (r === ".")
135
- return "";
136
- if (r.startsWith("./"))
137
- return r.replace("./", "");
138
- if (r.startsWith("/")) {
139
- const s = r.slice(1);
140
- return s.endsWith("/") ? s.slice(0, -1) : s;
141
- }
142
- return r;
143
- })(t);
144
- return o ? o.endsWith("/") ? `${o}${e}` : `${o}/${e}` : e;
145
- };
146
- function inferAutoPublicPath(t) {
147
- return t.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
148
- }
149
- function generateSnapshotFromManifest(t, e = {}) {
150
- var n, o;
151
- const { remotes: r = {}, overrides: s = {}, version: u } = e;
152
- let l;
153
- const d = () => "publicPath" in t.metaData ? t.metaData.publicPath === "auto" && u ? inferAutoPublicPath(u) : t.metaData.publicPath : t.metaData.getPublicPath, p = Object.keys(s);
154
- let m = {};
155
- if (!Object.keys(r).length) {
156
- var _;
157
- m = ((_ = t.remotes) == null ? void 0 : _.reduce((R, T) => {
158
- let P;
159
- const w = T.federationContainerName;
160
- return p.includes(w) ? P = s[w] : "version" in T ? P = T.version : P = T.entry, R[w] = {
161
- matchedVersion: P
162
- }, R;
163
- }, {})) || {};
164
- }
165
- Object.keys(r).forEach((R) => m[R] = {
166
- // overrides will override dependencies
167
- matchedVersion: p.includes(R) ? s[R] : r[R]
168
- });
169
- const { remoteEntry: { path: y, name: b, type: S }, types: $, buildInfo: { buildVersion: E }, globalName: I, ssrRemoteEntry: A } = t.metaData, { exposes: O } = t;
170
- let v = {
171
- version: u || "",
172
- buildVersion: E,
173
- globalName: I,
174
- remoteEntry: simpleJoinRemoteEntry(y, b),
175
- remoteEntryType: S,
176
- remoteTypes: simpleJoinRemoteEntry($.path, $.name),
177
- remoteTypesZip: $.zip || "",
178
- remoteTypesAPI: $.api || "",
179
- remotesInfo: m,
180
- shared: t == null ? void 0 : t.shared.map((R) => ({
181
- assets: R.assets,
182
- sharedName: R.name,
183
- version: R.version
184
- })),
185
- modules: O == null ? void 0 : O.map((R) => ({
186
- moduleName: R.name,
187
- modulePath: R.path,
188
- assets: R.assets
189
- }))
190
- };
191
- if ((n = t.metaData) != null && n.prefetchInterface) {
192
- const R = t.metaData.prefetchInterface;
193
- v = _extends$9({}, v, {
194
- prefetchInterface: R
195
- });
196
- }
197
- if ((o = t.metaData) != null && o.prefetchEntry) {
198
- const { path: R, name: T, type: P } = t.metaData.prefetchEntry;
199
- v = _extends$9({}, v, {
200
- prefetchEntry: simpleJoinRemoteEntry(R, T),
201
- prefetchEntryType: P
202
- });
203
- }
204
- if ("publicPath" in t.metaData ? l = _extends$9({}, v, {
205
- publicPath: d()
206
- }) : l = _extends$9({}, v, {
207
- getPublicPath: d()
208
- }), A) {
209
- const R = simpleJoinRemoteEntry(A.path, A.name);
210
- l.ssrRemoteEntry = R, l.ssrRemoteEntryType = "commonjs-module";
211
- }
212
- return l;
213
- }
214
- function isManifestProvider(t) {
215
- return !!("remoteEntry" in t && t.remoteEntry.includes(MANIFEST_EXT));
216
- }
217
- async function safeWrapper(t, e) {
218
- try {
219
- return await t();
220
- } catch (n) {
221
- warn$1(n);
222
- return;
223
- }
224
- }
225
- function isStaticResourcesEqual(t, e) {
226
- const n = /^(https?:)?\/\//i, o = t.replace(n, "").replace(/\/$/, ""), r = e.replace(n, "").replace(/\/$/, "");
227
- return o === r;
228
- }
229
- function createScript(t) {
230
- let e = null, n = !0, o = 2e4, r;
231
- const s = document.getElementsByTagName("script");
232
- for (let l = 0; l < s.length; l++) {
233
- const d = s[l], p = d.getAttribute("src");
234
- if (p && isStaticResourcesEqual(p, t.url)) {
235
- e = d, n = !1;
236
- break;
237
- }
238
- }
239
- if (!e) {
240
- e = document.createElement("script"), e.type = "text/javascript", e.src = t.url;
241
- let l;
242
- t.createScriptHook && (l = t.createScriptHook(t.url, t.attrs), l instanceof HTMLScriptElement ? e = l : typeof l == "object" && ("script" in l && l.script && (e = l.script), "timeout" in l && l.timeout && (o = l.timeout)));
243
- const d = t.attrs;
244
- d && !l && Object.keys(d).forEach((p) => {
245
- e && (p === "async" || p === "defer" ? e[p] = d[p] : e.getAttribute(p) || e.setAttribute(p, d[p]));
246
- });
247
- }
248
- const u = (l, d) => {
249
- var p;
250
- if (clearTimeout(r), e && (e.onerror = null, e.onload = null, safeWrapper(() => {
251
- const { needDeleteScript: _ = !0 } = t;
252
- _ && e != null && e.parentNode && e.parentNode.removeChild(e);
253
- }), l)) {
254
- var m;
255
- const _ = l(d);
256
- return t == null || (m = t.cb) == null || m.call(t), _;
257
- }
258
- t == null || (p = t.cb) == null || p.call(t);
259
- };
260
- return e.onerror = u.bind(null, e.onerror), e.onload = u.bind(null, e.onload), r = setTimeout(() => {
261
- u(null, new Error(`Remote script "${t.url}" time-outed.`));
262
- }, o), {
263
- script: e,
264
- needAttach: n
265
- };
266
- }
267
- function createLink(t) {
268
- let e = null, n = !0;
269
- const o = document.getElementsByTagName("link");
270
- for (let s = 0; s < o.length; s++) {
271
- const u = o[s], l = u.getAttribute("href"), d = u.getAttribute("ref");
272
- if (l && isStaticResourcesEqual(l, t.url) && d === t.attrs.ref) {
273
- e = u, n = !1;
274
- break;
275
- }
276
- }
277
- if (!e) {
278
- e = document.createElement("link"), e.setAttribute("href", t.url);
279
- let s;
280
- const u = t.attrs;
281
- t.createLinkHook && (s = t.createLinkHook(t.url, u), s instanceof HTMLLinkElement && (e = s)), u && !s && Object.keys(u).forEach((l) => {
282
- e && !e.getAttribute(l) && e.setAttribute(l, u[l]);
283
- });
284
- }
285
- const r = (s, u) => {
286
- if (e && (e.onerror = null, e.onload = null, safeWrapper(() => {
287
- const { needDeleteLink: l = !0 } = t;
288
- l && e != null && e.parentNode && e.parentNode.removeChild(e);
289
- }), s)) {
290
- const l = s(u);
291
- return t.cb(), l;
292
- }
293
- t.cb();
294
- };
295
- return e.onerror = r.bind(null, e.onerror), e.onload = r.bind(null, e.onload), {
296
- link: e,
297
- needAttach: n
298
- };
299
- }
300
- function loadScript(t, e) {
301
- const { attrs: n = {}, createScriptHook: o } = e;
302
- return new Promise((r, s) => {
303
- const { script: u, needAttach: l } = createScript({
304
- url: t,
305
- cb: r,
306
- attrs: _extends$9({
307
- fetchpriority: "high"
308
- }, n),
309
- createScriptHook: o,
310
- needDeleteScript: !0
311
- });
312
- l && document.head.appendChild(u);
313
- });
314
- }
315
- function importNodeModule(t) {
316
- if (!t)
317
- throw new Error("import specifier is required");
318
- return new Function("name", "return import(name)")(t).then((n) => n).catch((n) => {
319
- throw console.error(`Error importing module ${t}:`, n), n;
320
- });
321
- }
322
- const loadNodeFetch = async () => {
323
- const t = await importNodeModule("node-fetch");
324
- return t.default || t;
325
- }, lazyLoaderHookFetch = async (t, e) => {
326
- const n = __webpack_require__.federation.instance.loaderHook, r = await ((s, u) => n.lifecycle.fetch.emit(s, u))(t, e || {});
327
- return !r || !(r instanceof Response) ? (typeof fetch > "u" ? await loadNodeFetch() : fetch)(t, e || {}) : r;
328
- };
329
- function createScriptNode(url, cb, attrs, createScriptHook) {
330
- if (createScriptHook) {
331
- const t = createScriptHook(url);
332
- t && typeof t == "object" && "url" in t && (url = t.url);
333
- }
334
- let urlObj;
335
- try {
336
- urlObj = new URL(url);
337
- } catch (t) {
338
- console.error("Error constructing URL:", t), cb(new Error(`Invalid URL: ${t}`));
339
- return;
340
- }
341
- const getFetch = async () => {
342
- if (typeof __webpack_require__ < "u")
343
- try {
344
- if (__webpack_require__.federation.instance.loaderHook.lifecycle.fetch)
345
- return lazyLoaderHookFetch;
346
- } catch (t) {
347
- console.warn("federation.instance.loaderHook.lifecycle.fetch failed:", t);
348
- }
349
- return typeof fetch > "u" ? loadNodeFetch() : fetch;
350
- }, handleScriptFetch = async (f, urlObj) => {
351
- try {
352
- var _vm_constants;
353
- const res = await f(urlObj.href), data = await res.text(), [path, vm] = await Promise.all([
354
- importNodeModule("path"),
355
- importNodeModule("vm")
356
- ]), scriptContext = {
357
- exports: {},
358
- module: {
359
- exports: {}
360
- }
361
- }, urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/"), filename = path.basename(urlObj.pathname);
362
- var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
363
- const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
364
- })`, {
365
- filename,
366
- 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
367
- });
368
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
369
- const exportedInterface = scriptContext.module.exports || scriptContext.exports;
370
- if (attrs && exportedInterface && attrs.globalName) {
371
- const t = exportedInterface[attrs.globalName] || exportedInterface;
372
- cb(void 0, t);
373
- return;
374
- }
375
- cb(void 0, exportedInterface);
376
- } catch (t) {
377
- cb(t instanceof Error ? t : new Error(`Script execution error: ${t}`));
378
- }
379
- };
380
- getFetch().then((t) => handleScriptFetch(t, urlObj)).catch((t) => {
381
- cb(t);
382
- });
383
- }
384
- function loadScriptNode(t, e) {
385
- return new Promise((n, o) => {
386
- createScriptNode(t, (r, s) => {
387
- if (r)
388
- o(r);
389
- else {
390
- var u, l;
391
- const d = (e == null || (u = e.attrs) == null ? void 0 : u.globalName) || `__FEDERATION_${e == null || (l = e.attrs) == null ? void 0 : l.name}:custom__`, p = globalThis[d] = s;
392
- n(p);
393
- }
394
- }, e.attrs, e.createScriptHook);
395
- });
396
- }
397
- function getBuilderId() {
398
- return typeof FEDERATION_BUILD_IDENTIFIER < "u" ? FEDERATION_BUILD_IDENTIFIER : "";
399
- }
400
- const LOG_CATEGORY = "[ Federation Runtime ]";
401
- function assert(t, e) {
402
- t || error(e);
403
- }
404
- function error(t) {
405
- throw t instanceof Error ? (t.message = `${LOG_CATEGORY}: ${t.message}`, t) : new Error(`${LOG_CATEGORY}: ${t}`);
406
- }
407
- function warn(t) {
408
- t instanceof Error ? (t.message = `${LOG_CATEGORY}: ${t.message}`, console.warn(t)) : console.warn(`${LOG_CATEGORY}: ${t}`);
409
- }
410
- function addUniqueItem(t, e) {
411
- return t.findIndex((n) => n === e) === -1 && t.push(e), t;
412
- }
413
- function getFMId(t) {
414
- return "version" in t && t.version ? `${t.name}:${t.version}` : "entry" in t && t.entry ? `${t.name}:${t.entry}` : `${t.name}`;
415
- }
416
- function isRemoteInfoWithEntry(t) {
417
- return typeof t.entry < "u";
418
- }
419
- function isPureRemoteEntry(t) {
420
- return !t.entry.includes(".json") && t.entry.includes(".js");
421
- }
422
- function isObject(t) {
423
- return t && typeof t == "object";
424
- }
425
- const objectToString = Object.prototype.toString;
426
- function isPlainObject(t) {
427
- return objectToString.call(t) === "[object Object]";
428
- }
429
- function arrayOptions(t) {
430
- return Array.isArray(t) ? t : [
431
- t
432
- ];
433
- }
434
- function getRemoteEntryInfoFromSnapshot(t) {
435
- const e = {
436
- url: "",
437
- type: "global",
438
- globalName: ""
439
- };
440
- return isBrowserEnv() ? "remoteEntry" in t ? {
441
- url: t.remoteEntry,
442
- type: t.remoteEntryType,
443
- globalName: t.globalName
444
- } : e : "ssrRemoteEntry" in t ? {
445
- url: t.ssrRemoteEntry || e.url,
446
- type: t.ssrRemoteEntryType || e.type,
447
- globalName: t.globalName
448
- } : e;
449
- }
450
- const processModuleAlias = (t, e) => {
451
- let n;
452
- return t.endsWith("/") ? n = t.slice(0, -1) : n = t, e.startsWith(".") && (e = e.slice(1)), n = n + e, n;
453
- };
454
- function _extends$1$1() {
455
- return _extends$1$1 = Object.assign || function(t) {
456
- for (var e = 1; e < arguments.length; e++) {
457
- var n = arguments[e];
458
- for (var o in n)
459
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
460
- }
461
- return t;
462
- }, _extends$1$1.apply(this, arguments);
463
- }
464
- function _object_without_properties_loose$1(t, e) {
465
- if (t == null)
466
- return {};
467
- var n = {}, o = Object.keys(t), r, s;
468
- for (s = 0; s < o.length; s++)
469
- r = o[s], !(e.indexOf(r) >= 0) && (n[r] = t[r]);
470
- return n;
471
- }
472
- const nativeGlobal = (() => {
473
- try {
474
- return new Function("return this")();
475
- } catch {
476
- return globalThis;
477
- }
478
- })(), Global = nativeGlobal;
479
- function definePropertyGlobalVal(t, e, n) {
480
- Object.defineProperty(t, e, {
481
- value: n,
482
- configurable: !1,
483
- writable: !0
484
- });
485
- }
486
- function includeOwnProperty(t, e) {
487
- return Object.hasOwnProperty.call(t, e);
488
- }
489
- includeOwnProperty(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__") || definePropertyGlobalVal(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
490
- const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
491
- function setGlobalDefaultVal(t) {
492
- var e, n, o, r, s, u;
493
- includeOwnProperty(t, "__VMOK__") && !includeOwnProperty(t, "__FEDERATION__") && definePropertyGlobalVal(t, "__FEDERATION__", t.__VMOK__), includeOwnProperty(t, "__FEDERATION__") || (definePropertyGlobalVal(t, "__FEDERATION__", {
494
- __GLOBAL_PLUGIN__: [],
495
- __INSTANCES__: [],
496
- moduleInfo: {},
497
- __SHARE__: {},
498
- __MANIFEST_LOADING__: {},
499
- __PRELOADED_MAP__: /* @__PURE__ */ new Map()
500
- }), definePropertyGlobalVal(t, "__VMOK__", t.__FEDERATION__));
501
- var l;
502
- (l = (e = t.__FEDERATION__).__GLOBAL_PLUGIN__) != null || (e.__GLOBAL_PLUGIN__ = []);
503
- var d;
504
- (d = (n = t.__FEDERATION__).__INSTANCES__) != null || (n.__INSTANCES__ = []);
505
- var p;
506
- (p = (o = t.__FEDERATION__).moduleInfo) != null || (o.moduleInfo = {});
507
- var m;
508
- (m = (r = t.__FEDERATION__).__SHARE__) != null || (r.__SHARE__ = {});
509
- var _;
510
- (_ = (s = t.__FEDERATION__).__MANIFEST_LOADING__) != null || (s.__MANIFEST_LOADING__ = {});
511
- var y;
512
- (y = (u = t.__FEDERATION__).__PRELOADED_MAP__) != null || (u.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
513
- }
514
- setGlobalDefaultVal(globalThis);
515
- setGlobalDefaultVal(nativeGlobal);
516
- function resetFederationGlobalInfo() {
517
- globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [], globalThis.__FEDERATION__.__INSTANCES__ = [], globalThis.__FEDERATION__.moduleInfo = {}, globalThis.__FEDERATION__.__SHARE__ = {}, globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
518
- }
519
- function getGlobalFederationInstance(t, e) {
520
- const n = getBuilderId();
521
- return globalThis.__FEDERATION__.__INSTANCES__.find((o) => !!(n && o.options.id === getBuilderId() || o.options.name === t && !o.options.version && !e || o.options.name === t && e && o.options.version === e));
522
- }
523
- function setGlobalFederationInstance(t) {
524
- globalThis.__FEDERATION__.__INSTANCES__.push(t);
525
- }
526
- function getGlobalFederationConstructor() {
527
- return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
528
- }
529
- function setGlobalFederationConstructor(t, e = isDebugMode()) {
530
- e && (globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = t, globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.0");
531
- }
532
- function getInfoWithoutType(t, e) {
533
- if (typeof e == "string") {
534
- if (t[e])
535
- return {
536
- value: t[e],
537
- key: e
538
- };
539
- {
540
- const o = Object.keys(t);
541
- for (const r of o) {
542
- const [s, u] = r.split(":"), l = `${s}:${e}`, d = t[l];
543
- if (d)
544
- return {
545
- value: d,
546
- key: l
547
- };
548
- }
549
- return {
550
- value: void 0,
551
- key: e
552
- };
553
- }
554
- } else
555
- throw new Error("key must be string");
556
- }
557
- const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo, getTargetSnapshotInfoByModuleInfo = (t, e) => {
558
- const n = getFMId(t), o = getInfoWithoutType(e, n).value;
559
- if (o && !o.version && "version" in t && t.version && (o.version = t.version), o)
560
- return o;
561
- if ("version" in t && t.version) {
562
- const { version: r } = t, s = _object_without_properties_loose$1(t, [
563
- "version"
564
- ]), u = getFMId(s), l = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, u).value;
565
- if ((l == null ? void 0 : l.version) === r)
566
- return l;
567
- }
568
- }, getGlobalSnapshotInfoByModuleInfo = (t) => getTargetSnapshotInfoByModuleInfo(t, nativeGlobal.__FEDERATION__.moduleInfo), setGlobalSnapshotInfoByModuleInfo = (t, e) => {
569
- const n = getFMId(t);
570
- return nativeGlobal.__FEDERATION__.moduleInfo[n] = e, nativeGlobal.__FEDERATION__.moduleInfo;
571
- }, addGlobalSnapshot = (t) => (nativeGlobal.__FEDERATION__.moduleInfo = _extends$1$1({}, nativeGlobal.__FEDERATION__.moduleInfo, t), () => {
572
- const e = Object.keys(t);
573
- for (const n of e)
574
- delete nativeGlobal.__FEDERATION__.moduleInfo[n];
575
- }), getRemoteEntryExports = (t, e) => {
576
- const n = e || `__FEDERATION_${t}:custom__`, o = globalThis[n];
577
- return {
578
- remoteEntryKey: n,
579
- entryExports: o
580
- };
581
- }, registerGlobalPlugins = (t) => {
582
- const { __GLOBAL_PLUGIN__: e } = nativeGlobal.__FEDERATION__;
583
- t.forEach((n) => {
584
- e.findIndex((o) => o.name === n.name) === -1 ? e.push(n) : warn(`The plugin ${n.name} has been registered.`);
585
- });
586
- }, getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__, getPreloaded = (t) => globalThis.__FEDERATION__.__PRELOADED_MAP__.get(t), setPreloaded = (t) => globalThis.__FEDERATION__.__PRELOADED_MAP__.set(t, !0);
587
- function registerPlugins(t, e) {
588
- const n = getGlobalHostPlugins();
589
- return n.length > 0 && n.forEach((o) => {
590
- t != null && t.find((r) => r.name !== o.name) && t.push(o);
591
- }), t && t.length > 0 && t.forEach((o) => {
592
- e.forEach((r) => {
593
- r.applyPlugin(o);
594
- });
595
- }), t;
596
- }
597
- const DEFAULT_SCOPE = "default", DEFAULT_REMOTE_TYPE = "global";
598
- class SyncHook {
599
- on(e) {
600
- typeof e == "function" && this.listeners.add(e);
601
- }
602
- once(e) {
603
- const n = this;
604
- this.on(function o(...r) {
605
- return n.remove(o), e.apply(null, r);
606
- });
607
- }
608
- emit(...e) {
609
- let n;
610
- return this.listeners.size > 0 && this.listeners.forEach((o) => {
611
- n = o(...e);
612
- }), n;
613
- }
614
- remove(e) {
615
- this.listeners.delete(e);
616
- }
617
- removeAll() {
618
- this.listeners.clear();
619
- }
620
- constructor(e) {
621
- this.type = "", this.listeners = /* @__PURE__ */ new Set(), e && (this.type = e);
622
- }
623
- }
624
- class AsyncHook extends SyncHook {
625
- emit(...e) {
626
- let n;
627
- const o = Array.from(this.listeners);
628
- if (o.length > 0) {
629
- let r = 0;
630
- const s = (u) => u === !1 ? !1 : r < o.length ? Promise.resolve(o[r++].apply(null, e)).then(s) : u;
631
- n = s();
632
- }
633
- return Promise.resolve(n);
634
- }
635
- }
636
- function checkReturnData(t, e) {
637
- if (!isObject(e))
638
- return !1;
639
- if (t !== e) {
640
- for (const n in t)
641
- if (!(n in e))
642
- return !1;
643
- }
644
- return !0;
645
- }
646
- class SyncWaterfallHook extends SyncHook {
647
- emit(e) {
648
- isObject(e) || error(`The data for the "${this.type}" hook should be an object.`);
649
- for (const n of this.listeners)
650
- try {
651
- const o = n(e);
652
- if (checkReturnData(e, o))
653
- e = o;
654
- else {
655
- this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
656
- break;
657
- }
658
- } catch (o) {
659
- warn(o), this.onerror(o);
660
- }
661
- return e;
662
- }
663
- constructor(e) {
664
- super(), this.onerror = error, this.type = e;
665
- }
666
- }
667
- class AsyncWaterfallHook extends SyncHook {
668
- emit(e) {
669
- isObject(e) || error(`The response data for the "${this.type}" hook must be an object.`);
670
- const n = Array.from(this.listeners);
671
- if (n.length > 0) {
672
- let o = 0;
673
- const r = (u) => (warn(u), this.onerror(u), e), s = (u) => {
674
- if (checkReturnData(e, u)) {
675
- if (e = u, o < n.length)
676
- try {
677
- return Promise.resolve(n[o++](e)).then(s, r);
678
- } catch (l) {
679
- return r(l);
680
- }
681
- } else
682
- this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
683
- return e;
684
- };
685
- return Promise.resolve(s(e));
686
- }
687
- return Promise.resolve(e);
688
- }
689
- constructor(e) {
690
- super(), this.onerror = error, this.type = e;
691
- }
692
- }
693
- class PluginSystem {
694
- applyPlugin(e) {
695
- assert(isPlainObject(e), "Plugin configuration is invalid.");
696
- const n = e.name;
697
- assert(n, "A name must be provided by the plugin."), this.registerPlugins[n] || (this.registerPlugins[n] = e, Object.keys(this.lifecycle).forEach((o) => {
698
- const r = e[o];
699
- r && this.lifecycle[o].on(r);
700
- }));
701
- }
702
- removePlugin(e) {
703
- assert(e, "A name is required.");
704
- const n = this.registerPlugins[e];
705
- assert(n, `The plugin "${e}" is not registered.`), Object.keys(n).forEach((o) => {
706
- o !== "name" && this.lifecycle[o].remove(n[o]);
707
- });
708
- }
709
- // eslint-disable-next-line @typescript-eslint/no-shadow
710
- inherit({ lifecycle: e, registerPlugins: n }) {
711
- Object.keys(e).forEach((o) => {
712
- assert(!this.lifecycle[o], `The hook "${o}" has a conflict and cannot be inherited.`), this.lifecycle[o] = e[o];
713
- }), Object.keys(n).forEach((o) => {
714
- assert(!this.registerPlugins[o], `The plugin "${o}" has a conflict and cannot be inherited.`), this.applyPlugin(n[o]);
715
- });
716
- }
717
- constructor(e) {
718
- this.registerPlugins = {}, this.lifecycle = e, this.lifecycleKeys = Object.keys(e);
719
- }
720
- }
721
- const buildIdentifier = "[0-9A-Za-z-]+", build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`, numericIdentifier = "0|[1-9]\\d*", numericIdentifierLoose = "[0-9]+", nonNumericIdentifier = "\\d*[a-zA-Z-][a-zA-Z0-9-]*", preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`, preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`, preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`, preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`, xRangeIdentifier = `${numericIdentifier}|x|X|\\*`, xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`, hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`, mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`, loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`, gtlt = "((?:<|>)?=?)", comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`, loneTilde = "(?:~>?)", tildeTrim = `(\\s*)${loneTilde}\\s+`, loneCaret = "(?:\\^)", caretTrim = `(\\s*)${loneCaret}\\s+`, star = "(<|>)?=?\\s*\\*", caret = `^${loneCaret}${xRangePlain}$`, mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`, fullPlain = `v?${mainVersion}${preRelease}?${build}?`, tilde = `^${loneTilde}${xRangePlain}$`, xRange = `^${gtlt}\\s*${xRangePlain}$`, comparator = `^${gtlt}\\s*(${fullPlain})$|^$`, gte0 = "^\\s*>=\\s*0.0.0\\s*$";
722
- function parseRegex(t) {
723
- return new RegExp(t);
724
- }
725
- function isXVersion(t) {
726
- return !t || t.toLowerCase() === "x" || t === "*";
727
- }
728
- function pipe(...t) {
729
- return (e) => t.reduce((n, o) => o(n), e);
730
- }
731
- function extractComparator(t) {
732
- return t.match(parseRegex(comparator));
733
- }
734
- function combineVersion(t, e, n, o) {
735
- const r = `${t}.${e}.${n}`;
736
- return o ? `${r}-${o}` : r;
737
- }
738
- function parseHyphen(t) {
739
- return t.replace(parseRegex(hyphenRange), (e, n, o, r, s, u, l, d, p, m, _, y) => (isXVersion(o) ? n = "" : isXVersion(r) ? n = `>=${o}.0.0` : isXVersion(s) ? n = `>=${o}.${r}.0` : n = `>=${n}`, isXVersion(p) ? d = "" : isXVersion(m) ? d = `<${Number(p) + 1}.0.0-0` : isXVersion(_) ? d = `<${p}.${Number(m) + 1}.0-0` : y ? d = `<=${p}.${m}.${_}-${y}` : d = `<=${d}`, `${n} ${d}`.trim()));
740
- }
741
- function parseComparatorTrim(t) {
742
- return t.replace(parseRegex(comparatorTrim), "$1$2$3");
743
- }
744
- function parseTildeTrim(t) {
745
- return t.replace(parseRegex(tildeTrim), "$1~");
746
- }
747
- function parseCaretTrim(t) {
748
- return t.replace(parseRegex(caretTrim), "$1^");
749
- }
750
- function parseCarets(t) {
751
- return t.trim().split(/\s+/).map((e) => e.replace(parseRegex(caret), (n, o, r, s, u) => isXVersion(o) ? "" : isXVersion(r) ? `>=${o}.0.0 <${Number(o) + 1}.0.0-0` : isXVersion(s) ? o === "0" ? `>=${o}.${r}.0 <${o}.${Number(r) + 1}.0-0` : `>=${o}.${r}.0 <${Number(o) + 1}.0.0-0` : u ? o === "0" ? r === "0" ? `>=${o}.${r}.${s}-${u} <${o}.${r}.${Number(s) + 1}-0` : `>=${o}.${r}.${s}-${u} <${o}.${Number(r) + 1}.0-0` : `>=${o}.${r}.${s}-${u} <${Number(o) + 1}.0.0-0` : o === "0" ? r === "0" ? `>=${o}.${r}.${s} <${o}.${r}.${Number(s) + 1}-0` : `>=${o}.${r}.${s} <${o}.${Number(r) + 1}.0-0` : `>=${o}.${r}.${s} <${Number(o) + 1}.0.0-0`)).join(" ");
752
- }
753
- function parseTildes(t) {
754
- return t.trim().split(/\s+/).map((e) => e.replace(parseRegex(tilde), (n, o, r, s, u) => isXVersion(o) ? "" : isXVersion(r) ? `>=${o}.0.0 <${Number(o) + 1}.0.0-0` : isXVersion(s) ? `>=${o}.${r}.0 <${o}.${Number(r) + 1}.0-0` : u ? `>=${o}.${r}.${s}-${u} <${o}.${Number(r) + 1}.0-0` : `>=${o}.${r}.${s} <${o}.${Number(r) + 1}.0-0`)).join(" ");
755
- }
756
- function parseXRanges(t) {
757
- return t.split(/\s+/).map((e) => e.trim().replace(parseRegex(xRange), (n, o, r, s, u, l) => {
758
- const d = isXVersion(r), p = d || isXVersion(s), m = p || isXVersion(u);
759
- return o === "=" && m && (o = ""), l = "", d ? o === ">" || o === "<" ? "<0.0.0-0" : "*" : o && m ? (p && (s = 0), u = 0, o === ">" ? (o = ">=", p ? (r = Number(r) + 1, s = 0, u = 0) : (s = Number(s) + 1, u = 0)) : o === "<=" && (o = "<", p ? r = Number(r) + 1 : s = Number(s) + 1), o === "<" && (l = "-0"), `${o + r}.${s}.${u}${l}`) : p ? `>=${r}.0.0${l} <${Number(r) + 1}.0.0-0` : m ? `>=${r}.${s}.0${l} <${r}.${Number(s) + 1}.0-0` : n;
760
- })).join(" ");
761
- }
762
- function parseStar(t) {
763
- return t.trim().replace(parseRegex(star), "");
764
- }
765
- function parseGTE0(t) {
766
- return t.trim().replace(parseRegex(gte0), "");
767
- }
768
- function compareAtom(t, e) {
769
- return t = Number(t) || t, e = Number(e) || e, t > e ? 1 : t === e ? 0 : -1;
770
- }
771
- function comparePreRelease(t, e) {
772
- const { preRelease: n } = t, { preRelease: o } = e;
773
- if (n === void 0 && o)
774
- return 1;
775
- if (n && o === void 0)
776
- return -1;
777
- if (n === void 0 && o === void 0)
778
- return 0;
779
- for (let r = 0, s = n.length; r <= s; r++) {
780
- const u = n[r], l = o[r];
781
- if (u !== l)
782
- return u === void 0 && l === void 0 ? 0 : u ? l ? compareAtom(u, l) : -1 : 1;
783
- }
784
- return 0;
785
- }
786
- function compareVersion(t, e) {
787
- return compareAtom(t.major, e.major) || compareAtom(t.minor, e.minor) || compareAtom(t.patch, e.patch) || comparePreRelease(t, e);
788
- }
789
- function eq(t, e) {
790
- return t.version === e.version;
791
- }
792
- function compare(t, e) {
793
- switch (t.operator) {
794
- case "":
795
- case "=":
796
- return eq(t, e);
797
- case ">":
798
- return compareVersion(t, e) < 0;
799
- case ">=":
800
- return eq(t, e) || compareVersion(t, e) < 0;
801
- case "<":
802
- return compareVersion(t, e) > 0;
803
- case "<=":
804
- return eq(t, e) || compareVersion(t, e) > 0;
805
- case void 0:
806
- return !0;
807
- default:
808
- return !1;
809
- }
810
- }
811
- function parseComparatorString(t) {
812
- return pipe(
813
- // handle caret
814
- // ^ --> * (any, kinda silly)
815
- // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
816
- // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
817
- // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
818
- // ^1.2.3 --> >=1.2.3 <2.0.0-0
819
- // ^1.2.0 --> >=1.2.0 <2.0.0-0
820
- parseCarets,
821
- // handle tilde
822
- // ~, ~> --> * (any, kinda silly)
823
- // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
824
- // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
825
- // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
826
- // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
827
- // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
828
- parseTildes,
829
- parseXRanges,
830
- parseStar
831
- )(t);
832
- }
833
- function parseRange(t) {
834
- return pipe(
835
- // handle hyphenRange
836
- // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
837
- parseHyphen,
838
- // handle trim comparator
839
- // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
840
- parseComparatorTrim,
841
- // handle trim tilde
842
- // `~ 1.2.3` => `~1.2.3`
843
- parseTildeTrim,
844
- // handle trim caret
845
- // `^ 1.2.3` => `^1.2.3`
846
- parseCaretTrim
847
- )(t.trim()).split(/\s+/).join(" ");
848
- }
849
- function satisfy(t, e) {
850
- if (!t)
851
- return !1;
852
- const r = parseRange(e).split(" ").map((y) => parseComparatorString(y)).join(" ").split(/\s+/).map((y) => parseGTE0(y)), s = extractComparator(t);
853
- if (!s)
854
- return !1;
855
- const [, u, , l, d, p, m] = s, _ = {
856
- operator: u,
857
- version: combineVersion(l, d, p, m),
858
- major: l,
859
- minor: d,
860
- patch: p,
861
- preRelease: m == null ? void 0 : m.split(".")
862
- };
863
- for (const y of r) {
864
- const b = extractComparator(y);
865
- if (!b)
866
- return !1;
867
- const [, S, , $, E, I, A] = b, O = {
868
- operator: S,
869
- version: combineVersion($, E, I, A),
870
- major: $,
871
- minor: E,
872
- patch: I,
873
- preRelease: A == null ? void 0 : A.split(".")
874
- };
875
- if (!compare(O, _))
876
- return !1;
877
- }
878
- return !0;
879
- }
880
- function _extends$8() {
881
- return _extends$8 = Object.assign || function(t) {
882
- for (var e = 1; e < arguments.length; e++) {
883
- var n = arguments[e];
884
- for (var o in n)
885
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
886
- }
887
- return t;
888
- }, _extends$8.apply(this, arguments);
889
- }
890
- function formatShare(t, e, n, o) {
891
- let r;
892
- "get" in t ? r = t.get : "lib" in t ? r = () => Promise.resolve(t.lib) : r = () => Promise.resolve(() => {
893
- throw new Error(`Can not get shared '${n}'!`);
894
- }), t.strategy && warn('"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"');
895
- var s, u, l;
896
- return _extends$8({
897
- deps: [],
898
- useIn: [],
899
- from: e,
900
- loading: null
901
- }, t, {
902
- shareConfig: _extends$8({
903
- requiredVersion: `^${t.version}`,
904
- singleton: !1,
905
- eager: !1,
906
- strictVersion: !1
907
- }, t.shareConfig),
908
- get: r,
909
- loaded: t != null && t.loaded || "lib" in t ? !0 : void 0,
910
- version: (s = t.version) != null ? s : "0",
911
- scope: Array.isArray(t.scope) ? t.scope : [
912
- (u = t.scope) != null ? u : "default"
913
- ],
914
- strategy: ((l = t.strategy) != null ? l : o) || "version-first"
915
- });
916
- }
917
- function formatShareConfigs(t, e) {
918
- const n = e.shared || {}, o = e.name, r = Object.keys(n).reduce((u, l) => {
919
- const d = arrayOptions(n[l]);
920
- return u[l] = u[l] || [], d.forEach((p) => {
921
- u[l].push(formatShare(p, o, l, e.shareStrategy));
922
- }), u;
923
- }, {}), s = _extends$8({}, t.shared);
924
- return Object.keys(r).forEach((u) => {
925
- s[u] ? r[u].forEach((l) => {
926
- s[u].find((p) => p.version === l.version) || s[u].push(l);
927
- }) : s[u] = r[u];
928
- }), {
929
- shared: s,
930
- shareInfos: r
931
- };
932
- }
933
- function versionLt(t, e) {
934
- const n = (o) => {
935
- if (!Number.isNaN(Number(o))) {
936
- const s = o.split(".");
937
- let u = o;
938
- for (let l = 0; l < 3 - s.length; l++)
939
- u += ".0";
940
- return u;
941
- }
942
- return o;
943
- };
944
- return !!satisfy(n(t), `<=${n(e)}`);
945
- }
946
- const findVersion = (t, e) => {
947
- const n = e || function(o, r) {
948
- return versionLt(o, r);
949
- };
950
- return Object.keys(t).reduce((o, r) => !o || n(o, r) || o === "0" ? r : o, 0);
951
- }, isLoaded = (t) => !!t.loaded || typeof t.lib == "function";
952
- function findSingletonVersionOrderByVersion(t, e, n) {
953
- const o = t[e][n], r = function(s, u) {
954
- return !isLoaded(o[s]) && versionLt(s, u);
955
- };
956
- return findVersion(t[e][n], r);
957
- }
958
- function findSingletonVersionOrderByLoaded(t, e, n) {
959
- const o = t[e][n], r = function(s, u) {
960
- return isLoaded(o[u]) ? isLoaded(o[s]) ? !!versionLt(s, u) : !0 : isLoaded(o[s]) ? !1 : versionLt(s, u);
961
- };
962
- return findVersion(t[e][n], r);
963
- }
964
- function getFindShareFunction(t) {
965
- return t === "loaded-first" ? findSingletonVersionOrderByLoaded : findSingletonVersionOrderByVersion;
966
- }
967
- function getRegisteredShare(t, e, n, o) {
968
- if (!t)
969
- return;
970
- const { shareConfig: r, scope: s = DEFAULT_SCOPE, strategy: u } = n, l = Array.isArray(s) ? s : [
971
- s
972
- ];
973
- for (const d of l)
974
- if (r && t[d] && t[d][e]) {
975
- const { requiredVersion: p } = r, _ = getFindShareFunction(u)(t, d, e), y = () => {
976
- if (r.singleton) {
977
- if (typeof p == "string" && !satisfy(_, p)) {
978
- const $ = `Version ${_} from ${_ && t[d][e][_].from} of shared singleton module ${e} does not satisfy the requirement of ${n.from} which needs ${p})`;
979
- r.strictVersion ? error($) : warn($);
980
- }
981
- return t[d][e][_];
982
- } else {
983
- if (p === !1 || p === "*" || satisfy(_, p))
984
- return t[d][e][_];
985
- for (const [$, E] of Object.entries(t[d][e]))
986
- if (satisfy($, p))
987
- return E;
988
- }
989
- }, b = {
990
- shareScopeMap: t,
991
- scope: d,
992
- pkgName: e,
993
- version: _,
994
- GlobalFederation: Global.__FEDERATION__,
995
- resolver: y
996
- };
997
- return (o.emit(b) || b).resolver();
998
- }
999
- }
1000
- function getGlobalShareScope() {
1001
- return Global.__FEDERATION__.__SHARE__;
1002
- }
1003
- function getTargetSharedOptions(t) {
1004
- const { pkgName: e, extraOptions: n, shareInfos: o } = t, r = (l) => {
1005
- if (!l)
1006
- return;
1007
- const d = {};
1008
- l.forEach((_) => {
1009
- d[_.version] = _;
1010
- });
1011
- const m = findVersion(d, function(_, y) {
1012
- return !isLoaded(d[_]) && versionLt(_, y);
1013
- });
1014
- return d[m];
1015
- };
1016
- var s;
1017
- const u = (s = n == null ? void 0 : n.resolver) != null ? s : r;
1018
- return Object.assign({}, u(o[e]), n == null ? void 0 : n.customShareInfo);
1019
- }
1020
- function matchRemoteWithNameAndExpose(t, e) {
1021
- for (const n of t) {
1022
- const o = e.startsWith(n.name);
1023
- let r = e.replace(n.name, "");
1024
- if (o) {
1025
- if (r.startsWith("/")) {
1026
- const l = n.name;
1027
- return r = `.${r}`, {
1028
- pkgNameOrAlias: l,
1029
- expose: r,
1030
- remote: n
1031
- };
1032
- } else if (r === "")
1033
- return {
1034
- pkgNameOrAlias: n.name,
1035
- expose: ".",
1036
- remote: n
1037
- };
1038
- }
1039
- const s = n.alias && e.startsWith(n.alias);
1040
- let u = n.alias && e.replace(n.alias, "");
1041
- if (n.alias && s) {
1042
- if (u && u.startsWith("/")) {
1043
- const l = n.alias;
1044
- return u = `.${u}`, {
1045
- pkgNameOrAlias: l,
1046
- expose: u,
1047
- remote: n
1048
- };
1049
- } else if (u === "")
1050
- return {
1051
- pkgNameOrAlias: n.alias,
1052
- expose: ".",
1053
- remote: n
1054
- };
1055
- }
1056
- }
1057
- }
1058
- function matchRemote(t, e) {
1059
- for (const n of t)
1060
- if (e === n.name || n.alias && e === n.alias)
1061
- return n;
1062
- }
1063
- function _extends$7() {
1064
- return _extends$7 = Object.assign || function(t) {
1065
- for (var e = 1; e < arguments.length; e++) {
1066
- var n = arguments[e];
1067
- for (var o in n)
1068
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1069
- }
1070
- return t;
1071
- }, _extends$7.apply(this, arguments);
1072
- }
1073
- async function loadEsmEntry({ entry: t, remoteEntryExports: e }) {
1074
- return new Promise((n, o) => {
1075
- try {
1076
- e ? n(e) : new Function("callbacks", `import("${t}").then(callbacks[0]).catch(callbacks[1])`)([
1077
- n,
1078
- o
1079
- ]);
1080
- } catch (r) {
1081
- o(r);
1082
- }
1083
- });
1084
- }
1085
- async function loadSystemJsEntry({ entry: t, remoteEntryExports: e }) {
1086
- return new Promise((n, o) => {
1087
- try {
1088
- e ? n(e) : new Function("callbacks", `System.import("${t}").then(callbacks[0]).catch(callbacks[1])`)([
1089
- n,
1090
- o
1091
- ]);
1092
- } catch (r) {
1093
- o(r);
1094
- }
1095
- });
1096
- }
1097
- async function loadEntryScript({ name: t, globalName: e, entry: n, createScriptHook: o }) {
1098
- const { entryExports: r } = getRemoteEntryExports(t, e);
1099
- return r || loadScript(n, {
1100
- attrs: {},
1101
- createScriptHook: (s, u) => {
1102
- const l = o.emit({
1103
- url: s,
1104
- attrs: u
1105
- });
1106
- if (l && (l instanceof HTMLScriptElement || "script" in l || "timeout" in l))
1107
- return l;
1108
- }
1109
- }).then(() => {
1110
- const { remoteEntryKey: s, entryExports: u } = getRemoteEntryExports(t, e);
1111
- return assert(u, `
1112
- Unable to use the ${t}'s '${n}' URL with ${s}'s globalName to get remoteEntry exports.
1113
- Possible reasons could be:
1114
-
1115
- 1. '${n}' is not the correct URL, or the remoteEntry resource or name is incorrect.
1116
-
1117
- 2. ${s} cannot be used to get remoteEntry exports in the window object.
1118
- `), u;
1119
- }).catch((s) => {
1120
- throw s;
1121
- });
1122
- }
1123
- async function loadEntryDom({ remoteInfo: t, remoteEntryExports: e, createScriptHook: n }) {
1124
- const { entry: o, entryGlobalName: r, name: s, type: u } = t;
1125
- switch (u) {
1126
- case "esm":
1127
- case "module":
1128
- return loadEsmEntry({
1129
- entry: o,
1130
- remoteEntryExports: e
1131
- });
1132
- case "system":
1133
- return loadSystemJsEntry({
1134
- entry: o,
1135
- remoteEntryExports: e
1136
- });
1137
- default:
1138
- return loadEntryScript({
1139
- entry: o,
1140
- globalName: r,
1141
- name: s,
1142
- createScriptHook: n
1143
- });
1144
- }
1145
- }
1146
- async function loadEntryNode({ remoteInfo: t, createScriptHook: e }) {
1147
- const { entry: n, entryGlobalName: o, name: r } = t, { entryExports: s } = getRemoteEntryExports(r, o);
1148
- return s || loadScriptNode(n, {
1149
- attrs: {
1150
- name: r,
1151
- globalName: o
52
+ u.log("createBridgeComponent render router info>>>", {
53
+ name: e.moduleName,
54
+ router: s
55
+ }), e.memoryRoute ? s.push(e.memoryRoute.entryPath).then(() => {
56
+ n.use(s), n.mount(e.dom);
57
+ }) : (n.use(s), n.mount(e.dom));
1152
58
  },
1153
- createScriptHook: (u, l) => {
1154
- const d = e.emit({
1155
- url: u,
1156
- attrs: l
1157
- });
1158
- if (d && "url" in d)
1159
- return d;
59
+ destroy(e) {
60
+ u.log("createBridgeComponent destroy Info", e);
61
+ const n = o.get(e == null ? void 0 : e.dom);
62
+ n == null || n.unmount();
1160
63
  }
1161
- }).then(() => {
1162
- const { remoteEntryKey: u, entryExports: l } = getRemoteEntryExports(r, o);
1163
- return assert(l, `
1164
- Unable to use the ${r}'s '${n}' URL with ${u}'s globalName to get remoteEntry exports.
1165
- Possible reasons could be:
1166
-
1167
- 1. '${n}' is not the correct URL, or the remoteEntry resource or name is incorrect.
1168
-
1169
- 2. ${u} cannot be used to get remoteEntry exports in the window object.
1170
- `), l;
1171
- }).catch((u) => {
1172
- throw u;
1173
64
  });
1174
65
  }
1175
- function getRemoteEntryUniqueKey(t) {
1176
- const { entry: e, name: n } = t;
1177
- return composeKeyWithSeparator(n, e);
1178
- }
1179
- async function getRemoteEntry({ origin: t, remoteEntryExports: e, remoteInfo: n }) {
1180
- const o = getRemoteEntryUniqueKey(n);
1181
- if (e)
1182
- return e;
1183
- if (!globalLoading[o]) {
1184
- const r = t.remoteHandler.hooks.lifecycle.loadEntry;
1185
- if (r.listeners.size)
1186
- globalLoading[o] = r.emit({
1187
- createScriptHook: t.loaderHook.lifecycle.createScript,
1188
- remoteInfo: n,
1189
- remoteEntryExports: e
1190
- }).then((s) => s || void 0);
1191
- else {
1192
- const s = t.loaderHook.lifecycle.createScript;
1193
- isBrowserEnv() ? globalLoading[o] = loadEntryDom({
1194
- remoteInfo: n,
1195
- remoteEntryExports: e,
1196
- createScriptHook: s
1197
- }) : globalLoading[o] = loadEntryNode({
1198
- remoteInfo: n,
1199
- createScriptHook: s
1200
- });
1201
- }
1202
- }
1203
- return globalLoading[o];
1204
- }
1205
- function getRemoteInfo(t) {
1206
- return _extends$7({}, t, {
1207
- entry: "entry" in t ? t.entry : "",
1208
- type: t.type || DEFAULT_REMOTE_TYPE,
1209
- entryGlobalName: t.entryGlobalName || t.name,
1210
- shareScope: t.shareScope || DEFAULT_SCOPE
1211
- });
1212
- }
1213
- function _extends$6() {
1214
- return _extends$6 = Object.assign || function(t) {
1215
- for (var e = 1; e < arguments.length; e++) {
1216
- var n = arguments[e];
1217
- for (var o in n)
1218
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1219
- }
1220
- return t;
1221
- }, _extends$6.apply(this, arguments);
1222
- }
1223
- let Module = class {
1224
- async getEntry() {
1225
- if (this.remoteEntryExports)
1226
- return this.remoteEntryExports;
1227
- const e = await getRemoteEntry({
1228
- origin: this.host,
1229
- remoteInfo: this.remoteInfo,
1230
- remoteEntryExports: this.remoteEntryExports
1231
- });
1232
- return assert(e, `remoteEntryExports is undefined
1233
- ${safeToString(this.remoteInfo)}`), this.remoteEntryExports = e, this.remoteEntryExports;
1234
- }
1235
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1236
- async get(e, n, o) {
1237
- const { loadFactory: r = !0 } = o || {
1238
- loadFactory: !0
1239
- }, s = await this.getEntry();
1240
- if (!this.inited) {
1241
- const m = this.host.shareScopeMap, _ = this.remoteInfo.shareScope || "default";
1242
- m[_] || (m[_] = {});
1243
- const y = m[_], b = [], S = {
1244
- version: this.remoteInfo.version || ""
1245
- };
1246
- Object.defineProperty(S, "shareScopeMap", {
1247
- value: m,
1248
- // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
1249
- enumerable: !1
1250
- });
1251
- const $ = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1252
- shareScope: y,
1253
- // @ts-ignore shareScopeMap will be set by Object.defineProperty
1254
- remoteEntryInitOptions: S,
1255
- initScope: b,
1256
- remoteInfo: this.remoteInfo,
1257
- origin: this.host
1258
- });
1259
- typeof (s == null ? void 0 : s.init) > "u" && console.error('The remote entry interface does not contain "init"', `
1260
- `, "Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]", `
1261
- `, "Ensure that window[nameOfRemote] is returning a {get,init} object."), await s.init($.shareScope, $.initScope, $.remoteEntryInitOptions), await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, $, {
1262
- remoteEntryExports: s
1263
- }));
1264
- }
1265
- this.lib = s, this.inited = !0;
1266
- const u = await s.get(n);
1267
- assert(u, `${getFMId(this.remoteInfo)} remote don't export ${n}.`);
1268
- const l = processModuleAlias(this.remoteInfo.name, n), d = this.wraperFactory(u, l);
1269
- return r ? await d() : d;
1270
- }
1271
- wraperFactory(e, n) {
1272
- function o(r, s) {
1273
- r && typeof r == "object" && Object.isExtensible(r) && !Object.getOwnPropertyDescriptor(r, Symbol.for("mf_module_id")) && Object.defineProperty(r, Symbol.for("mf_module_id"), {
1274
- value: s,
1275
- enumerable: !1
1276
- });
1277
- }
1278
- return e instanceof Promise ? async () => {
1279
- const r = await e();
1280
- return o(r, n), r;
1281
- } : () => {
1282
- const r = e();
1283
- return o(r, n), r;
1284
- };
1285
- }
1286
- constructor({ remoteInfo: e, host: n }) {
1287
- this.inited = !1, this.lib = void 0, this.remoteInfo = e, this.host = n;
1288
- }
1289
- };
1290
- function _extends$5() {
1291
- return _extends$5 = Object.assign || function(t) {
1292
- for (var e = 1; e < arguments.length; e++) {
1293
- var n = arguments[e];
1294
- for (var o in n)
1295
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1296
- }
1297
- return t;
1298
- }, _extends$5.apply(this, arguments);
1299
- }
1300
- function defaultPreloadArgs(t) {
1301
- return _extends$5({
1302
- resourceCategory: "sync",
1303
- share: !0,
1304
- depsRemote: !0,
1305
- prefetchInterface: !1
1306
- }, t);
1307
- }
1308
- function formatPreloadArgs(t, e) {
1309
- return e.map((n) => {
1310
- const o = matchRemote(t, n.nameOrAlias);
1311
- return assert(o, `Unable to preload ${n.nameOrAlias} as it is not included in ${!o && safeToString({
1312
- remoteInfo: o,
1313
- remotes: t
1314
- })}`), {
1315
- remote: o,
1316
- preloadConfig: defaultPreloadArgs(n)
1317
- };
1318
- });
1319
- }
1320
- function normalizePreloadExposes(t) {
1321
- return t ? t.map((e) => e === "." ? e : e.startsWith("./") ? e.replace("./", "") : e) : [];
1322
- }
1323
- function preloadAssets(t, e, n, o = !0) {
1324
- const { cssAssets: r, jsAssetsWithoutEntry: s, entryAssets: u } = n;
1325
- if (e.options.inBrowser) {
1326
- if (u.forEach((l) => {
1327
- const { moduleInfo: d } = l, p = e.moduleCache.get(t.name);
1328
- getRemoteEntry(p ? {
1329
- origin: e,
1330
- remoteInfo: d,
1331
- remoteEntryExports: p.remoteEntryExports
1332
- } : {
1333
- origin: e,
1334
- remoteInfo: d,
1335
- remoteEntryExports: void 0
1336
- });
1337
- }), o) {
1338
- const l = {
1339
- rel: "preload",
1340
- as: "style",
1341
- crossorigin: "anonymous"
1342
- };
1343
- r.forEach((d) => {
1344
- const { link: p, needAttach: m } = createLink({
1345
- url: d,
1346
- cb: () => {
1347
- },
1348
- attrs: l,
1349
- createLinkHook: (_, y) => {
1350
- const b = e.loaderHook.lifecycle.createLink.emit({
1351
- url: _,
1352
- attrs: y
1353
- });
1354
- if (b instanceof HTMLLinkElement)
1355
- return b;
1356
- }
1357
- });
1358
- m && document.head.appendChild(p);
1359
- });
1360
- } else {
1361
- const l = {
1362
- rel: "stylesheet",
1363
- type: "text/css"
1364
- };
1365
- r.forEach((d) => {
1366
- const { link: p, needAttach: m } = createLink({
1367
- url: d,
1368
- cb: () => {
1369
- },
1370
- attrs: l,
1371
- createLinkHook: (_, y) => {
1372
- const b = e.loaderHook.lifecycle.createLink.emit({
1373
- url: _,
1374
- attrs: y
1375
- });
1376
- if (b instanceof HTMLLinkElement)
1377
- return b;
1378
- },
1379
- needDeleteLink: !1
1380
- });
1381
- m && document.head.appendChild(p);
1382
- });
1383
- }
1384
- if (o) {
1385
- const l = {
1386
- rel: "preload",
1387
- as: "script",
1388
- crossorigin: "anonymous"
1389
- };
1390
- s.forEach((d) => {
1391
- const { link: p, needAttach: m } = createLink({
1392
- url: d,
1393
- cb: () => {
1394
- },
1395
- attrs: l,
1396
- createLinkHook: (_, y) => {
1397
- const b = e.loaderHook.lifecycle.createLink.emit({
1398
- url: _,
1399
- attrs: y
1400
- });
1401
- if (b instanceof HTMLLinkElement)
1402
- return b;
1403
- }
1404
- });
1405
- m && document.head.appendChild(p);
1406
- });
1407
- } else {
1408
- const l = {
1409
- fetchpriority: "high",
1410
- type: (t == null ? void 0 : t.type) === "module" ? "module" : "text/javascript"
1411
- };
1412
- s.forEach((d) => {
1413
- const { script: p, needAttach: m } = createScript({
1414
- url: d,
1415
- cb: () => {
1416
- },
1417
- attrs: l,
1418
- createScriptHook: (_, y) => {
1419
- const b = e.loaderHook.lifecycle.createScript.emit({
1420
- url: _,
1421
- attrs: y
1422
- });
1423
- if (b instanceof HTMLScriptElement)
1424
- return b;
1425
- },
1426
- needDeleteScript: !0
1427
- });
1428
- m && document.head.appendChild(p);
1429
- });
1430
- }
1431
- }
1432
- }
1433
- function _extends$4() {
1434
- return _extends$4 = Object.assign || function(t) {
1435
- for (var e = 1; e < arguments.length; e++) {
1436
- var n = arguments[e];
1437
- for (var o in n)
1438
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1439
- }
1440
- return t;
1441
- }, _extends$4.apply(this, arguments);
1442
- }
1443
- function assignRemoteInfo(t, e) {
1444
- const n = getRemoteEntryInfoFromSnapshot(e);
1445
- n.url || error(`The attribute remoteEntry of ${t.name} must not be undefined.`);
1446
- let o = getResourceUrl(e, n.url);
1447
- !isBrowserEnv() && !o.startsWith("http") && (o = `https:${o}`), t.type = n.type, t.entryGlobalName = n.globalName, t.entry = o, t.version = e.version, t.buildVersion = e.buildVersion;
1448
- }
1449
- function snapshotPlugin() {
1450
- return {
1451
- name: "snapshot-plugin",
1452
- async afterResolve(t) {
1453
- const { remote: e, pkgNameOrAlias: n, expose: o, origin: r, remoteInfo: s } = t;
1454
- if (!isRemoteInfoWithEntry(e) || !isPureRemoteEntry(e)) {
1455
- const { remoteSnapshot: u, globalSnapshot: l } = await r.snapshotHandler.loadRemoteSnapshotInfo(e);
1456
- assignRemoteInfo(s, u);
1457
- const d = {
1458
- remote: e,
1459
- preloadConfig: {
1460
- nameOrAlias: n,
1461
- exposes: [
1462
- o
1463
- ],
1464
- resourceCategory: "sync",
1465
- share: !1,
1466
- depsRemote: !1
1467
- }
1468
- }, p = await r.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1469
- origin: r,
1470
- preloadOptions: d,
1471
- remoteInfo: s,
1472
- remote: e,
1473
- remoteSnapshot: u,
1474
- globalSnapshot: l
1475
- });
1476
- return p && preloadAssets(s, r, p, !1), _extends$4({}, t, {
1477
- remoteSnapshot: u
1478
- });
1479
- }
1480
- return t;
1481
- }
1482
- };
1483
- }
1484
- function splitId(t) {
1485
- const e = t.split(":");
1486
- return e.length === 1 ? {
1487
- name: e[0],
1488
- version: void 0
1489
- } : e.length === 2 ? {
1490
- name: e[0],
1491
- version: e[1]
1492
- } : {
1493
- name: e[1],
1494
- version: e[2]
1495
- };
1496
- }
1497
- function traverseModuleInfo(t, e, n, o, r = {}, s) {
1498
- const u = getFMId(e), { value: l } = getInfoWithoutType(t, u), d = s || l;
1499
- if (d && !isManifestProvider(d) && (n(d, e, o), d.remotesInfo)) {
1500
- const p = Object.keys(d.remotesInfo);
1501
- for (const m of p) {
1502
- if (r[m])
1503
- continue;
1504
- r[m] = !0;
1505
- const _ = splitId(m), y = d.remotesInfo[m];
1506
- traverseModuleInfo(t, {
1507
- name: _.name,
1508
- version: y.matchedVersion
1509
- }, n, !1, r, void 0);
1510
- }
1511
- }
1512
- }
1513
- function generatePreloadAssets(t, e, n, o, r) {
1514
- const s = [], u = [], l = [], d = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set(), { options: m } = t, { preloadConfig: _ } = e, { depsRemote: y } = _;
1515
- if (traverseModuleInfo(o, n, (E, I, A) => {
1516
- let O;
1517
- if (A)
1518
- O = _;
1519
- else if (Array.isArray(y)) {
1520
- const N = y.find((L) => L.nameOrAlias === I.name || L.nameOrAlias === I.alias);
1521
- if (!N)
1522
- return;
1523
- O = defaultPreloadArgs(N);
1524
- } else if (y === !0)
1525
- O = _;
1526
- else
1527
- return;
1528
- const v = getResourceUrl(E, getRemoteEntryInfoFromSnapshot(E).url);
1529
- v && l.push({
1530
- name: I.name,
1531
- moduleInfo: {
1532
- name: I.name,
1533
- entry: v,
1534
- type: "remoteEntryType" in E ? E.remoteEntryType : "global",
1535
- entryGlobalName: "globalName" in E ? E.globalName : I.name,
1536
- shareScope: "",
1537
- version: "version" in E ? E.version : void 0
1538
- },
1539
- url: v
1540
- });
1541
- let R = "modules" in E ? E.modules : [];
1542
- const T = normalizePreloadExposes(O.exposes);
1543
- if (T.length && "modules" in E) {
1544
- var P;
1545
- R = E == null || (P = E.modules) == null ? void 0 : P.reduce((N, L) => ((T == null ? void 0 : T.indexOf(L.moduleName)) !== -1 && N.push(L), N), []);
1546
- }
1547
- function w(N) {
1548
- const L = N.map((x) => getResourceUrl(E, x));
1549
- return O.filter ? L.filter(O.filter) : L;
1550
- }
1551
- if (R) {
1552
- const N = R.length;
1553
- for (let L = 0; L < N; L++) {
1554
- const x = R[L], k = `${I.name}/${x.moduleName}`;
1555
- t.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
1556
- id: x.moduleName === "." ? I.name : k,
1557
- name: I.name,
1558
- remoteSnapshot: E,
1559
- preloadConfig: O,
1560
- remote: I,
1561
- origin: t
1562
- }), !getPreloaded(k) && (O.resourceCategory === "all" ? (s.push(...w(x.assets.css.async)), s.push(...w(x.assets.css.sync)), u.push(...w(x.assets.js.async)), u.push(...w(x.assets.js.sync))) : (O.resourceCategory = "sync") && (s.push(...w(x.assets.css.sync)), u.push(...w(x.assets.js.sync))), setPreloaded(k));
1563
- }
1564
- }
1565
- }, !0, {}, r), r.shared) {
1566
- const E = (I, A) => {
1567
- const O = getRegisteredShare(t.shareScopeMap, A.sharedName, I, t.sharedHandler.hooks.lifecycle.resolveShare);
1568
- O && typeof O.lib == "function" && (A.assets.js.sync.forEach((v) => {
1569
- d.add(v);
1570
- }), A.assets.css.sync.forEach((v) => {
1571
- p.add(v);
1572
- }));
1573
- };
1574
- r.shared.forEach((I) => {
1575
- var A;
1576
- const O = (A = m.shared) == null ? void 0 : A[I.sharedName];
1577
- if (!O)
1578
- return;
1579
- const v = I.version ? O.find((T) => T.version === I.version) : O;
1580
- if (!v)
1581
- return;
1582
- arrayOptions(v).forEach((T) => {
1583
- E(T, I);
1584
- });
1585
- });
1586
- }
1587
- const S = u.filter((E) => !d.has(E));
1588
- return {
1589
- cssAssets: s.filter((E) => !p.has(E)),
1590
- jsAssetsWithoutEntry: S,
1591
- entryAssets: l
1592
- };
1593
- }
1594
- const generatePreloadAssetsPlugin = function() {
1595
- return {
1596
- name: "generate-preload-assets-plugin",
1597
- async generatePreloadAssets(t) {
1598
- const { origin: e, preloadOptions: n, remoteInfo: o, remote: r, globalSnapshot: s, remoteSnapshot: u } = t;
1599
- return isRemoteInfoWithEntry(r) && isPureRemoteEntry(r) ? {
1600
- cssAssets: [],
1601
- jsAssetsWithoutEntry: [],
1602
- entryAssets: [
1603
- {
1604
- name: r.name,
1605
- url: r.entry,
1606
- moduleInfo: {
1607
- name: o.name,
1608
- entry: r.entry,
1609
- type: "global",
1610
- entryGlobalName: "",
1611
- shareScope: ""
1612
- }
1613
- }
1614
- ]
1615
- } : (assignRemoteInfo(o, u), generatePreloadAssets(e, n, o, s, u));
1616
- }
1617
- };
1618
- };
1619
- function _extends$3() {
1620
- return _extends$3 = Object.assign || function(t) {
1621
- for (var e = 1; e < arguments.length; e++) {
1622
- var n = arguments[e];
1623
- for (var o in n)
1624
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1625
- }
1626
- return t;
1627
- }, _extends$3.apply(this, arguments);
1628
- }
1629
- function getGlobalRemoteInfo(t, e) {
1630
- const n = getGlobalSnapshotInfoByModuleInfo({
1631
- name: e.options.name,
1632
- version: e.options.version
1633
- }), o = n && "remotesInfo" in n && n.remotesInfo && getInfoWithoutType(n.remotesInfo, t.name).value;
1634
- return o && o.matchedVersion ? {
1635
- hostGlobalSnapshot: n,
1636
- globalSnapshot: getGlobalSnapshot(),
1637
- remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1638
- name: t.name,
1639
- version: o.matchedVersion
1640
- })
1641
- } : {
1642
- hostGlobalSnapshot: void 0,
1643
- globalSnapshot: getGlobalSnapshot(),
1644
- remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1645
- name: t.name,
1646
- version: "version" in t ? t.version : void 0
1647
- })
1648
- };
1649
- }
1650
- class SnapshotHandler {
1651
- async loadSnapshot(e) {
1652
- const { options: n } = this.HostInstance, { hostGlobalSnapshot: o, remoteSnapshot: r, globalSnapshot: s } = this.getGlobalRemoteInfo(e), { remoteSnapshot: u, globalSnapshot: l } = await this.hooks.lifecycle.loadSnapshot.emit({
1653
- options: n,
1654
- moduleInfo: e,
1655
- hostGlobalSnapshot: o,
1656
- remoteSnapshot: r,
1657
- globalSnapshot: s
1658
- });
1659
- return {
1660
- remoteSnapshot: u,
1661
- globalSnapshot: l
1662
- };
1663
- }
1664
- // eslint-disable-next-line max-lines-per-function
1665
- async loadRemoteSnapshotInfo(e) {
1666
- const { options: n } = this.HostInstance;
1667
- await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
1668
- options: n,
1669
- moduleInfo: e
1670
- });
1671
- let o = getGlobalSnapshotInfoByModuleInfo({
1672
- name: this.HostInstance.options.name,
1673
- version: this.HostInstance.options.version
1674
- });
1675
- o || (o = {
1676
- version: this.HostInstance.options.version || "",
1677
- remoteEntry: "",
1678
- remotesInfo: {}
1679
- }, addGlobalSnapshot({
1680
- [this.HostInstance.options.name]: o
1681
- })), o && "remotesInfo" in o && !getInfoWithoutType(o.remotesInfo, e.name).value && ("version" in e || "entry" in e) && (o.remotesInfo = _extends$3({}, o == null ? void 0 : o.remotesInfo, {
1682
- [e.name]: {
1683
- matchedVersion: "version" in e ? e.version : e.entry
1684
- }
1685
- }));
1686
- const { hostGlobalSnapshot: r, remoteSnapshot: s, globalSnapshot: u } = this.getGlobalRemoteInfo(e), { remoteSnapshot: l, globalSnapshot: d } = await this.hooks.lifecycle.loadSnapshot.emit({
1687
- options: n,
1688
- moduleInfo: e,
1689
- hostGlobalSnapshot: r,
1690
- remoteSnapshot: s,
1691
- globalSnapshot: u
1692
- });
1693
- let p, m;
1694
- if (l)
1695
- if (isManifestProvider(l)) {
1696
- const _ = isBrowserEnv() ? l.remoteEntry : l.ssrRemoteEntry || l.remoteEntry || "", y = await this.getManifestJson(_, e, {}), b = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, e, {
1697
- // The global remote may be overridden
1698
- // Therefore, set the snapshot key to the global address of the actual request
1699
- entry: _
1700
- }), y);
1701
- p = y, m = b;
1702
- } else {
1703
- const { remoteSnapshot: _ } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1704
- options: this.HostInstance.options,
1705
- moduleInfo: e,
1706
- remoteSnapshot: l,
1707
- from: "global"
1708
- });
1709
- p = _, m = d;
1710
- }
1711
- else if (isRemoteInfoWithEntry(e)) {
1712
- const _ = await this.getManifestJson(e.entry, e, {}), y = setGlobalSnapshotInfoByModuleInfo(e, _), { remoteSnapshot: b } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1713
- options: this.HostInstance.options,
1714
- moduleInfo: e,
1715
- remoteSnapshot: _,
1716
- from: "global"
1717
- });
1718
- p = b, m = y;
1719
- } else
1720
- error(`
1721
- Cannot get remoteSnapshot with the name: '${e.name}', version: '${e.version}' from __FEDERATION__.moduleInfo. The following reasons may be causing the problem:
1722
-
1723
- 1. The Deploy platform did not deliver the correct data. You can use __FEDERATION__.moduleInfo to check the remoteInfo.
1724
-
1725
- 2. The remote '${e.name}' version '${e.version}' is not released.
1726
-
1727
- The transformed module info: ${JSON.stringify(d)}
1728
- `);
1729
- return await this.hooks.lifecycle.afterLoadSnapshot.emit({
1730
- options: n,
1731
- moduleInfo: e,
1732
- remoteSnapshot: p
1733
- }), {
1734
- remoteSnapshot: p,
1735
- globalSnapshot: m
1736
- };
1737
- }
1738
- getGlobalRemoteInfo(e) {
1739
- return getGlobalRemoteInfo(e, this.HostInstance);
1740
- }
1741
- async getManifestJson(e, n, o) {
1742
- const r = async () => {
1743
- let u = this.manifestCache.get(e);
1744
- if (u)
1745
- return u;
1746
- try {
1747
- let l = await this.loaderHook.lifecycle.fetch.emit(e, {});
1748
- return (!l || !(l instanceof Response)) && (l = await fetch(e, {})), u = await l.json(), assert(u.metaData && u.exposes && u.shared, `${e} is not a federation manifest`), this.manifestCache.set(e, u), u;
1749
- } catch (l) {
1750
- delete this.manifestLoading[e], error(`Failed to get manifestJson for ${n.name}. The manifest URL is ${e}. Please ensure that the manifestUrl is accessible.
1751
-
1752
- Error message:
1753
-
1754
- ${l}`);
1755
- }
1756
- }, s = async () => {
1757
- const u = await r(), l = generateSnapshotFromManifest(u, {
1758
- version: e
1759
- }), { remoteSnapshot: d } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1760
- options: this.HostInstance.options,
1761
- moduleInfo: n,
1762
- manifestJson: u,
1763
- remoteSnapshot: l,
1764
- manifestUrl: e,
1765
- from: "manifest"
1766
- });
1767
- return d;
1768
- };
1769
- return this.manifestLoading[e] || (this.manifestLoading[e] = s().then((u) => u)), this.manifestLoading[e];
1770
- }
1771
- constructor(e) {
1772
- this.loadingHostSnapshot = null, this.manifestCache = /* @__PURE__ */ new Map(), this.hooks = new PluginSystem({
1773
- beforeLoadRemoteSnapshot: new AsyncHook("beforeLoadRemoteSnapshot"),
1774
- loadSnapshot: new AsyncWaterfallHook("loadGlobalSnapshot"),
1775
- loadRemoteSnapshot: new AsyncWaterfallHook("loadRemoteSnapshot"),
1776
- afterLoadSnapshot: new AsyncWaterfallHook("afterLoadSnapshot")
1777
- }), this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__, this.HostInstance = e, this.loaderHook = e.loaderHook;
1778
- }
1779
- }
1780
- function _extends$2() {
1781
- return _extends$2 = Object.assign || function(t) {
1782
- for (var e = 1; e < arguments.length; e++) {
1783
- var n = arguments[e];
1784
- for (var o in n)
1785
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
1786
- }
1787
- return t;
1788
- }, _extends$2.apply(this, arguments);
1789
- }
1790
- function _object_without_properties_loose(t, e) {
1791
- if (t == null)
1792
- return {};
1793
- var n = {}, o = Object.keys(t), r, s;
1794
- for (s = 0; s < o.length; s++)
1795
- r = o[s], !(e.indexOf(r) >= 0) && (n[r] = t[r]);
1796
- return n;
1797
- }
1798
- class SharedHandler {
1799
- // register shared in shareScopeMap
1800
- registerShared(e, n) {
1801
- const { shareInfos: o, shared: r } = formatShareConfigs(e, n);
1802
- return Object.keys(o).forEach((u) => {
1803
- o[u].forEach((d) => {
1804
- !getRegisteredShare(this.shareScopeMap, u, d, this.hooks.lifecycle.resolveShare) && d && d.lib && this.setShared({
1805
- pkgName: u,
1806
- lib: d.lib,
1807
- get: d.get,
1808
- loaded: !0,
1809
- shared: d,
1810
- from: n.name
1811
- });
1812
- });
1813
- }), {
1814
- shareInfos: o,
1815
- shared: r
1816
- };
1817
- }
1818
- async loadShare(e, n) {
1819
- const { host: o } = this, r = getTargetSharedOptions({
1820
- pkgName: e,
1821
- extraOptions: n,
1822
- shareInfos: o.options.shared
1823
- });
1824
- r != null && r.scope && await Promise.all(r.scope.map(async (p) => {
1825
- await Promise.all(this.initializeSharing(p, {
1826
- strategy: r.strategy
1827
- }));
1828
- }));
1829
- const s = await this.hooks.lifecycle.beforeLoadShare.emit({
1830
- pkgName: e,
1831
- shareInfo: r,
1832
- shared: o.options.shared,
1833
- origin: o
1834
- }), { shareInfo: u } = s;
1835
- assert(u, `Cannot find ${e} Share in the ${o.options.name}. Please ensure that the ${e} Share parameters have been injected`);
1836
- const l = getRegisteredShare(this.shareScopeMap, e, u, this.hooks.lifecycle.resolveShare), d = (p) => {
1837
- p.useIn || (p.useIn = []), addUniqueItem(p.useIn, o.options.name);
1838
- };
1839
- if (l && l.lib)
1840
- return d(l), l.lib;
1841
- if (l && l.loading && !l.loaded) {
1842
- const p = await l.loading;
1843
- return l.loaded = !0, l.lib || (l.lib = p), d(l), p;
1844
- } else if (l) {
1845
- const m = (async () => {
1846
- const _ = await l.get();
1847
- u.lib = _, u.loaded = !0, d(u);
1848
- const y = getRegisteredShare(this.shareScopeMap, e, u, this.hooks.lifecycle.resolveShare);
1849
- return y && (y.lib = _, y.loaded = !0), _;
1850
- })();
1851
- return this.setShared({
1852
- pkgName: e,
1853
- loaded: !1,
1854
- shared: l,
1855
- from: o.options.name,
1856
- lib: null,
1857
- loading: m
1858
- }), m;
1859
- } else {
1860
- if (n != null && n.customShareInfo)
1861
- return !1;
1862
- const m = (async () => {
1863
- const _ = await u.get();
1864
- u.lib = _, u.loaded = !0, d(u);
1865
- const y = getRegisteredShare(this.shareScopeMap, e, u, this.hooks.lifecycle.resolveShare);
1866
- return y && (y.lib = _, y.loaded = !0), _;
1867
- })();
1868
- return this.setShared({
1869
- pkgName: e,
1870
- loaded: !1,
1871
- shared: u,
1872
- from: o.options.name,
1873
- lib: null,
1874
- loading: m
1875
- }), m;
1876
- }
1877
- }
1878
- /**
1879
- * This function initializes the sharing sequence (executed only once per share scope).
1880
- * It accepts one argument, the name of the share scope.
1881
- * If the share scope does not exist, it creates one.
1882
- */
1883
- // eslint-disable-next-line @typescript-eslint/member-ordering
1884
- initializeSharing(e = DEFAULT_SCOPE, n) {
1885
- const { host: o } = this, r = n == null ? void 0 : n.from, s = n == null ? void 0 : n.strategy;
1886
- let u = n == null ? void 0 : n.initScope;
1887
- const l = [];
1888
- if (r !== "build") {
1889
- const { initTokens: S } = this;
1890
- u || (u = []);
1891
- let $ = S[e];
1892
- if ($ || ($ = S[e] = {
1893
- from: this.host.name
1894
- }), u.indexOf($) >= 0)
1895
- return l;
1896
- u.push($);
1897
- }
1898
- const d = this.shareScopeMap, p = o.options.name;
1899
- d[e] || (d[e] = {});
1900
- const m = d[e], _ = (S, $) => {
1901
- var E;
1902
- const { version: I, eager: A } = $;
1903
- m[S] = m[S] || {};
1904
- const O = m[S], v = O[I], R = !!(v && (v.eager || (E = v.shareConfig) != null && E.eager));
1905
- (!v || v.strategy !== "loaded-first" && !v.loaded && (!A != !R ? A : p > v.from)) && (O[I] = $);
1906
- }, y = (S) => S && S.init && S.init(d[e], u), b = async (S) => {
1907
- const { module: $ } = await o.remoteHandler.getRemoteModuleAndOptions({
1908
- id: S
1909
- });
1910
- if ($.getEntry) {
1911
- const E = await $.getEntry();
1912
- $.inited || (await y(E), $.inited = !0);
1913
- }
1914
- };
1915
- return Object.keys(o.options.shared).forEach((S) => {
1916
- o.options.shared[S].forEach((E) => {
1917
- E.scope.includes(e) && _(S, E);
1918
- });
1919
- }), (o.options.shareStrategy === "version-first" || s === "version-first") && o.options.remotes.forEach((S) => {
1920
- S.shareScope === e && l.push(b(S.name));
1921
- }), l;
1922
- }
1923
- // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
1924
- // 1. If the loaded shared already exists globally, then it will be reused
1925
- // 2. If lib exists in local shared, it will be used directly
1926
- // 3. If the local get returns something other than Promise, then it will be used directly
1927
- loadShareSync(e, n) {
1928
- const { host: o } = this, r = getTargetSharedOptions({
1929
- pkgName: e,
1930
- extraOptions: n,
1931
- shareInfos: o.options.shared
1932
- });
1933
- r != null && r.scope && r.scope.forEach((l) => {
1934
- this.initializeSharing(l, {
1935
- strategy: r.strategy
1936
- });
1937
- });
1938
- const s = getRegisteredShare(this.shareScopeMap, e, r, this.hooks.lifecycle.resolveShare), u = (l) => {
1939
- l.useIn || (l.useIn = []), addUniqueItem(l.useIn, o.options.name);
1940
- };
1941
- if (s) {
1942
- if (typeof s.lib == "function")
1943
- return u(s), s.loaded || (s.loaded = !0, s.from === o.options.name && (r.loaded = !0)), s.lib;
1944
- if (typeof s.get == "function") {
1945
- const l = s.get();
1946
- if (!(l instanceof Promise))
1947
- return u(s), this.setShared({
1948
- pkgName: e,
1949
- loaded: !0,
1950
- from: o.options.name,
1951
- lib: l,
1952
- shared: s
1953
- }), l;
1954
- }
1955
- }
1956
- if (r.lib)
1957
- return r.loaded || (r.loaded = !0), r.lib;
1958
- if (r.get) {
1959
- const l = r.get();
1960
- if (l instanceof Promise)
1961
- throw new Error(`
1962
- The loadShareSync function was unable to load ${e}. The ${e} could not be found in ${o.options.name}.
1963
- Possible reasons for failure:
1964
-
1965
- 1. The ${e} share was registered with the 'get' attribute, but loadShare was not used beforehand.
1966
-
1967
- 2. The ${e} share was not registered with the 'lib' attribute.
1968
-
1969
- `);
1970
- return r.lib = l, this.setShared({
1971
- pkgName: e,
1972
- loaded: !0,
1973
- from: o.options.name,
1974
- lib: r.lib,
1975
- shared: r
1976
- }), r.lib;
1977
- }
1978
- throw new Error(`
1979
- The loadShareSync function was unable to load ${e}. The ${e} could not be found in ${o.options.name}.
1980
- Possible reasons for failure:
1981
-
1982
- 1. The ${e} share was registered with the 'get' attribute, but loadShare was not used beforehand.
1983
-
1984
- 2. The ${e} share was not registered with the 'lib' attribute.
1985
-
1986
- `);
1987
- }
1988
- initShareScopeMap(e, n, o = {}) {
1989
- const { host: r } = this;
1990
- this.shareScopeMap[e] = n, this.hooks.lifecycle.initContainerShareScopeMap.emit({
1991
- shareScope: n,
1992
- options: r.options,
1993
- origin: r,
1994
- scopeName: e,
1995
- hostShareScopeMap: o.hostShareScopeMap
1996
- });
1997
- }
1998
- setShared({ pkgName: e, shared: n, from: o, lib: r, loading: s, loaded: u, get: l }) {
1999
- const { version: d, scope: p = "default" } = n, m = _object_without_properties_loose(n, [
2000
- "version",
2001
- "scope"
2002
- ]);
2003
- (Array.isArray(p) ? p : [
2004
- p
2005
- ]).forEach((y) => {
2006
- this.shareScopeMap[y] || (this.shareScopeMap[y] = {}), this.shareScopeMap[y][e] || (this.shareScopeMap[y][e] = {}), !this.shareScopeMap[y][e][d] && (this.shareScopeMap[y][e][d] = _extends$2({
2007
- version: d,
2008
- scope: [
2009
- "default"
2010
- ]
2011
- }, m, {
2012
- lib: r,
2013
- loaded: u,
2014
- loading: s
2015
- }), l && (this.shareScopeMap[y][e][d].get = l));
2016
- });
2017
- }
2018
- _setGlobalShareScopeMap(e) {
2019
- const n = getGlobalShareScope(), o = e.id || e.name;
2020
- o && !n[o] && (n[o] = this.shareScopeMap);
2021
- }
2022
- constructor(e) {
2023
- this.hooks = new PluginSystem({
2024
- afterResolve: new AsyncWaterfallHook("afterResolve"),
2025
- beforeLoadShare: new AsyncWaterfallHook("beforeLoadShare"),
2026
- // not used yet
2027
- loadShare: new AsyncHook(),
2028
- resolveShare: new SyncWaterfallHook("resolveShare"),
2029
- // maybe will change, temporarily for internal use only
2030
- initContainerShareScopeMap: new SyncWaterfallHook("initContainerShareScopeMap")
2031
- }), this.host = e, this.shareScopeMap = {}, this.initTokens = {}, this._setGlobalShareScopeMap(e.options);
2032
- }
2033
- }
2034
- function _extends$1() {
2035
- return _extends$1 = Object.assign || function(t) {
2036
- for (var e = 1; e < arguments.length; e++) {
2037
- var n = arguments[e];
2038
- for (var o in n)
2039
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
2040
- }
2041
- return t;
2042
- }, _extends$1.apply(this, arguments);
2043
- }
2044
- class RemoteHandler {
2045
- formatAndRegisterRemote(e, n) {
2046
- return (n.remotes || []).reduce((r, s) => (this.registerRemote(s, r, {
2047
- force: !1
2048
- }), r), e.remotes);
2049
- }
2050
- setIdToRemoteMap(e, n) {
2051
- const { remote: o, expose: r } = n, { name: s, alias: u } = o;
2052
- if (this.idToRemoteMap[e] = {
2053
- name: o.name,
2054
- expose: r
2055
- }, u && e.startsWith(s)) {
2056
- const l = e.replace(s, u);
2057
- this.idToRemoteMap[l] = {
2058
- name: o.name,
2059
- expose: r
2060
- };
2061
- return;
2062
- }
2063
- if (u && e.startsWith(u)) {
2064
- const l = e.replace(u, s);
2065
- this.idToRemoteMap[l] = {
2066
- name: o.name,
2067
- expose: r
2068
- };
2069
- }
2070
- }
2071
- // eslint-disable-next-line max-lines-per-function
2072
- // eslint-disable-next-line @typescript-eslint/member-ordering
2073
- async loadRemote(e, n) {
2074
- const { host: o } = this;
2075
- try {
2076
- const { loadFactory: r = !0 } = n || {
2077
- loadFactory: !0
2078
- }, { module: s, moduleOptions: u, remoteMatchInfo: l } = await this.getRemoteModuleAndOptions({
2079
- id: e
2080
- }), { pkgNameOrAlias: d, remote: p, expose: m, id: _ } = l, y = await s.get(_, m, n), b = await this.hooks.lifecycle.onLoad.emit({
2081
- id: _,
2082
- pkgNameOrAlias: d,
2083
- expose: m,
2084
- exposeModule: r ? y : void 0,
2085
- exposeModuleFactory: r ? void 0 : y,
2086
- remote: p,
2087
- options: u,
2088
- moduleInstance: s,
2089
- origin: o
2090
- });
2091
- return this.setIdToRemoteMap(e, l), typeof b == "function" ? b : y;
2092
- } catch (r) {
2093
- const { from: s = "runtime" } = n || {
2094
- from: "runtime"
2095
- }, u = await this.hooks.lifecycle.errorLoadRemote.emit({
2096
- id: e,
2097
- error: r,
2098
- from: s,
2099
- lifecycle: "onLoad",
2100
- origin: o
2101
- });
2102
- if (!u)
2103
- throw r;
2104
- return u;
2105
- }
2106
- }
2107
- // eslint-disable-next-line @typescript-eslint/member-ordering
2108
- async preloadRemote(e) {
2109
- const { host: n } = this;
2110
- await this.hooks.lifecycle.beforePreloadRemote.emit({
2111
- preloadOps: e,
2112
- options: n.options,
2113
- origin: n
2114
- });
2115
- const o = formatPreloadArgs(n.options.remotes, e);
2116
- await Promise.all(o.map(async (r) => {
2117
- const { remote: s } = r, u = getRemoteInfo(s), { globalSnapshot: l, remoteSnapshot: d } = await n.snapshotHandler.loadRemoteSnapshotInfo(s), p = await this.hooks.lifecycle.generatePreloadAssets.emit({
2118
- origin: n,
2119
- preloadOptions: r,
2120
- remote: s,
2121
- remoteInfo: u,
2122
- globalSnapshot: l,
2123
- remoteSnapshot: d
2124
- });
2125
- p && preloadAssets(u, n, p);
2126
- }));
2127
- }
2128
- registerRemotes(e, n) {
2129
- const { host: o } = this;
2130
- e.forEach((r) => {
2131
- this.registerRemote(r, o.options.remotes, {
2132
- force: n == null ? void 0 : n.force
2133
- });
2134
- });
2135
- }
2136
- async getRemoteModuleAndOptions(e) {
2137
- const { host: n } = this, { id: o } = e;
2138
- let r;
2139
- try {
2140
- r = await this.hooks.lifecycle.beforeRequest.emit({
2141
- id: o,
2142
- options: n.options,
2143
- origin: n
2144
- });
2145
- } catch (S) {
2146
- if (r = await this.hooks.lifecycle.errorLoadRemote.emit({
2147
- id: o,
2148
- options: n.options,
2149
- origin: n,
2150
- from: "runtime",
2151
- error: S,
2152
- lifecycle: "beforeRequest"
2153
- }), !r)
2154
- throw S;
2155
- }
2156
- const { id: s } = r, u = matchRemoteWithNameAndExpose(n.options.remotes, s);
2157
- assert(u, `
2158
- Unable to locate ${s} in ${n.options.name}. Potential reasons for failure include:
2159
-
2160
- 1. ${s} was not included in the 'remotes' parameter of ${n.options.name || "the host"}.
2161
-
2162
- 2. ${s} could not be found in the 'remotes' of ${n.options.name} with either 'name' or 'alias' attributes.
2163
- 3. ${s} is not online, injected, or loaded.
2164
- 4. ${s} cannot be accessed on the expected.
2165
- 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${s}.
2166
- `);
2167
- const { remote: l } = u, d = getRemoteInfo(l), p = await n.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
2168
- id: s
2169
- }, u, {
2170
- options: n.options,
2171
- origin: n,
2172
- remoteInfo: d
2173
- })), { remote: m, expose: _ } = p;
2174
- assert(m && _, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${s}.`);
2175
- let y = n.moduleCache.get(m.name);
2176
- const b = {
2177
- host: n,
2178
- remoteInfo: d
2179
- };
2180
- return y || (y = new Module(b), n.moduleCache.set(m.name, y)), {
2181
- module: y,
2182
- moduleOptions: b,
2183
- remoteMatchInfo: p
2184
- };
2185
- }
2186
- registerRemote(e, n, o) {
2187
- const { host: r } = this, s = () => {
2188
- if (e.alias) {
2189
- const l = n.find((d) => {
2190
- var p;
2191
- return e.alias && (d.name.startsWith(e.alias) || ((p = d.alias) == null ? void 0 : p.startsWith(e.alias)));
2192
- });
2193
- assert(!l, `The alias ${e.alias} of remote ${e.name} is not allowed to be the prefix of ${l && l.name} name or alias`);
2194
- }
2195
- "entry" in e && isBrowserEnv() && !e.entry.startsWith("http") && (e.entry = new URL(e.entry, window.location.origin).href), e.shareScope || (e.shareScope = DEFAULT_SCOPE), e.type || (e.type = DEFAULT_REMOTE_TYPE);
2196
- };
2197
- this.hooks.lifecycle.beforeRegisterRemote.emit({
2198
- remote: e,
2199
- origin: r
2200
- });
2201
- const u = n.find((l) => l.name === e.name);
2202
- if (!u)
2203
- s(), n.push(e), this.hooks.lifecycle.registerRemote.emit({
2204
- remote: e,
2205
- origin: r
2206
- });
2207
- else {
2208
- const l = [
2209
- `The remote "${e.name}" is already registered.`,
2210
- o != null && o.force ? "Hope you have known that OVERRIDE it may have some unexpected errors" : 'If you want to merge the remote, you can set "force: true".'
2211
- ];
2212
- o != null && o.force && (this.removeRemote(u), s(), n.push(e), this.hooks.lifecycle.registerRemote.emit({
2213
- remote: e,
2214
- origin: r
2215
- })), warn$1(l.join(" "));
2216
- }
2217
- }
2218
- removeRemote(e) {
2219
- try {
2220
- const { host: o } = this, { name: r } = e, s = o.options.remotes.findIndex((l) => l.name === r);
2221
- s !== -1 && o.options.remotes.splice(s, 1);
2222
- const u = o.moduleCache.get(e.name);
2223
- if (u) {
2224
- const l = u.remoteInfo, d = l.entryGlobalName;
2225
- if (globalThis[d]) {
2226
- var n;
2227
- (n = Object.getOwnPropertyDescriptor(globalThis, d)) != null && n.configurable ? delete globalThis[d] : globalThis[d] = void 0;
2228
- }
2229
- const p = getRemoteEntryUniqueKey(u.remoteInfo);
2230
- globalLoading[p] && delete globalLoading[p], o.snapshotHandler.manifestCache.delete(l.entry);
2231
- let m = l.buildVersion ? composeKeyWithSeparator(l.name, l.buildVersion) : l.name;
2232
- const _ = globalThis.__FEDERATION__.__INSTANCES__.findIndex((b) => l.buildVersion ? b.options.id === m : b.name === m);
2233
- if (_ !== -1) {
2234
- const b = globalThis.__FEDERATION__.__INSTANCES__[_];
2235
- m = b.options.id || m;
2236
- const S = getGlobalShareScope();
2237
- let $ = !0;
2238
- const E = [];
2239
- Object.keys(S).forEach((I) => {
2240
- const A = S[I];
2241
- A && Object.keys(A).forEach((O) => {
2242
- const v = A[O];
2243
- v && Object.keys(v).forEach((R) => {
2244
- const T = v[R];
2245
- T && Object.keys(T).forEach((P) => {
2246
- const w = T[P];
2247
- w && typeof w == "object" && w.from === l.name && (w.loaded || w.loading ? (w.useIn = w.useIn.filter((N) => N !== l.name), w.useIn.length ? $ = !1 : E.push([
2248
- I,
2249
- O,
2250
- R,
2251
- P
2252
- ])) : E.push([
2253
- I,
2254
- O,
2255
- R,
2256
- P
2257
- ]));
2258
- });
2259
- });
2260
- });
2261
- }), $ && (b.shareScopeMap = {}, delete S[m]), E.forEach(([I, A, O, v]) => {
2262
- var R, T, P;
2263
- (P = S[I]) == null || (T = P[A]) == null || (R = T[O]) == null || delete R[v];
2264
- }), globalThis.__FEDERATION__.__INSTANCES__.splice(_, 1);
2265
- }
2266
- const { hostGlobalSnapshot: y } = getGlobalRemoteInfo(e, o);
2267
- if (y) {
2268
- const b = y && "remotesInfo" in y && y.remotesInfo && getInfoWithoutType(y.remotesInfo, e.name).key;
2269
- b && (delete y.remotesInfo[b], Global.__FEDERATION__.__MANIFEST_LOADING__[b] && delete Global.__FEDERATION__.__MANIFEST_LOADING__[b]);
2270
- }
2271
- o.moduleCache.delete(e.name);
2272
- }
2273
- } catch (o) {
2274
- console.log("removeRemote fail: ", o);
2275
- }
2276
- }
2277
- constructor(e) {
2278
- this.hooks = new PluginSystem({
2279
- beforeRegisterRemote: new SyncWaterfallHook("beforeRegisterRemote"),
2280
- registerRemote: new SyncWaterfallHook("registerRemote"),
2281
- beforeRequest: new AsyncWaterfallHook("beforeRequest"),
2282
- onLoad: new AsyncHook("onLoad"),
2283
- handlePreloadModule: new SyncHook("handlePreloadModule"),
2284
- errorLoadRemote: new AsyncHook("errorLoadRemote"),
2285
- beforePreloadRemote: new AsyncHook("beforePreloadRemote"),
2286
- generatePreloadAssets: new AsyncHook("generatePreloadAssets"),
2287
- // not used yet
2288
- afterPreloadRemote: new AsyncHook(),
2289
- loadEntry: new AsyncHook()
2290
- }), this.host = e, this.idToRemoteMap = {};
2291
- }
2292
- }
2293
- function _extends() {
2294
- return _extends = Object.assign || function(t) {
2295
- for (var e = 1; e < arguments.length; e++) {
2296
- var n = arguments[e];
2297
- for (var o in n)
2298
- Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
2299
- }
2300
- return t;
2301
- }, _extends.apply(this, arguments);
2302
- }
2303
- class FederationHost {
2304
- initOptions(e) {
2305
- this.registerPlugins(e.plugins);
2306
- const n = this.formatOptions(this.options, e);
2307
- return this.options = n, n;
2308
- }
2309
- async loadShare(e, n) {
2310
- return this.sharedHandler.loadShare(e, n);
2311
- }
2312
- // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
2313
- // 1. If the loaded shared already exists globally, then it will be reused
2314
- // 2. If lib exists in local shared, it will be used directly
2315
- // 3. If the local get returns something other than Promise, then it will be used directly
2316
- loadShareSync(e, n) {
2317
- return this.sharedHandler.loadShareSync(e, n);
2318
- }
2319
- initializeSharing(e = DEFAULT_SCOPE, n) {
2320
- return this.sharedHandler.initializeSharing(e, n);
2321
- }
2322
- initRawContainer(e, n, o) {
2323
- const r = getRemoteInfo({
2324
- name: e,
2325
- entry: n
2326
- }), s = new Module({
2327
- host: this,
2328
- remoteInfo: r
2329
- });
2330
- return s.remoteEntryExports = o, this.moduleCache.set(e, s), s;
2331
- }
2332
- // eslint-disable-next-line max-lines-per-function
2333
- // eslint-disable-next-line @typescript-eslint/member-ordering
2334
- async loadRemote(e, n) {
2335
- return this.remoteHandler.loadRemote(e, n);
2336
- }
2337
- // eslint-disable-next-line @typescript-eslint/member-ordering
2338
- async preloadRemote(e) {
2339
- return this.remoteHandler.preloadRemote(e);
2340
- }
2341
- initShareScopeMap(e, n, o = {}) {
2342
- this.sharedHandler.initShareScopeMap(e, n, o);
2343
- }
2344
- formatOptions(e, n) {
2345
- const { shared: o } = formatShareConfigs(e, n), { userOptions: r, options: s } = this.hooks.lifecycle.beforeInit.emit({
2346
- origin: this,
2347
- userOptions: n,
2348
- options: e,
2349
- shareInfo: o
2350
- }), u = this.remoteHandler.formatAndRegisterRemote(s, r), { shared: l } = this.sharedHandler.registerShared(s, r), d = [
2351
- ...s.plugins
2352
- ];
2353
- r.plugins && r.plugins.forEach((m) => {
2354
- d.includes(m) || d.push(m);
2355
- });
2356
- const p = _extends({}, e, n, {
2357
- plugins: d,
2358
- remotes: u,
2359
- shared: l
2360
- });
2361
- return this.hooks.lifecycle.init.emit({
2362
- origin: this,
2363
- options: p
2364
- }), p;
2365
- }
2366
- registerPlugins(e) {
2367
- const n = registerPlugins(e, [
2368
- this.hooks,
2369
- this.remoteHandler.hooks,
2370
- this.sharedHandler.hooks,
2371
- this.snapshotHandler.hooks,
2372
- this.loaderHook
2373
- ]);
2374
- this.options.plugins = this.options.plugins.reduce((o, r) => (r && o && !o.find((s) => s.name === r.name) && o.push(r), o), n || []);
2375
- }
2376
- registerRemotes(e, n) {
2377
- return this.remoteHandler.registerRemotes(e, n);
2378
- }
2379
- constructor(e) {
2380
- this.hooks = new PluginSystem({
2381
- beforeInit: new SyncWaterfallHook("beforeInit"),
2382
- init: new SyncHook(),
2383
- // maybe will change, temporarily for internal use only
2384
- beforeInitContainer: new AsyncWaterfallHook("beforeInitContainer"),
2385
- // maybe will change, temporarily for internal use only
2386
- initContainer: new AsyncWaterfallHook("initContainer")
2387
- }), this.version = "0.6.0", this.moduleCache = /* @__PURE__ */ new Map(), this.loaderHook = new PluginSystem({
2388
- // FIXME: may not be suitable , not open to the public yet
2389
- getModuleInfo: new SyncHook(),
2390
- createScript: new SyncHook(),
2391
- createLink: new SyncHook(),
2392
- // only work for manifest , so not open to the public yet
2393
- fetch: new AsyncHook()
2394
- });
2395
- const n = {
2396
- id: getBuilderId(),
2397
- name: e.name,
2398
- plugins: [
2399
- snapshotPlugin(),
2400
- generatePreloadAssetsPlugin()
2401
- ],
2402
- remotes: [],
2403
- shared: {},
2404
- inBrowser: isBrowserEnv()
2405
- };
2406
- this.name = e.name, this.options = n, this.snapshotHandler = new SnapshotHandler(this), this.sharedHandler = new SharedHandler(this), this.remoteHandler = new RemoteHandler(this), this.shareScopeMap = this.sharedHandler.shareScopeMap, this.registerPlugins([
2407
- ...n.plugins,
2408
- ...e.plugins || []
2409
- ]), this.options = this.formatOptions(n, e);
2410
- }
2411
- }
2412
- let FederationInstance = null;
2413
- function getInstance() {
2414
- return FederationInstance;
2415
- }
2416
- setGlobalFederationConstructor(FederationHost);
2417
- var pluginHelper$1 = /* @__PURE__ */ Object.freeze({
2418
- __proto__: null,
2419
- SyncHook,
2420
- AsyncHook,
2421
- SyncWaterfallHook,
2422
- AsyncWaterfallHook,
2423
- PluginSystem
2424
- });
2425
- const ShareUtils = {
2426
- getRegisteredShare,
2427
- getGlobalShareScope
2428
- }, GlobalUtils = {
2429
- Global,
2430
- nativeGlobal,
2431
- resetFederationGlobalInfo,
2432
- getGlobalFederationInstance,
2433
- setGlobalFederationInstance,
2434
- getGlobalFederationConstructor,
2435
- setGlobalFederationConstructor,
2436
- getInfoWithoutType,
2437
- getGlobalSnapshot,
2438
- getTargetSnapshotInfoByModuleInfo,
2439
- getGlobalSnapshotInfoByModuleInfo,
2440
- setGlobalSnapshotInfoByModuleInfo,
2441
- addGlobalSnapshot,
2442
- getRemoteEntryExports,
2443
- registerGlobalPlugins,
2444
- getGlobalHostPlugins,
2445
- getPreloaded,
2446
- setPreloaded,
2447
- registerPlugins,
2448
- pluginHelper: pluginHelper$1
2449
- };
2450
- var helpers = {
2451
- global: GlobalUtils,
2452
- share: ShareUtils
2453
- };
2454
- const registerPlugin = helpers.global.registerPlugins, pluginHelper = helpers.global.pluginHelper, host = getInstance(), pluginSystem = new pluginHelper.PluginSystem({
2455
- bridgeRender: new pluginHelper.SyncHook(),
2456
- bridgeDestroy: new pluginHelper.SyncHook()
2457
- });
2458
- registerPlugin(
2459
- host.options.plugins,
2460
- [pluginSystem]
2461
- );
2462
- const RemoteApp = /* @__PURE__ */ defineComponent({
66
+ const N = /* @__PURE__ */ y({
2463
67
  name: "RemoteApp",
2464
68
  props: {
2465
69
  moduleName: String,
@@ -2468,71 +72,64 @@ const RemoteApp = /* @__PURE__ */ defineComponent({
2468
72
  providerInfo: Function
2469
73
  },
2470
74
  setup(t) {
2471
- const e = ref(null), n = ref(null), o = ref(""), r = useRoute(), s = () => {
2472
- var p;
2473
- const l = (p = t.providerInfo) == null ? void 0 : p.call(t);
2474
- n.value = l;
2475
- const d = {
75
+ const o = l(null), e = l(null), n = l(""), r = g(), a = () => {
76
+ var i;
77
+ const m = (i = t.providerInfo) == null ? void 0 : i.call(t);
78
+ e.value = m;
79
+ const c = {
2476
80
  name: t.moduleName,
2477
- dom: e.value,
81
+ dom: o.value,
2478
82
  basename: t.basename,
2479
83
  memoryRoute: t.memoryRoute
2480
84
  };
2481
- LoggerInstance.log("createRemoteComponent LazyComponent render >>>", d), pluginSystem.lifecycle.bridgeRender.emit({
2482
- ...d
2483
- }), l.render(d);
2484
- }, u = watch(() => r.path, (l) => {
2485
- l !== r.path && s(), o.value !== "" && o.value !== l && (LoggerInstance.log("createRemoteComponent dispatchPopstateEnv >>>", {
85
+ u.log("createRemoteComponent LazyComponent render >>>", c), m.render(c);
86
+ }, s = b(() => r.path, (m) => {
87
+ m !== r.path && a(), n.value !== "" && n.value !== m && (u.log("createRemoteComponent dispatchPopstateEnv >>>", {
2486
88
  ...t,
2487
89
  pathname: r.path
2488
- }), f()), o.value = l;
90
+ }), I()), n.value = m;
2489
91
  });
2490
- return onMounted(() => {
2491
- s();
2492
- }), onBeforeUnmount(() => {
2493
- var l;
2494
- LoggerInstance.log("createRemoteComponent LazyComponent destroy >>>", {
92
+ return v(() => {
93
+ a();
94
+ }), R(() => {
95
+ var m;
96
+ u.log("createRemoteComponent LazyComponent destroy >>>", {
2495
97
  ...t
2496
- }), u(), pluginSystem.lifecycle.bridgeDestroy.emit({
2497
- name: t.moduleName,
2498
- dom: e.value,
2499
- basename: t.basename,
2500
- memoryRoute: t.memoryRoute
2501
- }), (l = n.value) == null || l.destroy({
2502
- dom: e.value
98
+ }), s(), (m = e.value) == null || m.destroy({
99
+ dom: o.value
2503
100
  });
2504
- }), () => createVNode("div", {
2505
- ref: e
101
+ }), () => f("div", {
102
+ ref: o
2506
103
  }, null);
2507
104
  }
2508
105
  });
2509
- function createRemoteComponent(t) {
2510
- return defineAsyncComponent({
106
+ function D(t) {
107
+ return C({
2511
108
  __APP_VERSION__: "0.6.0",
2512
109
  //@ts-ignore
2513
110
  loader: async () => {
2514
- var d;
2515
- const e = useRoute();
2516
- let n = "/";
2517
- const o = (d = e.matched[0]) == null ? void 0 : d.path;
2518
- o && (o.endsWith("/:pathMatch(.*)*") ? n = o.replace("/:pathMatch(.*)*", "") : n = e.matched[0].path);
111
+ var c;
112
+ const o = g();
113
+ let e = "/";
114
+ const n = (c = o.matched[0]) == null ? void 0 : c.path;
115
+ n && (n.endsWith("/:pathMatch(.*)*") ? e = n.replace("/:pathMatch(.*)*", "") : e = o.matched[0].path);
2519
116
  const r = (t == null ? void 0 : t.export) || "default";
2520
- LoggerInstance.log("createRemoteComponent LazyComponent create >>>", {
2521
- basename: n,
117
+ u.log("createRemoteComponent LazyComponent create >>>", {
118
+ basename: e,
2522
119
  info: t
2523
120
  });
2524
- const s = await t.loader(), u = s && s[Symbol.for("mf_module_id")], l = s[r];
2525
- if (LoggerInstance.log(
121
+ const a = await t.loader(), s = a && a[Symbol.for("mf_module_id")], m = a[r];
122
+ if (u.log(
2526
123
  "createRemoteComponent LazyComponent loadRemote info >>>",
2527
- { name: u, module: s, exportName: r, basename: n, route: e }
2528
- ), r in s && typeof l == "function")
124
+ { name: s, module: a, exportName: r, basename: e, route: o }
125
+ ), r in a && typeof m == "function")
2529
126
  return {
2530
127
  render() {
2531
- return h(RemoteApp, {
2532
- moduleName: u,
128
+ return w(N, {
129
+ moduleName: s,
2533
130
  ...t,
2534
- providerInfo: l,
2535
- basename: n
131
+ providerInfo: m,
132
+ basename: e
2536
133
  });
2537
134
  }
2538
135
  };
@@ -2549,6 +146,6 @@ function createRemoteComponent(t) {
2549
146
  });
2550
147
  }
2551
148
  export {
2552
- createBridgeComponent,
2553
- createRemoteComponent
149
+ B as createBridgeComponent,
150
+ D as createRemoteComponent
2554
151
  };