@module-federation/devtools 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703

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 (203) hide show
  1. package/README.md +3 -0
  2. package/dist/es/App.css +6 -5
  3. package/dist/es/App.js +211 -63
  4. package/dist/es/App.module.js +1 -1
  5. package/dist/es/App_module.css +41 -39
  6. package/dist/es/component/DependencyGraph/index.js +11 -12
  7. package/dist/es/component/DependencyGraph/index_module.css +20 -17
  8. package/dist/es/component/DependencyGraphItem/index.js +23 -10
  9. package/dist/es/component/DependencyGraphItem/index_module.css +7 -7
  10. package/dist/es/component/Form/index.js +24 -31
  11. package/dist/es/component/Form/index.module.js +1 -1
  12. package/dist/es/component/Form/index_module.css +22 -25
  13. package/dist/es/component/LanguageSwitch.js +50 -0
  14. package/dist/es/component/Layout/index.js +27 -10
  15. package/dist/es/component/Layout/index_module.css +7 -7
  16. package/dist/es/component/LoadingTrace/index.js +944 -0
  17. package/dist/es/component/LoadingTrace/index.module.js +5 -0
  18. package/dist/es/component/LoadingTrace/index_module.css +876 -0
  19. package/dist/es/component/ModuleInfo/index.js +65 -41
  20. package/dist/es/component/ModuleInfo/index_module.css +12 -11
  21. package/dist/es/component/SharedDepsExplorer/FocusResultDisplay.js +5 -3
  22. package/dist/es/component/SharedDepsExplorer/FocusResultDisplay_module.css +5 -5
  23. package/dist/es/component/SharedDepsExplorer/index.js +223 -96
  24. package/dist/es/component/SharedDepsExplorer/index_module.css +12 -2
  25. package/dist/es/component/SharedDepsExplorer/share-utils.js +21 -5
  26. package/dist/es/component/ThemeToggle.js +19 -0
  27. package/dist/es/component/ThemeToggle.module.js +5 -0
  28. package/dist/es/component/ThemeToggle_module.css +12 -0
  29. package/dist/es/hooks/useDevtoolsTheme.js +77 -0
  30. package/dist/es/i18n/index.js +688 -0
  31. package/dist/es/utils/chrome/fast-refresh.js +297 -173
  32. package/dist/es/utils/chrome/index.js +42 -22
  33. package/dist/es/utils/chrome/messages.js +7 -1
  34. package/dist/es/utils/chrome/observability-plugin.js +93 -0
  35. package/dist/es/utils/chrome/observability-shared.js +99 -0
  36. package/dist/es/utils/chrome/observability.js +208 -0
  37. package/dist/es/utils/chrome/override-remote.js +7 -0
  38. package/dist/es/utils/chrome/post-message-listener.js +22 -4
  39. package/dist/es/utils/chrome/post-message-start.js +4 -10
  40. package/dist/es/utils/chrome/post-message.js +12 -3
  41. package/dist/es/utils/chrome/resolve-basic-proxy-core.js +4 -0
  42. package/dist/es/utils/chrome/safe-post-message.js +124 -0
  43. package/dist/es/utils/chrome/snapshot-plugin.js +2 -36
  44. package/dist/es/utils/data/index.js +5 -25
  45. package/dist/es/utils/sdk/graph.js +25 -11
  46. package/dist/es/vendor/basic-proxy-core.js +155 -0
  47. package/dist/es/worker/index.js +27 -8
  48. package/dist/lib/App.css +6 -5
  49. package/dist/lib/App.js +208 -64
  50. package/dist/lib/App.module.js +1 -2
  51. package/dist/lib/App_module.css +41 -39
  52. package/dist/lib/component/DependencyGraph/index.js +11 -13
  53. package/dist/lib/component/DependencyGraph/index.module.js +0 -1
  54. package/dist/lib/component/DependencyGraph/index_module.css +20 -17
  55. package/dist/lib/component/DependencyGraphItem/index.js +23 -11
  56. package/dist/lib/component/DependencyGraphItem/index.module.js +0 -1
  57. package/dist/lib/component/DependencyGraphItem/index_module.css +7 -7
  58. package/dist/lib/component/Form/index.js +24 -32
  59. package/dist/lib/component/Form/index.module.js +1 -2
  60. package/dist/lib/component/Form/index_module.css +22 -25
  61. package/dist/lib/component/LanguageSwitch.js +79 -0
  62. package/dist/lib/component/Layout/index.js +27 -11
  63. package/dist/lib/component/Layout/index.module.js +0 -1
  64. package/dist/lib/component/Layout/index_module.css +7 -7
  65. package/dist/lib/component/LoadingTrace/index.js +953 -0
  66. package/dist/lib/component/LoadingTrace/index.module.js +24 -0
  67. package/dist/lib/component/LoadingTrace/index_module.css +876 -0
  68. package/dist/lib/component/ModuleInfo/index.js +65 -42
  69. package/dist/lib/component/ModuleInfo/index.module.js +0 -1
  70. package/dist/lib/component/ModuleInfo/index_module.css +12 -11
  71. package/dist/lib/component/SharedDepsExplorer/FocusResultDisplay.js +5 -4
  72. package/dist/lib/component/SharedDepsExplorer/FocusResultDisplay.module.js +0 -1
  73. package/dist/lib/component/SharedDepsExplorer/FocusResultDisplay_module.css +5 -5
  74. package/dist/lib/component/SharedDepsExplorer/index.js +217 -95
  75. package/dist/lib/component/SharedDepsExplorer/index.module.js +0 -1
  76. package/dist/lib/component/SharedDepsExplorer/index_module.css +12 -2
  77. package/dist/lib/component/SharedDepsExplorer/share-utils.js +21 -6
  78. package/dist/lib/component/ThemeToggle.js +48 -0
  79. package/dist/lib/component/ThemeToggle.module.js +24 -0
  80. package/dist/lib/component/ThemeToggle_module.css +12 -0
  81. package/dist/lib/hooks/useDevtoolsTheme.js +100 -0
  82. package/dist/lib/i18n/index.js +721 -0
  83. package/dist/lib/init.js +0 -1
  84. package/dist/lib/template/constant.js +0 -1
  85. package/dist/lib/template/index.js +0 -1
  86. package/dist/lib/utils/chrome/fast-refresh.js +250 -136
  87. package/dist/lib/utils/chrome/index.js +43 -23
  88. package/dist/lib/utils/chrome/messages.js +11 -3
  89. package/dist/lib/utils/chrome/observability-plugin.js +85 -0
  90. package/dist/lib/utils/chrome/observability-shared.js +125 -0
  91. package/dist/lib/utils/chrome/observability.js +233 -0
  92. package/dist/lib/utils/chrome/override-remote.js +20 -0
  93. package/dist/lib/utils/chrome/post-message-init.js +0 -1
  94. package/dist/lib/utils/chrome/post-message-listener.js +19 -5
  95. package/dist/lib/utils/chrome/post-message-start.js +4 -11
  96. package/dist/lib/utils/chrome/post-message.js +12 -4
  97. package/dist/lib/utils/chrome/resolve-basic-proxy-core.js +27 -0
  98. package/dist/lib/utils/chrome/safe-post-message.js +147 -0
  99. package/dist/lib/utils/chrome/snapshot-plugin.js +5 -47
  100. package/dist/lib/utils/chrome/storage.js +0 -1
  101. package/dist/lib/utils/data/index.js +6 -29
  102. package/dist/lib/utils/index.js +0 -1
  103. package/dist/lib/utils/sdk/graph.js +25 -12
  104. package/dist/lib/utils/sdk/index.js +0 -1
  105. package/dist/lib/utils/types/common.js +0 -1
  106. package/dist/lib/utils/types/index.js +0 -1
  107. package/dist/lib/vendor/basic-proxy-core.js +147 -0
  108. package/dist/lib/worker/index.js +27 -9
  109. package/dist/types/App.css +13 -0
  110. package/dist/types/App.js +519 -0
  111. package/dist/types/App.module.js +24 -0
  112. package/dist/types/App_module.css +307 -0
  113. package/dist/types/component/DependencyGraph/index.js +225 -0
  114. package/dist/types/component/DependencyGraph/index.module.js +24 -0
  115. package/dist/types/component/DependencyGraph/index_module.css +100 -0
  116. package/dist/types/component/DependencyGraphItem/index.js +124 -0
  117. package/dist/types/component/DependencyGraphItem/index.module.js +24 -0
  118. package/dist/types/component/DependencyGraphItem/index_module.css +95 -0
  119. package/dist/types/component/Form/index.js +372 -0
  120. package/dist/types/component/Form/index.module.js +24 -0
  121. package/dist/types/component/Form/index_module.css +198 -0
  122. package/dist/types/component/LanguageSwitch.js +79 -0
  123. package/dist/types/component/Layout/index.js +471 -0
  124. package/dist/types/component/Layout/index.module.js +24 -0
  125. package/dist/types/component/Layout/index_module.css +68 -0
  126. package/dist/types/component/LoadingTrace/index.js +953 -0
  127. package/dist/types/component/LoadingTrace/index.module.js +24 -0
  128. package/dist/types/component/LoadingTrace/index_module.css +876 -0
  129. package/dist/types/component/ModuleInfo/index.js +342 -0
  130. package/dist/types/component/ModuleInfo/index.module.js +24 -0
  131. package/dist/types/component/ModuleInfo/index_module.css +184 -0
  132. package/dist/types/component/SharedDepsExplorer/FocusResultDisplay.js +64 -0
  133. package/dist/types/component/SharedDepsExplorer/FocusResultDisplay.module.js +24 -0
  134. package/dist/types/component/SharedDepsExplorer/FocusResultDisplay_module.css +45 -0
  135. package/dist/types/component/SharedDepsExplorer/index.js +635 -0
  136. package/dist/types/component/SharedDepsExplorer/index.module.js +24 -0
  137. package/dist/types/component/SharedDepsExplorer/index_module.css +467 -0
  138. package/dist/types/component/SharedDepsExplorer/share-utils.js +252 -0
  139. package/dist/types/component/ThemeToggle.js +48 -0
  140. package/dist/types/component/ThemeToggle.module.js +24 -0
  141. package/dist/types/component/ThemeToggle_module.css +12 -0
  142. package/dist/types/hooks/useDevtoolsTheme.js +100 -0
  143. package/dist/types/i18n/index.js +721 -0
  144. package/dist/types/init.js +8 -0
  145. package/dist/types/src/App.d.ts +1 -1
  146. package/dist/types/src/component/DependencyGraph/index.d.ts +1 -1
  147. package/dist/types/src/component/DependencyGraphItem/index.d.ts +1 -1
  148. package/dist/types/src/component/Form/index.d.ts +1 -1
  149. package/dist/types/src/component/LanguageSwitch.d.ts +2 -0
  150. package/dist/types/src/component/Layout/index.d.ts +1 -1
  151. package/dist/types/src/component/LoadingTrace/index.d.ts +6 -0
  152. package/dist/types/src/component/ModuleInfo/index.d.ts +1 -1
  153. package/dist/types/src/component/SharedDepsExplorer/index.d.ts +1 -1
  154. package/dist/types/src/component/SharedDepsExplorer/share-utils.d.ts +3 -2
  155. package/dist/types/src/component/ThemeToggle.d.ts +8 -0
  156. package/dist/types/src/hooks/useDevtoolsTheme.d.ts +2 -0
  157. package/dist/types/src/i18n/index.d.ts +5 -0
  158. package/dist/types/src/template/constant.d.ts +1 -1
  159. package/dist/types/src/utils/chrome/index.d.ts +2 -1
  160. package/dist/types/src/utils/chrome/messages.d.ts +3 -0
  161. package/dist/types/src/utils/chrome/observability-plugin.d.ts +1 -0
  162. package/dist/types/src/utils/chrome/observability-shared.d.ts +41 -0
  163. package/dist/types/src/utils/chrome/observability.d.ts +110 -0
  164. package/dist/types/src/utils/chrome/override-remote.d.ts +1 -0
  165. package/dist/types/src/utils/chrome/post-message-listener.d.ts +1 -0
  166. package/dist/types/src/utils/chrome/post-message-start.d.ts +1 -1
  167. package/dist/types/src/utils/chrome/resolve-basic-proxy-core.d.ts +6 -0
  168. package/dist/types/src/utils/chrome/safe-post-message.d.ts +1 -0
  169. package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +0 -3
  170. package/dist/types/src/utils/data/index.d.ts +1 -2
  171. package/dist/types/src/utils/sdk/graph.d.ts +1 -1
  172. package/dist/types/src/utils/sdk/index.d.ts +2 -2
  173. package/dist/types/stories/index.stories.d.ts +2 -1
  174. package/dist/types/template/constant.js +84 -0
  175. package/dist/types/template/index.js +21 -0
  176. package/dist/types/utils/chrome/fast-refresh.js +329 -0
  177. package/dist/types/utils/chrome/index.js +321 -0
  178. package/dist/types/utils/chrome/messages.js +39 -0
  179. package/dist/types/utils/chrome/observability-plugin.js +85 -0
  180. package/dist/types/utils/chrome/observability-shared.js +125 -0
  181. package/dist/types/utils/chrome/observability.js +233 -0
  182. package/dist/types/utils/chrome/override-remote.js +20 -0
  183. package/dist/types/utils/chrome/post-message-init.js +5 -0
  184. package/dist/types/utils/chrome/post-message-listener.js +36 -0
  185. package/dist/types/utils/chrome/post-message-start.js +10 -0
  186. package/dist/types/utils/chrome/post-message.js +91 -0
  187. package/dist/types/utils/chrome/resolve-basic-proxy-core.js +27 -0
  188. package/dist/types/utils/chrome/safe-post-message.js +147 -0
  189. package/dist/types/utils/chrome/snapshot-plugin.js +17 -0
  190. package/dist/types/utils/chrome/storage.js +71 -0
  191. package/dist/types/utils/data/index.js +83 -0
  192. package/dist/types/utils/index.js +27 -0
  193. package/dist/types/utils/sdk/graph.js +213 -0
  194. package/dist/types/utils/sdk/index.js +104 -0
  195. package/dist/types/utils/types/common.js +15 -0
  196. package/dist/types/utils/types/index.js +21 -0
  197. package/dist/types/vendor/basic-proxy-core.js +147 -0
  198. package/dist/types/worker/index.js +175 -0
  199. package/install-deps.bash +7 -3
  200. package/package.json +47 -28
  201. package/dist/es/utils/data/snapshot.js +0 -82
  202. package/dist/lib/utils/data/snapshot.js +0 -107
  203. package/dist/types/src/utils/data/snapshot.d.ts +0 -3
