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