@module-federation/devtools 2.7.0 → 2.8.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.
- package/dist/types/App.css +13 -0
- package/dist/types/App.js +519 -0
- package/dist/types/App.module.js +24 -0
- package/dist/types/App_module.css +307 -0
- package/dist/types/component/DependencyGraph/index.js +225 -0
- package/dist/types/component/DependencyGraph/index.module.js +24 -0
- package/dist/types/component/DependencyGraph/index_module.css +100 -0
- package/dist/types/component/DependencyGraphItem/index.js +124 -0
- package/dist/types/component/DependencyGraphItem/index.module.js +24 -0
- package/dist/types/component/DependencyGraphItem/index_module.css +95 -0
- package/dist/types/component/Form/index.js +372 -0
- package/dist/types/component/Form/index.module.js +24 -0
- package/dist/types/component/Form/index_module.css +198 -0
- package/dist/types/component/LanguageSwitch.js +79 -0
- package/dist/types/component/Layout/index.js +471 -0
- package/dist/types/component/Layout/index.module.js +24 -0
- package/dist/types/component/Layout/index_module.css +68 -0
- package/dist/types/component/LoadingTrace/index.js +953 -0
- package/dist/types/component/LoadingTrace/index.module.js +24 -0
- package/dist/types/component/LoadingTrace/index_module.css +876 -0
- package/dist/types/component/ModuleInfo/index.js +342 -0
- package/dist/types/component/ModuleInfo/index.module.js +24 -0
- package/dist/types/component/ModuleInfo/index_module.css +184 -0
- package/dist/types/component/SharedDepsExplorer/FocusResultDisplay.js +64 -0
- package/dist/types/component/SharedDepsExplorer/FocusResultDisplay.module.js +24 -0
- package/dist/types/component/SharedDepsExplorer/FocusResultDisplay_module.css +45 -0
- package/dist/types/component/SharedDepsExplorer/index.js +638 -0
- package/dist/types/component/SharedDepsExplorer/index.module.js +24 -0
- package/dist/types/component/SharedDepsExplorer/index_module.css +467 -0
- package/dist/types/component/SharedDepsExplorer/share-utils.js +252 -0
- package/dist/types/component/ThemeToggle.js +48 -0
- package/dist/types/component/ThemeToggle.module.js +24 -0
- package/dist/types/component/ThemeToggle_module.css +12 -0
- package/dist/types/hooks/useDevtoolsTheme.js +100 -0
- package/dist/types/i18n/index.js +721 -0
- package/dist/types/init.js +8 -0
- package/dist/types/src/App.d.ts +1 -1
- package/dist/types/src/component/DependencyGraph/index.d.ts +1 -1
- package/dist/types/src/component/DependencyGraphItem/index.d.ts +1 -1
- package/dist/types/src/component/Form/index.d.ts +1 -1
- package/dist/types/src/component/LanguageSwitch.d.ts +1 -1
- package/dist/types/src/component/Layout/index.d.ts +1 -1
- package/dist/types/src/component/LoadingTrace/index.d.ts +1 -1
- package/dist/types/src/component/ModuleInfo/index.d.ts +1 -1
- package/dist/types/src/component/SharedDepsExplorer/index.d.ts +1 -1
- package/dist/types/src/i18n/index.d.ts +1 -1
- package/dist/types/src/template/constant.d.ts +1 -1
- package/dist/types/src/utils/chrome/observability.d.ts +1 -1
- package/dist/types/src/utils/data/index.d.ts +1 -1
- package/dist/types/stories/index.stories.d.ts +2 -1
- package/dist/types/template/constant.js +84 -0
- package/dist/types/template/index.js +21 -0
- package/dist/types/utils/chrome/fast-refresh.js +329 -0
- package/dist/types/utils/chrome/index.js +321 -0
- package/dist/types/utils/chrome/messages.js +39 -0
- package/dist/types/utils/chrome/observability-plugin.js +85 -0
- package/dist/types/utils/chrome/observability-shared.js +125 -0
- package/dist/types/utils/chrome/observability.js +233 -0
- package/dist/types/utils/chrome/override-remote.js +17 -0
- package/dist/types/utils/chrome/post-message-init.js +5 -0
- package/dist/types/utils/chrome/post-message-listener.js +36 -0
- package/dist/types/utils/chrome/post-message-start.js +10 -0
- package/dist/types/utils/chrome/post-message.js +91 -0
- package/dist/types/utils/chrome/safe-post-message.js +147 -0
- package/dist/types/utils/chrome/snapshot-plugin.js +17 -0
- package/dist/types/utils/chrome/storage.js +71 -0
- package/dist/types/utils/data/index.js +83 -0
- package/dist/types/utils/index.js +27 -0
- package/dist/types/utils/sdk/graph.js +213 -0
- package/dist/types/utils/sdk/index.js +104 -0
- package/dist/types/utils/types/common.js +15 -0
- package/dist/types/utils/types/index.js +21 -0
- package/dist/types/vendor/basic-proxy-core.js +147 -0
- package/dist/types/worker/index.js +175 -0
- package/package.json +6 -6
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var chrome_exports = {};
|
|
57
|
+
__export(chrome_exports, {
|
|
58
|
+
TabInfo: () => TabInfo,
|
|
59
|
+
getCurrentTabId: () => getCurrentTabId,
|
|
60
|
+
getGlobalModuleInfo: () => getGlobalModuleInfo,
|
|
61
|
+
getInspectWindowTabId: () => getInspectWindowTabId,
|
|
62
|
+
getScope: () => getScope,
|
|
63
|
+
getTabs: () => getTabs,
|
|
64
|
+
getUrl: () => getUrl,
|
|
65
|
+
injectPostMessage: () => injectPostMessage,
|
|
66
|
+
injectScript: () => injectScript,
|
|
67
|
+
injectToast: () => injectToast,
|
|
68
|
+
normalizeModuleInfoPayload: () => normalizeModuleInfoPayload,
|
|
69
|
+
refreshModuleInfo: () => refreshModuleInfo,
|
|
70
|
+
setChromeStorage: () => setChromeStorage,
|
|
71
|
+
setTargetTab: () => setTargetTab,
|
|
72
|
+
syncActiveTab: () => syncActiveTab
|
|
73
|
+
});
|
|
74
|
+
module.exports = __toCommonJS(chrome_exports);
|
|
75
|
+
var import_constant = require("../../template/constant");
|
|
76
|
+
var import_sdk2 = require("../sdk");
|
|
77
|
+
var import_safe_post_message = require("./safe-post-message");
|
|
78
|
+
__reExport(chrome_exports, require("./storage"), module.exports);
|
|
79
|
+
const isModuleInfoRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
80
|
+
const isModuleInfoSyncMessage = (value) => isModuleInfoRecord(value) && ("moduleInfo" in value || "updateModule" in value || "share" in value);
|
|
81
|
+
const normalizeModuleInfoPayload = (moduleInfo) => {
|
|
82
|
+
const sanitized = (0, import_safe_post_message.sanitizePostMessagePayload)(moduleInfo);
|
|
83
|
+
if (!isModuleInfoRecord(sanitized)) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
return Object.entries(sanitized).reduce(
|
|
87
|
+
(moduleMap, [moduleId, snapshot]) => {
|
|
88
|
+
if (moduleId === "extendInfos" || isModuleInfoRecord(snapshot)) {
|
|
89
|
+
moduleMap[moduleId] = snapshot;
|
|
90
|
+
}
|
|
91
|
+
return moduleMap;
|
|
92
|
+
},
|
|
93
|
+
{}
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
const sleep = (num) => {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
resolve();
|
|
100
|
+
}, num);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const injectPostMessage = (postMessageUrl) => {
|
|
104
|
+
const script = document.createElement("script");
|
|
105
|
+
script.src = postMessageUrl;
|
|
106
|
+
document.getElementsByTagName("head")[0].appendChild(script);
|
|
107
|
+
};
|
|
108
|
+
const TabInfo = {
|
|
109
|
+
currentTabId: 0
|
|
110
|
+
};
|
|
111
|
+
const setTargetTab = (tab) => {
|
|
112
|
+
if (!tab || typeof tab.id !== "number") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
window.targetTab = tab;
|
|
116
|
+
TabInfo.currentTabId = tab.id;
|
|
117
|
+
};
|
|
118
|
+
const syncActiveTab = (tabId) => __async(void 0, null, function* () {
|
|
119
|
+
try {
|
|
120
|
+
if (typeof tabId === "number") {
|
|
121
|
+
const tab = yield chrome.tabs.get(tabId);
|
|
122
|
+
setTargetTab(tab);
|
|
123
|
+
return tab;
|
|
124
|
+
}
|
|
125
|
+
const tabs = yield getTabs({
|
|
126
|
+
active: true,
|
|
127
|
+
lastFocusedWindow: true
|
|
128
|
+
});
|
|
129
|
+
const activeTab = Array.isArray(tabs) ? tabs[0] : void 0;
|
|
130
|
+
setTargetTab(activeTab);
|
|
131
|
+
return activeTab;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.warn("[Module Federation Devtools] syncActiveTab failed", error);
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
function getCurrentTabId() {
|
|
138
|
+
return TabInfo.currentTabId;
|
|
139
|
+
}
|
|
140
|
+
function getInspectWindowTabId() {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
if ((_a = chrome == null ? void 0 : chrome.devtools) == null ? void 0 : _a.inspectedWindow) {
|
|
144
|
+
if (chrome.isDevMode) {
|
|
145
|
+
resolve(0);
|
|
146
|
+
}
|
|
147
|
+
chrome.devtools.inspectedWindow.eval(
|
|
148
|
+
'typeof window.__FEDERATION__ !== "undefined" || typeof window.__VMOK__ !== "undefined"',
|
|
149
|
+
function(info, error) {
|
|
150
|
+
const { tabId } = chrome.devtools.inspectedWindow;
|
|
151
|
+
getTabs().then((tabs) => {
|
|
152
|
+
const target = Array.isArray(tabs) ? tabs.find((tab) => tab.id === tabId) : void 0;
|
|
153
|
+
setTargetTab(target);
|
|
154
|
+
});
|
|
155
|
+
console.log(
|
|
156
|
+
"chrome.devtools.inspectedWindow.tabId",
|
|
157
|
+
chrome.devtools.inspectedWindow.tabId
|
|
158
|
+
);
|
|
159
|
+
TabInfo.currentTabId = tabId;
|
|
160
|
+
resolve(tabId);
|
|
161
|
+
if (error) {
|
|
162
|
+
reject(error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
} else {
|
|
167
|
+
if ((_b = window.targetTab) == null ? void 0 : _b.id) {
|
|
168
|
+
const tabId = window.targetTab.id;
|
|
169
|
+
TabInfo.currentTabId = tabId;
|
|
170
|
+
resolve(tabId);
|
|
171
|
+
} else {
|
|
172
|
+
throw Error(`can't get active tab`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const refreshModuleInfo = () => __async(void 0, null, function* () {
|
|
178
|
+
var _a;
|
|
179
|
+
if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
|
|
180
|
+
}
|
|
181
|
+
yield sleep(50);
|
|
182
|
+
const postMessageStartUrl = getUrl("post-message-start.js");
|
|
183
|
+
yield injectScript(injectPostMessage, false, postMessageStartUrl);
|
|
184
|
+
});
|
|
185
|
+
const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
|
|
188
|
+
callback(normalizeModuleInfoPayload((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo));
|
|
189
|
+
}
|
|
190
|
+
yield sleep(300);
|
|
191
|
+
const listener = (message) => {
|
|
192
|
+
const { data } = message;
|
|
193
|
+
if (!isModuleInfoSyncMessage(data) || (data == null ? void 0 : data.appInfos)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
197
|
+
(0, import_sdk2.definePropertyGlobalVal)(window, "__FEDERATION__", {});
|
|
198
|
+
(0, import_sdk2.definePropertyGlobalVal)(window, "__VMOK__", window.__FEDERATION__);
|
|
199
|
+
}
|
|
200
|
+
window.__FEDERATION__.originModuleInfo = "moduleInfo" in data ? normalizeModuleInfoPayload(data.moduleInfo) : normalizeModuleInfoPayload(
|
|
201
|
+
window.__FEDERATION__.originModuleInfo || window.__FEDERATION__.moduleInfo
|
|
202
|
+
);
|
|
203
|
+
const updateModule = data.updateModule;
|
|
204
|
+
if (isModuleInfoRecord(updateModule) && typeof updateModule.name === "string") {
|
|
205
|
+
const updateModuleName = updateModule.name;
|
|
206
|
+
const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
|
|
207
|
+
const shouldUpdate = !moduleIds.some(
|
|
208
|
+
(id) => id.includes(updateModuleName)
|
|
209
|
+
);
|
|
210
|
+
if (shouldUpdate) {
|
|
211
|
+
const destination = typeof updateModule.entry === "string" ? updateModule.entry : typeof updateModule.version === "string" ? updateModule.version : void 0;
|
|
212
|
+
if (destination) {
|
|
213
|
+
window.__FEDERATION__.originModuleInfo[`${updateModuleName}:${destination}`] = {
|
|
214
|
+
remoteEntry: destination,
|
|
215
|
+
version: destination
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (data == null ? void 0 : data.share) {
|
|
221
|
+
window.__FEDERATION__.__SHARE__ = (0, import_safe_post_message.sanitizePostMessagePayload)(
|
|
222
|
+
data.share
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
window.__FEDERATION__.moduleInfo = normalizeModuleInfoPayload(
|
|
226
|
+
window.__FEDERATION__.originModuleInfo
|
|
227
|
+
);
|
|
228
|
+
console.log("getGlobalModuleInfo window", window.__FEDERATION__);
|
|
229
|
+
callback(window.__FEDERATION__.moduleInfo);
|
|
230
|
+
};
|
|
231
|
+
chrome.runtime.onMessage.addListener(listener);
|
|
232
|
+
yield refreshModuleInfo();
|
|
233
|
+
return () => chrome.runtime.onMessage.removeListener(listener);
|
|
234
|
+
});
|
|
235
|
+
const getTabs = (queryOptions = {}) => chrome.tabs.query(queryOptions);
|
|
236
|
+
const getScope = () => __async(void 0, null, function* () {
|
|
237
|
+
const activeTab = window.targetTab;
|
|
238
|
+
const tabId = activeTab == null ? void 0 : activeTab.id;
|
|
239
|
+
return tabId ? String(tabId) : "noScope";
|
|
240
|
+
});
|
|
241
|
+
const injectScript = (excuteScript, world = false, ...args) => __async(void 0, null, function* () {
|
|
242
|
+
yield getInspectWindowTabId();
|
|
243
|
+
return chrome.scripting.executeScript({
|
|
244
|
+
target: {
|
|
245
|
+
tabId: getCurrentTabId()
|
|
246
|
+
},
|
|
247
|
+
func: excuteScript,
|
|
248
|
+
world: world ? "MAIN" : "ISOLATED",
|
|
249
|
+
args
|
|
250
|
+
}).then((results) => {
|
|
251
|
+
var _a;
|
|
252
|
+
console.log("InjectScript success, excuteScript:", args);
|
|
253
|
+
if (Array.isArray(results) && results.length) {
|
|
254
|
+
return (_a = results[0]) == null ? void 0 : _a.result;
|
|
255
|
+
}
|
|
256
|
+
return void 0;
|
|
257
|
+
}).catch((e) => {
|
|
258
|
+
console.log(e, "InjectScript fail, excuteScript:", args);
|
|
259
|
+
return void 0;
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
const getUrl = (file) => {
|
|
263
|
+
try {
|
|
264
|
+
const pathSet = chrome.runtime.getURL(file).split("/");
|
|
265
|
+
const fileName = pathSet.pop();
|
|
266
|
+
pathSet.push("static", "js", fileName);
|
|
267
|
+
return pathSet.join("/");
|
|
268
|
+
} catch (e) {
|
|
269
|
+
return "";
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const injectToast = (toastUtilUrl, e2eFlag) => {
|
|
273
|
+
const ele = document.querySelector(`[data-e2e=${e2eFlag}]`);
|
|
274
|
+
if (ele) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const scriptToast = document.createElement("script");
|
|
278
|
+
scriptToast.src = toastUtilUrl;
|
|
279
|
+
scriptToast.dataset.e2e = e2eFlag;
|
|
280
|
+
document.getElementsByTagName("head")[0].appendChild(scriptToast);
|
|
281
|
+
};
|
|
282
|
+
const setChromeStorage = (formData) => {
|
|
283
|
+
getScope().then((scope) => __async(void 0, null, function* () {
|
|
284
|
+
const data = yield chrome.storage.sync.get("FormID");
|
|
285
|
+
const storeData = data[import_constant.FormID];
|
|
286
|
+
const scopes = Object.keys(storeData || {});
|
|
287
|
+
let filterOutDatedData = storeData || {};
|
|
288
|
+
const { length } = scopes;
|
|
289
|
+
if (length >= 10) {
|
|
290
|
+
filterOutDatedData = scopes.slice(0, length - 3).reduce((memo, cur) => {
|
|
291
|
+
memo[cur] = storeData[cur];
|
|
292
|
+
return memo;
|
|
293
|
+
}, {});
|
|
294
|
+
}
|
|
295
|
+
const existRules = storeData == null ? void 0 : storeData[scope];
|
|
296
|
+
chrome.storage.sync.set({
|
|
297
|
+
[import_constant.FormID]: __spreadProps(__spreadValues({}, filterOutDatedData), {
|
|
298
|
+
[scope]: __spreadValues(__spreadValues({}, existRules), formData)
|
|
299
|
+
})
|
|
300
|
+
});
|
|
301
|
+
}));
|
|
302
|
+
};
|
|
303
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
304
|
+
0 && (module.exports = {
|
|
305
|
+
TabInfo,
|
|
306
|
+
getCurrentTabId,
|
|
307
|
+
getGlobalModuleInfo,
|
|
308
|
+
getInspectWindowTabId,
|
|
309
|
+
getScope,
|
|
310
|
+
getTabs,
|
|
311
|
+
getUrl,
|
|
312
|
+
injectPostMessage,
|
|
313
|
+
injectScript,
|
|
314
|
+
injectToast,
|
|
315
|
+
normalizeModuleInfoPayload,
|
|
316
|
+
refreshModuleInfo,
|
|
317
|
+
setChromeStorage,
|
|
318
|
+
setTargetTab,
|
|
319
|
+
syncActiveTab,
|
|
320
|
+
...require("./storage")
|
|
321
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var messages_exports = {};
|
|
19
|
+
__export(messages_exports, {
|
|
20
|
+
MESSAGE_ACTIVE_TAB_CHANGED: () => MESSAGE_ACTIVE_TAB_CHANGED,
|
|
21
|
+
MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT: () => MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
|
|
22
|
+
MESSAGE_OPEN_SIDE_PANEL: () => MESSAGE_OPEN_SIDE_PANEL,
|
|
23
|
+
OBSERVABILITY_DEVTOOLS_SOURCE: () => OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
24
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY: () => OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(messages_exports);
|
|
27
|
+
const MESSAGE_OPEN_SIDE_PANEL = "mf-devtools/open-side-panel";
|
|
28
|
+
const MESSAGE_ACTIVE_TAB_CHANGED = "mf-devtools/active-tab-changed";
|
|
29
|
+
const MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT = "mf-devtools/observability-event";
|
|
30
|
+
const OBSERVABILITY_DEVTOOLS_SOURCE = "module-federation/observability";
|
|
31
|
+
const OBSERVABILITY_DEVTOOLS_STORAGE_KEY = "__MF_DEVTOOLS_OBSERVABILITY_CONFIG__";
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
MESSAGE_ACTIVE_TAB_CHANGED,
|
|
35
|
+
MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
|
|
36
|
+
MESSAGE_OPEN_SIDE_PANEL,
|
|
37
|
+
OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
38
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
39
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var import_chrome_devtool = require("@module-federation/observability-plugin/chrome-devtool");
|
|
2
|
+
var import_messages = require("./messages");
|
|
3
|
+
var import_observability_shared = require("./observability-shared");
|
|
4
|
+
const DEVTOOLS_PLUGIN_NAME = "observability-plugin:chrome-extension";
|
|
5
|
+
const LEGACY_DEVTOOLS_PLUGIN_NAME = "observability-plugin-devtools";
|
|
6
|
+
const getFederationWindow = () => window;
|
|
7
|
+
const safeReadStoredConfig = () => {
|
|
8
|
+
var _a;
|
|
9
|
+
try {
|
|
10
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(
|
|
11
|
+
import_messages.OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
12
|
+
);
|
|
13
|
+
if (!raw) {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
return (0, import_observability_shared.normalizeObservabilityDevtoolsConfig)(JSON.parse(raw));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const defineWritableGlobal = (key, value) => {
|
|
22
|
+
const targetWindow = getFederationWindow();
|
|
23
|
+
try {
|
|
24
|
+
Object.defineProperty(targetWindow, key, {
|
|
25
|
+
value,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true
|
|
28
|
+
});
|
|
29
|
+
} catch (e) {
|
|
30
|
+
targetWindow[key] = value;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const ensureFederationGlobal = () => {
|
|
34
|
+
var _a;
|
|
35
|
+
const targetWindow = getFederationWindow();
|
|
36
|
+
const federation = targetWindow.__FEDERATION__ || targetWindow.__VMOK__ || {};
|
|
37
|
+
if (!targetWindow.__FEDERATION__) {
|
|
38
|
+
defineWritableGlobal("__FEDERATION__", federation);
|
|
39
|
+
}
|
|
40
|
+
if (!targetWindow.__VMOK__) {
|
|
41
|
+
defineWritableGlobal("__VMOK__", targetWindow.__FEDERATION__);
|
|
42
|
+
}
|
|
43
|
+
if (!((_a = targetWindow.__FEDERATION__) == null ? void 0 : _a.__GLOBAL_PLUGIN__)) {
|
|
44
|
+
targetWindow.__FEDERATION__ = targetWindow.__FEDERATION__ || federation;
|
|
45
|
+
targetWindow.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
46
|
+
}
|
|
47
|
+
return targetWindow.__FEDERATION__;
|
|
48
|
+
};
|
|
49
|
+
const notifyInstalled = (status, reason, config) => {
|
|
50
|
+
try {
|
|
51
|
+
window.postMessage(
|
|
52
|
+
{
|
|
53
|
+
schemaVersion: 1,
|
|
54
|
+
source: import_messages.OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
55
|
+
kind: status,
|
|
56
|
+
reason,
|
|
57
|
+
config,
|
|
58
|
+
createdAt: Date.now()
|
|
59
|
+
},
|
|
60
|
+
"*"
|
|
61
|
+
);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const install = () => {
|
|
66
|
+
const config = safeReadStoredConfig();
|
|
67
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const federation = ensureFederationGlobal();
|
|
71
|
+
const globalPlugins = (federation == null ? void 0 : federation.__GLOBAL_PLUGIN__) || [];
|
|
72
|
+
if (globalPlugins.some(
|
|
73
|
+
(plugin2) => (plugin2 == null ? void 0 : plugin2.name) === DEVTOOLS_PLUGIN_NAME || (plugin2 == null ? void 0 : plugin2.name) === LEGACY_DEVTOOLS_PLUGIN_NAME
|
|
74
|
+
)) {
|
|
75
|
+
notifyInstalled("skipped", "already-installed", config);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const plugin = (0, import_chrome_devtool.ChromeObservabilityPlugin)(
|
|
79
|
+
(0, import_observability_shared.createObservabilityPluginOptions)(config)
|
|
80
|
+
);
|
|
81
|
+
globalPlugins.push(plugin);
|
|
82
|
+
federation.__GLOBAL_PLUGIN__ = globalPlugins;
|
|
83
|
+
notifyInstalled("installed", void 0, config);
|
|
84
|
+
};
|
|
85
|
+
install();
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var observability_shared_exports = {};
|
|
19
|
+
__export(observability_shared_exports, {
|
|
20
|
+
CHROME_OBSERVABILITY_SCOPE: () => CHROME_OBSERVABILITY_SCOPE,
|
|
21
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG: () => DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
22
|
+
createObservabilityPluginOptions: () => createObservabilityPluginOptions,
|
|
23
|
+
normalizeObservabilityDevtoolsConfig: () => normalizeObservabilityDevtoolsConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(observability_shared_exports);
|
|
26
|
+
var import_messages = require("./messages");
|
|
27
|
+
const CHROME_OBSERVABILITY_SCOPE = "chrome_extension";
|
|
28
|
+
const MIN_EVENTS = 10;
|
|
29
|
+
const MAX_EVENTS = 1e3;
|
|
30
|
+
const DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG = {
|
|
31
|
+
enabled: true,
|
|
32
|
+
level: "verbose",
|
|
33
|
+
maxEvents: 300,
|
|
34
|
+
console: true,
|
|
35
|
+
browser: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
scope: CHROME_OBSERVABILITY_SCOPE,
|
|
38
|
+
mode: "development"
|
|
39
|
+
},
|
|
40
|
+
trace: {
|
|
41
|
+
printStart: true
|
|
42
|
+
},
|
|
43
|
+
react: {
|
|
44
|
+
injectLoadedCallback: false,
|
|
45
|
+
remoteIds: []
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
49
|
+
const normalizeBoolean = (value, fallback) => typeof value === "boolean" ? value : fallback;
|
|
50
|
+
const normalizeLevel = (value) => value === "error" || value === "summary" || value === "verbose" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.level;
|
|
51
|
+
const normalizeMode = (value) => value === "production" || value === "development" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.mode;
|
|
52
|
+
const normalizeMaxEvents = (value) => {
|
|
53
|
+
const parsed = Number(value);
|
|
54
|
+
if (!Number.isFinite(parsed)) {
|
|
55
|
+
return DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.maxEvents;
|
|
56
|
+
}
|
|
57
|
+
return Math.max(MIN_EVENTS, Math.min(MAX_EVENTS, Math.floor(parsed)));
|
|
58
|
+
};
|
|
59
|
+
const normalizeScope = (value) => {
|
|
60
|
+
if (typeof value !== "string") {
|
|
61
|
+
return CHROME_OBSERVABILITY_SCOPE;
|
|
62
|
+
}
|
|
63
|
+
const trimmed = value.trim().replace(/[^\w:@.-]+/g, "-");
|
|
64
|
+
return trimmed || CHROME_OBSERVABILITY_SCOPE;
|
|
65
|
+
};
|
|
66
|
+
const normalizeObservabilityDevtoolsConfig = (value) => {
|
|
67
|
+
const source = isObject(value) ? value : {};
|
|
68
|
+
const browser = isObject(source.browser) ? source.browser : {};
|
|
69
|
+
const trace = isObject(source.trace) ? source.trace : {};
|
|
70
|
+
return {
|
|
71
|
+
enabled: normalizeBoolean(
|
|
72
|
+
source.enabled,
|
|
73
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.enabled
|
|
74
|
+
),
|
|
75
|
+
level: normalizeLevel(source.level),
|
|
76
|
+
maxEvents: normalizeMaxEvents(source.maxEvents),
|
|
77
|
+
console: normalizeBoolean(
|
|
78
|
+
source.console,
|
|
79
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.console
|
|
80
|
+
),
|
|
81
|
+
browser: {
|
|
82
|
+
enabled: normalizeBoolean(
|
|
83
|
+
browser.enabled,
|
|
84
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.enabled
|
|
85
|
+
),
|
|
86
|
+
scope: normalizeScope(browser.scope),
|
|
87
|
+
mode: normalizeMode(browser.mode)
|
|
88
|
+
},
|
|
89
|
+
trace: {
|
|
90
|
+
printStart: normalizeBoolean(
|
|
91
|
+
trace.printStart,
|
|
92
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.trace.printStart
|
|
93
|
+
)
|
|
94
|
+
},
|
|
95
|
+
react: {
|
|
96
|
+
injectLoadedCallback: false,
|
|
97
|
+
remoteIds: []
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const createObservabilityPluginOptions = (config) => ({
|
|
102
|
+
enabled: config.enabled,
|
|
103
|
+
level: config.level,
|
|
104
|
+
maxEvents: config.maxEvents,
|
|
105
|
+
console: config.console,
|
|
106
|
+
browser: {
|
|
107
|
+
enabled: config.browser.enabled,
|
|
108
|
+
scope: config.browser.scope,
|
|
109
|
+
mode: config.browser.mode
|
|
110
|
+
},
|
|
111
|
+
trace: {
|
|
112
|
+
printStart: config.trace.printStart
|
|
113
|
+
},
|
|
114
|
+
devtools: {
|
|
115
|
+
enabled: true,
|
|
116
|
+
source: import_messages.OBSERVABILITY_DEVTOOLS_SOURCE
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
CHROME_OBSERVABILITY_SCOPE,
|
|
122
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
123
|
+
createObservabilityPluginOptions,
|
|
124
|
+
normalizeObservabilityDevtoolsConfig
|
|
125
|
+
});
|