@module-federation/devtools 2.3.3 → 2.5.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 (48) hide show
  1. package/README.md +3 -0
  2. package/dist/es/App.js +17 -2
  3. package/dist/es/App_module.css +3 -3
  4. package/dist/es/component/LoadingTrace/index.js +944 -0
  5. package/dist/es/component/LoadingTrace/index.module.js +5 -0
  6. package/dist/es/component/LoadingTrace/index_module.css +876 -0
  7. package/dist/es/i18n/index.js +178 -0
  8. package/dist/es/utils/chrome/fast-refresh.js +297 -173
  9. package/dist/es/utils/chrome/index.js +3 -4
  10. package/dist/es/utils/chrome/messages.js +7 -1
  11. package/dist/es/utils/chrome/observability-plugin.js +93 -0
  12. package/dist/es/utils/chrome/observability-shared.js +99 -0
  13. package/dist/es/utils/chrome/observability.js +208 -0
  14. package/dist/es/utils/chrome/override-remote.js +2 -42
  15. package/dist/es/utils/chrome/post-message-listener.js +14 -0
  16. package/dist/es/utils/chrome/snapshot-plugin.js +2 -36
  17. package/dist/es/utils/data/index.js +5 -25
  18. package/dist/es/vendor/basic-proxy-core.js +155 -0
  19. package/dist/es/worker/index.js +27 -8
  20. package/dist/lib/App.js +17 -2
  21. package/dist/lib/App_module.css +3 -3
  22. package/dist/lib/component/LoadingTrace/index.js +954 -0
  23. package/dist/lib/component/LoadingTrace/index.module.js +25 -0
  24. package/dist/lib/component/LoadingTrace/index_module.css +876 -0
  25. package/dist/lib/i18n/index.js +178 -0
  26. package/dist/lib/utils/chrome/fast-refresh.js +250 -135
  27. package/dist/lib/utils/chrome/index.js +3 -4
  28. package/dist/lib/utils/chrome/messages.js +11 -2
  29. package/dist/lib/utils/chrome/observability-plugin.js +86 -0
  30. package/dist/lib/utils/chrome/observability-shared.js +126 -0
  31. package/dist/lib/utils/chrome/observability.js +234 -0
  32. package/dist/lib/utils/chrome/override-remote.js +5 -52
  33. package/dist/lib/utils/chrome/post-message-listener.js +11 -0
  34. package/dist/lib/utils/chrome/snapshot-plugin.js +5 -46
  35. package/dist/lib/utils/data/index.js +6 -28
  36. package/dist/lib/vendor/basic-proxy-core.js +147 -0
  37. package/dist/lib/worker/index.js +27 -8
  38. package/dist/types/src/component/LoadingTrace/index.d.ts +6 -0
  39. package/dist/types/src/utils/chrome/messages.d.ts +3 -0
  40. package/dist/types/src/utils/chrome/observability-plugin.d.ts +1 -0
  41. package/dist/types/src/utils/chrome/observability-shared.d.ts +41 -0
  42. package/dist/types/src/utils/chrome/observability.d.ts +110 -0
  43. package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +0 -3
  44. package/dist/types/src/utils/data/index.d.ts +0 -1
  45. package/package.json +4 -3
  46. package/dist/es/utils/data/snapshot.js +0 -82
  47. package/dist/lib/utils/data/snapshot.js +0 -107
  48. 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();
@@ -70,10 +70,11 @@ const syncActiveTab = (tabId) => __async(void 0, null, function* () {
70
70
  setTargetTab(tab);
71
71
  return tab;
72
72
  }
73
- const [activeTab] = yield getTabs({
73
+ const tabs = yield getTabs({
74
74
  active: true,
75
75
  lastFocusedWindow: true
76
76
  });
77
+ const activeTab = Array.isArray(tabs) ? tabs[0] : void 0;
77
78
  setTargetTab(activeTab);
78
79
  return activeTab;
79
80
  } catch (error) {
@@ -96,9 +97,7 @@ function getInspectWindowTabId() {
96
97
  function(info, error) {
97
98
  const { tabId } = chrome.devtools.inspectedWindow;
98
99
  getTabs().then((tabs) => {
99
- const target = tabs.find(
100
- (tab) => tab.id === tabId
101
- );
100
+ const target = Array.isArray(tabs) ? tabs.find((tab) => tab.id === tabId) : void 0;
102
101
  setTargetTab(target);
103
102
  });
104
103
  console.log(
@@ -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
  };
@@ -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();