@module-federation/bridge-react 2.0.0 → 2.1.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/base.cjs.js +4 -4
  3. package/dist/base.es.js +5 -5
  4. package/dist/{bridge-base-CIgEZf8X.mjs → bridge-base-B7EKIpJ7.mjs} +1 -1
  5. package/dist/{bridge-base-1Grpgans.js → bridge-base-BLno0Ytr.js} +1 -1
  6. package/dist/{createHelpers-C9qvVTND.mjs → createHelpers-4fOvXdyD.mjs} +2 -2
  7. package/dist/{createHelpers-2UBGLdcA.js → createHelpers-DVr-JIwn.js} +2 -2
  8. package/dist/data-fetch-server-middleware.cjs.js +4 -4
  9. package/dist/data-fetch-server-middleware.es.js +2 -2
  10. package/dist/data-fetch-utils.cjs.js +2 -2
  11. package/dist/data-fetch-utils.es.js +4 -4
  12. package/dist/{index-DyQNwY2M.mjs → index-CafhxM-l.mjs} +1 -1
  13. package/dist/{index-DRSBaSu3.js → index-Cmp3JjCw.js} +2 -2
  14. package/dist/index.cjs.js +5 -5
  15. package/dist/index.es.js +6 -6
  16. package/dist/{lazy-load-component-plugin-9KkACgWW.js → lazy-load-component-plugin-B0jL1C-H.js} +2 -2
  17. package/dist/{lazy-load-component-plugin-GtenP5tG.mjs → lazy-load-component-plugin-CXfIn_mH.mjs} +2 -2
  18. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  19. package/dist/lazy-load-component-plugin.es.js +2 -2
  20. package/dist/lazy-utils.cjs.js +2 -2
  21. package/dist/lazy-utils.es.js +7 -7
  22. package/dist/logger-BWq2gts-.mjs +138 -0
  23. package/dist/logger-DT66A_Pv.js +137 -0
  24. package/dist/prefetch-CmkSilpl.mjs +861 -0
  25. package/dist/prefetch-CvCACzJH.js +860 -0
  26. package/dist/router-v5.cjs.js +1 -1
  27. package/dist/router-v5.es.js +1 -1
  28. package/dist/router-v6.cjs.js +1 -1
  29. package/dist/router-v6.es.js +1 -1
  30. package/dist/router-v7.cjs.js +1 -1
  31. package/dist/router-v7.es.js +1 -1
  32. package/dist/router.cjs.js +1 -1
  33. package/dist/router.es.js +1 -1
  34. package/dist/{utils-tM9yE73c.js → utils-BelRTG4G.js} +18 -4
  35. package/dist/{utils--qTri1IN.mjs → utils-DYUQLv_v.mjs} +21 -7
  36. package/dist/v18.cjs.js +1 -1
  37. package/dist/v18.es.js +1 -1
  38. package/dist/v19.cjs.js +1 -1
  39. package/dist/v19.es.js +1 -1
  40. package/package.json +6 -6
  41. package/dist/index.esm-BWaKho-8.js +0 -491
  42. package/dist/index.esm-CPwSeCvw.mjs +0 -492
  43. package/dist/prefetch-BvksZRMd.js +0 -1390
  44. package/dist/prefetch-Cj92jrl5.mjs +0 -1391
