@module-federation/bridge-react 0.0.0-next-20241113115843 → 0.0.0-next-20241114041727
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 +4 -4
- package/dist/context-BcJ-YlNr.cjs +354 -0
- package/dist/context-CUbFnlO5.js +355 -0
- package/dist/index.cjs.js +47 -2852
- package/dist/index.es.js +45 -2850
- 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 +1 -1
- package/dist/router.es.js +1 -1
- package/package.json +4 -4
- package/vite.config.ts +1 -0
- package/dist/context-3_giwitw.js +0 -857
- package/dist/context-C9uJCrqC.cjs +0 -856
|
@@ -0,0 +1,355 @@
|
|
|
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
|
+
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
244
|
+
const BROWSER_LOG_VALUE = "1";
|
|
245
|
+
function isBrowserEnv() {
|
|
246
|
+
return typeof window !== "undefined";
|
|
247
|
+
}
|
|
248
|
+
function isBrowserDebug() {
|
|
249
|
+
try {
|
|
250
|
+
if (isBrowserEnv() && window.localStorage) {
|
|
251
|
+
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
function isDebugMode() {
|
|
259
|
+
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
|
|
260
|
+
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
261
|
+
}
|
|
262
|
+
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
return isBrowserDebug();
|
|
266
|
+
}
|
|
267
|
+
const PREFIX = "[ Module Federation ]";
|
|
268
|
+
function setDebug(loggerInstance) {
|
|
269
|
+
if (isDebugMode()) {
|
|
270
|
+
loggerInstance.level = "verbose";
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function setPrefix(loggerInstance, prefix) {
|
|
274
|
+
loggerInstance.labels = {
|
|
275
|
+
warn: `${prefix} Warn`,
|
|
276
|
+
error: `${prefix} Error`,
|
|
277
|
+
success: `${prefix} Success`,
|
|
278
|
+
info: `${prefix} Info`,
|
|
279
|
+
ready: `${prefix} Ready`,
|
|
280
|
+
debug: `${prefix} Debug`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function createLogger(prefix) {
|
|
284
|
+
const loggerInstance = browser.createLogger({
|
|
285
|
+
labels: {
|
|
286
|
+
warn: `${PREFIX} Warn`,
|
|
287
|
+
error: `${PREFIX} Error`,
|
|
288
|
+
success: `${PREFIX} Success`,
|
|
289
|
+
info: `${PREFIX} Info`,
|
|
290
|
+
ready: `${PREFIX} Ready`,
|
|
291
|
+
debug: `${PREFIX} Debug`
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
setDebug(loggerInstance);
|
|
295
|
+
setPrefix(loggerInstance, prefix);
|
|
296
|
+
return loggerInstance;
|
|
297
|
+
}
|
|
298
|
+
createLogger(PREFIX);
|
|
299
|
+
const LoggerInstance = createLogger(
|
|
300
|
+
"[ Module Federation Bridge React ]"
|
|
301
|
+
);
|
|
302
|
+
function atLeastReact18(React2) {
|
|
303
|
+
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) {
|
|
304
|
+
const majorVersionString = React2.version.split(".")[0];
|
|
305
|
+
try {
|
|
306
|
+
return Number(majorVersionString) >= 18;
|
|
307
|
+
} catch (err) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function pathJoin(...args) {
|
|
315
|
+
const res = args.reduce((res2, path) => {
|
|
316
|
+
let nPath = path;
|
|
317
|
+
if (!nPath || typeof nPath !== "string") {
|
|
318
|
+
return res2;
|
|
319
|
+
}
|
|
320
|
+
if (nPath[0] !== "/") {
|
|
321
|
+
nPath = `/${nPath}`;
|
|
322
|
+
}
|
|
323
|
+
const lastIndex = nPath.length - 1;
|
|
324
|
+
if (nPath[lastIndex] === "/") {
|
|
325
|
+
nPath = nPath.substring(0, lastIndex);
|
|
326
|
+
}
|
|
327
|
+
return res2 + nPath;
|
|
328
|
+
}, "");
|
|
329
|
+
return res || "/";
|
|
330
|
+
}
|
|
331
|
+
const getModuleName = (id) => {
|
|
332
|
+
if (!id) {
|
|
333
|
+
return id;
|
|
334
|
+
}
|
|
335
|
+
const idArray = id.split("/");
|
|
336
|
+
if (idArray.length < 2) {
|
|
337
|
+
return id;
|
|
338
|
+
}
|
|
339
|
+
return idArray[0] + "/" + idArray[1];
|
|
340
|
+
};
|
|
341
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
342
|
+
if (!moduleName) {
|
|
343
|
+
return "";
|
|
344
|
+
}
|
|
345
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
346
|
+
return `bridge-root-component-${name}`;
|
|
347
|
+
};
|
|
348
|
+
const RouterContext = React__default.createContext(null);
|
|
349
|
+
export {
|
|
350
|
+
LoggerInstance as L,
|
|
351
|
+
RouterContext as R,
|
|
352
|
+
atLeastReact18 as a,
|
|
353
|
+
getRootDomDefaultClassName as g,
|
|
354
|
+
pathJoin as p
|
|
355
|
+
};
|