@module-federation/bridge-react 0.19.1 → 0.20.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 (35) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/__tests__/bridge.spec.tsx +37 -14
  3. package/dist/{bridge-base-Ds850AOx.js → bridge-base-Bn6DO0Fi.js} +1 -1
  4. package/dist/{bridge-base-BwHtOqw_.mjs → bridge-base-DxcR1fja.mjs} +1 -1
  5. package/dist/data-fetch-server-middleware.cjs.js +2 -2
  6. package/dist/data-fetch-server-middleware.es.js +2 -2
  7. package/dist/data-fetch-utils.cjs.js +2 -2
  8. package/dist/data-fetch-utils.es.js +4 -4
  9. package/dist/{index-rAO0Wr0M.mjs → index-Dm-M9ouh.mjs} +1 -1
  10. package/dist/{index-eN2xRRXs.js → index-DqCpgmgH.js} +1 -1
  11. package/dist/index.cjs.js +5 -5
  12. package/dist/index.es.js +5 -5
  13. package/dist/{index.esm-Ju4RY-yW.js → index.esm-CzoIcLts.js} +76 -46
  14. package/dist/{index.esm-CtI0uQUR.mjs → index.esm-JLwyxgUK.mjs} +81 -51
  15. package/dist/{lazy-load-component-plugin-Dmzr-hGo.mjs → lazy-load-component-plugin-Bcm5-gd8.mjs} +2 -2
  16. package/dist/{lazy-load-component-plugin-vtpWwn-P.js → lazy-load-component-plugin-C-qNUGjT.js} +2 -2
  17. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  18. package/dist/lazy-load-component-plugin.es.js +2 -2
  19. package/dist/lazy-utils.cjs.js +2 -2
  20. package/dist/lazy-utils.es.js +2 -2
  21. package/dist/{prefetch-DtZwviM-.mjs → prefetch-COMVhC39.mjs} +63 -139
  22. package/dist/{prefetch-HjsWsmMr.js → prefetch-NDhOcbO7.js} +63 -139
  23. package/dist/router-v5.cjs.js +1 -1
  24. package/dist/router-v5.es.js +1 -1
  25. package/dist/router-v6.cjs.js +1 -1
  26. package/dist/router-v6.es.js +1 -1
  27. package/dist/router.cjs.js +1 -1
  28. package/dist/router.es.js +1 -1
  29. package/dist/{utils-vIpCrZmn.js → utils-0HFFqmd4.js} +1 -1
  30. package/dist/{utils-VSOJTX_o.mjs → utils-BTpxHmva.mjs} +1 -1
  31. package/dist/v18.cjs.js +1 -1
  32. package/dist/v18.es.js +1 -1
  33. package/dist/v19.cjs.js +1 -1
  34. package/dist/v19.es.js +1 -1
  35. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
+ ## 0.20.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 0008621: test(bridge-react): stabilize async assertions for bridge tests
8
+ - Updated dependencies [37346d4]
9
+ - Updated dependencies [639a83b]
10
+ - @module-federation/sdk@0.20.0
11
+ - @module-federation/bridge-shared@0.20.0
12
+
3
13
  ## 0.19.1
4
14
 
5
15
  ### Patch Changes
@@ -7,7 +7,7 @@ import {
7
7
  screen,
8
8
  waitFor,
9
9
  } from '@testing-library/react';
10
- import { createContainer, getHtml, sleep } from './util';
10
+ import { createContainer, getHtml } from './util';
11
11
 
