@module-federation/devtools 0.0.0-next-20250925034616 → 0.0.0-perf-devtools-20260106124142

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 (92) hide show
  1. package/dist/es/App.js +328 -22
  2. package/dist/es/App.module.js +1 -1
  3. package/dist/es/App_module.css +291 -5
  4. package/dist/es/component/DependencyGraph/index.js +205 -0
  5. package/dist/es/component/DependencyGraph/index.module.js +5 -0
  6. package/dist/es/component/DependencyGraph/index_module.css +97 -0
  7. package/dist/es/component/{GraphItem → DependencyGraphItem}/index.js +15 -6
  8. package/dist/es/component/DependencyGraphItem/index.module.js +5 -0
  9. package/dist/es/component/DependencyGraphItem/index_module.css +95 -0
  10. package/dist/es/component/Form/index.js +191 -109
  11. package/dist/es/component/Form/index.module.js +1 -1
  12. package/dist/es/component/Form/index_module.css +179 -25
  13. package/dist/es/component/Layout/index.js +288 -51
  14. package/dist/es/component/Layout/index.module.js +1 -1
  15. package/dist/es/component/Layout/index_module.css +52 -32
  16. package/dist/es/component/ModuleInfo/index.js +289 -0
  17. package/dist/es/component/ModuleInfo/index.module.js +5 -0
  18. package/dist/es/component/ModuleInfo/index_module.css +183 -0
  19. package/dist/es/component/SharedDepsExplorer/FocusResultDisplay.js +39 -0
  20. package/dist/es/component/SharedDepsExplorer/index.js +505 -0
  21. package/dist/es/component/SharedDepsExplorer/share-utils.js +206 -0
  22. package/dist/es/index.css +15 -0
  23. package/dist/es/template/constant.js +5 -19
  24. package/dist/es/utils/chrome/fast-refresh.js +80 -7
  25. package/dist/es/utils/chrome/index.js +91 -38
  26. package/dist/es/utils/chrome/messages.js +6 -0
  27. package/dist/es/utils/chrome/post-message-listener.js +2 -1
  28. package/dist/es/utils/chrome/post-message-start.js +10 -2
  29. package/dist/es/utils/chrome/storage.js +6 -1
  30. package/dist/es/utils/sdk/graph.js +25 -4
  31. package/dist/es/utils/sdk/index.js +9 -0
  32. package/dist/es/worker/index.js +168 -1
  33. package/dist/lib/App.js +318 -17
  34. package/dist/lib/App.module.js +1 -1
  35. package/dist/lib/App_module.css +291 -5
  36. package/dist/lib/component/DependencyGraph/index.js +227 -0
  37. package/dist/lib/component/{GraphItem → DependencyGraph}/index.module.js +1 -1
  38. package/dist/lib/component/DependencyGraph/index_module.css +97 -0
  39. package/dist/lib/component/{GraphItem → DependencyGraphItem}/index.js +18 -9
  40. package/dist/lib/component/{Graph → DependencyGraphItem}/index.module.js +1 -1
  41. package/dist/lib/component/DependencyGraphItem/index_module.css +95 -0
  42. package/dist/lib/component/Form/index.js +188 -107
  43. package/dist/lib/component/Form/index.module.js +1 -1
  44. package/dist/lib/component/Form/index_module.css +179 -25
  45. package/dist/lib/component/Layout/index.js +280 -48
  46. package/dist/lib/component/Layout/index.module.js +1 -1
  47. package/dist/lib/component/Layout/index_module.css +52 -32
  48. package/dist/lib/component/ModuleInfo/index.js +319 -0
  49. package/dist/lib/component/ModuleInfo/index.module.js +25 -0
  50. package/dist/lib/component/ModuleInfo/index_module.css +183 -0
  51. package/dist/lib/component/SharedDepsExplorer/FocusResultDisplay.js +59 -0
  52. package/dist/lib/component/SharedDepsExplorer/index.js +512 -0
  53. package/dist/lib/component/SharedDepsExplorer/share-utils.js +237 -0
  54. package/dist/lib/index.css +15 -0
  55. package/dist/lib/template/constant.js +7 -17
  56. package/dist/lib/utils/chrome/fast-refresh.js +77 -8
  57. package/dist/lib/utils/chrome/index.js +94 -38
  58. package/dist/lib/utils/chrome/messages.js +31 -0
  59. package/dist/lib/utils/chrome/post-message-listener.js +2 -1
  60. package/dist/lib/utils/chrome/post-message-start.js +10 -2
  61. package/dist/lib/utils/chrome/storage.js +5 -0
  62. package/dist/lib/utils/sdk/graph.js +25 -4
  63. package/dist/lib/utils/sdk/index.js +10 -0
  64. package/dist/lib/worker/index.js +156 -1
  65. package/dist/types/src/App.d.ts +0 -1
  66. package/dist/types/src/component/{Graph → DependencyGraph}/index.d.ts +0 -1
  67. package/dist/types/src/component/{GraphItem → DependencyGraphItem}/index.d.ts +0 -1
  68. package/dist/types/src/component/Form/index.d.ts +2 -0
  69. package/dist/types/src/component/Layout/index.d.ts +0 -1
  70. package/dist/types/src/component/ModuleInfo/index.d.ts +8 -0
  71. package/dist/types/src/component/SharedDepsExplorer/FocusResultDisplay.d.ts +15 -0
  72. package/dist/types/src/component/SharedDepsExplorer/index.d.ts +6 -0
  73. package/dist/types/src/component/SharedDepsExplorer/share-utils.d.ts +44 -0
  74. package/dist/types/src/index.d.ts +2 -1
  75. package/dist/types/src/init.d.ts +0 -1
  76. package/dist/types/src/template/constant.d.ts +3 -5
  77. package/dist/types/src/utils/chrome/index.d.ts +5 -3
  78. package/dist/types/src/utils/chrome/messages.d.ts +2 -0
  79. package/dist/types/src/utils/chrome/storage.d.ts +5 -4
  80. package/dist/types/src/utils/sdk/graph.d.ts +2 -1
  81. package/dist/types/src/utils/sdk/index.d.ts +1 -0
  82. package/dist/types/src/utils/types/common.d.ts +4 -0
  83. package/dist/types/src/worker/index.d.ts +1 -0
  84. package/package.json +18 -14
  85. package/dist/es/component/Graph/index.js +0 -127
  86. package/dist/es/component/Graph/index.module.js +0 -5
  87. package/dist/es/component/Graph/index_module.css +0 -12
  88. package/dist/es/component/GraphItem/index.module.js +0 -5
  89. package/dist/es/component/GraphItem/index_module.css +0 -61
  90. package/dist/lib/component/Graph/index.js +0 -149
  91. package/dist/lib/component/Graph/index_module.css +0 -12
  92. package/dist/lib/component/GraphItem/index_module.css +0 -61
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var share_utils_exports = {};
20
+ __export(share_utils_exports, {
21
+ computeLoadedStatus: () => computeLoadedStatus,
22
+ computeReuseStatus: () => computeReuseStatus,
23
+ computeShareStats: () => computeShareStats,
24
+ findPackageProvider: () => findPackageProvider,
25
+ getFilterOptions: () => getFilterOptions,
26
+ getReusedVersions: () => getReusedVersions,
27
+ groupByProviderScopePackage: () => groupByProviderScopePackage,
28
+ normalizeShareData: () => normalizeShareData
29
+ });
30
+ module.exports = __toCommonJS(share_utils_exports);
31
+ function isRecord(value) {
32
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
33
+ }
34
+ function computeLoadedStatus(entry) {
35
+ if (entry.loaded === true) {
36
+ return "loaded";
37
+ }
38
+ if (entry.loading) {
39
+ return "loading";
40
+ }
41
+ return "not-loaded";
42
+ }
43
+ function computeReuseStatus(entry) {
44
+ const useIn = Array.isArray(entry.useIn) ? entry.useIn : [];
45
+ const { from } = entry;
46
+ const reused = useIn.some((consumer) => consumer && consumer !== from);
47
+ return reused;
48
+ }
49
+ function normalizeEntry({
50
+ provider,
51
+ scope,
52
+ packageName,
53
+ versionKey,
54
+ entry
55
+ }) {
56
+ var _a;
57
+ if (!isRecord(entry)) {
58
+ return null;
59
+ }
60
+ const sharedEntry = entry;
61
+ const loadedStatus = computeLoadedStatus(sharedEntry);
62
+ const reuseStatus = computeReuseStatus(sharedEntry);
63
+ const useIn = Array.isArray(sharedEntry.useIn) ? sharedEntry.useIn : [];
64
+ return {
65
+ id: `${provider}::${scope}::${packageName}::${versionKey}`,
66
+ provider,
67
+ scope,
68
+ packageName,
69
+ version: sharedEntry.version || versionKey,
70
+ from: sharedEntry.from,
71
+ useIn,
72
+ shareConfig: (_a = sharedEntry.shareConfig) != null ? _a : {},
73
+ strategy: sharedEntry.strategy,
74
+ loaded: sharedEntry.loaded,
75
+ loading: sharedEntry.loading,
76
+ loadedStatus,
77
+ reuseStatus
78
+ };
79
+ }
80
+ function normalizeShareData(raw) {
81
+ if (!raw || !isRecord(raw)) {
82
+ return [];
83
+ }
84
+ const items = [];
85
+ Object.entries(raw).forEach(([topKey, topValue]) => {
86
+ if (!isRecord(topValue)) {
87
+ return;
88
+ }
89
+ if (topKey === "default") {
90
+ const provider2 = "default";
91
+ const scope = "default";
92
+ const packagesObj = topValue;
93
+ Object.entries(packagesObj).forEach(([pkgName, versions]) => {
94
+ if (pkgName === "version" || !isRecord(versions)) {
95
+ return;
96
+ }
97
+ Object.entries(versions).forEach(([versionKey, entry]) => {
98
+ const normalized = normalizeEntry({
99
+ provider: provider2,
100
+ scope,
101
+ packageName: pkgName,
102
+ versionKey,
103
+ entry
104
+ });
105
+ if (normalized) {
106
+ items.push(normalized);
107
+ }
108
+ });
109
+ });
110
+ return;
111
+ }
112
+ const provider = topKey;
113
+ const scopesObj = topValue;
114
+ Object.entries(scopesObj).forEach(([scopeName, scopeValue]) => {
115
+ if (scopeName === "version" || !isRecord(scopeValue)) {
116
+ return;
117
+ }
118
+ const packagesObj = scopeValue;
119
+ Object.entries(packagesObj).forEach(([pkgName, versions]) => {
120
+ if (pkgName === "version" || !isRecord(versions)) {
121
+ return;
122
+ }
123
+ Object.entries(versions).forEach(([versionKey, entry]) => {
124
+ const normalized = normalizeEntry({
125
+ provider,
126
+ scope: scopeName,
127
+ packageName: pkgName,
128
+ versionKey,
129
+ entry
130
+ });
131
+ if (normalized) {
132
+ items.push(normalized);
133
+ }
134
+ });
135
+ });
136
+ });
137
+ });
138
+ return items;
139
+ }
140
+ function computeShareStats(versions) {
141
+ const providerSet = /* @__PURE__ */ new Set();
142
+ const scopeSet = /* @__PURE__ */ new Set();
143
+ const packageSet = /* @__PURE__ */ new Set();
144
+ let loadedCount = 0;
145
+ let reusedCount = 0;
146
+ versions.forEach((v) => {
147
+ providerSet.add(v.provider);
148
+ scopeSet.add(v.scope);
149
+ packageSet.add(v.packageName);
150
+ if (v.loadedStatus === "loaded") {
151
+ loadedCount += 1;
152
+ }
153
+ if (v.reuseStatus) {
154
+ reusedCount += 1;
155
+ }
156
+ });
157
+ return {
158
+ totalProviders: providerSet.size,
159
+ totalScopes: scopeSet.size,
160
+ totalPackages: packageSet.size,
161
+ totalVersions: versions.length,
162
+ loadedCount,
163
+ reusedCount
164
+ };
165
+ }
166
+ function groupByProviderScopePackage(versions) {
167
+ const tree = {};
168
+ versions.forEach((v) => {
169
+ if (!tree[v.provider]) {
170
+ tree[v.provider] = {};
171
+ }
172
+ if (!tree[v.provider][v.scope]) {
173
+ tree[v.provider][v.scope] = {};
174
+ }
175
+ if (!tree[v.provider][v.scope][v.packageName]) {
176
+ tree[v.provider][v.scope][v.packageName] = [];
177
+ }
178
+ tree[v.provider][v.scope][v.packageName].push(v);
179
+ });
180
+ return tree;
181
+ }
182
+ function getFilterOptions(versions) {
183
+ const providerSet = /* @__PURE__ */ new Set();
184
+ const scopeSet = /* @__PURE__ */ new Set();
185
+ const packageSet = /* @__PURE__ */ new Set();
186
+ const versionSet = /* @__PURE__ */ new Set();
187
+ versions.forEach((v) => {
188
+ providerSet.add(v.provider);
189
+ scopeSet.add(v.scope);
190
+ packageSet.add(v.packageName);
191
+ versionSet.add(v.version);
192
+ });
193
+ return {
194
+ providers: Array.from(providerSet).sort(),
195
+ scopes: Array.from(scopeSet).sort(),
196
+ packages: Array.from(packageSet).sort(),
197
+ versions: Array.from(versionSet).sort()
198
+ };
199
+ }
200
+ function findPackageProvider(versions, packageName, version) {
201
+ var _a;
202
+ const candidates = versions.filter(
203
+ (v) => v.packageName === packageName && (!version || v.version === version)
204
+ );
205
+ if (!candidates.length) {
206
+ return null;
207
+ }
208
+ const providers = Array.from(new Set(candidates.map((v) => v.from))).sort();
209
+ const hasLoaded = candidates.some((v) => v.loadedStatus === "loaded");
210
+ const hasLoading = !hasLoaded && candidates.some((v) => v.loadedStatus === "loading");
211
+ let status = "not-loaded";
212
+ if (hasLoaded) {
213
+ status = "loaded";
214
+ } else if (hasLoading) {
215
+ status = "loading";
216
+ }
217
+ return {
218
+ packageName,
219
+ version: version || ((_a = candidates[0]) == null ? void 0 : _a.version),
220
+ providers,
221
+ status
222
+ };
223
+ }
224
+ function getReusedVersions(versions) {
225
+ return versions.filter((v) => v.reuseStatus === true);
226
+ }
227
+ // Annotate the CommonJS export names for ESM import in node:
228
+ 0 && (module.exports = {
229
+ computeLoadedStatus,
230
+ computeReuseStatus,
231
+ computeShareStats,
232
+ findPackageProvider,
233
+ getFilterOptions,
234
+ getReusedVersions,
235
+ groupByProviderScopePackage,
236
+ normalizeShareData
237
+ });
@@ -0,0 +1,15 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+ .loaded-status-tag {
5
+ color: white !important;
6
+ background-color: black !important;
7
+ }
8
+ .reused-status-tag {
9
+ background-color: greenyellow !important;
10
+ }
11
+ .common-tag {
12
+ color: rgb(113 113 122 / var(--tw-text-opacity)) !important;
13
+ background-color: #fff !important;
14
+ border-color: rgba(228, 228, 231, 0.5) !important;
15
+ }
@@ -2,21 +2,7 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
6
  var __export = (target, all) => {
21
7
  for (var name in all)
22
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -34,7 +20,9 @@ var constant_exports = {};
34
20
  __export(constant_exports, {
35
21
  BROWSER_ENV_KEY: () => BROWSER_ENV_KEY,
36
22
  ENABLEHMR: () => ENABLEHMR,
23
+ ENABLE_CLIP: () => ENABLE_CLIP,
37
24
  FormID: () => FormID,
25
+ __EAGER_SHARE__: () => __EAGER_SHARE__,
38
26
  __ENABLE_FAST_REFRESH__: () => __ENABLE_FAST_REFRESH__,
39
27
  __FEDERATION_DEVTOOLS__: () => __FEDERATION_DEVTOOLS__,
40
28
  defaultDataItem: () => defaultDataItem,
@@ -45,6 +33,7 @@ __export(constant_exports, {
45
33
  module.exports = __toCommonJS(constant_exports);
46
34
  const FormID = "FormID";
47
35
  const ENABLEHMR = "enableHMR";
36
+ const ENABLE_CLIP = "enableClip";
48
37
  const proxyFormField = "proxyFormField";
49
38
  const defaultDataItem = {
50
39
  key: "",
@@ -52,9 +41,7 @@ const defaultDataItem = {
52
41
  checked: true
53
42
  };
54
43
  const defaultModuleData = {
55
- proxyFormField: [
56
- __spreadValues({}, defaultDataItem)
57
- ]
44
+ proxyFormField: []
58
45
  };
59
46
  const statusInfo = {
60
47
  noProxy: {
@@ -79,13 +66,16 @@ const statusInfo = {
79
66
  }
80
67
  };
81
68
  const __ENABLE_FAST_REFRESH__ = "enableFastRefresh";
69
+ const __EAGER_SHARE__ = "eagerShare";
82
70
  const BROWSER_ENV_KEY = "MF_ENV";
83
71
  const __FEDERATION_DEVTOOLS__ = "__MF_DEVTOOLS__";
84
72
  // Annotate the CommonJS export names for ESM import in node:
85
73
  0 && (module.exports = {
86
74
  BROWSER_ENV_KEY,
87
75
  ENABLEHMR,
76
+ ENABLE_CLIP,
88
77
  FormID,
78
+ __EAGER_SHARE__,
89
79
  __ENABLE_FAST_REFRESH__,
90
80
  __FEDERATION_DEVTOOLS__,
91
81
  defaultDataItem,
@@ -50,8 +50,45 @@ var __async = (__this, __arguments, generator) => {
50
50
  var import_sdk = require("@module-federation/sdk");
51
51
  var import__ = require("../index");
52
52
  var import_sdk2 = require("../sdk");
53
- var import_template = require("../../template");
53
+ var import_constant = require("../../template/constant");
54
54
  var _a;
55
+ const SUPPORT_PKGS = ["react", "react-dom"];
56
+ const fetchAndExecuteUmdSync = (url) => {
57
+ try {
58
+ const response = new XMLHttpRequest();
59
+ response.open("GET", url, false);
60
+ response.overrideMimeType("text/plain");
61
+ response.send();
62
+ if (response.status === 200) {
63
+ const scriptContent = response.responseText;
64
+ const moduleFunction = new Function(scriptContent);
65
+ return moduleFunction(window);
66
+ } else {
67
+ throw new Error(
68
+ `Failed to load module from ${url}: HTTP ${response.status}`
69
+ );
70
+ }
71
+ } catch (error) {
72
+ throw new Error(`Failed to fetch module from ${url}: ${error.message}`);
73
+ }
74
+ };
75
+ const getDevtoolsMessage = () => {
76
+ const devtoolsMessageStr = localStorage.getItem(import_constant.__FEDERATION_DEVTOOLS__);
77
+ if (devtoolsMessageStr) {
78
+ try {
79
+ return JSON.parse(devtoolsMessageStr);
80
+ } catch (e) {
81
+ console.debug("Fast Refresh Plugin Error: ", e);
82
+ }
83
+ }
84
+ return null;
85
+ };
86
+ const devtoolsMessage = getDevtoolsMessage();
87
+ if ((devtoolsMessage == null ? void 0 : devtoolsMessage[import_constant.__ENABLE_FAST_REFRESH__]) && (devtoolsMessage == null ? void 0 : devtoolsMessage[import_constant.__EAGER_SHARE__])) {
88
+ const [_name, version] = devtoolsMessage[import_constant.__EAGER_SHARE__];
89
+ fetchAndExecuteUmdSync((0, import__.getUnpkgUrl)("react", version));
90
+ fetchAndExecuteUmdSync((0, import__.getUnpkgUrl)("react-dom", version));
91
+ }
55
92
  const fastRefreshPlugin = () => {
56
93
  return {
57
94
  name: "mf-fast-refresh-plugin",
@@ -59,17 +96,22 @@ const fastRefreshPlugin = () => {
59
96
  var _b = _a2, { userOptions } = _b, args = __objRest(_b, ["userOptions"]);
60
97
  const shareInfo = userOptions.shared;
61
98
  const twinsShareInfo = args.shareInfo;
62
- let enableFastRefresh;
63
- let devtoolsMessage;
64
- const devtoolsMessageStr = localStorage.getItem(import_template.__FEDERATION_DEVTOOLS__);
99
+ let enableFastRefresh = false;
100
+ let devtoolsMessage2 = {};
101
+ const devtoolsMessageStr = localStorage.getItem(import_constant.__FEDERATION_DEVTOOLS__);
65
102
  if (devtoolsMessageStr) {
66
103
  try {
67
- devtoolsMessage = JSON.parse(devtoolsMessageStr);
68
- enableFastRefresh = devtoolsMessage == null ? void 0 : devtoolsMessage.enableFastRefresh;
104
+ devtoolsMessage2 = JSON.parse(devtoolsMessageStr);
105
+ enableFastRefresh = devtoolsMessage2 == null ? void 0 : devtoolsMessage2[import_constant.__ENABLE_FAST_REFRESH__];
69
106
  } catch (e) {
70
107
  console.debug("Fast Refresh Plugin Error: ", e);
71
108
  }
72
109
  }
110
+ if (!enableFastRefresh) {
111
+ return __spreadValues({
112
+ userOptions
113
+ }, args);
114
+ }
73
115
  if (shareInfo && (0, import__.isObject)(shareInfo)) {
74
116
  let orderResolve;
75
117
  const orderPromise = new Promise((resolve) => {
@@ -82,10 +124,37 @@ const fastRefreshPlugin = () => {
82
124
  twinsSharedArr = Array.isArray(twinsShareInfo[share]) ? twinsShareInfo[share] : [twinsShareInfo[share]];
83
125
  }
84
126
  sharedArr.forEach((shared, idx) => {
127
+ var _a3;
128
+ if (!SUPPORT_PKGS.includes(share)) {
129
+ return;
130
+ }
131
+ if ((_a3 = shared.shareConfig) == null ? void 0 : _a3.eager) {
132
+ if (!(devtoolsMessage2 == null ? void 0 : devtoolsMessage2[import_constant.__EAGER_SHARE__])) {
133
+ const eagerShare = [];
134
+ eagerShare.push(share, shared.version);
135
+ devtoolsMessage2[import_constant.__EAGER_SHARE__] = eagerShare;
136
+ localStorage.setItem(
137
+ import_constant.__FEDERATION_DEVTOOLS__,
138
+ JSON.stringify(devtoolsMessage2)
139
+ );
140
+ window.location.reload();
141
+ }
142
+ if (share === "react-dom") {
143
+ shared.lib = () => window.ReactDOM;
144
+ }
145
+ if (share === "react") {
146
+ shared.lib = () => window.React;
147
+ }
148
+ return;
149
+ }
85
150
  let get;
86
151
  if (share === "react") {
87
152
  get = () => (0, import_sdk.loadScript)((0, import__.getUnpkgUrl)(share, shared.version), {
88
- attrs: { defer: true, async: false }
153
+ attrs: {
154
+ defer: false,
155
+ async: false,
156
+ "data-mf-injected": "true"
157
+ }
89
158
  }).then(() => {
90
159
  orderResolve();
91
160
  });
@@ -97,7 +166,7 @@ const fastRefreshPlugin = () => {
97
166
  })
98
167
  );
99
168
  }
100
- if (enableFastRefresh && typeof get === "function") {
169
+ if (typeof get === "function") {
101
170
  if (share === "react") {
102
171
  shared.get = () => __async(this, null, function* () {
103
172
  if (!window.React) {
@@ -66,7 +66,10 @@ __export(chrome_exports, {
66
66
  injectPostMessage: () => injectPostMessage,
67
67
  injectScript: () => injectScript,
68
68
  injectToast: () => injectToast,
69
- setChromeStorage: () => setChromeStorage
69
+ refreshModuleInfo: () => refreshModuleInfo,
70
+ setChromeStorage: () => setChromeStorage,
71
+ setTargetTab: () => setTargetTab,
72
+ syncActiveTab: () => syncActiveTab
70
73
  });
71
74
  module.exports = __toCommonJS(chrome_exports);
72
75
  var import_constant = require("../../template/constant");
@@ -87,12 +90,37 @@ const injectPostMessage = (postMessageUrl) => {
87
90
  const TabInfo = {
88
91
  currentTabId: 0
89
92
  };
93
+ const setTargetTab = (tab) => {
94
+ if (!tab || typeof tab.id !== "number") {
95
+ return;
96
+ }
97
+ window.targetTab = tab;
98
+ TabInfo.currentTabId = tab.id;
99
+ };
100
+ const syncActiveTab = (tabId) => __async(void 0, null, function* () {
101
+ try {
102
+ if (typeof tabId === "number") {
103
+ const tab = yield chrome.tabs.get(tabId);
104
+ setTargetTab(tab);
105
+ return tab;
106
+ }
107
+ const [activeTab] = yield getTabs({
108
+ active: true,
109
+ lastFocusedWindow: true
110
+ });
111
+ setTargetTab(activeTab);
112
+ return activeTab;
113
+ } catch (error) {
114
+ console.warn("[Module Federation Devtools] syncActiveTab failed", error);
115
+ return void 0;
116
+ }
117
+ });
90
118
  function getCurrentTabId() {
91
119
  return TabInfo.currentTabId;
92
120
  }
93
121
  function getInspectWindowTabId() {
94
122
  return new Promise((resolve, reject) => {
95
- var _a;
123
+ var _a, _b;
96
124
  if ((_a = chrome == null ? void 0 : chrome.devtools) == null ? void 0 : _a.inspectedWindow) {
97
125
  if (chrome.isDevMode) {
98
126
  resolve(0);
@@ -105,7 +133,7 @@ function getInspectWindowTabId() {
105
133
  const target = tabs.find(
106
134
  (tab) => tab.id === tabId
107
135
  );
108
- window.targetTab = target;
136
+ setTargetTab(target);
109
137
  });
110
138
  console.log(
111
139
  "chrome.devtools.inspectedWindow.tabId",
@@ -119,7 +147,7 @@ function getInspectWindowTabId() {
119
147
  }
120
148
  );
121
149
  } else {
122
- if (window.targetTab && window.targetTab.id) {
150
+ if ((_b = window.targetTab) == null ? void 0 : _b.id) {
123
151
  const tabId = window.targetTab.id;
124
152
  TabInfo.currentTabId = tabId;
125
153
  resolve(tabId);
@@ -129,48 +157,67 @@ function getInspectWindowTabId() {
129
157
  }
130
158
  });
131
159
  }
160
+ const refreshModuleInfo = () => __async(void 0, null, function* () {
161
+ var _a;
162
+ if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
163
+ }
164
+ yield sleep(50);
165
+ const postMessageStartUrl = getUrl("post-message-start.js");
166
+ yield injectScript(injectPostMessage, false, postMessageStartUrl);
167
+ });
132
168
  const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
169
+ var _a, _b;
170
+ if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
171
+ callback(
172
+ JSON.parse(
173
+ JSON.stringify((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo)
174
+ )
175
+ );
176
+ }
133
177
  yield sleep(300);
134
- chrome.runtime.onMessage.addListener(
135
- (message) => {
136
- const { origin, data } = message;
137
- if (!data || (data == null ? void 0 : data.appInfos)) {
138
- return;
139
- }
140
- if (!(window == null ? void 0 : window.__FEDERATION__)) {
141
- (0, import_sdk2.definePropertyGlobalVal)(window, "__FEDERATION__", {});
142
- (0, import_sdk2.definePropertyGlobalVal)(window, "__VMOK__", window.__FEDERATION__);
143
- }
144
- window.__FEDERATION__.originModuleInfo = JSON.parse(
145
- JSON.stringify(data == null ? void 0 : data.moduleInfo)
178
+ const listener = (message) => {
179
+ const { data } = message;
180
+ if (!data || (data == null ? void 0 : data.appInfos)) {
181
+ return;
182
+ }
183
+ if (!(window == null ? void 0 : window.__FEDERATION__)) {
184
+ (0, import_sdk2.definePropertyGlobalVal)(window, "__FEDERATION__", {});
185
+ (0, import_sdk2.definePropertyGlobalVal)(window, "__VMOK__", window.__FEDERATION__);
186
+ }
187
+ window.__FEDERATION__.originModuleInfo = JSON.parse(
188
+ JSON.stringify(data == null ? void 0 : data.moduleInfo)
189
+ );
190
+ if (data == null ? void 0 : data.updateModule) {
191
+ const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
192
+ const shouldUpdate = !moduleIds.some(
193
+ (id) => id.includes(data.updateModule.name)
146
194
  );
147
- if (data == null ? void 0 : data.updateModule) {
148
- const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
149
- const shouldUpdate = !moduleIds.some(
150
- (id) => id.includes(data.updateModule.name)
151
- );
152
- if (shouldUpdate) {
153
- const destination = data.updateModule.entry || data.updateModule.version;
154
- window.__FEDERATION__.originModuleInfo[`${data.updateModule.name}:${destination}`] = {
155
- remoteEntry: destination,
156
- version: destination
157
- };
158
- }
195
+ if (shouldUpdate) {
196
+ const destination = data.updateModule.entry || data.updateModule.version;
197
+ window.__FEDERATION__.originModuleInfo[`${data.updateModule.name}:${destination}`] = {
198
+ remoteEntry: destination,
199
+ version: destination
200
+ };
159
201
  }
160
- window.__FEDERATION__.moduleInfo = JSON.parse(
161
- JSON.stringify(window.__FEDERATION__.originModuleInfo)
162
- );
163
- callback(window.__FEDERATION__.moduleInfo);
164
202
  }
165
- );
166
- const postMessageStartUrl = getUrl("post-message-start.js");
167
- yield injectScript(injectPostMessage, false, postMessageStartUrl);
203
+ if (data == null ? void 0 : data.share) {
204
+ window.__FEDERATION__.__SHARE__ = data.share;
205
+ }
206
+ window.__FEDERATION__.moduleInfo = JSON.parse(
207
+ JSON.stringify(window.__FEDERATION__.originModuleInfo)
208
+ );
209
+ console.log("getGlobalModuleInfo window", window.__FEDERATION__);
210
+ callback(window.__FEDERATION__.moduleInfo);
211
+ };
212
+ chrome.runtime.onMessage.addListener(listener);
213
+ yield refreshModuleInfo();
214
+ return () => chrome.runtime.onMessage.removeListener(listener);
168
215
  });
169
216
  const getTabs = (queryOptions = {}) => chrome.tabs.query(queryOptions);
170
217
  const getScope = () => __async(void 0, null, function* () {
171
218
  const activeTab = window.targetTab;
172
- const favIconUrl = activeTab == null ? void 0 : activeTab.favIconUrl;
173
- return favIconUrl || "noScope";
219
+ const tabId = activeTab == null ? void 0 : activeTab.id;
220
+ return tabId ? String(tabId) : "noScope";
174
221
  });
175
222
  const injectScript = (excuteScript, world = false, ...args) => __async(void 0, null, function* () {
176
223
  yield getInspectWindowTabId();
@@ -181,10 +228,16 @@ const injectScript = (excuteScript, world = false, ...args) => __async(void 0, n
181
228
  func: excuteScript,
182
229
  world: world ? "MAIN" : "ISOLATED",
183
230
  args
184
- }).then(() => {
231
+ }).then((results) => {
232
+ var _a;
185
233
  console.log("InjectScript success, excuteScript:", args);
234
+ if (Array.isArray(results) && results.length) {
235
+ return (_a = results[0]) == null ? void 0 : _a.result;
236
+ }
237
+ return void 0;
186
238
  }).catch((e) => {
187
239
  console.log(e, "InjectScript fail, excuteScript:", args);
240
+ return void 0;
188
241
  });
189
242
  });
190
243
  const getUrl = (file) => {
@@ -240,6 +293,9 @@ const setChromeStorage = (formData) => {
240
293
  injectPostMessage,
241
294
  injectScript,
242
295
  injectToast,
296
+ refreshModuleInfo,
243
297
  setChromeStorage,
298
+ setTargetTab,
299
+ syncActiveTab,
244
300
  ...require("./storage")
245
301
  });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var messages_exports = {};
20
+ __export(messages_exports, {
21
+ MESSAGE_ACTIVE_TAB_CHANGED: () => MESSAGE_ACTIVE_TAB_CHANGED,
22
+ MESSAGE_OPEN_SIDE_PANEL: () => MESSAGE_OPEN_SIDE_PANEL
23
+ });
24
+ module.exports = __toCommonJS(messages_exports);
25
+ const MESSAGE_OPEN_SIDE_PANEL = "mf-devtools/open-side-panel";
26
+ const MESSAGE_ACTIVE_TAB_CHANGED = "mf-devtools/active-tab-changed";
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ MESSAGE_ACTIVE_TAB_CHANGED,
30
+ MESSAGE_OPEN_SIDE_PANEL
31
+ });
@@ -11,7 +11,8 @@ if (window.moduleHandler) {
11
11
  origin,
12
12
  data: {
13
13
  moduleInfo: data.moduleInfo,
14
- updateModule: data.updateModule
14
+ updateModule: data.updateModule,
15
+ share: data.share
15
16
  }
16
17
  }).catch(() => {
17
18
  return false;