@module-federation/bridge-react 0.0.0-next-20241113115843 → 0.0.0-next-20241114065146
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 +3 -13
- package/dist/context-BBLu8BlQ.cjs +336 -0
- package/dist/context-BcyT-d0V.js +337 -0
- package/dist/index.cjs.js +17 -2863
- package/dist/index.d.ts +4 -11
- package/dist/index.es.js +17 -2863
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +2 -2
- package/dist/router.es.js +2 -2
- package/package.json +3 -4
- package/src/create.tsx +2 -2
- package/src/provider.tsx +6 -33
- package/src/remote/index.tsx +3 -42
- package/src/router-v5.tsx +1 -0
- package/src/router.tsx +1 -1
- package/src/utils.ts +0 -22
- package/dist/context-3_giwitw.js +0 -857
- package/dist/context-C9uJCrqC.cjs +0 -856
package/dist/context-3_giwitw.js
DELETED
|
@@ -1,857 +0,0 @@
|
|
|
1
|
-
import React__default from "react";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var browser_exports = {};
|
|
20
|
-
__export(browser_exports, {
|
|
21
|
-
createLogger: () => createLogger2,
|
|
22
|
-
logger: () => logger
|
|
23
|
-
});
|
|
24
|
-
var browser = __toCommonJS(browser_exports);
|
|
25
|
-
var supportsSubstitutions = void 0;
|
|
26
|
-
var supportColor = () => {
|
|
27
|
-
if (typeof supportsSubstitutions !== "undefined") {
|
|
28
|
-
return supportsSubstitutions;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const testString = "color test";
|
|
32
|
-
const css = "color: red;";
|
|
33
|
-
const originalConsoleLog = console.log;
|
|
34
|
-
console.log = (...args) => {
|
|
35
|
-
if (args[0] === `%c${testString}` && args[1] === css) {
|
|
36
|
-
supportsSubstitutions = true;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
console.log(`%c${testString}`, css);
|
|
40
|
-
console.log = originalConsoleLog;
|
|
41
|
-
} catch (e) {
|
|
42
|
-
supportsSubstitutions = false;
|
|
43
|
-
}
|
|
44
|
-
return supportsSubstitutions;
|
|
45
|
-
};
|
|
46
|
-
var ansiToCss = {
|
|
47
|
-
"bold": "font-weight: bold;",
|
|
48
|
-
"red": "color: red;",
|
|
49
|
-
"green": "color: green;",
|
|
50
|
-
"orange": "color: orange;",
|
|
51
|
-
"dodgerblue": "color: dodgerblue;",
|
|
52
|
-
"magenta": "color: magenta;",
|
|
53
|
-
"gray": "color: gray;"
|
|
54
|
-
};
|
|
55
|
-
var formatter = (key) => supportColor() ? (input) => {
|
|
56
|
-
if (Array.isArray(input)) {
|
|
57
|
-
const [label, style] = input;
|
|
58
|
-
return [`%c${label.replace("%c", "")}`, style ? `${ansiToCss[key]}${style}` : `${ansiToCss[key] || ""}`];
|
|
59
|
-
}
|
|
60
|
-
return [`%c${String(input).replace("%c", "")}`, ansiToCss[key] || ""];
|
|
61
|
-
} : (input) => [String(input)];
|
|
62
|
-
var bold = formatter("bold");
|
|
63
|
-
var red = formatter("red");
|
|
64
|
-
var green = formatter("green");
|
|
65
|
-
var orange = formatter("orange");
|
|
66
|
-
var dodgerblue = formatter("dodgerblue");
|
|
67
|
-
var magenta = formatter("magenta");
|
|
68
|
-
formatter("gray");
|
|
69
|
-
function getLabel(type, logType, labels) {
|
|
70
|
-
let label = [""];
|
|
71
|
-
if ("label" in logType) {
|
|
72
|
-
label = [labels[type] || logType.label || ""];
|
|
73
|
-
label = bold(logType.color ? logType.color(label) : label[0]);
|
|
74
|
-
}
|
|
75
|
-
label = label.filter(Boolean);
|
|
76
|
-
return label;
|
|
77
|
-
}
|
|
78
|
-
function finalLog(label, text, args, message) {
|
|
79
|
-
if (label.length) {
|
|
80
|
-
if (Array.isArray(message)) {
|
|
81
|
-
console.log(...label, ...message);
|
|
82
|
-
} else {
|
|
83
|
-
console.log(...label, text);
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
Array.isArray(message) ? console.log(...message) : console.log(text, ...args);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
var LOG_LEVEL = {
|
|
90
|
-
error: 0,
|
|
91
|
-
warn: 1,
|
|
92
|
-
info: 2,
|
|
93
|
-
log: 3,
|
|
94
|
-
verbose: 4
|
|
95
|
-
};
|
|
96
|
-
var errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/;
|
|
97
|
-
var anonymousErrorStackRegExp = /at\s.*\(<anonymous>\)$/;
|
|
98
|
-
var isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
|
99
|
-
var createLogger$1 = (options = {}, { getLabel: getLabel2, handleError, finalLog: finalLog2, greet, LOG_TYPES: LOG_TYPES2 }) => {
|
|
100
|
-
let maxLevel = options.level || "log";
|
|
101
|
-
let customLabels = options.labels || {};
|
|
102
|
-
let log = (type, message, ...args) => {
|
|
103
|
-
if (LOG_LEVEL[LOG_TYPES2[type].level] > LOG_LEVEL[maxLevel]) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (message === void 0 || message === null) {
|
|
107
|
-
return console.log();
|
|
108
|
-
}
|
|
109
|
-
let logType = LOG_TYPES2[type];
|
|
110
|
-
let text = "";
|
|
111
|
-
const label = getLabel2(type, logType, customLabels);
|
|
112
|
-
if (message instanceof Error) {
|
|
113
|
-
if (message.stack) {
|
|
114
|
-
let [name, ...rest] = message.stack.split("\n");
|
|
115
|
-
if (name.startsWith("Error: ")) {
|
|
116
|
-
name = name.slice(7);
|
|
117
|
-
}
|
|
118
|
-
text = `${name}
|
|
119
|
-
${handleError(rest.join("\n"))}`;
|
|
120
|
-
} else {
|
|
121
|
-
text = message.message;
|
|
122
|
-
}
|
|
123
|
-
} else if (logType.level === "error" && typeof message === "string") {
|
|
124
|
-
let lines = message.split("\n");
|
|
125
|
-
text = lines.map((line) => isErrorStackMessage(line) ? handleError(line) : line).join("\n");
|
|
126
|
-
} else {
|
|
127
|
-
text = `${message}`;
|
|
128
|
-
}
|
|
129
|
-
finalLog2(label, text, args, message);
|
|
130
|
-
};
|
|
131
|
-
let logger2 = {
|
|
132
|
-
// greet
|
|
133
|
-
greet: (message) => log("log", greet(message))
|
|
134
|
-
};
|
|
135
|
-
Object.keys(LOG_TYPES2).forEach((key) => {
|
|
136
|
-
logger2[key] = (...args) => log(key, ...args);
|
|
137
|
-
});
|
|
138
|
-
Object.defineProperty(logger2, "level", {
|
|
139
|
-
get: () => maxLevel,
|
|
140
|
-
set(val) {
|
|
141
|
-
maxLevel = val;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
Object.defineProperty(logger2, "labels", {
|
|
145
|
-
get: () => customLabels,
|
|
146
|
-
set(val) {
|
|
147
|
-
customLabels = val;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
logger2.override = (customLogger) => {
|
|
151
|
-
Object.assign(logger2, customLogger);
|
|
152
|
-
};
|
|
153
|
-
return logger2;
|
|
154
|
-
};
|
|
155
|
-
var startColor = [189, 255, 243];
|
|
156
|
-
var endColor = [74, 194, 154];
|
|
157
|
-
var isWord = (char) => !/[\s\n]/.test(char);
|
|
158
|
-
function gradient(message) {
|
|
159
|
-
if (!supportColor()) {
|
|
160
|
-
return [message];
|
|
161
|
-
}
|
|
162
|
-
const chars = [...message];
|
|
163
|
-
const words = chars.filter(isWord);
|
|
164
|
-
const steps = words.length - 1;
|
|
165
|
-
if (steps === 0) {
|
|
166
|
-
console.log(`%c${message}`, `color: rgb(${startColor.join(",")}); font-weight: bold;`);
|
|
167
|
-
return [message];
|
|
168
|
-
}
|
|
169
|
-
let output = "";
|
|
170
|
-
let styles = [];
|
|
171
|
-
chars.forEach((char) => {
|
|
172
|
-
if (isWord(char)) {
|
|
173
|
-
const progress = words.indexOf(char) / steps;
|
|
174
|
-
const r = Math.round(startColor[0] + (endColor[0] - startColor[0]) * progress);
|
|
175
|
-
const g = Math.round(startColor[1] + (endColor[1] - startColor[1]) * progress);
|
|
176
|
-
const b = Math.round(startColor[2] + (endColor[2] - startColor[2]) * progress);
|
|
177
|
-
output += `%c${char}`;
|
|
178
|
-
styles.push(`color: rgb(${r},${g},${b}); font-weight: bold;`);
|
|
179
|
-
} else {
|
|
180
|
-
output += char;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
return [output, ...styles];
|
|
184
|
-
}
|
|
185
|
-
var LOG_TYPES = {
|
|
186
|
-
// Level error
|
|
187
|
-
error: {
|
|
188
|
-
label: "error",
|
|
189
|
-
level: "error",
|
|
190
|
-
color: red
|
|
191
|
-
},
|
|
192
|
-
// Level warn
|
|
193
|
-
warn: {
|
|
194
|
-
label: "warn",
|
|
195
|
-
level: "warn",
|
|
196
|
-
color: orange
|
|
197
|
-
},
|
|
198
|
-
// Level info
|
|
199
|
-
info: {
|
|
200
|
-
label: "info",
|
|
201
|
-
level: "info",
|
|
202
|
-
color: dodgerblue
|
|
203
|
-
},
|
|
204
|
-
start: {
|
|
205
|
-
label: "start",
|
|
206
|
-
level: "info",
|
|
207
|
-
color: dodgerblue
|
|
208
|
-
},
|
|
209
|
-
ready: {
|
|
210
|
-
label: "ready",
|
|
211
|
-
level: "info",
|
|
212
|
-
color: green
|
|
213
|
-
},
|
|
214
|
-
success: {
|
|
215
|
-
label: "success",
|
|
216
|
-
level: "info",
|
|
217
|
-
color: green
|
|
218
|
-
},
|
|
219
|
-
// Level log
|
|
220
|
-
log: {
|
|
221
|
-
level: "log"
|
|
222
|
-
},
|
|
223
|
-
// Level debug
|
|
224
|
-
debug: {
|
|
225
|
-
label: "debug",
|
|
226
|
-
level: "verbose",
|
|
227
|
-
color: magenta
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
function createLogger2(options = {}) {
|
|
231
|
-
return createLogger$1(options, {
|
|
232
|
-
handleError: (msg) => msg,
|
|
233
|
-
getLabel,
|
|
234
|
-
gradient,
|
|
235
|
-
finalLog,
|
|
236
|
-
LOG_TYPES,
|
|
237
|
-
greet: (msg) => {
|
|
238
|
-
return gradient(msg);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
var logger = createLogger2();
|
|
243
|
-
function _extends() {
|
|
244
|
-
_extends = Object.assign || function assign(target) {
|
|
245
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
246
|
-
var source = arguments[i];
|
|
247
|
-
for (var key in source)
|
|
248
|
-
if (Object.prototype.hasOwnProperty.call(source, key))
|
|
249
|
-
target[key] = source[key];
|
|
250
|
-
}
|
|
251
|
-
return target;
|
|
252
|
-
};
|
|
253
|
-
return _extends.apply(this, arguments);
|
|
254
|
-
}
|
|
255
|
-
const MANIFEST_EXT = ".json";
|
|
256
|
-
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
257
|
-
const BROWSER_LOG_VALUE = "1";
|
|
258
|
-
const SEPARATOR = ":";
|
|
259
|
-
function isBrowserEnv() {
|
|
260
|
-
return typeof window !== "undefined";
|
|
261
|
-
}
|
|
262
|
-
function isBrowserDebug() {
|
|
263
|
-
try {
|
|
264
|
-
if (isBrowserEnv() && window.localStorage) {
|
|
265
|
-
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
266
|
-
}
|
|
267
|
-
} catch (error) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
function isDebugMode() {
|
|
273
|
-
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
|
|
274
|
-
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
275
|
-
}
|
|
276
|
-
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
return isBrowserDebug();
|
|
280
|
-
}
|
|
281
|
-
const PREFIX = "[ Module Federation ]";
|
|
282
|
-
function setDebug(loggerInstance) {
|
|
283
|
-
if (isDebugMode()) {
|
|
284
|
-
loggerInstance.level = "verbose";
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
function setPrefix(loggerInstance, prefix) {
|
|
288
|
-
loggerInstance.labels = {
|
|
289
|
-
warn: `${prefix} Warn`,
|
|
290
|
-
error: `${prefix} Error`,
|
|
291
|
-
success: `${prefix} Success`,
|
|
292
|
-
info: `${prefix} Info`,
|
|
293
|
-
ready: `${prefix} Ready`,
|
|
294
|
-
debug: `${prefix} Debug`
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
function createLogger(prefix) {
|
|
298
|
-
const loggerInstance = browser.createLogger({
|
|
299
|
-
labels: {
|
|
300
|
-
warn: `${PREFIX} Warn`,
|
|
301
|
-
error: `${PREFIX} Error`,
|
|
302
|
-
success: `${PREFIX} Success`,
|
|
303
|
-
info: `${PREFIX} Info`,
|
|
304
|
-
ready: `${PREFIX} Ready`,
|
|
305
|
-
debug: `${PREFIX} Debug`
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
setDebug(loggerInstance);
|
|
309
|
-
setPrefix(loggerInstance, prefix);
|
|
310
|
-
return loggerInstance;
|
|
311
|
-
}
|
|
312
|
-
createLogger(PREFIX);
|
|
313
|
-
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
314
|
-
const composeKeyWithSeparator = function(...args) {
|
|
315
|
-
if (!args.length) {
|
|
316
|
-
return "";
|
|
317
|
-
}
|
|
318
|
-
return args.reduce((sum, cur) => {
|
|
319
|
-
if (!cur) {
|
|
320
|
-
return sum;
|
|
321
|
-
}
|
|
322
|
-
if (!sum) {
|
|
323
|
-
return cur;
|
|
324
|
-
}
|
|
325
|
-
return `${sum}${SEPARATOR}${cur}`;
|
|
326
|
-
}, "");
|
|
327
|
-
};
|
|
328
|
-
const getResourceUrl = (module, sourceUrl) => {
|
|
329
|
-
if ("getPublicPath" in module) {
|
|
330
|
-
let publicPath;
|
|
331
|
-
if (!module.getPublicPath.startsWith("function")) {
|
|
332
|
-
publicPath = new Function(module.getPublicPath)();
|
|
333
|
-
} else {
|
|
334
|
-
publicPath = new Function("return " + module.getPublicPath)()();
|
|
335
|
-
}
|
|
336
|
-
return `${publicPath}${sourceUrl}`;
|
|
337
|
-
} else if ("publicPath" in module) {
|
|
338
|
-
return `${module.publicPath}${sourceUrl}`;
|
|
339
|
-
} else {
|
|
340
|
-
console.warn("Cannot get resource URL. If in debug mode, please ignore.", module, sourceUrl);
|
|
341
|
-
return "";
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
const warn = (msg) => {
|
|
345
|
-
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
346
|
-
};
|
|
347
|
-
function safeToString(info) {
|
|
348
|
-
try {
|
|
349
|
-
return JSON.stringify(info, null, 2);
|
|
350
|
-
} catch (e) {
|
|
351
|
-
return "";
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const simpleJoinRemoteEntry = (rPath, rName) => {
|
|
355
|
-
if (!rPath) {
|
|
356
|
-
return rName;
|
|
357
|
-
}
|
|
358
|
-
const transformPath = (str) => {
|
|
359
|
-
if (str === ".") {
|
|
360
|
-
return "";
|
|
361
|
-
}
|
|
362
|
-
if (str.startsWith("./")) {
|
|
363
|
-
return str.replace("./", "");
|
|
364
|
-
}
|
|
365
|
-
if (str.startsWith("/")) {
|
|
366
|
-
const strWithoutSlash = str.slice(1);
|
|
367
|
-
if (strWithoutSlash.endsWith("/")) {
|
|
368
|
-
return strWithoutSlash.slice(0, -1);
|
|
369
|
-
}
|
|
370
|
-
return strWithoutSlash;
|
|
371
|
-
}
|
|
372
|
-
return str;
|
|
373
|
-
};
|
|
374
|
-
const transformedPath = transformPath(rPath);
|
|
375
|
-
if (!transformedPath) {
|
|
376
|
-
return rName;
|
|
377
|
-
}
|
|
378
|
-
if (transformedPath.endsWith("/")) {
|
|
379
|
-
return `${transformedPath}${rName}`;
|
|
380
|
-
}
|
|
381
|
-
return `${transformedPath}/${rName}`;
|
|
382
|
-
};
|
|
383
|
-
function inferAutoPublicPath(url2) {
|
|
384
|
-
return url2.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
|
385
|
-
}
|
|
386
|
-
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
387
|
-
var _manifest_metaData, _manifest_metaData1;
|
|
388
|
-
const { remotes = {}, overrides = {}, version } = options;
|
|
389
|
-
let remoteSnapshot;
|
|
390
|
-
const getPublicPath = () => {
|
|
391
|
-
if ("publicPath" in manifest.metaData) {
|
|
392
|
-
if (manifest.metaData.publicPath === "auto" && version) {
|
|
393
|
-
return inferAutoPublicPath(version);
|
|
394
|
-
}
|
|
395
|
-
return manifest.metaData.publicPath;
|
|
396
|
-
} else {
|
|
397
|
-
return manifest.metaData.getPublicPath;
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
const overridesKeys = Object.keys(overrides);
|
|
401
|
-
let remotesInfo = {};
|
|
402
|
-
if (!Object.keys(remotes).length) {
|
|
403
|
-
var _manifest_remotes;
|
|
404
|
-
remotesInfo = ((_manifest_remotes = manifest.remotes) == null ? void 0 : _manifest_remotes.reduce((res2, next) => {
|
|
405
|
-
let matchedVersion;
|
|
406
|
-
const name = next.federationContainerName;
|
|
407
|
-
if (overridesKeys.includes(name)) {
|
|
408
|
-
matchedVersion = overrides[name];
|
|
409
|
-
} else {
|
|
410
|
-
if ("version" in next) {
|
|
411
|
-
matchedVersion = next.version;
|
|
412
|
-
} else {
|
|
413
|
-
matchedVersion = next.entry;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
res2[name] = {
|
|
417
|
-
matchedVersion
|
|
418
|
-
};
|
|
419
|
-
return res2;
|
|
420
|
-
}, {})) || {};
|
|
421
|
-
}
|
|
422
|
-
Object.keys(remotes).forEach((key) => remotesInfo[key] = {
|
|
423
|
-
// overrides will override dependencies
|
|
424
|
-
matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
|
|
425
|
-
});
|
|
426
|
-
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
|
|
427
|
-
const { exposes } = manifest;
|
|
428
|
-
let basicRemoteSnapshot = {
|
|
429
|
-
version: version ? version : "",
|
|
430
|
-
buildVersion,
|
|
431
|
-
globalName,
|
|
432
|
-
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
433
|
-
remoteEntryType,
|
|
434
|
-
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
435
|
-
remoteTypesZip: remoteTypes.zip || "",
|
|
436
|
-
remoteTypesAPI: remoteTypes.api || "",
|
|
437
|
-
remotesInfo,
|
|
438
|
-
shared: manifest == null ? void 0 : manifest.shared.map((item) => ({
|
|
439
|
-
assets: item.assets,
|
|
440
|
-
sharedName: item.name,
|
|
441
|
-
version: item.version
|
|
442
|
-
})),
|
|
443
|
-
modules: exposes == null ? void 0 : exposes.map((expose) => ({
|
|
444
|
-
moduleName: expose.name,
|
|
445
|
-
modulePath: expose.path,
|
|
446
|
-
assets: expose.assets
|
|
447
|
-
}))
|
|
448
|
-
};
|
|
449
|
-
if ((_manifest_metaData = manifest.metaData) == null ? void 0 : _manifest_metaData.prefetchInterface) {
|
|
450
|
-
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
451
|
-
basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
452
|
-
prefetchInterface
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
if ((_manifest_metaData1 = manifest.metaData) == null ? void 0 : _manifest_metaData1.prefetchEntry) {
|
|
456
|
-
const { path: path2, name, type } = manifest.metaData.prefetchEntry;
|
|
457
|
-
basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
458
|
-
prefetchEntry: simpleJoinRemoteEntry(path2, name),
|
|
459
|
-
prefetchEntryType: type
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
if ("publicPath" in manifest.metaData) {
|
|
463
|
-
remoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
464
|
-
publicPath: getPublicPath()
|
|
465
|
-
});
|
|
466
|
-
} else {
|
|
467
|
-
remoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
468
|
-
getPublicPath: getPublicPath()
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
if (ssrRemoteEntry) {
|
|
472
|
-
const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
|
|
473
|
-
remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
|
|
474
|
-
remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || "commonjs-module";
|
|
475
|
-
}
|
|
476
|
-
return remoteSnapshot;
|
|
477
|
-
}
|
|
478
|
-
function isManifestProvider(moduleInfo) {
|
|
479
|
-
if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
|
|
480
|
-
return true;
|
|
481
|
-
} else {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
async function safeWrapper(callback, disableWarn) {
|
|
486
|
-
try {
|
|
487
|
-
const res2 = await callback();
|
|
488
|
-
return res2;
|
|
489
|
-
} catch (e) {
|
|
490
|
-
warn(e);
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function isStaticResourcesEqual(url1, url2) {
|
|
495
|
-
const REG_EXP = /^(https?:)?\/\//i;
|
|
496
|
-
const relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
|
|
497
|
-
const relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
|
|
498
|
-
return relativeUrl1 === relativeUrl2;
|
|
499
|
-
}
|
|
500
|
-
function createScript(info) {
|
|
501
|
-
let script2 = null;
|
|
502
|
-
let needAttach = true;
|
|
503
|
-
let timeout = 2e4;
|
|
504
|
-
let timeoutId;
|
|
505
|
-
const scripts = document.getElementsByTagName("script");
|
|
506
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
507
|
-
const s = scripts[i];
|
|
508
|
-
const scriptSrc = s.getAttribute("src");
|
|
509
|
-
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
510
|
-
script2 = s;
|
|
511
|
-
needAttach = false;
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
if (!script2) {
|
|
516
|
-
const attrs2 = info.attrs;
|
|
517
|
-
script2 = document.createElement("script");
|
|
518
|
-
script2.type = (attrs2 == null ? void 0 : attrs2["type"]) === "module" ? "module" : "text/javascript";
|
|
519
|
-
let createScriptRes = void 0;
|
|
520
|
-
if (info.createScriptHook) {
|
|
521
|
-
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
522
|
-
if (createScriptRes instanceof HTMLScriptElement) {
|
|
523
|
-
script2 = createScriptRes;
|
|
524
|
-
} else if (typeof createScriptRes === "object") {
|
|
525
|
-
if ("script" in createScriptRes && createScriptRes.script) {
|
|
526
|
-
script2 = createScriptRes.script;
|
|
527
|
-
}
|
|
528
|
-
if ("timeout" in createScriptRes && createScriptRes.timeout) {
|
|
529
|
-
timeout = createScriptRes.timeout;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (!script2.src) {
|
|
534
|
-
script2.src = info.url;
|
|
535
|
-
}
|
|
536
|
-
if (attrs2 && !createScriptRes) {
|
|
537
|
-
Object.keys(attrs2).forEach((name) => {
|
|
538
|
-
if (script2) {
|
|
539
|
-
if (name === "async" || name === "defer") {
|
|
540
|
-
script2[name] = attrs2[name];
|
|
541
|
-
} else if (!script2.getAttribute(name)) {
|
|
542
|
-
script2.setAttribute(name, attrs2[name]);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
const onScriptComplete = async (prev, event) => {
|
|
549
|
-
var _info_cb;
|
|
550
|
-
clearTimeout(timeoutId);
|
|
551
|
-
if (script2) {
|
|
552
|
-
script2.onerror = null;
|
|
553
|
-
script2.onload = null;
|
|
554
|
-
safeWrapper(() => {
|
|
555
|
-
const { needDeleteScript = true } = info;
|
|
556
|
-
if (needDeleteScript) {
|
|
557
|
-
(script2 == null ? void 0 : script2.parentNode) && script2.parentNode.removeChild(script2);
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
if (prev && typeof prev === "function") {
|
|
561
|
-
var _info_cb1;
|
|
562
|
-
const result = prev(event);
|
|
563
|
-
if (result instanceof Promise) {
|
|
564
|
-
var _info_cb2;
|
|
565
|
-
const res2 = await result;
|
|
566
|
-
info == null ? void 0 : (_info_cb2 = info.cb) == null ? void 0 : _info_cb2.call(info);
|
|
567
|
-
return res2;
|
|
568
|
-
}
|
|
569
|
-
info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
|
|
570
|
-
return result;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
|
|
574
|
-
};
|
|
575
|
-
script2.onerror = onScriptComplete.bind(null, script2.onerror);
|
|
576
|
-
script2.onload = onScriptComplete.bind(null, script2.onload);
|
|
577
|
-
timeoutId = setTimeout(() => {
|
|
578
|
-
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
579
|
-
}, timeout);
|
|
580
|
-
return {
|
|
581
|
-
script: script2,
|
|
582
|
-
needAttach
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
function createLink(info) {
|
|
586
|
-
let link = null;
|
|
587
|
-
let needAttach = true;
|
|
588
|
-
const links = document.getElementsByTagName("link");
|
|
589
|
-
for (let i = 0; i < links.length; i++) {
|
|
590
|
-
const l = links[i];
|
|
591
|
-
const linkHref = l.getAttribute("href");
|
|
592
|
-
const linkRef = l.getAttribute("ref");
|
|
593
|
-
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs["ref"]) {
|
|
594
|
-
link = l;
|
|
595
|
-
needAttach = false;
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
if (!link) {
|
|
600
|
-
link = document.createElement("link");
|
|
601
|
-
link.setAttribute("href", info.url);
|
|
602
|
-
let createLinkRes = void 0;
|
|
603
|
-
const attrs2 = info.attrs;
|
|
604
|
-
if (info.createLinkHook) {
|
|
605
|
-
createLinkRes = info.createLinkHook(info.url, attrs2);
|
|
606
|
-
if (createLinkRes instanceof HTMLLinkElement) {
|
|
607
|
-
link = createLinkRes;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
if (attrs2 && !createLinkRes) {
|
|
611
|
-
Object.keys(attrs2).forEach((name) => {
|
|
612
|
-
if (link && !link.getAttribute(name)) {
|
|
613
|
-
link.setAttribute(name, attrs2[name]);
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const onLinkComplete = (prev, event) => {
|
|
619
|
-
if (link) {
|
|
620
|
-
link.onerror = null;
|
|
621
|
-
link.onload = null;
|
|
622
|
-
safeWrapper(() => {
|
|
623
|
-
const { needDeleteLink = true } = info;
|
|
624
|
-
if (needDeleteLink) {
|
|
625
|
-
(link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
if (prev) {
|
|
629
|
-
const res2 = prev(event);
|
|
630
|
-
info.cb();
|
|
631
|
-
return res2;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
info.cb();
|
|
635
|
-
};
|
|
636
|
-
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
637
|
-
link.onload = onLinkComplete.bind(null, link.onload);
|
|
638
|
-
return {
|
|
639
|
-
link,
|
|
640
|
-
needAttach
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
function loadScript(url2, info) {
|
|
644
|
-
const { attrs: attrs2 = {}, createScriptHook } = info;
|
|
645
|
-
return new Promise((resolve, _reject) => {
|
|
646
|
-
const { script: script2, needAttach } = createScript({
|
|
647
|
-
url: url2,
|
|
648
|
-
cb: resolve,
|
|
649
|
-
attrs: _extends({
|
|
650
|
-
fetchpriority: "high"
|
|
651
|
-
}, attrs2),
|
|
652
|
-
createScriptHook,
|
|
653
|
-
needDeleteScript: true
|
|
654
|
-
});
|
|
655
|
-
needAttach && document.head.appendChild(script2);
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
function importNodeModule(name) {
|
|
659
|
-
if (!name) {
|
|
660
|
-
throw new Error("import specifier is required");
|
|
661
|
-
}
|
|
662
|
-
const importModule = new Function("name", `return import(name)`);
|
|
663
|
-
return importModule(name).then((res2) => res2).catch((error) => {
|
|
664
|
-
console.error(`Error importing module ${name}:`, error);
|
|
665
|
-
throw error;
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
const loadNodeFetch = async () => {
|
|
669
|
-
const fetchModule = await importNodeModule("node-fetch");
|
|
670
|
-
return fetchModule.default || fetchModule;
|
|
671
|
-
};
|
|
672
|
-
const lazyLoaderHookFetch = async (input, init, loaderHook2) => {
|
|
673
|
-
const hook = (url2, init2) => {
|
|
674
|
-
return loaderHook2.lifecycle.fetch.emit(url2, init2);
|
|
675
|
-
};
|
|
676
|
-
const res2 = await hook(input, init || {});
|
|
677
|
-
if (!res2 || !(res2 instanceof Response)) {
|
|
678
|
-
const fetchFunction = typeof fetch === "undefined" ? await loadNodeFetch() : fetch;
|
|
679
|
-
return fetchFunction(input, init || {});
|
|
680
|
-
}
|
|
681
|
-
return res2;
|
|
682
|
-
};
|
|
683
|
-
function createScriptNode(url, cb, attrs, loaderHook) {
|
|
684
|
-
if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
|
|
685
|
-
const hookResult = loaderHook.createScriptHook(url);
|
|
686
|
-
if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
|
|
687
|
-
url = hookResult.url;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
let urlObj;
|
|
691
|
-
try {
|
|
692
|
-
urlObj = new URL(url);
|
|
693
|
-
} catch (e) {
|
|
694
|
-
console.error("Error constructing URL:", e);
|
|
695
|
-
cb(new Error(`Invalid URL: ${e}`));
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
const getFetch = async () => {
|
|
699
|
-
if (loaderHook == null ? void 0 : loaderHook.fetch) {
|
|
700
|
-
return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
|
|
701
|
-
}
|
|
702
|
-
return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
|
|
703
|
-
};
|
|
704
|
-
const handleScriptFetch = async (f, urlObj) => {
|
|
705
|
-
try {
|
|
706
|
-
var _vm_constants;
|
|
707
|
-
const res = await f(urlObj.href);
|
|
708
|
-
const data = await res.text();
|
|
709
|
-
const [path, vm] = await Promise.all([
|
|
710
|
-
importNodeModule("path"),
|
|
711
|
-
importNodeModule("vm")
|
|
712
|
-
]);
|
|
713
|
-
const scriptContext = {
|
|
714
|
-
exports: {},
|
|
715
|
-
module: {
|
|
716
|
-
exports: {}
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
|
|
720
|
-
const filename = path.basename(urlObj.pathname);
|
|
721
|
-
var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
722
|
-
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
|
|
723
|
-
})`, {
|
|
724
|
-
filename,
|
|
725
|
-
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
|
|
726
|
-
});
|
|
727
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
|
|
728
|
-
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
729
|
-
if (attrs && exportedInterface && attrs["globalName"]) {
|
|
730
|
-
const container = exportedInterface[attrs["globalName"]] || exportedInterface;
|
|
731
|
-
cb(void 0, container);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
cb(void 0, exportedInterface);
|
|
735
|
-
} catch (e) {
|
|
736
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
getFetch().then(async (f2) => {
|
|
740
|
-
if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") {
|
|
741
|
-
return loadModule(urlObj.href, {
|
|
742
|
-
fetch: f2,
|
|
743
|
-
vm: await importNodeModule("vm")
|
|
744
|
-
}).then(async (module) => {
|
|
745
|
-
await module.evaluate();
|
|
746
|
-
cb(void 0, module.namespace);
|
|
747
|
-
}).catch((e) => {
|
|
748
|
-
cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
handleScriptFetch(f2, urlObj);
|
|
752
|
-
}).catch((err) => {
|
|
753
|
-
cb(err);
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
function loadScriptNode(url2, info) {
|
|
757
|
-
return new Promise((resolve, reject) => {
|
|
758
|
-
createScriptNode(url2, (error, scriptContext2) => {
|
|
759
|
-
if (error) {
|
|
760
|
-
reject(error);
|
|
761
|
-
} else {
|
|
762
|
-
var _info_attrs, _info_attrs1;
|
|
763
|
-
const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs["globalName"]) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1["name"]}:custom__`;
|
|
764
|
-
const entryExports = globalThis[remoteEntryKey] = scriptContext2;
|
|
765
|
-
resolve(entryExports);
|
|
766
|
-
}
|
|
767
|
-
}, info.attrs, info.loaderHook);
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
async function loadModule(url2, options) {
|
|
771
|
-
const { fetch: fetch1, vm: vm2 } = options;
|
|
772
|
-
const response = await fetch1(url2);
|
|
773
|
-
const code = await response.text();
|
|
774
|
-
const module = new vm2.SourceTextModule(code, {
|
|
775
|
-
// @ts-ignore
|
|
776
|
-
importModuleDynamically: async (specifier, script2) => {
|
|
777
|
-
const resolvedUrl = new URL(specifier, url2).href;
|
|
778
|
-
return loadModule(resolvedUrl, options);
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
await module.link(async (specifier) => {
|
|
782
|
-
const resolvedUrl = new URL(specifier, url2).href;
|
|
783
|
-
const module2 = await loadModule(resolvedUrl, options);
|
|
784
|
-
return module2;
|
|
785
|
-
});
|
|
786
|
-
return module;
|
|
787
|
-
}
|
|
788
|
-
const LoggerInstance = createLogger(
|
|
789
|
-
"[ Module Federation Bridge React ]"
|
|
790
|
-
);
|
|
791
|
-
function atLeastReact18(React2) {
|
|
792
|
-
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) {
|
|
793
|
-
const majorVersionString = React2.version.split(".")[0];
|
|
794
|
-
try {
|
|
795
|
-
return Number(majorVersionString) >= 18;
|
|
796
|
-
} catch (err) {
|
|
797
|
-
return false;
|
|
798
|
-
}
|
|
799
|
-
} else {
|
|
800
|
-
return false;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function pathJoin(...args) {
|
|
804
|
-
const res2 = args.reduce((res22, path2) => {
|
|
805
|
-
let nPath = path2;
|
|
806
|
-
if (!nPath || typeof nPath !== "string") {
|
|
807
|
-
return res22;
|
|
808
|
-
}
|
|
809
|
-
if (nPath[0] !== "/") {
|
|
810
|
-
nPath = `/${nPath}`;
|
|
811
|
-
}
|
|
812
|
-
const lastIndex = nPath.length - 1;
|
|
813
|
-
if (nPath[lastIndex] === "/") {
|
|
814
|
-
nPath = nPath.substring(0, lastIndex);
|
|
815
|
-
}
|
|
816
|
-
return res22 + nPath;
|
|
817
|
-
}, "");
|
|
818
|
-
return res2 || "/";
|
|
819
|
-
}
|
|
820
|
-
const getModuleName = (id) => {
|
|
821
|
-
if (!id) {
|
|
822
|
-
return id;
|
|
823
|
-
}
|
|
824
|
-
const idArray = id.split("/");
|
|
825
|
-
if (idArray.length < 2) {
|
|
826
|
-
return id;
|
|
827
|
-
}
|
|
828
|
-
return idArray[0] + "/" + idArray[1];
|
|
829
|
-
};
|
|
830
|
-
const getRootDomDefaultClassName = (moduleName) => {
|
|
831
|
-
if (!moduleName) {
|
|
832
|
-
return "";
|
|
833
|
-
}
|
|
834
|
-
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
835
|
-
return `bridge-root-component-${name}`;
|
|
836
|
-
};
|
|
837
|
-
const RouterContext = React__default.createContext(null);
|
|
838
|
-
export {
|
|
839
|
-
LoggerInstance as L,
|
|
840
|
-
RouterContext as R,
|
|
841
|
-
isBrowserEnv as a,
|
|
842
|
-
isManifestProvider as b,
|
|
843
|
-
createLogger as c,
|
|
844
|
-
composeKeyWithSeparator as d,
|
|
845
|
-
createLink as e,
|
|
846
|
-
createScript as f,
|
|
847
|
-
getResourceUrl as g,
|
|
848
|
-
generateSnapshotFromManifest as h,
|
|
849
|
-
isDebugMode as i,
|
|
850
|
-
loadScript as j,
|
|
851
|
-
getRootDomDefaultClassName as k,
|
|
852
|
-
loadScriptNode as l,
|
|
853
|
-
atLeastReact18 as m,
|
|
854
|
-
pathJoin as p,
|
|
855
|
-
safeToString as s,
|
|
856
|
-
warn as w
|
|
857
|
-
};
|