@@ -1,30 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __objRest = (source, exclude) => {
18
- var target = {};
19
- for (var prop in source)
20
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
- target[prop] = source[prop];
22
- if (source != null && __getOwnPropSymbols)
23
- for (var prop of __getOwnPropSymbols(source)) {
24
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
- target[prop] = source[prop];
26
- }
27
- return target;
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
28
4
  };
29
5
  var __async = (__this, __arguments, generator) => {
30
6
  return new Promise((resolve, reject) => {
@@ -46,173 +22,321 @@ var __async = (__this, __arguments, generator) => {
46
22
  step((generator = generator.apply(__this, __arguments)).next());
47
23
  });
48
24
  };
49
- var _a;
50
- import { loadScript } from "@module-federation/sdk";
51
- import { isObject, getUnpkgUrl } from "../index";
25
+ import { getUnpkgUrl } from "../index";
52
26
  import { definePropertyGlobalVal } from "../sdk";
53
27
  import {
54
28
  __FEDERATION_DEVTOOLS__,
55
29
  __EAGER_SHARE__,
56
30
  __ENABLE_FAST_REFRESH__
57
31
  } from "../../template/constant";
58
- const SUPPORT_PKGS = ["react", "react-dom"];
59
- const fetchAndExecuteUmdSync = (url) => {
60
- try {
61
- const response = new XMLHttpRequest();
62
- response.open("GET", url, false);
63
- response.overrideMimeType("text/plain");
64
- response.send();
65
- if (response.status === 200) {
66
- const scriptContent = response.responseText;
67
- const moduleFunction = new Function(scriptContent);
68
- return moduleFunction(window);
69
- } else {
70
- throw new Error(
71
- `Failed to load module from ${url}: HTTP ${response.status}`
32
+ var require_fast_refresh = __commonJS({
33
+ "src/utils/chrome/fast-refresh.ts"(exports) {
34
+ var _a;
35
+ const SUPPORT_PKGS = ["react", "react-dom"];
36
+ const DEFAULT_SHARE_SCOPE = "default";
37
+ const DEFAULT_GLOBAL_KEY_MAP = {
38
+ react: "React",
39
+ "react-dom": "ReactDOM"
40
+ };
41
+ const sanitizeWindowKey = (value) => value.replace(/[^a-zA-Z0-9_$]/g, "_");
42
+ const getShareScopes = (scope) => Array.isArray(scope) && scope.length ? scope : [DEFAULT_SHARE_SCOPE];
43
+ const getDefaultGlobalKey = (pkgName) => DEFAULT_GLOBAL_KEY_MAP[pkgName];
44
+ const getScopedGlobalKey = (scope, pkgName) => `${sanitizeWindowKey(scope)}_${sanitizeWindowKey(pkgName)}`;
45
+ const getWindowValue = (key) => window[key];
46
+ const setWindowValue = (key, value) => {
47
+ window[key] = value;
48
+ };
49
+ const setScopeGlobals = (pkgName, scopes, source) => {
50
+ if (!source) {
51
+ return source;
52
+ }
53
+ scopes.forEach((scope) => {
54
+ setWindowValue(getScopedGlobalKey(scope, pkgName), source);
55
+ });
56
+ return source;
57
+ };
58
+ const getScopeGlobal = (pkgName, scopes) => {
59
+ for (const scope of scopes) {
60
+ const scopeGlobal = getWindowValue(getScopedGlobalKey(scope, pkgName));
61
+ if (scopeGlobal) {
62
+ return scopeGlobal;
63
+ }
64
+ }
65
+ return void 0;
66
+ };
67
+ const getEagerShareInfo = (eagerShare) => {
68
+ if (!Array.isArray(eagerShare) || eagerShare.length < 2) {
69
+ return null;
70
+ }
71
+ const [, version, scopes] = eagerShare;
72
+ if (typeof version !== "string") {
73
+ return null;
74
+ }
75
+ return {
76
+ version,
77
+ scopes: getShareScopes(scopes)
78
+ };
79
+ };
80
+ const updateEagerShareInfo = (devtoolsMessage2, pkgName, version, scopes) => {
81
+ const existing = getEagerShareInfo(devtoolsMessage2[__EAGER_SHARE__]);
82
+ const mergedScopes = Array.from(
83
+ /* @__PURE__ */ new Set([...(existing == null ? void 0 : existing.scopes) || [], ...scopes])
72
84
  );
73
- }
74
- } catch (error) {
75
- throw new Error(`Failed to fetch module from ${url}: ${error.message}`);
76
- }
77
- };
78
- const getDevtoolsMessage = () => {
79
- const devtoolsMessageStr = localStorage.getItem(__FEDERATION_DEVTOOLS__);
80
- if (devtoolsMessageStr) {
81
- try {
82
- return JSON.parse(devtoolsMessageStr);
83
- } catch (e) {
84
- console.debug("Fast Refresh Plugin Error: ", e);
85
- }
86
- }
87
- return null;
88
- };
89
- const devtoolsMessage = getDevtoolsMessage();
90
- if ((devtoolsMessage == null ? void 0 : devtoolsMessage[__ENABLE_FAST_REFRESH__]) && (devtoolsMessage == null ? void 0 : devtoolsMessage[__EAGER_SHARE__])) {
91
- const [_name, version] = devtoolsMessage[__EAGER_SHARE__];
92
- fetchAndExecuteUmdSync(getUnpkgUrl("react", version));
93
- fetchAndExecuteUmdSync(getUnpkgUrl("react-dom", version));
94
- }
95
- const fastRefreshPlugin = () => {
96
- return {
97
- name: "mf-fast-refresh-plugin",
98
- beforeInit(_a2) {
99
- var _b = _a2, { userOptions } = _b, args = __objRest(_b, ["userOptions"]);
100
- const shareInfo = userOptions.shared;
101
- const twinsShareInfo = args.shareInfo;
102
- let enableFastRefresh = false;
103
- let devtoolsMessage2 = {};
85
+ devtoolsMessage2[__EAGER_SHARE__] = [pkgName, version, mergedScopes];
86
+ return {
87
+ shouldReload: !existing || existing.version !== version
88
+ };
89
+ };
90
+ const requestUmdSourceSync = (url) => {
91
+ try {
92
+ const response = new XMLHttpRequest();
93
+ response.open("GET", url, false);
94
+ response.overrideMimeType("text/plain");
95
+ response.send();
96
+ if (response.status === 200) {
97
+ return response.responseText;
98
+ }
99
+ throw new Error(
100
+ `Failed to load module from ${url}: HTTP ${response.status}`
101
+ );
102
+ } catch (error) {
103
+ throw new Error(`Failed to fetch module from ${url}: ${error.message}`);
104
+ }
105
+ };
106
+ const requestUmdSource = (url) => new Promise((resolve, reject) => {
107
+ try {
108
+ const response = new XMLHttpRequest();
109
+ response.open("GET", url, true);
110
+ response.overrideMimeType("text/plain");
111
+ response.onload = () => {
112
+ if (response.status === 200) {
113
+ resolve(response.responseText);
114
+ return;
115
+ }
116
+ reject(
117
+ new Error(
118
+ `Failed to load module from ${url}: HTTP ${response.status}`
119
+ )
120
+ );
121
+ };
122
+ response.onerror = () => {
123
+ reject(new Error(`Failed to fetch module from ${url}`));
124
+ };
125
+ response.send();
126
+ } catch (error) {
127
+ reject(new Error(`Failed to fetch module from ${url}: ${error.message}`));
128
+ }
129
+ });
130
+ const createUmdSandbox = (pkgName, scopes) => {
131
+ const sandboxTarget = /* @__PURE__ */ Object.create(null);
132
+ const sandbox = new Proxy(sandboxTarget, {
133
+ get(target, key) {
134
+ if (typeof key === "symbol") {
135
+ return Reflect.get(target, key);
136
+ }
137
+ if (key in target) {
138
+ return target[key];
139
+ }
140
+ const value = window[key];
141
+ return typeof value === "function" ? value.bind(window) : value;
142
+ },
143
+ set(target, key, value) {
144
+ target[key] = value;
145
+ return true;
146
+ },
147
+ has(target, key) {
148
+ return key in target || key in window;
149
+ }
150
+ });
151
+ sandboxTarget.window = sandbox;
152
+ sandboxTarget.self = sandbox;
153
+ sandboxTarget.globalThis = sandbox;
154
+ sandboxTarget.global = sandbox;
155
+ sandboxTarget.document = window.document;
156
+ if (pkgName === "react-dom") {
157
+ sandboxTarget.React = getScopeGlobal("react", scopes);
158
+ }
159
+ return sandbox;
160
+ };
161
+ const executeUmdModule = (scriptContent, pkgName, scopes) => {
162
+ const sandbox = createUmdSandbox(pkgName, scopes);
163
+ const moduleFunction = new Function(
164
+ "window",
165
+ "self",
166
+ "globalThis",
167
+ "global",
168
+ "document",
169
+ "exports",
170
+ "module",
171
+ "define",
172
+ "require",
173
+ scriptContent
174
+ );
175
+ moduleFunction.call(
176
+ sandbox,
177
+ sandbox,
178
+ sandbox,
179
+ sandbox,
180
+ sandbox,
181
+ sandbox.document,
182
+ void 0,
183
+ void 0,
184
+ void 0,
185
+ void 0
186
+ );
187
+ return sandbox[getDefaultGlobalKey(pkgName)];
188
+ };
189
+ const loadUmdModuleSync = (pkgName, version, scopes) => executeUmdModule(
190
+ requestUmdSourceSync(getUnpkgUrl(pkgName, version)),
191
+ pkgName,
192
+ scopes
193
+ );
194
+ const loadUmdModule = (pkgName, version, scopes) => __async(exports, null, function* () {
195
+ return executeUmdModule(
196
+ yield requestUmdSource(getUnpkgUrl(pkgName, version)),
197
+ pkgName,
198
+ scopes
199
+ );
200
+ });
201
+ const getDevtoolsMessage = () => {
104
202
  const devtoolsMessageStr = localStorage.getItem(__FEDERATION_DEVTOOLS__);
105
203
  if (devtoolsMessageStr) {
106
204
  try {
107
- devtoolsMessage2 = JSON.parse(devtoolsMessageStr);
108
- enableFastRefresh = devtoolsMessage2 == null ? void 0 : devtoolsMessage2[__ENABLE_FAST_REFRESH__];
205
+ return JSON.parse(devtoolsMessageStr);
109
206
  } catch (e) {
110
207
  console.debug("Fast Refresh Plugin Error: ", e);
111
208
  }
112
209
  }
113
- if (!enableFastRefresh) {
114
- return __spreadValues({
115
- userOptions
116
- }, args);
117
- }
118
- if (shareInfo && isObject(shareInfo)) {
119
- let orderResolve;
120
- const orderPromise = new Promise((resolve) => {
121
- orderResolve = resolve;
122
- });
123
- Object.keys(shareInfo).forEach((share) => __async(this, null, function* () {
124
- const sharedArr = Array.isArray(shareInfo[share]) ? shareInfo[share] : [shareInfo[share]];
125
- let twinsSharedArr;
126
- if (twinsShareInfo) {
127
- twinsSharedArr = Array.isArray(twinsShareInfo[share]) ? twinsShareInfo[share] : [twinsShareInfo[share]];
210
+ return null;
211
+ };
212
+ const devtoolsMessage = getDevtoolsMessage();
213
+ const eagerShareInfo = getEagerShareInfo(devtoolsMessage == null ? void 0 : devtoolsMessage[__EAGER_SHARE__]);
214
+ if ((devtoolsMessage == null ? void 0 : devtoolsMessage[__ENABLE_FAST_REFRESH__]) && eagerShareInfo) {
215
+ const { version, scopes } = eagerShareInfo;
216
+ setScopeGlobals("react", scopes, loadUmdModuleSync("react", version, scopes));
217
+ setScopeGlobals(
218
+ "react-dom",
219
+ scopes,
220
+ loadUmdModuleSync("react-dom", version, scopes)
221
+ );
222
+ }
223
+ const fastRefreshPlugin = () => {
224
+ let orderResolve;
225
+ const orderPromise = new Promise((resolve) => {
226
+ orderResolve = resolve;
227
+ });
228
+ return {
229
+ name: "mf-fast-refresh-plugin",
230
+ beforeRegisterShare(args) {
231
+ var _a2;
232
+ const { pkgName, shared } = args;
233
+ if (!SUPPORT_PKGS.includes(pkgName)) {
234
+ return args;
128
235
  }
129
- sharedArr.forEach((shared, idx) => {
130
- var _a3;
131
- if (!SUPPORT_PKGS.includes(share)) {
132
- return;
236
+ const supportPkgName = pkgName;
237
+ const shareScopes = getShareScopes(shared.scope);
238
+ let enableFastRefresh = false;
239
+ let devtoolsMessage2 = {};
240
+ const devtoolsMessageStr = localStorage.getItem(__FEDERATION_DEVTOOLS__);
241
+ if (devtoolsMessageStr) {
242
+ try {
243
+ devtoolsMessage2 = JSON.parse(devtoolsMessageStr);
244
+ enableFastRefresh = devtoolsMessage2 == null ? void 0 : devtoolsMessage2[__ENABLE_FAST_REFRESH__];
245
+ } catch (e) {
246
+ console.debug("Fast Refresh Plugin Error: ", e);
133
247
  }
134
- if ((_a3 = shared.shareConfig) == null ? void 0 : _a3.eager) {
135
- if (!(devtoolsMessage2 == null ? void 0 : devtoolsMessage2[__EAGER_SHARE__])) {
136
- const eagerShare = [];
137
- eagerShare.push(share, shared.version);
138
- devtoolsMessage2[__EAGER_SHARE__] = eagerShare;
139
- localStorage.setItem(
140
- __FEDERATION_DEVTOOLS__,
141
- JSON.stringify(devtoolsMessage2)
142
- );
248
+ }
249
+ if (!enableFastRefresh) {
250
+ return args;
251
+ }
252
+ if (((_a2 = shared.shareConfig) == null ? void 0 : _a2.eager) || shared.lib) {
253
+ if (!(devtoolsMessage2 == null ? void 0 : devtoolsMessage2[__EAGER_SHARE__])) {
254
+ const eagerShareInfo2 = updateEagerShareInfo(
255
+ devtoolsMessage2,
256
+ pkgName,
257
+ shared.version,
258
+ shareScopes
259
+ );
260
+ localStorage.setItem(
261
+ __FEDERATION_DEVTOOLS__,
262
+ JSON.stringify(devtoolsMessage2)
263
+ );
264
+ if (eagerShareInfo2.shouldReload) {
143
265
  window.location.reload();
144
266
  }
145
- if (share === "react-dom") {
146
- shared.lib = () => window.ReactDOM;
147
- }
148
- if (share === "react") {
149
- shared.lib = () => window.React;
150
- }
151
- return;
267
+ } else {
268
+ updateEagerShareInfo(
269
+ devtoolsMessage2,
270
+ pkgName,
271
+ shared.version,
272
+ shareScopes
273
+ );
274
+ localStorage.setItem(
275
+ __FEDERATION_DEVTOOLS__,
276
+ JSON.stringify(devtoolsMessage2)
277
+ );
278
+ }
279
+ if (pkgName === "react-dom") {
280
+ shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
152
281
  }
153
- let get;
154
- if (share === "react") {
155
- get = () => loadScript(getUnpkgUrl(share, shared.version), {
156
- attrs: {
157
- defer: false,
158
- async: false,
159
- "data-mf-injected": "true"
282
+ if (pkgName === "react") {
283
+ shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
284
+ }
285
+ return args;
286
+ }
287
+ let get;
288
+ if (pkgName === "react") {
289
+ get = () => loadUmdModule(supportPkgName, shared.version, shareScopes).then((moduleValue) => {
290
+ setScopeGlobals(supportPkgName, shareScopes, moduleValue);
291
+ return moduleValue;
292
+ }).then(() => {
293
+ orderResolve();
294
+ });
295
+ }
296
+ if (pkgName === "react-dom") {
297
+ get = () => orderPromise.then(
298
+ () => loadUmdModule(supportPkgName, shared.version, shareScopes)
299
+ ).then((result) => {
300
+ setScopeGlobals(supportPkgName, shareScopes, result);
301
+ return result;
302
+ });
303
+ }
304
+ if (typeof get === "function") {
305
+ const finalGet = get;
306
+ if (pkgName === "react") {
307
+ shared.get = () => __async(this, null, function* () {
308
+ if (!getScopeGlobal(supportPkgName, shareScopes)) {
309
+ yield finalGet();
310
+ console.warn(
311
+ "[Module Federation HMR]: You are using Module Federation Devtools to debug online host, it will cause your project load Dev mode React and ReactDOM. If not in this mode, please disable it in Module Federation Devtools"
312
+ );
160
313
  }
161
- }).then(() => {
162
- orderResolve();
314
+ shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
315
+ return () => getScopeGlobal(supportPkgName, shareScopes);
163
316
  });
164
317
  }
165
- if (share === "react-dom") {
166
- get = () => orderPromise.then(
167
- () => loadScript(getUnpkgUrl(share, shared.version), {
168
- attrs: { defer: true, async: false }
169
- })
170
- );
171
- }
172
- if (typeof get === "function") {
173
- if (share === "react") {
174
- shared.get = () => __async(this, null, function* () {
175
- if (!window.React) {
176
- yield get();
177
- console.warn(
178
- "[Module Federation HMR]: You are using Module Federation Devtools to debug online host, it will cause your project load Dev mode React and ReactDOM. If not in this mode, please disable it in Module Federation Devtools"
179
- );
180
- }
181
- shared.lib = () => window.React;
182
- return () => window.React;
183
- });
184
- }
185
- if (share === "react-dom") {
186
- shared.get = () => __async(this, null, function* () {
187
- if (!window.ReactDOM) {
188
- yield get();
189
- }
190
- shared.lib = () => window.ReactDOM;
191
- return () => window.ReactDOM;
192
- });
193
- }
194
- if (twinsShareInfo) {
195
- twinsSharedArr[idx].get = shared.get;
196
- }
318
+ if (pkgName === "react-dom") {
319
+ shared.get = () => __async(this, null, function* () {
320
+ if (!getScopeGlobal(supportPkgName, shareScopes)) {
321
+ yield finalGet();
322
+ }
323
+ shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
324
+ return () => getScopeGlobal(supportPkgName, shareScopes);
325
+ });
197
326
  }
198
- });
199
- }));
200
- return __spreadValues({
201
- userOptions
202
- }, args);
203
- } else {
204
- return __spreadValues({
205
- userOptions
206
- }, args);
207
- }
327
+ }
328
+ return args;
329
+ }
330
+ };
331
+ };
332
+ if (!(window == null ? void 0 : window.__FEDERATION__)) {
333
+ definePropertyGlobalVal(window, "__FEDERATION__", {});
334
+ definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
208
335
  }
209
- };
210
- };
211
- if (!(window == null ? void 0 : window.__FEDERATION__)) {
212
- definePropertyGlobalVal(window, "__FEDERATION__", {});
213
- definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
214
- }
215
- if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
216
- window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
217
- }
218
- (_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(fastRefreshPlugin());
336
+ if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
337
+ window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
338
+ }
339
+ (_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(fastRefreshPlugin());
340
+ }
341
+ });
342
+ export default require_fast_refresh();
@@ -39,7 +39,25 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import { FormID } from "../../template/constant";
41
41
  import { definePropertyGlobalVal } from "../sdk";
42
+ import { sanitizePostMessagePayload } from "./safe-post-message";
42
43
  export * from "./storage";
44
+ const isModuleInfoRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
45
+ const isModuleInfoSyncMessage = (value) => isModuleInfoRecord(value) && ("moduleInfo" in value || "updateModule" in value || "share" in value);
46
+ const normalizeModuleInfoPayload = (moduleInfo) => {
47
+ const sanitized = sanitizePostMessagePayload(moduleInfo);
48
+ if (!isModuleInfoRecord(sanitized)) {
49
+ return {};
50
+ }
51
+ return Object.entries(sanitized).reduce(
52
+ (moduleMap, [moduleId, snapshot]) => {
53
+ if (moduleId === "extendInfos" || isModuleInfoRecord(snapshot)) {
54
+ moduleMap[moduleId] = snapshot;
55
+ }
56
+ return moduleMap;
57
+ },
58
+ {}
59
+ );
60
+ };
43
61
  const sleep = (num) => {
44
62
  return new Promise((resolve) => {
45
63
  setTimeout(() => {
@@ -69,10 +87,11 @@ const syncActiveTab = (tabId) => __async(void 0, null, function* () {
69
87
  setTargetTab(tab);
70
88
  return tab;
71
89
  }
72
- const [activeTab] = yield getTabs({
90
+ const tabs = yield getTabs({
73
91
  active: true,
74
92
  lastFocusedWindow: true
75
93
  });
94
+ const activeTab = Array.isArray(tabs) ? tabs[0] : void 0;
76
95
  setTargetTab(activeTab);
77
96
  return activeTab;
78
97
  } catch (error) {
@@ -95,9 +114,7 @@ function getInspectWindowTabId() {
95
114
  function(info, error) {
96
115
  const { tabId } = chrome.devtools.inspectedWindow;
97
116
  getTabs().then((tabs) => {
98
- const target = tabs.find(
99
- (tab) => tab.id === tabId
100
- );
117
+ const target = Array.isArray(tabs) ? tabs.find((tab) => tab.id === tabId) : void 0;
101
118
  setTargetTab(target);
102
119
  });
103
120
  console.log(
@@ -133,43 +150,45 @@ const refreshModuleInfo = () => __async(void 0, null, function* () {
133
150
  const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
134
151
  var _a, _b;
135
152
  if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
136
- callback(
137
- JSON.parse(
138
- JSON.stringify((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo)
139
- )
140
- );
153
+ callback(normalizeModuleInfoPayload((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo));
141
154
  }
142
155
  yield sleep(300);
143
156
  const listener = (message) => {
144
157
  const { data } = message;
145
- if (!data || (data == null ? void 0 : data.appInfos)) {
158
+ if (!isModuleInfoSyncMessage(data) || (data == null ? void 0 : data.appInfos)) {
146
159
  return;
147
160
  }
148
161
  if (!(window == null ? void 0 : window.__FEDERATION__)) {
149
162
  definePropertyGlobalVal(window, "__FEDERATION__", {});
150
163
  definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
151
164
  }
152
- window.__FEDERATION__.originModuleInfo = JSON.parse(
153
- JSON.stringify(data == null ? void 0 : data.moduleInfo)
165
+ window.__FEDERATION__.originModuleInfo = "moduleInfo" in data ? normalizeModuleInfoPayload(data.moduleInfo) : normalizeModuleInfoPayload(
166
+ window.__FEDERATION__.originModuleInfo || window.__FEDERATION__.moduleInfo
154
167
  );
155
- if (data == null ? void 0 : data.updateModule) {
168
+ const updateModule = data.updateModule;
169
+ if (isModuleInfoRecord(updateModule) && typeof updateModule.name === "string") {
170
+ const updateModuleName = updateModule.name;
156
171
  const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
157
172
  const shouldUpdate = !moduleIds.some(
158
- (id) => id.includes(data.updateModule.name)
173
+ (id) => id.includes(updateModuleName)
159
174
  );
160
175
  if (shouldUpdate) {
161
- const destination = data.updateModule.entry || data.updateModule.version;
162
- window.__FEDERATION__.originModuleInfo[`${data.updateModule.name}:${destination}`] = {
163
- remoteEntry: destination,
164
- version: destination
165
- };
176
+ const destination = typeof updateModule.entry === "string" ? updateModule.entry : typeof updateModule.version === "string" ? updateModule.version : void 0;
177
+ if (destination) {
178
+ window.__FEDERATION__.originModuleInfo[`${updateModuleName}:${destination}`] = {
179
+ remoteEntry: destination,
180
+ version: destination
181
+ };
182
+ }
166
183
  }
167
184
  }
168
185
  if (data == null ? void 0 : data.share) {
169
- window.__FEDERATION__.__SHARE__ = data.share;
186
+ window.__FEDERATION__.__SHARE__ = sanitizePostMessagePayload(
187
+ data.share
188
+ );
170
189
  }
171
- window.__FEDERATION__.moduleInfo = JSON.parse(
172
- JSON.stringify(window.__FEDERATION__.originModuleInfo)
190
+ window.__FEDERATION__.moduleInfo = normalizeModuleInfoPayload(
191
+ window.__FEDERATION__.originModuleInfo
173
192
  );
174
193
  console.log("getGlobalModuleInfo window", window.__FEDERATION__);
175
194
  callback(window.__FEDERATION__.moduleInfo);
@@ -257,6 +276,7 @@ export {
257
276
  injectPostMessage,
258
277
  injectScript,
259
278
  injectToast,
279
+ normalizeModuleInfoPayload,
260
280
  refreshModuleInfo,
261
281
  setChromeStorage,
262
282
  setTargetTab,
@@ -1,6 +1,12 @@
1
1
  const MESSAGE_OPEN_SIDE_PANEL = "mf-devtools/open-side-panel";
2
2
  const MESSAGE_ACTIVE_TAB_CHANGED = "mf-devtools/active-tab-changed";
3
+ const MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT = "mf-devtools/observability-event";
4
+ const OBSERVABILITY_DEVTOOLS_SOURCE = "module-federation/observability";
5
+ const OBSERVABILITY_DEVTOOLS_STORAGE_KEY = "__MF_DEVTOOLS_OBSERVABILITY_CONFIG__";
3
6
  export {
4
7
  MESSAGE_ACTIVE_TAB_CHANGED,
5
- MESSAGE_OPEN_SIDE_PANEL
8
+ MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
9
+ MESSAGE_OPEN_SIDE_PANEL,
10
+ OBSERVABILITY_DEVTOOLS_SOURCE,
11
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY
6
12
  };