@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
@@ -0,0 +1,93 @@
1
+ import {
2
+ ChromeObservabilityPlugin
3
+ } from "@module-federation/observability-plugin/chrome-devtool";
4
+ import {
5
+ OBSERVABILITY_DEVTOOLS_SOURCE,
6
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY
7
+ } from "./messages";
8
+ import {
9
+ createObservabilityPluginOptions,
10
+ normalizeObservabilityDevtoolsConfig
11
+ } from "./observability-shared";
12
+ const DEVTOOLS_PLUGIN_NAME = "observability-plugin:chrome-extension";
13
+ const LEGACY_DEVTOOLS_PLUGIN_NAME = "observability-plugin-devtools";
14
+ const getFederationWindow = () => window;
15
+ const safeReadStoredConfig = () => {
16
+ var _a;
17
+ try {
18
+ const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(
19
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY
20
+ );
21
+ if (!raw) {
22
+ return void 0;
23
+ }
24
+ return normalizeObservabilityDevtoolsConfig(JSON.parse(raw));
25
+ } catch (e) {
26
+ return void 0;
27
+ }
28
+ };
29
+ const defineWritableGlobal = (key, value) => {
30
+ const targetWindow = getFederationWindow();
31
+ try {
32
+ Object.defineProperty(targetWindow, key, {
33
+ value,
34
+ configurable: true,
35
+ writable: true
36
+ });
37
+ } catch (e) {
38
+ targetWindow[key] = value;
39
+ }
40
+ };
41
+ const ensureFederationGlobal = () => {
42
+ var _a;
43
+ const targetWindow = getFederationWindow();
44
+ const federation = targetWindow.__FEDERATION__ || targetWindow.__VMOK__ || {};
45
+ if (!targetWindow.__FEDERATION__) {
46
+ defineWritableGlobal("__FEDERATION__", federation);
47
+ }
48
+ if (!targetWindow.__VMOK__) {
49
+ defineWritableGlobal("__VMOK__", targetWindow.__FEDERATION__);
50
+ }
51
+ if (!((_a = targetWindow.__FEDERATION__) == null ? void 0 : _a.__GLOBAL_PLUGIN__)) {
52
+ targetWindow.__FEDERATION__ = targetWindow.__FEDERATION__ || federation;
53
+ targetWindow.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
54
+ }
55
+ return targetWindow.__FEDERATION__;
56
+ };
57
+ const notifyInstalled = (status, reason, config) => {
58
+ try {
59
+ window.postMessage(
60
+ {
61
+ schemaVersion: 1,
62
+ source: OBSERVABILITY_DEVTOOLS_SOURCE,
63
+ kind: status,
64
+ reason,
65
+ config,
66
+ createdAt: Date.now()
67
+ },
68
+ "*"
69
+ );
70
+ } catch (e) {
71
+ }
72
+ };
73
+ const install = () => {
74
+ const config = safeReadStoredConfig();
75
+ if (!(config == null ? void 0 : config.enabled)) {
76
+ return;
77
+ }
78
+ const federation = ensureFederationGlobal();
79
+ const globalPlugins = (federation == null ? void 0 : federation.__GLOBAL_PLUGIN__) || [];
80
+ if (globalPlugins.some(
81
+ (plugin2) => (plugin2 == null ? void 0 : plugin2.name) === DEVTOOLS_PLUGIN_NAME || (plugin2 == null ? void 0 : plugin2.name) === LEGACY_DEVTOOLS_PLUGIN_NAME
82
+ )) {
83
+ notifyInstalled("skipped", "already-installed", config);
84
+ return;
85
+ }
86
+ const plugin = ChromeObservabilityPlugin(
87
+ createObservabilityPluginOptions(config)
88
+ );
89
+ globalPlugins.push(plugin);
90
+ federation.__GLOBAL_PLUGIN__ = globalPlugins;
91
+ notifyInstalled("installed", void 0, config);
92
+ };
93
+ install();
@@ -0,0 +1,99 @@
1
+ import { OBSERVABILITY_DEVTOOLS_SOURCE } from "./messages";
2
+ const CHROME_OBSERVABILITY_SCOPE = "chrome_extension";
3
+ const MIN_EVENTS = 10;
4
+ const MAX_EVENTS = 1e3;
5
+ const DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG = {
6
+ enabled: true,
7
+ level: "verbose",
8
+ maxEvents: 300,
9
+ console: true,
10
+ browser: {
11
+ enabled: true,
12
+ scope: CHROME_OBSERVABILITY_SCOPE,
13
+ mode: "development"
14
+ },
15
+ trace: {
16
+ printStart: true
17
+ },
18
+ react: {
19
+ injectLoadedCallback: false,
20
+ remoteIds: []
21
+ }
22
+ };
23
+ const isObject = (value) => typeof value === "object" && value !== null;
24
+ const normalizeBoolean = (value, fallback) => typeof value === "boolean" ? value : fallback;
25
+ const normalizeLevel = (value) => value === "error" || value === "summary" || value === "verbose" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.level;
26
+ const normalizeMode = (value) => value === "production" || value === "development" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.mode;
27
+ const normalizeMaxEvents = (value) => {
28
+ const parsed = Number(value);
29
+ if (!Number.isFinite(parsed)) {
30
+ return DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.maxEvents;
31
+ }
32
+ return Math.max(MIN_EVENTS, Math.min(MAX_EVENTS, Math.floor(parsed)));
33
+ };
34
+ const normalizeScope = (value) => {
35
+ if (typeof value !== "string") {
36
+ return CHROME_OBSERVABILITY_SCOPE;
37
+ }
38
+ const trimmed = value.trim().replace(/[^\w:@.-]+/g, "-");
39
+ return trimmed || CHROME_OBSERVABILITY_SCOPE;
40
+ };
41
+ const normalizeObservabilityDevtoolsConfig = (value) => {
42
+ const source = isObject(value) ? value : {};
43
+ const browser = isObject(source.browser) ? source.browser : {};
44
+ const trace = isObject(source.trace) ? source.trace : {};
45
+ return {
46
+ enabled: normalizeBoolean(
47
+ source.enabled,
48
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.enabled
49
+ ),
50
+ level: normalizeLevel(source.level),
51
+ maxEvents: normalizeMaxEvents(source.maxEvents),
52
+ console: normalizeBoolean(
53
+ source.console,
54
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.console
55
+ ),
56
+ browser: {
57
+ enabled: normalizeBoolean(
58
+ browser.enabled,
59
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.enabled
60
+ ),
61
+ scope: normalizeScope(browser.scope),
62
+ mode: normalizeMode(browser.mode)
63
+ },
64
+ trace: {
65
+ printStart: normalizeBoolean(
66
+ trace.printStart,
67
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.trace.printStart
68
+ )
69
+ },
70
+ react: {
71
+ injectLoadedCallback: false,
72
+ remoteIds: []
73
+ }
74
+ };
75
+ };
76
+ const createObservabilityPluginOptions = (config) => ({
77
+ enabled: config.enabled,
78
+ level: config.level,
79
+ maxEvents: config.maxEvents,
80
+ console: config.console,
81
+ browser: {
82
+ enabled: config.browser.enabled,
83
+ scope: config.browser.scope,
84
+ mode: config.browser.mode
85
+ },
86
+ trace: {
87
+ printStart: config.trace.printStart
88
+ },
89
+ devtools: {
90
+ enabled: true,
91
+ source: OBSERVABILITY_DEVTOOLS_SOURCE
92
+ }
93
+ });
94
+ export {
95
+ CHROME_OBSERVABILITY_SCOPE,
96
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
97
+ createObservabilityPluginOptions,
98
+ normalizeObservabilityDevtoolsConfig
99
+ };
@@ -0,0 +1,208 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { injectScript } from "./index";
22
+ import { OBSERVABILITY_DEVTOOLS_STORAGE_KEY } from "./messages";
23
+ import {
24
+ CHROME_OBSERVABILITY_SCOPE,
25
+ DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
26
+ normalizeObservabilityDevtoolsConfig
27
+ } from "./observability-shared";
28
+ const USER_OBSERVABILITY_PLUGIN_NAME = "observability-plugin";
29
+ const CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin:chrome-extension";
30
+ const LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin-devtools";
31
+ const OBSERVABILITY_SNAPSHOT_CONTEXT = {
32
+ chromeScope: CHROME_OBSERVABILITY_SCOPE,
33
+ userPluginName: USER_OBSERVABILITY_PLUGIN_NAME,
34
+ chromePluginNames: [
35
+ CHROME_OBSERVABILITY_PLUGIN_NAME,
36
+ LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME
37
+ ]
38
+ };
39
+ const readConfigFromPage = (storageKey) => {
40
+ var _a;
41
+ try {
42
+ const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
43
+ return raw ? JSON.parse(raw) : null;
44
+ } catch (e) {
45
+ return null;
46
+ }
47
+ };
48
+ const writeConfigToPage = (storageKey, config) => {
49
+ var _a;
50
+ (_a = window.localStorage) == null ? void 0 : _a.setItem(storageKey, JSON.stringify(config));
51
+ return config;
52
+ };
53
+ const removeConfigFromPage = (storageKey) => {
54
+ var _a;
55
+ (_a = window.localStorage) == null ? void 0 : _a.removeItem(storageKey);
56
+ return true;
57
+ };
58
+ const reloadPage = () => {
59
+ var _a;
60
+ (_a = globalThis.location) == null ? void 0 : _a.reload();
61
+ };
62
+ const readSnapshotFromPage = (storageKey, context) => {
63
+ const chromeScope = typeof (context == null ? void 0 : context.chromeScope) === "string" ? context.chromeScope : "chrome_extension";
64
+ const userPluginName = typeof (context == null ? void 0 : context.userPluginName) === "string" ? context.userPluginName : "observability-plugin";
65
+ const chromePluginNames = Array.isArray(context == null ? void 0 : context.chromePluginNames) ? context.chromePluginNames : [
66
+ "observability-plugin:chrome-extension",
67
+ "observability-plugin-devtools"
68
+ ];
69
+ const safeCopy = (value) => {
70
+ try {
71
+ return JSON.parse(JSON.stringify(value));
72
+ } catch (e) {
73
+ return void 0;
74
+ }
75
+ };
76
+ const rawConfig = (() => {
77
+ var _a;
78
+ try {
79
+ const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
80
+ return raw ? JSON.parse(raw) : null;
81
+ } catch (e) {
82
+ return null;
83
+ }
84
+ })();
85
+ const federation = window.__FEDERATION__ || window.__VMOK__;
86
+ const readers = (federation == null ? void 0 : federation.__OBSERVABILITY__) || {};
87
+ const reports = [];
88
+ const scopes = Object.keys(readers);
89
+ const isChromeObservabilityPluginName = (name) => chromePluginNames.includes(String(name));
90
+ const hasUserObservabilityPluginFromInstances = Array.isArray(
91
+ federation == null ? void 0 : federation.__INSTANCES__
92
+ ) ? federation.__INSTANCES__.some((instance) => {
93
+ var _a;
94
+ const plugins = (_a = instance == null ? void 0 : instance.options) == null ? void 0 : _a.plugins;
95
+ if (!Array.isArray(plugins)) {
96
+ return false;
97
+ }
98
+ return plugins.some(
99
+ (plugin) => (plugin == null ? void 0 : plugin.name) === userPluginName && !isChromeObservabilityPluginName(plugin == null ? void 0 : plugin.name)
100
+ );
101
+ }) : false;
102
+ const hasUserObservabilityPluginFromReaders = scopes.some(
103
+ (scope) => scope !== chromeScope
104
+ );
105
+ scopes.forEach((scope) => {
106
+ const reader = readers[scope];
107
+ if (!reader || typeof reader.getReports !== "function") {
108
+ return;
109
+ }
110
+ try {
111
+ const scopeReports = reader.getReports({ limit: 100 });
112
+ if (!Array.isArray(scopeReports)) {
113
+ return;
114
+ }
115
+ scopeReports.forEach((report) => {
116
+ const copied = safeCopy(report);
117
+ if (copied == null ? void 0 : copied.traceId) {
118
+ copied.__scope = scope;
119
+ reports.push(copied);
120
+ }
121
+ });
122
+ } catch (e) {
123
+ }
124
+ });
125
+ return {
126
+ config: rawConfig,
127
+ stored: Boolean(rawConfig),
128
+ scopes,
129
+ reports,
130
+ hasUserObservabilityPlugin: hasUserObservabilityPluginFromInstances || hasUserObservabilityPluginFromReaders
131
+ };
132
+ };
133
+ const readObservabilityConfig = () => __async(void 0, null, function* () {
134
+ const config = yield injectScript(
135
+ readConfigFromPage,
136
+ false,
137
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY
138
+ );
139
+ return normalizeObservabilityDevtoolsConfig(
140
+ config || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
141
+ );
142
+ });
143
+ const applyObservabilityConfig = (config) => __async(void 0, null, function* () {
144
+ return injectScript(
145
+ writeConfigToPage,
146
+ false,
147
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
148
+ normalizeObservabilityDevtoolsConfig(config)
149
+ );
150
+ });
151
+ const disableObservabilityConfig = () => __async(void 0, null, function* () {
152
+ return injectScript(removeConfigFromPage, false, OBSERVABILITY_DEVTOOLS_STORAGE_KEY);
153
+ });
154
+ const reloadInspectedPage = () => __async(void 0, null, function* () {
155
+ return injectScript(reloadPage, false);
156
+ });
157
+ const readObservabilitySnapshot = () => __async(void 0, null, function* () {
158
+ const snapshot = yield injectScript(
159
+ readSnapshotFromPage,
160
+ true,
161
+ OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
162
+ OBSERVABILITY_SNAPSHOT_CONTEXT
163
+ );
164
+ return {
165
+ config: normalizeObservabilityDevtoolsConfig(
166
+ (snapshot == null ? void 0 : snapshot.config) || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
167
+ ),
168
+ stored: Boolean(snapshot == null ? void 0 : snapshot.stored),
169
+ scopes: Array.isArray(snapshot == null ? void 0 : snapshot.scopes) ? snapshot.scopes : [],
170
+ reports: Array.isArray(snapshot == null ? void 0 : snapshot.reports) ? snapshot.reports : [],
171
+ hasUserObservabilityPlugin: Boolean(snapshot == null ? void 0 : snapshot.hasUserObservabilityPlugin)
172
+ };
173
+ });
174
+ const mergeObservabilityReports = (currentReports, incomingReports) => {
175
+ const merged = /* @__PURE__ */ new Map();
176
+ currentReports.forEach((report) => {
177
+ if (report.traceId) {
178
+ merged.set(report.traceId, report);
179
+ }
180
+ });
181
+ incomingReports.forEach((report) => {
182
+ if (report.traceId) {
183
+ merged.set(report.traceId, report);
184
+ }
185
+ });
186
+ return Array.from(merged.values()).sort((left, right) => {
187
+ if ((right.updatedAt || 0) !== (left.updatedAt || 0)) {
188
+ return (right.updatedAt || 0) - (left.updatedAt || 0);
189
+ }
190
+ return (right.startedAt || 0) - (left.startedAt || 0);
191
+ });
192
+ };
193
+ const getObservabilityReportScopeLabel = (report) => {
194
+ const scope = report.__scope;
195
+ if (!scope || scope === CHROME_OBSERVABILITY_SCOPE) {
196
+ return void 0;
197
+ }
198
+ return `custom: ${scope}`;
199
+ };
200
+ export {
201
+ applyObservabilityConfig,
202
+ disableObservabilityConfig,
203
+ getObservabilityReportScopeLabel,
204
+ mergeObservabilityReports,
205
+ readObservabilityConfig,
206
+ readObservabilitySnapshot,
207
+ reloadInspectedPage
208
+ };
@@ -0,0 +1,7 @@
1
+ import {
2
+ resolveBasicProxyCore
3
+ } from "./resolve-basic-proxy-core";
4
+ const basicProxyCore = resolveBasicProxyCore(
5
+ require("../../vendor/basic-proxy-core.js")
6
+ );
7
+ basicProxyCore.registerOverridePlugin(globalThis);
@@ -1,18 +1,36 @@
1
+ import { sanitizePostMessagePayload } from "./safe-post-message";
2
+ import {
3
+ MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
4
+ OBSERVABILITY_DEVTOOLS_SOURCE
5
+ } from "./messages";
6
+ const isModuleInfoPayload = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
7
+ const getMessageData = (data) => Boolean(data) && typeof data === "object" ? data : {};
1
8
  if (window.moduleHandler) {
2
9
  window.removeEventListener("message", window.moduleHandler);
3
10
  } else {
4
11
  window.moduleHandler = (event) => {
5
- const { origin, data } = event;
6
- if (!data.moduleInfo) {
12
+ const { origin } = event;
13
+ const data = getMessageData(event.data);
14
+ if ((data == null ? void 0 : data.source) === OBSERVABILITY_DEVTOOLS_SOURCE) {
15
+ chrome.runtime.sendMessage({
16
+ type: MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
17
+ origin,
18
+ data: sanitizePostMessagePayload(data)
19
+ }).catch(() => {
20
+ return false;
21
+ });
22
+ return;
23
+ }
24
+ if (!isModuleInfoPayload(data.moduleInfo)) {
7
25
  return;
8
26
  }
9
27
  chrome.runtime.sendMessage({
10
28
  origin,
11
- data: {
29
+ data: sanitizePostMessagePayload({
12
30
  moduleInfo: data.moduleInfo,
13
31
  updateModule: data.updateModule,
14
32
  share: data.share
15
- }
33
+ })
16
34
  }).catch(() => {
17
35
  return false;
18
36
  });
@@ -1,16 +1,10 @@
1
1
  var _a, _b;
2
+ import { sanitizePostMessagePayload } from "./safe-post-message";
2
3
  const moduleInfo = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.moduleInfo;
3
4
  window.postMessage(
4
- {
5
+ sanitizePostMessagePayload({
5
6
  moduleInfo,
6
- share: JSON.parse(
7
- JSON.stringify((_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__, (_key, value) => {
8
- if (typeof value === "function") {
9
- return "Function";
10
- }
11
- return value;
12
- })
13
- )
14
- },
7
+ share: (_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__
8
+ }),
15
9
  "*"
16
10
  );
@@ -29,18 +29,27 @@ var __objRest = (source, exclude) => {
29
29
  var _a;
30
30
  import helpers from "@module-federation/runtime/helpers";
31
31
  import { definePropertyGlobalVal } from "../sdk";
32
+ import { sanitizePostMessagePayload } from "./safe-post-message";
32
33
  const getModuleInfo = () => {
33
34
  return {
34
35
  name: "mf-devtool-getModuleInfo-plugin",
35
36
  loadRemoteSnapshot(_a2) {
36
- var _b = _a2, { options, moduleInfo, remoteSnapshot } = _b, res = __objRest(_b, ["options", "moduleInfo", "remoteSnapshot"]);
37
+ var _b = _a2, {
38
+ options,
39
+ moduleInfo,
40
+ remoteSnapshot
41
+ } = _b, res = __objRest(_b, [
42
+ "options",
43
+ "moduleInfo",
44
+ "remoteSnapshot"
45
+ ]);
37
46
  const globalSnapshot = helpers.global.getGlobalSnapshot();
38
47
  if (!options || options.inBrowser) {
39
48
  window.postMessage(
40
- {
49
+ sanitizePostMessagePayload({
41
50
  moduleInfo: globalSnapshot,
42
51
  updateModule: moduleInfo
43
- },
52
+ }),
44
53
  "*"
45
54
  );
46
55
  }
@@ -0,0 +1,4 @@
1
+ const resolveBasicProxyCore = (basicProxyCoreModule) => "default" in basicProxyCoreModule ? basicProxyCoreModule.default : basicProxyCoreModule;
2
+ export {
3
+ resolveBasicProxyCore
4
+ };
@@ -0,0 +1,124 @@
1
+ const FUNCTION_PLACEHOLDER = "function(){}";
2
+ const UNDEFINED_PLACEHOLDER = "[undefined]";
3
+ const CIRCULAR_PLACEHOLDER = "[circular]";
4
+ const NON_SERIALIZABLE_PLACEHOLDER = "[unserializable]";
5
+ const toStringTag = (value) => Object.prototype.toString.call(value).slice(8, -1);
6
+ const isPlainObject = (value) => {
7
+ if (!value || typeof value !== "object") {
8
+ return false;
9
+ }
10
+ const proto = Object.getPrototypeOf(value);
11
+ return proto === Object.prototype || proto === null;
12
+ };
13
+ const sanitizeValue = (value, seen) => {
14
+ if (value === null || typeof value === "string" || typeof value === "number") {
15
+ return Number.isNaN(value) ? "[NaN]" : value;
16
+ }
17
+ if (typeof value === "boolean") {
18
+ return value;
19
+ }
20
+ if (typeof value === "function") {
21
+ return FUNCTION_PLACEHOLDER;
22
+ }
23
+ if (typeof value === "undefined") {
24
+ return UNDEFINED_PLACEHOLDER;
25
+ }
26
+ if (typeof value === "bigint" || typeof value === "symbol") {
27
+ return String(value);
28
+ }
29
+ if (!(value instanceof Object)) {
30
+ return NON_SERIALIZABLE_PLACEHOLDER;
31
+ }
32
+ if (seen.has(value)) {
33
+ return CIRCULAR_PLACEHOLDER;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ const next2 = [];
37
+ seen.set(value, next2);
38
+ value.forEach((item, index) => {
39
+ next2[index] = sanitizeValue(item, seen);
40
+ });
41
+ return next2;
42
+ }
43
+ if (value instanceof Date) {
44
+ return value.toISOString();
45
+ }
46
+ if (value instanceof RegExp) {
47
+ return value.toString();
48
+ }
49
+ if (value instanceof Error) {
50
+ const next2 = {
51
+ name: value.name,
52
+ message: value.message,
53
+ stack: value.stack || ""
54
+ };
55
+ seen.set(value, next2);
56
+ return next2;
57
+ }
58
+ if (value instanceof Map) {
59
+ const next2 = [];
60
+ seen.set(value, next2);
61
+ next2.push(
62
+ ...Array.from(value.entries()).map(([key, item]) => [
63
+ sanitizeValue(key, seen),
64
+ sanitizeValue(item, seen)
65
+ ])
66
+ );
67
+ return next2;
68
+ }
69
+ if (value instanceof Set) {
70
+ const next2 = [];
71
+ seen.set(value, next2);
72
+ next2.push(
73
+ ...Array.from(value.values()).map((item) => sanitizeValue(item, seen))
74
+ );
75
+ return next2;
76
+ }
77
+ if (ArrayBuffer.isView(value)) {
78
+ return Array.from(new Uint8Array(value.buffer));
79
+ }
80
+ if (value instanceof ArrayBuffer) {
81
+ return Array.from(new Uint8Array(value));
82
+ }
83
+ if (typeof Node !== "undefined" && value instanceof Node) {
84
+ return `[${toStringTag(value)}]`;
85
+ }
86
+ if (typeof Window !== "undefined" && value instanceof Window) {
87
+ return "[Window]";
88
+ }
89
+ if (typeof Document !== "undefined" && value instanceof Document) {
90
+ return "[Document]";
91
+ }
92
+ const next = {};
93
+ seen.set(value, next);
94
+ const entries = isPlainObject(value) ? Object.keys(value).map((key) => {
95
+ try {
96
+ return [key, value[key]];
97
+ } catch (_error) {
98
+ return [key, NON_SERIALIZABLE_PLACEHOLDER];
99
+ }
100
+ }) : Reflect.ownKeys(value).map((key) => {
101
+ try {
102
+ return [
103
+ String(key),
104
+ value[key]
105
+ ];
106
+ } catch (_error) {
107
+ return [String(key), NON_SERIALIZABLE_PLACEHOLDER];
108
+ }
109
+ });
110
+ entries.forEach(([key, item]) => {
111
+ try {
112
+ next[key] = sanitizeValue(item, seen);
113
+ } catch (_error) {
114
+ next[key] = NON_SERIALIZABLE_PLACEHOLDER;
115
+ }
116
+ });
117
+ return next;
118
+ };
119
+ const sanitizePostMessagePayload = (payload) => {
120
+ return sanitizeValue(payload, /* @__PURE__ */ new WeakMap());
121
+ };
122
+ export {
123
+ sanitizePostMessagePayload
124
+ };
@@ -1,36 +1,2 @@
1
- var _a;
2
- import { MODULE_DEVTOOL_IDENTIFIER } from "@module-federation/sdk";
3
- import runtimeHelpers from "@module-federation/runtime/helpers";
4
- import { definePropertyGlobalVal } from "../sdk";
5
- const chromeDevtoolsPlugin = function() {
6
- return {
7
- name: "mf-chrome-devtools-inject-snapshot-plugin",
8
- beforeLoadRemoteSnapshot({ options }) {
9
- const { nativeGlobal } = runtimeHelpers.global;
10
- if (!options || options.inBrowser) {
11
- const realLocalStorage = nativeGlobal.localStorage || localStorage;
12
- const debugModuleInfoStr = realLocalStorage.getItem(
13
- MODULE_DEVTOOL_IDENTIFIER
14
- );
15
- if (debugModuleInfoStr && !nativeGlobal.__INIT_VMOK_CHROME_DEVTOOL_PLUGIN__) {
16
- const chromeDevtoolSnapshot = JSON.parse(debugModuleInfoStr);
17
- if (chromeDevtoolSnapshot) {
18
- runtimeHelpers.global.addGlobalSnapshot(chromeDevtoolSnapshot);
19
- nativeGlobal.__INIT_VMOK_CHROME_DEVTOOL_PLUGIN__ = true;
20
- console.warn(
21
- "[Module Federation Devtools]: You are using the chrome devtool to proxy online module"
22
- );
23
- }
24
- }
25
- }
26
- }
27
- };
28
- };
29
- if (!(window == null ? void 0 : window.__FEDERATION__)) {
30
- definePropertyGlobalVal(window, "__FEDERATION__", {});
31
- definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
32
- }
33
- if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
34
- window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
35
- }
36
- (_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(chromeDevtoolsPlugin());
1
+ const basicProxyCore = require("../../vendor/basic-proxy-core.js");
2
+ basicProxyCore.registerSnapshotPlugin(globalThis);