@module-federation/bridge-vue3 0.0.0-next-20240830100524 → 0.0.0-next-20240902075042

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