12
12
  describe('bridge', () => {
13
13
  let containerInfo: ReturnType<typeof createContainer>;
@@ -31,9 +31,13 @@ describe('bridge', () => {
31
31
  dom: containerInfo?.container,
32
32
  });
33
33
 
34
- await sleep(200);
35
- expect(document.querySelector('#container')!.innerHTML).toContain(
36
- '<div>life cycle render</div>',
34
+ await waitFor(
35
+ () => {
36
+ expect(document.querySelector('#container')?.innerHTML).toContain(
37
+ '<div>life cycle render</div>',
38
+ );
39
+ },
40
+ { timeout: 2000 },
37
41
  );
38
42
 
39
43
  lifeCycle.destroy({
@@ -41,7 +45,14 @@ describe('bridge', () => {
41
45
  moduleName: 'test',
42
46
  });
43
47
 
44
- expect(document.querySelector('#container')!.innerHTML).toContain('');
48
+ await waitFor(
49
+ () => {
50
+ expect(
51
+ (document.querySelector('#container')?.innerHTML || '').trim(),
52
+ ).toBe('');
53
+ },
54
+ { timeout: 2000 },
55
+ );
45
56
  });
46
57
 
47
58
  it('createRemoteAppComponent', async () => {
@@ -66,9 +77,13 @@ describe('bridge', () => {
66
77
  );
67
78
  expect(getHtml(container)).toMatch('loading');
68
79
 
69
- await sleep(200);
70
- expect(getHtml(container)).toMatch('life cycle render');
71
- expect(getHtml(container)).toMatch('hello world');
80
+ await waitFor(
81
+ () => {
82
+ expect(getHtml(container)).toMatch('life cycle render');
83
+ expect(getHtml(container)).toMatch('hello world');
84
+ },
85
+ { timeout: 2000 },
86
+ );
72
87
  });
73
88
 
74
89
  it('createRemoteAppComponent and obtain ref property', async () => {
@@ -97,10 +112,14 @@ describe('bridge', () => {
97
112
  );
98
113
  expect(getHtml(container)).toMatch('loading');
99
114
 
100
- await sleep(200);
101
- expect(getHtml(container)).toMatch('life cycle render');
102
- expect(getHtml(container)).toMatch('hello world');
103
- expect(ref.current).not.toBeNull();
115
+ await waitFor(
116
+ () => {
117
+ expect(getHtml(container)).toMatch('life cycle render');
118
+ expect(getHtml(container)).toMatch('hello world');
119
+ expect(ref.current).not.toBeNull();
120
+ },
121
+ { timeout: 2000 },
122
+ );
104
123
  });
105
124
 
106
125
  it('createRemoteAppComponent with custom createRoot prop', async () => {
@@ -131,7 +150,11 @@ describe('bridge', () => {
131
150
  const { container } = render(<RemoteComponent />);
132
151
  expect(getHtml(container)).toMatch('loading');
133
152
 
134
- await sleep(200);
135
- expect(renderMock).toHaveBeenCalledTimes(1);
153
+ await waitFor(
154
+ () => {
155
+ expect(renderMock).toHaveBeenCalledTimes(1);
156
+ },
157
+ { timeout: 2000 },
158
+ );
136
159
  });
137
160
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const React = require("react");
3
- const index = require("./index-eN2xRRXs.js");
3
+ const index = require("./index-DqCpgmgH.js");
4
4
  const plugin = require("./plugin.cjs.js");
5
5
  function _interopNamespaceDefault(e) {
6
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Component, createElement, createContext } from "react";
3
- import { L as LoggerInstance, R as RouterContext } from "./index-rAO0Wr0M.mjs";
3
+ import { L as LoggerInstance, R as RouterContext } from "./index-Dm-M9ouh.mjs";
4
4
  import { federationRuntime } from "./plugin.es.js";
5
5
  const ErrorBoundaryContext = createContext(null);
6
6
  const initialState = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const lazyUtils = require("./utils-vIpCrZmn.js");
3
- const index_esm = require("./index.esm-Ju4RY-yW.js");
2
+ const lazyUtils = require("./utils-0HFFqmd4.js");
3
+ const index_esm = require("./index.esm-CzoIcLts.js");
4
4
  function wrapSetTimeout(targetPromise, delay = 2e4, id) {
5
5
  if (targetPromise && typeof targetPromise.then === "function") {
6
6
  return new Promise((resolve, reject) => {
@@ -1,5 +1,5 @@
1
- import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-VSOJTX_o.mjs";
2
- import { M as MANIFEST_EXT, S as SEPARATOR } from "./index.esm-CtI0uQUR.mjs";
1
+ import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-BTpxHmva.mjs";
2
+ import { M as MANIFEST_EXT, S as SEPARATOR } from "./index.esm-JLwyxgUK.mjs";
3
3
  function wrapSetTimeout(targetPromise, delay = 2e4, id) {
4
4
  if (targetPromise && typeof targetPromise.then === "function") {
5
5
  return new Promise((resolve, reject) => {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const lazyUtils = require("./utils-vIpCrZmn.js");
4
- const prefetch = require("./prefetch-HjsWsmMr.js");
3
+ const lazyUtils = require("./utils-0HFFqmd4.js");
4
+ const prefetch = require("./prefetch-NDhOcbO7.js");
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
@@ -1,7 +1,7 @@
1
- import { x as DATA_FETCH_FUNCTION } from "./utils-VSOJTX_o.mjs";
2
- import { C, b, e, h, c, d, r } from "./utils-VSOJTX_o.mjs";
3
- import { d as dataFetchFunction } from "./prefetch-DtZwviM-.mjs";
4
- import { i, p } from "./prefetch-DtZwviM-.mjs";
1
+ import { x as DATA_FETCH_FUNCTION } from "./utils-BTpxHmva.mjs";
2
+ import { C, b, e, h, c, d, r } from "./utils-BTpxHmva.mjs";
3
+ import { d as dataFetchFunction } from "./prefetch-COMVhC39.mjs";
4
+ import { i, p } from "./prefetch-COMVhC39.mjs";
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
@@ -1,5 +1,5 @@
1
1
  import React__default from "react";
2
- import { c as createLogger } from "./index.esm-CtI0uQUR.mjs";
2
+ import { c as createLogger } from "./index.esm-JLwyxgUK.mjs";
3
3
  const RouterContext = React__default.createContext(null);
4
4
  const LoggerInstance = createLogger(
5
5
  "[ Module Federation Bridge React ]"
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const React = require("react");
3
- const index_esm = require("./index.esm-Ju4RY-yW.js");
3
+ const index_esm = require("./index.esm-CzoIcLts.js");
4
4
  const RouterContext = React.createContext(null);
5
5
  const LoggerInstance = index_esm.createLogger(
6
6
  "[ Module Federation Bridge React ]"
package/dist/index.cjs.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const bridgeBase = require("./bridge-base-Ds850AOx.js");
3
+ const bridgeBase = require("./bridge-base-Bn6DO0Fi.js");
4
4
  const ReactDOM = require("react-dom");
5
5
  const React = require("react");
6
- const index = require("./index-eN2xRRXs.js");
6
+ const index = require("./index-DqCpgmgH.js");
7
7
  const ReactRouterDOM = require("react-router-dom");
8
8
  const plugin = require("./plugin.cjs.js");
9
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-vtpWwn-P.js");
10
- const lazyUtils = require("./utils-vIpCrZmn.js");
9
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-C-qNUGjT.js");
10
+ const lazyUtils = require("./utils-0HFFqmd4.js");
11
11
  const dataFetchUtils = require("./data-fetch-utils.cjs.js");
12
- const prefetch = require("./prefetch-HjsWsmMr.js");
12
+ const prefetch = require("./prefetch-NDhOcbO7.js");
13
13
  function _interopNamespaceDefault(e2) {
14
14
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
15
15
  if (e2) {
package/dist/index.es.js CHANGED
@@ -1,13 +1,13 @@
1
- import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-BwHtOqw_.mjs";
1
+ import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-DxcR1fja.mjs";
2
2
  import ReactDOM from "react-dom";
3
3
  import React__default, { forwardRef, useContext, useState, useEffect, useRef } from "react";
4
- import { p as pathJoin, L as LoggerInstance, g as getRootDomDefaultClassName } from "./index-rAO0Wr0M.mjs";
4
+ import { p as pathJoin, L as LoggerInstance, g as getRootDomDefaultClassName } from "./index-Dm-M9ouh.mjs";
5
5
  import * as ReactRouterDOM from "react-router-dom";
6
6
  import { federationRuntime } from "./plugin.es.js";
7
- import { b, a, c, l } from "./lazy-load-component-plugin-Dmzr-hGo.mjs";
8
- import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-VSOJTX_o.mjs";
7
+ import { b, a, c, l } from "./lazy-load-component-plugin-Bcm5-gd8.mjs";
8
+ import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-BTpxHmva.mjs";
9
9
  import { callDataFetch } from "./data-fetch-utils.es.js";
10
- import { p } from "./prefetch-DtZwviM-.mjs";
10
+ import { p } from "./prefetch-COMVhC39.mjs";
11
11
  function createReact16Or17Root(container) {
12
12
  return {
13
13
  render(children) {
@@ -1,14 +1,4 @@
1
1
  "use strict";
2
- function _extends() {
3
- _extends = Object.assign || function assign(target) {
4
- for (var i = 1; i < arguments.length; i++) {
5
- var source = arguments[i];
6
- for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
7
- }
8
- return target;
9
- };
10
- return _extends.apply(this, arguments);
11
- }
12
2
  const MANIFEST_EXT = ".json";
13
3
  const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
14
4
  const SEPARATOR = ":";
@@ -52,40 +42,88 @@ const composeKeyWithSeparator = function(...args) {
52
42
  const warn = (msg) => {
53
43
  console.warn(`${LOG_CATEGORY}: ${msg}`);
54
44
  };
55
- let Logger = class Logger2 {
45
+ const PREFIX = "[ Module Federation ]";
46
+ const DEFAULT_DELEGATE = console;
47
+ class Logger {
48
+ constructor(prefix, delegate = DEFAULT_DELEGATE) {
49
+ this.prefix = prefix;
50
+ this.delegate = delegate ?? DEFAULT_DELEGATE;
51
+ }
56
52
  setPrefix(prefix) {
57
53
  this.prefix = prefix;
58
54
  }
55
+ setDelegate(delegate) {
56
+ this.delegate = delegate ?? DEFAULT_DELEGATE;
57
+ }
58
+ emit(method, args) {
59
+ const delegate = this.delegate;
60
+ const order = (() => {
61
+ switch (method) {
62
+ case "log":
63
+ return ["log", "info"];
64
+ case "info":
65
+ return ["info", "log"];
66
+ case "warn":
67
+ return ["warn", "info", "log"];
68
+ case "error":
69
+ return ["error", "warn", "log"];
70
+ case "debug":
71
+ default:
72
+ return ["debug", "log"];
73
+ }
74
+ })();
75
+ for (const candidate of order) {
76
+ const handler = delegate[candidate];
77
+ if (typeof handler === "function") {
78
+ handler.call(delegate, this.prefix, ...args);
79
+ return;
80
+ }
81
+ }
82
+ for (const candidate of order) {
83
+ const handler = DEFAULT_DELEGATE[candidate];
84
+ if (typeof handler === "function") {
85
+ handler.call(DEFAULT_DELEGATE, this.prefix, ...args);
86
+ return;
87
+ }
88
+ }
89
+ }
59
90
  log(...args) {
60
- console.log(this.prefix, ...args);
91
+ this.emit("log", args);
61
92
  }
62
93
  warn(...args) {
63
- console.log(this.prefix, ...args);
94
+ this.emit("warn", args);
64
95
  }
65
96
  error(...args) {
66
- console.log(this.prefix, ...args);
97
+ this.emit("error", args);
67
98
  }
68
99
  success(...args) {
69
- console.log(this.prefix, ...args);
100
+ this.emit("info", args);
70
101
  }
71
102
  info(...args) {
72
- console.log(this.prefix, ...args);
103
+ this.emit("info", args);
73
104
  }
74
105
  ready(...args) {
75
- console.log(this.prefix, ...args);
106
+ this.emit("info", args);
76
107
  }
77
108
  debug(...args) {
78
109
  if (isDebugMode()) {
79
- console.log(this.prefix, ...args);
110
+ this.emit("debug", args);
80
111
  }
81
112
  }
82
- constructor(prefix) {
83
- this.prefix = prefix;
84
- }
85
- };
113
+ }
86
114
  function createLogger(prefix) {
87
115
  return new Logger(prefix);
88
116
  }
117
+ function createInfrastructureLogger(prefix) {
118
+ const infrastructureLogger = new Logger(prefix);
119
+ Object.defineProperty(infrastructureLogger, "__mf_infrastructure_logger__", {
120
+ value: true,
121
+ enumerable: false,
122
+ configurable: false
123
+ });
124
+ return infrastructureLogger;
125
+ }
126
+ createInfrastructureLogger(PREFIX);
89
127
  async function safeWrapper(callback, disableWarn) {
90
128
  try {
91
129
  const res2 = await callback();
@@ -185,10 +223,7 @@ function createScript(info) {
185
223
  timeoutId = setTimeout(() => {
186
224
  onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
187
225
  }, timeout);
188
- return {
189
- script: script2,
190
- needAttach
191
- };
226
+ return { script: script2, needAttach };
192
227
  }
193
228
  function createLink(info) {
194
229
  let link = null;
@@ -250,10 +285,7 @@ function createLink(info) {
250
285
  };
251
286
  link.onerror = onLinkComplete.bind(null, link.onerror);
252
287
  link.onload = onLinkComplete.bind(null, link.onload);
253
- return {
254
- link,
255
- needAttach
256
- };
288
+ return { link, needAttach };
257
289
  }
258
290
  function loadScript(url2, info) {
259
291
  const { attrs: attrs2 = {}, createScriptHook } = info;
@@ -262,9 +294,10 @@ function loadScript(url2, info) {
262
294
  url: url2,
263
295
  cb: resolve,
264
296
  onErrorCallback: reject,
265
- attrs: _extends({
266
- fetchpriority: "high"
267
- }, attrs2),
297
+ attrs: {
298
+ fetchpriority: "high",
299
+ ...attrs2
300
+ },
268
301
  createScriptHook,
269
302
  needDeleteScript: true
270
303
  });
@@ -325,27 +358,24 @@ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "we
325
358
  return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
326
359
  };
327
360
  const handleScriptFetch = async (f, urlObj) => {
361
+ var _a;
328
362
  try {
329
- var _vm_constants;
330
363
  const res = await f(urlObj.href);
331
364
  const data = await res.text();
332
365
  const [path, vm] = await Promise.all([
333
366
  importNodeModule("path"),
334
367
  importNodeModule("vm")
335
368
  ]);
336
- const scriptContext = {
337
- exports: {},
338
- module: {
339
- exports: {}
340
- }
341
- };
369
+ const scriptContext = { exports: {}, module: { exports: {} } };
342
370
  const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
343
371
  const filename = path.basename(urlObj.pathname);
344
- var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
345
372
  const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
346
373
  })`, {
347
374
  filename,
348
- 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
375
+ importModuleDynamically: (
376
+ //@ts-ignore
377
+ ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
378
+ )
349
379
  });
350
380
  script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
351
381
  const exportedInterface = scriptContext.module.exports || scriptContext.exports;
@@ -381,11 +411,11 @@ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "we
381
411
  const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
382
412
  return new Promise((resolve, reject) => {
383
413
  createScriptNode(url2, (error, scriptContext2) => {
414
+ var _a, _b;
384
415
  if (error) {
385
416
  reject(error);
386
417
  } else {
387
- var _info_attrs, _info_attrs1;
388
- 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__`;
418
+ 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__`;
389
419
  const entryExports = globalThis[remoteEntryKey] = scriptContext2;
390
420
  resolve(entryExports);
391
421
  }
@@ -399,8 +429,8 @@ async function loadModule(url2, options) {
399
429
  if (esmModuleCache.has(url2)) {
400
430
  return esmModuleCache.get(url2);
401
431
  }
402
- const { fetch: fetch1, vm: vm2 } = options;
403
- const response = await fetch1(url2);
432
+ const { fetch: fetch2, vm: vm2 } = options;
433
+ const response = await fetch2(url2);
404
434
  const code = await response.text();
405
435
  const module2 = new vm2.SourceTextModule(code, {
406
436
  // @ts-ignore
@@ -1,13 +1,3 @@
1
- function _extends() {
2
- _extends = Object.assign || function assign(target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
6
- }
7
- return target;
8
- };
9
- return _extends.apply(this, arguments);
10
- }
11
1
  const MANIFEST_EXT = ".json";
12
2
  const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
13
3
  const SEPARATOR = ":";
@@ -51,40 +41,88 @@ const composeKeyWithSeparator = function(...args) {
51
41
  const warn = (msg) => {
52
42
  console.warn(`${LOG_CATEGORY}: ${msg}`);
53
43
  };
54
- let Logger = class Logger2 {
44
+ const PREFIX = "[ Module Federation ]";
45
+ const DEFAULT_DELEGATE = console;
46
+ class Logger {
47
+ constructor(prefix, delegate = DEFAULT_DELEGATE) {
48
+ this.prefix = prefix;
49
+ this.delegate = delegate ?? DEFAULT_DELEGATE;
50
+ }
55
51
  setPrefix(prefix) {
56
52
  this.prefix = prefix;
57
53
  }
54
+ setDelegate(delegate) {
55
+ this.delegate = delegate ?? DEFAULT_DELEGATE;
56
+ }
57
+ emit(method, args) {
58
+ const delegate = this.delegate;
59
+ const order = (() => {
60
+ switch (method) {
61
+ case "log":
62
+ return ["log", "info"];
63
+ case "info":
64
+ return ["info", "log"];
65
+ case "warn":
66
+ return ["warn", "info", "log"];
67
+ case "error":
68
+ return ["error", "warn", "log"];
69
+ case "debug":
70
+ default:
71
+ return ["debug", "log"];
72
+ }
73
+ })();
74
+ for (const candidate of order) {
75
+ const handler = delegate[candidate];
76
+ if (typeof handler === "function") {
77
+ handler.call(delegate, this.prefix, ...args);
78
+ return;
79
+ }
80
+ }
81
+ for (const candidate of order) {
82
+ const handler = DEFAULT_DELEGATE[candidate];
83
+ if (typeof handler === "function") {
84
+ handler.call(DEFAULT_DELEGATE, this.prefix, ...args);
85
+ return;
86
+ }
87
+ }
88
+ }
58
89
  log(...args) {
59
- console.log(this.prefix, ...args);
90
+ this.emit("log", args);
60
91
  }
61
92
  warn(...args) {
62
- console.log(this.prefix, ...args);
93
+ this.emit("warn", args);
63
94
  }
64
95
  error(...args) {
65
- console.log(this.prefix, ...args);
96
+ this.emit("error", args);
66
97
  }
67
98
  success(...args) {
68
- console.log(this.prefix, ...args);
99
+ this.emit("info", args);
69
100
  }
70
101
  info(...args) {
71
- console.log(this.prefix, ...args);
102
+ this.emit("info", args);
72
103
  }
73
104
  ready(...args) {
74
- console.log(this.prefix, ...args);
105
+ this.emit("info", args);
75
106
  }
76
107
  debug(...args) {
77
108
  if (isDebugMode()) {
78
- console.log(this.prefix, ...args);
109
+ this.emit("debug", args);
79
110
  }
80
111
  }
81
- constructor(prefix) {
82
- this.prefix = prefix;
83
- }
84
- };
112
+ }
85
113
  function createLogger(prefix) {
86
114
  return new Logger(prefix);
87
115
  }
116
+ function createInfrastructureLogger(prefix) {
117
+ const infrastructureLogger = new Logger(prefix);
118
+ Object.defineProperty(infrastructureLogger, "__mf_infrastructure_logger__", {
119
+ value: true,
120
+ enumerable: false,
121
+ configurable: false
122
+ });
123
+ return infrastructureLogger;
124
+ }
125
+ createInfrastructureLogger(PREFIX);
88
126
  async function safeWrapper(callback, disableWarn) {
89
127
  try {
90
128
  const res2 = await callback();
@@ -184,10 +222,7 @@ function createScript(info) {
184
222
  timeoutId = setTimeout(() => {
185
223
  onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
186
224
  }, timeout);
187
- return {
188
- script: script2,
189
- needAttach
190
- };
225
+ return { script: script2, needAttach };
191
226
  }
192
227
  function createLink(info) {
193
228
  let link = null;
@@ -249,10 +284,7 @@ function createLink(info) {
249
284
  };
250
285
  link.onerror = onLinkComplete.bind(null, link.onerror);
251
286
  link.onload = onLinkComplete.bind(null, link.onload);
252
- return {
253
- link,
254
- needAttach
255
- };
287
+ return { link, needAttach };
256
288
  }
257
289
  function loadScript(url2, info) {
258
290
  const { attrs: attrs2 = {}, createScriptHook } = info;
@@ -261,9 +293,10 @@ function loadScript(url2, info) {
261
293
  url: url2,
262
294
  cb: resolve,
263
295
  onErrorCallback: reject,
264
- attrs: _extends({
265
- fetchpriority: "high"
266
- }, attrs2),
296
+ attrs: {
297
+ fetchpriority: "high",
298
+ ...attrs2
299
+ },
267
300
  createScriptHook,
268
301
  needDeleteScript: true
269
302
  });
@@ -324,27 +357,24 @@ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "we
324
357
  return typeof fetch === "undefined" ? loadNodeFetch() : fetch;
325
358
  };
326
359
  const handleScriptFetch = async (f, urlObj) => {
360
+ var _a;
327
361
  try {
328
- var _vm_constants;
329
362
  const res = await f(urlObj.href);
330
363
  const data = await res.text();
331
364
  const [path, vm] = await Promise.all([
332
365
  importNodeModule("path"),
333
366
  importNodeModule("vm")
334
367
  ]);
335
- const scriptContext = {
336
- exports: {},
337
- module: {
338
- exports: {}
339
- }
340
- };
368
+ const scriptContext = { exports: {}, module: { exports: {} } };
341
369
  const urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
342
370
  const filename = path.basename(urlObj.pathname);
343
- var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
344
371
  const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
345
372
  })`, {
346
373
  filename,
347
- 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
374
+ importModuleDynamically: (
375
+ //@ts-ignore
376
+ ((_a = vm.constants) == null ? void 0 : _a.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
377
+ )
348
378
  });
349
379
  script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
350
380
  const exportedInterface = scriptContext.module.exports || scriptContext.exports;
@@ -380,11 +410,11 @@ const createScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "we
380
410
  const loadScriptNode = typeof ENV_TARGET === "undefined" || ENV_TARGET !== "web" ? (url2, info) => {
381
411
  return new Promise((resolve, reject) => {
382
412
  createScriptNode(url2, (error, scriptContext2) => {
413
+ var _a, _b;
383
414
  if (error) {
384
415
  reject(error);
385
416
  } else {
386
- var _info_attrs, _info_attrs1;
387
- 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__`;
417
+ 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__`;
388
418
  const entryExports = globalThis[remoteEntryKey] = scriptContext2;
389
419
  resolve(entryExports);
390
420
  }
@@ -398,8 +428,8 @@ async function loadModule(url2, options) {
398
428
  if (esmModuleCache.has(url2)) {
399
429
  return esmModuleCache.get(url2);
400
430
  }
401
- const { fetch: fetch1, vm: vm2 } = options;
402
- const response = await fetch1(url2);
431
+ const { fetch: fetch2, vm: vm2 } = options;
432
+ const response = await fetch2(url2);
403
433
  const code = await response.text();
404
434
  const module = new vm2.SourceTextModule(code, {
405
435
  // @ts-ignore
@@ -419,12 +449,12 @@ async function loadModule(url2, options) {
419
449
  export {
420
450
  MANIFEST_EXT as M,
421
451
  SEPARATOR as S,
422
- composeKeyWithSeparator as a,
423
- isDebugMode as b,
452
+ createLink as a,
453
+ createScript as b,
424
454
  createLogger as c,
425
- createLink as d,
426
- createScript as e,
455
+ isBrowserEnv as d,
456
+ composeKeyWithSeparator as e,
427
457
  loadScript as f,
428
- isBrowserEnv as i,
458
+ isDebugMode as i,
429
459
  loadScriptNode as l
430
460
  };