@@ -1,492 +0,0 @@
1
- const MANIFEST_EXT = ".json";
2
- const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
3
- const SEPARATOR = ":";
4
- function isBrowserEnv() {
5
- return typeof window !== "undefined" && typeof window.document !== "undefined";
6
- }
7
- function isBrowserDebug() {
8
- try {
9
- if (isBrowserEnv() && window.localStorage) {
10
- return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
11
- }
12
- } catch (error) {
13
- return false;
14
- }
15
- return false;
16
- }
17
- function isDebugMode() {
18
- if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
19
- return Boolean(process.env["FEDERATION_DEBUG"]);
20
- }
21
- if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
22
- return true;
23
- }
24
- return isBrowserDebug();
25
- }
26
- const LOG_CATEGORY = "[ Federation Runtime ]";
27
- const composeKeyWithSeparator = function(...args) {
28
- if (!args.length) {
29
- return "";
30
- }
31
- return args.reduce((sum, cur) => {
32
- if (!cur) {
33
- return sum;
34
- }
35
- if (!sum) {
36
- return cur;
37
- }
38
- return `${sum}${SEPARATOR}${cur}`;
39
- }, "");
40
- };
41
- const warn = (msg) => {
42
- console.warn(`${LOG_CATEGORY}: ${msg}`);
43
- };
44
- const PREFIX = "[ Module Federation ]";
45
- const DEFAULT_DELEGATE = console;
46
- const LOGGER_STACK_SKIP_TOKENS = [
47
- "logger.ts",
48
- "logger.js",
49
- "captureStackTrace",
50
- "Logger.emit",
51
- "Logger.log",
52
- "Logger.info",
53
- "Logger.warn",
54
- "Logger.error",
55
- "Logger.debug"
56
- ];
57
- function captureStackTrace() {
58
- try {
59
- const stack = new Error().stack;
60
- if (!stack) {
61
- return void 0;
62
- }
63
- const [, ...rawLines] = stack.split("\n");
64
- const filtered = rawLines.filter((line) => !LOGGER_STACK_SKIP_TOKENS.some((token) => line.includes(token)));
65
- if (!filtered.length) {
66
- return void 0;
67
- }
68
- const stackPreview = filtered.slice(0, 5).join("\n");
69
- return `Stack trace:
70
- ${stackPreview}`;
71
- } catch {
72
- return void 0;
73
- }
74
- }
75
- class Logger {
76
- constructor(prefix, delegate = DEFAULT_DELEGATE) {
77
- this.prefix = prefix;
78
- this.delegate = delegate ?? DEFAULT_DELEGATE;
79
- }
80
- setPrefix(prefix) {
81
- this.prefix = prefix;
82
- }
83
- setDelegate(delegate) {
84
- this.delegate = delegate ?? DEFAULT_DELEGATE;
85
- }
86
- emit(method, args) {
87
- const delegate = this.delegate;
88
- const debugMode = isDebugMode();
89
- const stackTrace = debugMode ? captureStackTrace() : void 0;
90
- const enrichedArgs = stackTrace ? [...args, stackTrace] : args;
91
- const order = (() => {
92
- switch (method) {
93
- case "log":
94
- return ["log", "info"];
95
- case "info":
96
- return ["info", "log"];
97
- case "warn":
98
- return ["warn", "info", "log"];
99
- case "error":
100
- return ["error", "warn", "log"];
101
- case "debug":
102
- default:
103
- return ["debug", "log"];
104
- }
105
- })();
106
- for (const candidate of order) {
107
- const handler = delegate[candidate];
108
- if (typeof handler === "function") {
109
- handler.call(delegate, this.prefix, ...enrichedArgs);
110
- return;
111
- }
112
- }
113
- for (const candidate of order) {
114
- const handler = DEFAULT_DELEGATE[candidate];
115
- if (typeof handler === "function") {
116
- handler.call(DEFAULT_DELEGATE, this.prefix, ...enrichedArgs);
117
- return;
118
- }
119
- }
120
- }
121
- log(...args) {
122
- this.emit("log", args);
123
- }
124
- warn(...args) {
125
- this.emit("warn", args);
126
- }
127
- error(...args) {
128
- this.emit("error", args);
129
- }
130
- success(...args) {
131
- this.emit("info", args);
132
- }
133
- info(...args) {
134
- this.emit("info", args);
135
- }
136
- ready(...args) {
137
- this.emit("info", args);
138
- }
139
- debug(...args) {
140
- if (isDebugMode()) {
141
- this.emit("debug", args);
142
- }
143
- }
144
- }
145
- function createLogger(prefix) {
146
- return new Logger(prefix);
147
- }
148
- function createInfrastructureLogger(prefix) {
149
- const infrastructureLogger = new Logger(prefix);
150
- Object.defineProperty(infrastructureLogger, "__mf_infrastructure_logger__", {
151
- value: true,
152
- enumerable: false,
153
- configurable: false
154
- });
155
- return infrastructureLogger;
156
- }
157
- createInfrastructureLogger(PREFIX);
158
- async function safeWrapper(callback, disableWarn) {
159
- try {
160
- const res2 = await callback();
161
- return res2;
162
- } catch (e) {
163
- warn(e);
164
- return;
165
- }
166
- }
167
- function isStaticResourcesEqual(url1, url2) {
168
- const REG_EXP = /^(https?:)?\/\//i;
169
- const relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
170
- const relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
171
- return relativeUrl1 === relativeUrl2;
172
- }
173
- function createScript(info) {
174
- let script2 = null;
175
- let needAttach = true;
176
- let timeout = 2e4;
177
- let timeoutId;
178
- const scripts = document.getElementsByTagName("script");
179
- for (let i = 0; i < scripts.length; i++) {
180
- const s = scripts[i];
181
- const scriptSrc = s.getAttribute("src");
182
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
183
- script2 = s;
184
- needAttach = false;
185
- break;
186
- }
187
- }
188
- if (!script2) {
189
- const attrs2 = info.attrs;
190
- script2 = document.createElement("script");
191
- script2.type = (attrs2 == null ? void 0 : attrs2["type"]) === "module" ? "module" : "text/javascript";
192
- let createScriptRes = void 0;
193
- if (info.createScriptHook) {
194
- createScriptRes = info.createScriptHook(info.url, info.attrs);
195
- if (createScriptRes instanceof HTMLScriptElement) {
196
- script2 = createScriptRes;
197
- } else if (typeof createScriptRes === "object") {
198
- if ("script" in createScriptRes && createScriptRes.script) {
199
- script2 = createScriptRes.script;
200
- }
201
- if ("timeout" in createScriptRes && createScriptRes.timeout) {
202
- timeout = createScriptRes.timeout;
203
- }
204
- }
205
- }
206
- if (!script2.src) {
207
- script2.src = info.url;
208
- }
209
- if (attrs2 && !createScriptRes) {
210
- Object.keys(attrs2).forEach((name) => {
211
- if (script2) {
212
- if (name === "async" || name === "defer") {
213
- script2[name] = attrs2[name];
214
- } else if (!script2.getAttribute(name)) {
215
- script2.setAttribute(name, attrs2[name]);
216
- }
217
- }
218
- });
219
- }
220
- }
221
- const onScriptComplete = async (prev, event) => {
222
- clearTimeout(timeoutId);
223
- const onScriptCompleteCallback = () => {
224
- if ((event == null ? void 0 : event.type) === "error") {
225
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
226
- } else {
227
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
228
- }
229
- };
230
- if (script2) {
231
- script2.onerror = null;
232
- script2.onload = null;
233
- safeWrapper(() => {
234
- const { needDeleteScript = true } = info;
235
- if (needDeleteScript) {
236
- (script2 == null ? void 0 : script2.parentNode) && script2.parentNode.removeChild(script2);
237
- }
238
- });
239
- if (prev && typeof prev === "function") {
240
- const result = prev(event);
241
- if (result instanceof Promise) {
242
- const res2 = await result;
243
- onScriptCompleteCallback();
244
- return res2;
245
- }
246
- onScriptCompleteCallback();
247
- return result;
248
- }
249
- }
250
- onScriptCompleteCallback();
251
- };
252
- script2.onerror = onScriptComplete.bind(null, script2.onerror);
253
- script2.onload = onScriptComplete.bind(null, script2.onload);
254
- timeoutId = setTimeout(() => {
255
- onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
256
- }, timeout);
257
- return { script: script2, needAttach };
258
- }
259
- function createLink(info) {
260
- let link = null;
261
- let needAttach = true;
262
- const links = document.getElementsByTagName("link");
263
- for (let i = 0; i < links.length; i++) {
264
- const l = links[i];
265
- const linkHref = l.getAttribute("href");
266
- const linkRel = l.getAttribute("rel");
267
- if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs["rel"]) {
268
- link = l;
269
- needAttach = false;
270
- break;
271
- }
272
- }
273
- if (!link) {
274
- link = document.createElement("link");
275
- link.setAttribute("href", info.url);
276
- let createLinkRes = void 0;
277
- const attrs2 = info.attrs;
278
- if (info.createLinkHook) {
279
- createLinkRes = info.createLinkHook(info.url, attrs2);
280
- if (createLinkRes instanceof HTMLLinkElement) {
281
- link = createLinkRes;
282
- }
283
- }
284
- if (attrs2 && !createLinkRes) {
285
- Object.keys(attrs2).forEach((name) => {
286
- if (link && !link.getAttribute(name)) {
287
- link.setAttribute(name, attrs2[name]);
288
- }
289
- });
290
- }
291
- }
292
- const onLinkComplete = (prev, event) => {
293
- const onLinkCompleteCallback = () => {
294
- if ((event == null ? void 0 : event.type) === "error") {
295
- (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
296
- } else {
297
- (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
298
- }
299
- };
300
- if (link) {
301
- link.onerror = null;
302
- link.onload = null;
303
- safeWrapper(() => {
304
- const { needDeleteLink = true } = info;
305
- if (needDeleteLink) {
306
- (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
307
- }
308
- });
309
- if (prev) {
310
- const res2 = prev(event);
311
- onLinkCompleteCallback();
312
- return res2;
313
- }
314
- }
315
- onLinkCompleteCallback();
316
- };
317
- link.onerror = onLinkComplete.bind(null, link.onerror);
318
- link.onload = onLinkComplete.bind(null, link.onload);
319
- return { link, needAttach };
320
- }
321
- function loadScript(url2, info) {
322
- const { attrs: attrs2 = {}, createScriptHook } = info;
323
- return new Promise((resolve, reject) => {
324
- const { script: script2, needAttach } = createScript({
325
- url: url2,
326
- cb: resolve,
327
- onErrorCallback: reject,
328
- attrs: {
329
- fetchpriority: "high",
330
- ...attrs2
331
- },
332
- createScriptHook,
333
- needDeleteScript: true
334
- });
335
- needAttach && document.head.appendChild(script2);
336
- });
337
- }
338
- const sdkImportCache = /* @__PURE__ */ new Map();
339
- function importNodeModule(name) {
340
- if (!name) {
341
- throw new Error("import specifier is required");
342
- }
343
- if (sdkImportCache.has(name)) {
344
- return sdkImportCache.get(name);
345
- }
346
- const importModule = new Function("name", `return import(name)`);
347
- const promise = importModule(name).then((res2) => res2).catch((error) => {
348
- console.error(`Error importing module ${name}:`, error);
349
- sdkImportCache.delete(name);
350
- throw error;
351
- });
352
- sdkImportCache.set(name, promise);
353
- return promise;
354
- }
355
- const loadNodeFetch = async () => {
356
- const fetchModule = await importNodeModule("node-fetch");
357
- return fetchModule.default || fetchModule;
358
- };
359
- const lazyLoaderHookFetch = async (input, init, loaderHook2) => {
360
- const hook = (url2, init2) => {
361
- return loaderHook2.lifecycle.fetch.emit(url2, init2);
362
- };
363
- const res2 = await hook(input, init || {});
364
- if (!res2 || !(res2 instanceof Response)) {
365
- const fetchFunction = typeof fetch === "undefined" ? await loadNodeFetch() : fetch;
366
- return fetchFunction(input, init || {});
367
- }
368
- return res2;
369
- };
370
- const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url, cb, attrs, loaderHook) => {
371
- if (loaderHook == null ? void 0 : loaderHook.createScriptHook) {
372
- const hookResult = loaderHook.createScriptHook(url);
373
- if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
374
- url = hookResult.url;
375
- }
376
- }
377
- let urlObj;
378
- try {
379
- urlObj = new URL(url);
380
- } catch (e) {
381
- console.error("Error constructing URL:", e);
382
- cb(new Error(`Invalid URL: ${e}`));
383
- return;
384
- }
385
- const getFetch = async () => {
386
- if (loaderHook == null ? void 0 : loaderHook.fetch) {
387
- return (input, init) => lazyLoaderHookFetch(input, init, loaderHook);
388
- }
389
- return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
390
- };
391
- const handleScriptFetch = async (f, urlObj) => {
392
- var _a;
393
- try {
394
- const res = await f(urlObj.href);
395
- const data = await res.text();
396
- const [path, vm] = await Promise.all([
397
- importNodeModule("path"),
398
- importNodeModule("vm")
399
- ]);
400
- const scriptContext = { exports: {}, module: { exports: {} } };
401
- const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
402
- const filename = path.basename(urlObj.pathname);
403
- const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
404
- })`, {
405
- filename,
406
- importModuleDynamically: (
407
- //@ts-ignore
408
- ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
409
- )
410
- });
411
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
412
- const exportedInterface = scriptContext.module.exports || scriptContext.exports;
413
- if (attrs && exportedInterface && attrs["globalName"]) {
414
- const container = exportedInterface[attrs["globalName"]] || exportedInterface;
415
- cb(void 0, container);
416
- return;
417
- }
418
- cb(void 0, exportedInterface);
419
- } catch (e) {
420
- cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
421
- }
422
- };
423
- getFetch().then(async (f2) => {
424
- if ((attrs == null ? void 0 : attrs["type"]) === "esm" || (attrs == null ? void 0 : attrs["type"]) === "module") {
425
- return loadModule(urlObj.href, {
426
- fetch: f2,
427
- vm: await importNodeModule("vm")
428
- }).then(async (module) => {
429
- await module.evaluate();
430
- cb(void 0, module.namespace);
431
- }).catch((e) => {
432
- cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
433
- });
434
- }
435
- handleScriptFetch(f2, urlObj);
436
- }).catch((err) => {
437
- cb(err);
438
- });
439
- } : (url2, cb2, attrs2, loaderHook2) => {
440
- cb2(new Error("createScriptNode is disabled in non-Node.js environment"));
441
- };
442
- const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
443
- return new Promise((resolve, reject) => {
444
- createScriptNode(url2, (error, scriptContext2) => {
445
- var _a, _b;
446
- if (error) {
447
- reject(error);
448
- } else {
449
- const remoteEntryKey = ((_a = info == null ? void 0 : info.attrs) == null ? void 0 : _a["globalName"]) || `__FEDERATION_${(_b = info == null ? void 0 : info.attrs) == null ? void 0 : _b["name"]}:custom__`;
450
- const entryExports = globalThis[remoteEntryKey] = scriptContext2;
451
- resolve(entryExports);
452
- }
453
- }, info.attrs, info.loaderHook);
454
- });
455
- } : (url2, info) => {
456
- throw new Error("loadScriptNode is disabled in non-Node.js environment");
457
- };
458
- const esmModuleCache = /* @__PURE__ */ new Map();
459
- async function loadModule(url2, options) {
460
- if (esmModuleCache.has(url2)) {
461
- return esmModuleCache.get(url2);
462
- }
463
- const { fetch: fetch2, vm: vm2 } = options;
464
- const response = await fetch2(url2);
465
- const code = await response.text();
466
- const module = new vm2.SourceTextModule(code, {
467
- // @ts-ignore
468
- importModuleDynamically: async (specifier, script2) => {
469
- const resolvedUrl = new URL(specifier, url2).href;
470
- return loadModule(resolvedUrl, options);
471
- }
472
- });
473
- esmModuleCache.set(url2, module);
474
- await module.link(async (specifier) => {
475
- const resolvedUrl = new URL(specifier, url2).href;
476
- const module2 = await loadModule(resolvedUrl, options);
477
- return module2;
478
- });
479
- return module;
480
- }
481
- export {
482
- MANIFEST_EXT as M,
483
- SEPARATOR as S,
484
- createLink as a,
485
- createScript as b,
486
- createLogger as c,
487
- isBrowserEnv as d,
488
- composeKeyWithSeparator as e,
489
- loadScript as f,
490
- isDebugMode as i,
491
- loadScriptNode as l
492
- };