@module-federation/bridge-vue3 0.0.0-next-20240927195332 → 0.0.0-next-20240930091801

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