@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.
- package/README.md +3 -0
- package/dist/es/App.js +17 -2
- package/dist/es/App_module.css +3 -3
- package/dist/es/component/LoadingTrace/index.js +944 -0
- package/dist/es/component/LoadingTrace/index.module.js +5 -0
- package/dist/es/component/LoadingTrace/index_module.css +876 -0
- package/dist/es/i18n/index.js +178 -0
- package/dist/es/utils/chrome/fast-refresh.js +297 -173
- package/dist/es/utils/chrome/index.js +3 -4
- package/dist/es/utils/chrome/messages.js +7 -1
- package/dist/es/utils/chrome/observability-plugin.js +93 -0
- package/dist/es/utils/chrome/observability-shared.js +99 -0
- package/dist/es/utils/chrome/observability.js +208 -0
- package/dist/es/utils/chrome/override-remote.js +2 -42
- package/dist/es/utils/chrome/post-message-listener.js +14 -0
- package/dist/es/utils/chrome/snapshot-plugin.js +2 -36
- package/dist/es/utils/data/index.js +5 -25
- package/dist/es/vendor/basic-proxy-core.js +155 -0
- package/dist/es/worker/index.js +27 -8
- package/dist/lib/App.js +17 -2
- package/dist/lib/App_module.css +3 -3
- package/dist/lib/component/LoadingTrace/index.js +954 -0
- package/dist/lib/component/LoadingTrace/index.module.js +25 -0
- package/dist/lib/component/LoadingTrace/index_module.css +876 -0
- package/dist/lib/i18n/index.js +178 -0
- package/dist/lib/utils/chrome/fast-refresh.js +250 -135
- package/dist/lib/utils/chrome/index.js +3 -4
- package/dist/lib/utils/chrome/messages.js +11 -2
- package/dist/lib/utils/chrome/observability-plugin.js +86 -0
- package/dist/lib/utils/chrome/observability-shared.js +126 -0
- package/dist/lib/utils/chrome/observability.js +234 -0
- package/dist/lib/utils/chrome/override-remote.js +5 -52
- package/dist/lib/utils/chrome/post-message-listener.js +11 -0
- package/dist/lib/utils/chrome/snapshot-plugin.js +5 -46
- package/dist/lib/utils/data/index.js +6 -28
- package/dist/lib/vendor/basic-proxy-core.js +147 -0
- package/dist/lib/worker/index.js +27 -8
- package/dist/types/src/component/LoadingTrace/index.d.ts +6 -0
- package/dist/types/src/utils/chrome/messages.d.ts +3 -0
- package/dist/types/src/utils/chrome/observability-plugin.d.ts +1 -0
- package/dist/types/src/utils/chrome/observability-shared.d.ts +41 -0
- package/dist/types/src/utils/chrome/observability.d.ts +110 -0
- package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +0 -3
- package/dist/types/src/utils/data/index.d.ts +0 -1
- package/package.json +4 -3
- package/dist/es/utils/data/snapshot.js +0 -82
- package/dist/lib/utils/data/snapshot.js +0 -107
- package/dist/types/src/utils/data/snapshot.d.ts +0 -3
package/dist/lib/i18n/index.js
CHANGED
|
@@ -45,6 +45,7 @@ const resources = {
|
|
|
45
45
|
proxy: "Proxy",
|
|
46
46
|
dependency: "Dependency graph",
|
|
47
47
|
share: "Shared",
|
|
48
|
+
loadingTrace: "Loading trace",
|
|
48
49
|
performance: "Performance"
|
|
49
50
|
},
|
|
50
51
|
header: {
|
|
@@ -263,6 +264,94 @@ const resources = {
|
|
|
263
264
|
shared: "Shared",
|
|
264
265
|
entry: "Entry",
|
|
265
266
|
version: "Version"
|
|
267
|
+
},
|
|
268
|
+
loadingTrace: {
|
|
269
|
+
title: "Loading Trace",
|
|
270
|
+
empty: "No loading report yet",
|
|
271
|
+
emptyEnableChrome: "No observability plugin was detected on the page. Enable Chrome observability to start collecting loading reports.",
|
|
272
|
+
status: {
|
|
273
|
+
enabled: "Observability is enabled for the current page.",
|
|
274
|
+
disabled: "Observability is not enabled for the current page.",
|
|
275
|
+
unavailable: "Current page is unavailable.",
|
|
276
|
+
reloading: "Configuration saved. Reloading current page.",
|
|
277
|
+
synced: "Reports synced.",
|
|
278
|
+
noReports: "No report found on the current page.",
|
|
279
|
+
userPlugin: "Application observability plugin detected. Syncing existing reports."
|
|
280
|
+
},
|
|
281
|
+
confirm: {
|
|
282
|
+
observeTitle: "Start observability?",
|
|
283
|
+
updateTitle: "Update configuration?",
|
|
284
|
+
content: "The current tab will reload after the configuration is saved."
|
|
285
|
+
},
|
|
286
|
+
actions: {
|
|
287
|
+
observeNow: "Observe now",
|
|
288
|
+
updateConfig: "Update config",
|
|
289
|
+
config: "Configuration",
|
|
290
|
+
disable: "Disable",
|
|
291
|
+
refresh: "Sync",
|
|
292
|
+
export: "Export",
|
|
293
|
+
confirm: "Confirm",
|
|
294
|
+
cancel: "Cancel"
|
|
295
|
+
},
|
|
296
|
+
config: {
|
|
297
|
+
level: "Level",
|
|
298
|
+
levelTip: "Controls how much event detail is kept. Verbose keeps the full timeline, summary keeps key results, and error focuses on failures.",
|
|
299
|
+
verbose: "Verbose",
|
|
300
|
+
summary: "Summary",
|
|
301
|
+
error: "Error",
|
|
302
|
+
console: "Console hints",
|
|
303
|
+
consoleTip: "Prints lightweight hints in the inspected page console. Turn it off when the page console should stay clean."
|
|
304
|
+
},
|
|
305
|
+
stats: {
|
|
306
|
+
state: "State",
|
|
307
|
+
reports: "Reports",
|
|
308
|
+
events: "Events",
|
|
309
|
+
latest: "Latest outcome",
|
|
310
|
+
customTip: "Custom means the inspected page already registered its own observability plugin, so reports are read from the page instead of only from the Chrome collection plugin."
|
|
311
|
+
},
|
|
312
|
+
reports: {
|
|
313
|
+
search: "Filter reports",
|
|
314
|
+
noMatch: "No matching report",
|
|
315
|
+
success: "Success",
|
|
316
|
+
failed: "Failed",
|
|
317
|
+
pending: "Pending",
|
|
318
|
+
recovered: "Recovered",
|
|
319
|
+
eventRecovered: "Recovered",
|
|
320
|
+
limited: "Basic observability",
|
|
321
|
+
lowVersionTip: "The current MF runtime version is too low, so only basic loading events can be collected. Fine-grained remoteEntry, init, expose, factory, and shared phases may be missing. Upgrade to 2.5.0+ for the full loading trace.",
|
|
322
|
+
unknownVersionTip: "The current MF runtime version cannot be detected, so Chrome observability may only collect basic loading events. Fine-grained remoteEntry, init, expose, factory, and shared phases may be missing."
|
|
323
|
+
},
|
|
324
|
+
currentLoad: {
|
|
325
|
+
title: "Current loading",
|
|
326
|
+
remoteReport: "Remote",
|
|
327
|
+
sharedReport: "Shared dependency",
|
|
328
|
+
consumer: "Current consumer",
|
|
329
|
+
request: "Request",
|
|
330
|
+
producer: "Producer",
|
|
331
|
+
remoteName: "Remote name",
|
|
332
|
+
expose: "Expose",
|
|
333
|
+
shared: "Shared dependency",
|
|
334
|
+
provider: "Provider",
|
|
335
|
+
requiredVersion: "Required version",
|
|
336
|
+
selectedVersion: "Selected version",
|
|
337
|
+
availableVersions: "Available versions"
|
|
338
|
+
},
|
|
339
|
+
loadedBefore: {
|
|
340
|
+
title: "Other consumer loading records",
|
|
341
|
+
consumerCount: "{{count}} consumer(s)",
|
|
342
|
+
producerLoaded: "Same producer was loaded before",
|
|
343
|
+
exposeLoaded: "Current expose was loaded before",
|
|
344
|
+
exposeNotLoaded: "Current expose was not loaded before",
|
|
345
|
+
consumer: "Consumer",
|
|
346
|
+
status: "Status",
|
|
347
|
+
exposes: "Loaded exposes",
|
|
348
|
+
unknownConsumer: "Unknown consumer",
|
|
349
|
+
entryReady: "remoteEntry is available",
|
|
350
|
+
entryMissing: "remoteEntry is not available",
|
|
351
|
+
initReady: "container was initialized",
|
|
352
|
+
initMissing: "container was not initialized",
|
|
353
|
+
noExposes: "No expose record"
|
|
354
|
+
}
|
|
266
355
|
}
|
|
267
356
|
}
|
|
268
357
|
},
|
|
@@ -274,6 +363,7 @@ const resources = {
|
|
|
274
363
|
proxy: "代理配置",
|
|
275
364
|
dependency: "依赖关系图",
|
|
276
365
|
share: "共享依赖",
|
|
366
|
+
loadingTrace: "加载追踪",
|
|
277
367
|
performance: "性能"
|
|
278
368
|
},
|
|
279
369
|
header: {
|
|
@@ -492,6 +582,94 @@ const resources = {
|
|
|
492
582
|
shared: "共享依赖",
|
|
493
583
|
entry: "入口",
|
|
494
584
|
version: "版本"
|
|
585
|
+
},
|
|
586
|
+
loadingTrace: {
|
|
587
|
+
title: "加载追踪",
|
|
588
|
+
empty: "暂无加载报告",
|
|
589
|
+
emptyEnableChrome: "当前页面未检测到观测插件。可以开启 Chrome 采集来收集加载报告。",
|
|
590
|
+
status: {
|
|
591
|
+
enabled: "当前页面已开启加载追踪。",
|
|
592
|
+
disabled: "当前页面未开启加载追踪。",
|
|
593
|
+
unavailable: "当前页面暂不可用。",
|
|
594
|
+
reloading: "配置已保存,正在刷新当前页面。",
|
|
595
|
+
synced: "报告已同步。",
|
|
596
|
+
noReports: "当前页面还没有报告。",
|
|
597
|
+
userPlugin: "已检测到页面自带观测插件,正在同步已有报告。"
|
|
598
|
+
},
|
|
599
|
+
confirm: {
|
|
600
|
+
observeTitle: "开启加载追踪?",
|
|
601
|
+
updateTitle: "更新配置?",
|
|
602
|
+
content: "保存配置后会刷新当前标签页。"
|
|
603
|
+
},
|
|
604
|
+
actions: {
|
|
605
|
+
observeNow: "开启采集",
|
|
606
|
+
updateConfig: "更新配置",
|
|
607
|
+
config: "配置",
|
|
608
|
+
disable: "关闭",
|
|
609
|
+
refresh: "同步",
|
|
610
|
+
export: "导出",
|
|
611
|
+
confirm: "确认",
|
|
612
|
+
cancel: "取消"
|
|
613
|
+
},
|
|
614
|
+
config: {
|
|
615
|
+
level: "记录级别",
|
|
616
|
+
levelTip: "控制保留多少事件细节。完整会保留完整链路,摘要只保留关键结果,错误只关注失败。",
|
|
617
|
+
verbose: "完整",
|
|
618
|
+
summary: "摘要",
|
|
619
|
+
error: "错误",
|
|
620
|
+
console: "控制台提示",
|
|
621
|
+
consoleTip: "在被调试页面的控制台打印轻量提示。如果想保持页面控制台干净,可以关闭。"
|
|
622
|
+
},
|
|
623
|
+
stats: {
|
|
624
|
+
state: "状态",
|
|
625
|
+
reports: "报告",
|
|
626
|
+
events: "事件",
|
|
627
|
+
latest: "最新结果",
|
|
628
|
+
customTip: "Custom 表示当前页面已经自己注册了观测插件,报告会从页面已有插件中读取,不只依赖 Chrome 插件注入采集。"
|
|
629
|
+
},
|
|
630
|
+
reports: {
|
|
631
|
+
search: "过滤报告",
|
|
632
|
+
noMatch: "没有匹配的报告",
|
|
633
|
+
success: "成功",
|
|
634
|
+
failed: "失败",
|
|
635
|
+
pending: "进行中",
|
|
636
|
+
recovered: "兜底成功",
|
|
637
|
+
eventRecovered: "兜底",
|
|
638
|
+
limited: "基础观测",
|
|
639
|
+
lowVersionTip: "当前 MF 运行时版本较低,只能采集基础加载事件。remoteEntry、init、expose、factory、shared 等细阶段可能缺失。升级到 2.5.0+ 后可获得完整链路。",
|
|
640
|
+
unknownVersionTip: "当前 MF 运行时版本无法识别,Chrome 观测可能只能采集基础加载事件。remoteEntry、init、expose、factory、shared 等细阶段可能缺失。"
|
|
641
|
+
},
|
|
642
|
+
currentLoad: {
|
|
643
|
+
title: "当前加载",
|
|
644
|
+
remoteReport: "远程模块",
|
|
645
|
+
sharedReport: "共享依赖",
|
|
646
|
+
consumer: "当前消费方",
|
|
647
|
+
request: "请求",
|
|
648
|
+
producer: "生产者",
|
|
649
|
+
remoteName: "生产者名称",
|
|
650
|
+
expose: "Expose",
|
|
651
|
+
shared: "共享依赖",
|
|
652
|
+
provider: "提供方",
|
|
653
|
+
requiredVersion: "要求版本",
|
|
654
|
+
selectedVersion: "实际版本",
|
|
655
|
+
availableVersions: "可用版本"
|
|
656
|
+
},
|
|
657
|
+
loadedBefore: {
|
|
658
|
+
title: "其他消费方加载记录",
|
|
659
|
+
consumerCount: "{{count}} 个消费方",
|
|
660
|
+
producerLoaded: "同一生产者之前已被加载",
|
|
661
|
+
exposeLoaded: "当前 expose 之前已被加载",
|
|
662
|
+
exposeNotLoaded: "当前 expose 之前未被加载",
|
|
663
|
+
consumer: "消费方",
|
|
664
|
+
status: "状态",
|
|
665
|
+
exposes: "已加载 expose",
|
|
666
|
+
unknownConsumer: "未知消费方",
|
|
667
|
+
entryReady: "remoteEntry 已拿到",
|
|
668
|
+
entryMissing: "remoteEntry 未拿到",
|
|
669
|
+
initReady: "容器已初始化",
|
|
670
|
+
initMissing: "容器未初始化",
|
|
671
|
+
noExposes: "暂无导出记录"
|
|
672
|
+
}
|
|
495
673
|
}
|
|
496
674
|
}
|
|
497
675
|
}
|
|
@@ -1,32 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __spreadValues = (a, b) => {
|
|
8
|
-
for (var prop in b || (b = {}))
|
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
|
11
|
-
if (__getOwnPropSymbols)
|
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
-
if (__propIsEnum.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
}
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
|
-
var __objRest = (source, exclude) => {
|
|
19
|
-
var target = {};
|
|
20
|
-
for (var prop in source)
|
|
21
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
22
|
-
target[prop] = source[prop];
|
|
23
|
-
if (source != null && __getOwnPropSymbols)
|
|
24
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
25
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
26
|
-
target[prop] = source[prop];
|
|
27
|
-
}
|
|
28
|
-
return target;
|
|
29
|
-
};
|
|
30
2
|
var __async = (__this, __arguments, generator) => {
|
|
31
3
|
return new Promise((resolve, reject) => {
|
|
32
4
|
var fulfilled = (value) => {
|
|
@@ -47,31 +19,176 @@ var __async = (__this, __arguments, generator) => {
|
|
|
47
19
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
48
20
|
});
|
|
49
21
|
};
|
|
50
|
-
var import_sdk = require("@module-federation/sdk");
|
|
51
22
|
var import__ = require("../index");
|
|
52
|
-
var
|
|
23
|
+
var import_sdk = require("../sdk");
|
|
53
24
|
var import_constant = require("../../template/constant");
|
|
54
25
|
var _a;
|
|
55
26
|
const SUPPORT_PKGS = ["react", "react-dom"];
|
|
56
|
-
const
|
|
27
|
+
const DEFAULT_SHARE_SCOPE = "default";
|
|
28
|
+
const DEFAULT_GLOBAL_KEY_MAP = {
|
|
29
|
+
react: "React",
|
|
30
|
+
"react-dom": "ReactDOM"
|
|
31
|
+
};
|
|
32
|
+
const sanitizeWindowKey = (value) => value.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
33
|
+
const getShareScopes = (scope) => Array.isArray(scope) && scope.length ? scope : [DEFAULT_SHARE_SCOPE];
|
|
34
|
+
const getDefaultGlobalKey = (pkgName) => DEFAULT_GLOBAL_KEY_MAP[pkgName];
|
|
35
|
+
const getScopedGlobalKey = (scope, pkgName) => `${sanitizeWindowKey(scope)}_${sanitizeWindowKey(pkgName)}`;
|
|
36
|
+
const getWindowValue = (key) => window[key];
|
|
37
|
+
const setWindowValue = (key, value) => {
|
|
38
|
+
window[key] = value;
|
|
39
|
+
};
|
|
40
|
+
const setScopeGlobals = (pkgName, scopes, source) => {
|
|
41
|
+
if (!source) {
|
|
42
|
+
return source;
|
|
43
|
+
}
|
|
44
|
+
scopes.forEach((scope) => {
|
|
45
|
+
setWindowValue(getScopedGlobalKey(scope, pkgName), source);
|
|
46
|
+
});
|
|
47
|
+
return source;
|
|
48
|
+
};
|
|
49
|
+
const getScopeGlobal = (pkgName, scopes) => {
|
|
50
|
+
for (const scope of scopes) {
|
|
51
|
+
const scopeGlobal = getWindowValue(getScopedGlobalKey(scope, pkgName));
|
|
52
|
+
if (scopeGlobal) {
|
|
53
|
+
return scopeGlobal;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
57
|
+
};
|
|
58
|
+
const getEagerShareInfo = (eagerShare) => {
|
|
59
|
+
if (!Array.isArray(eagerShare) || eagerShare.length < 2) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const [, version, scopes] = eagerShare;
|
|
63
|
+
if (typeof version !== "string") {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
version,
|
|
68
|
+
scopes: getShareScopes(scopes)
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const updateEagerShareInfo = (devtoolsMessage2, pkgName, version, scopes) => {
|
|
72
|
+
const existing = getEagerShareInfo(devtoolsMessage2[import_constant.__EAGER_SHARE__]);
|
|
73
|
+
const mergedScopes = Array.from(
|
|
74
|
+
/* @__PURE__ */ new Set([...(existing == null ? void 0 : existing.scopes) || [], ...scopes])
|
|
75
|
+
);
|
|
76
|
+
devtoolsMessage2[import_constant.__EAGER_SHARE__] = [pkgName, version, mergedScopes];
|
|
77
|
+
return {
|
|
78
|
+
shouldReload: !existing || existing.version !== version
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const requestUmdSourceSync = (url) => {
|
|
57
82
|
try {
|
|
58
83
|
const response = new XMLHttpRequest();
|
|
59
84
|
response.open("GET", url, false);
|
|
60
85
|
response.overrideMimeType("text/plain");
|
|
61
86
|
response.send();
|
|
62
87
|
if (response.status === 200) {
|
|
63
|
-
|
|
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
|
-
);
|
|
88
|
+
return response.responseText;
|
|
70
89
|
}
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Failed to load module from ${url}: HTTP ${response.status}`
|
|
92
|
+
);
|
|
71
93
|
} catch (error) {
|
|
72
94
|
throw new Error(`Failed to fetch module from ${url}: ${error.message}`);
|
|
73
95
|
}
|
|
74
96
|
};
|
|
97
|
+
const requestUmdSource = (url) => new Promise((resolve, reject) => {
|
|
98
|
+
try {
|
|
99
|
+
const response = new XMLHttpRequest();
|
|
100
|
+
response.open("GET", url, true);
|
|
101
|
+
response.overrideMimeType("text/plain");
|
|
102
|
+
response.onload = () => {
|
|
103
|
+
if (response.status === 200) {
|
|
104
|
+
resolve(response.responseText);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
reject(
|
|
108
|
+
new Error(
|
|
109
|
+
`Failed to load module from ${url}: HTTP ${response.status}`
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
response.onerror = () => {
|
|
114
|
+
reject(new Error(`Failed to fetch module from ${url}`));
|
|
115
|
+
};
|
|
116
|
+
response.send();
|
|
117
|
+
} catch (error) {
|
|
118
|
+
reject(new Error(`Failed to fetch module from ${url}: ${error.message}`));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const createUmdSandbox = (pkgName, scopes) => {
|
|
122
|
+
const sandboxTarget = /* @__PURE__ */ Object.create(null);
|
|
123
|
+
const sandbox = new Proxy(sandboxTarget, {
|
|
124
|
+
get(target, key) {
|
|
125
|
+
if (typeof key === "symbol") {
|
|
126
|
+
return Reflect.get(target, key);
|
|
127
|
+
}
|
|
128
|
+
if (key in target) {
|
|
129
|
+
return target[key];
|
|
130
|
+
}
|
|
131
|
+
const value = window[key];
|
|
132
|
+
return typeof value === "function" ? value.bind(window) : value;
|
|
133
|
+
},
|
|
134
|
+
set(target, key, value) {
|
|
135
|
+
target[key] = value;
|
|
136
|
+
return true;
|
|
137
|
+
},
|
|
138
|
+
has(target, key) {
|
|
139
|
+
return key in target || key in window;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
sandboxTarget.window = sandbox;
|
|
143
|
+
sandboxTarget.self = sandbox;
|
|
144
|
+
sandboxTarget.globalThis = sandbox;
|
|
145
|
+
sandboxTarget.global = sandbox;
|
|
146
|
+
sandboxTarget.document = window.document;
|
|
147
|
+
if (pkgName === "react-dom") {
|
|
148
|
+
sandboxTarget.React = getScopeGlobal("react", scopes);
|
|
149
|
+
}
|
|
150
|
+
return sandbox;
|
|
151
|
+
};
|
|
152
|
+
const executeUmdModule = (scriptContent, pkgName, scopes) => {
|
|
153
|
+
const sandbox = createUmdSandbox(pkgName, scopes);
|
|
154
|
+
const moduleFunction = new Function(
|
|
155
|
+
"window",
|
|
156
|
+
"self",
|
|
157
|
+
"globalThis",
|
|
158
|
+
"global",
|
|
159
|
+
"document",
|
|
160
|
+
"exports",
|
|
161
|
+
"module",
|
|
162
|
+
"define",
|
|
163
|
+
"require",
|
|
164
|
+
scriptContent
|
|
165
|
+
);
|
|
166
|
+
moduleFunction.call(
|
|
167
|
+
sandbox,
|
|
168
|
+
sandbox,
|
|
169
|
+
sandbox,
|
|
170
|
+
sandbox,
|
|
171
|
+
sandbox,
|
|
172
|
+
sandbox.document,
|
|
173
|
+
void 0,
|
|
174
|
+
void 0,
|
|
175
|
+
void 0,
|
|
176
|
+
void 0
|
|
177
|
+
);
|
|
178
|
+
return sandbox[getDefaultGlobalKey(pkgName)];
|
|
179
|
+
};
|
|
180
|
+
const loadUmdModuleSync = (pkgName, version, scopes) => executeUmdModule(
|
|
181
|
+
requestUmdSourceSync((0, import__.getUnpkgUrl)(pkgName, version)),
|
|
182
|
+
pkgName,
|
|
183
|
+
scopes
|
|
184
|
+
);
|
|
185
|
+
const loadUmdModule = (pkgName, version, scopes) => __async(exports, null, function* () {
|
|
186
|
+
return executeUmdModule(
|
|
187
|
+
yield requestUmdSource((0, import__.getUnpkgUrl)(pkgName, version)),
|
|
188
|
+
pkgName,
|
|
189
|
+
scopes
|
|
190
|
+
);
|
|
191
|
+
});
|
|
75
192
|
const getDevtoolsMessage = () => {
|
|
76
193
|
const devtoolsMessageStr = localStorage.getItem(import_constant.__FEDERATION_DEVTOOLS__);
|
|
77
194
|
if (devtoolsMessageStr) {
|
|
@@ -84,18 +201,31 @@ const getDevtoolsMessage = () => {
|
|
|
84
201
|
return null;
|
|
85
202
|
};
|
|
86
203
|
const devtoolsMessage = getDevtoolsMessage();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
204
|
+
const eagerShareInfo = getEagerShareInfo(devtoolsMessage == null ? void 0 : devtoolsMessage[import_constant.__EAGER_SHARE__]);
|
|
205
|
+
if ((devtoolsMessage == null ? void 0 : devtoolsMessage[import_constant.__ENABLE_FAST_REFRESH__]) && eagerShareInfo) {
|
|
206
|
+
const { version, scopes } = eagerShareInfo;
|
|
207
|
+
setScopeGlobals("react", scopes, loadUmdModuleSync("react", version, scopes));
|
|
208
|
+
setScopeGlobals(
|
|
209
|
+
"react-dom",
|
|
210
|
+
scopes,
|
|
211
|
+
loadUmdModuleSync("react-dom", version, scopes)
|
|
212
|
+
);
|
|
91
213
|
}
|
|
92
214
|
const fastRefreshPlugin = () => {
|
|
215
|
+
let orderResolve;
|
|
216
|
+
const orderPromise = new Promise((resolve) => {
|
|
217
|
+
orderResolve = resolve;
|
|
218
|
+
});
|
|
93
219
|
return {
|
|
94
220
|
name: "mf-fast-refresh-plugin",
|
|
95
|
-
|
|
96
|
-
var
|
|
97
|
-
const
|
|
98
|
-
|
|
221
|
+
beforeRegisterShare(args) {
|
|
222
|
+
var _a2;
|
|
223
|
+
const { pkgName, shared } = args;
|
|
224
|
+
if (!SUPPORT_PKGS.includes(pkgName)) {
|
|
225
|
+
return args;
|
|
226
|
+
}
|
|
227
|
+
const supportPkgName = pkgName;
|
|
228
|
+
const shareScopes = getShareScopes(shared.scope);
|
|
99
229
|
let enableFastRefresh = false;
|
|
100
230
|
let devtoolsMessage2 = {};
|
|
101
231
|
const devtoolsMessageStr = localStorage.getItem(import_constant.__FEDERATION_DEVTOOLS__);
|
|
@@ -108,106 +238,91 @@ const fastRefreshPlugin = () => {
|
|
|
108
238
|
}
|
|
109
239
|
}
|
|
110
240
|
if (!enableFastRefresh) {
|
|
111
|
-
return
|
|
112
|
-
userOptions
|
|
113
|
-
}, args);
|
|
241
|
+
return args;
|
|
114
242
|
}
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
243
|
+
if (((_a2 = shared.shareConfig) == null ? void 0 : _a2.eager) || shared.lib) {
|
|
244
|
+
if (!(devtoolsMessage2 == null ? void 0 : devtoolsMessage2[import_constant.__EAGER_SHARE__])) {
|
|
245
|
+
const eagerShareInfo2 = updateEagerShareInfo(
|
|
246
|
+
devtoolsMessage2,
|
|
247
|
+
pkgName,
|
|
248
|
+
shared.version,
|
|
249
|
+
shareScopes
|
|
250
|
+
);
|
|
251
|
+
localStorage.setItem(
|
|
252
|
+
import_constant.__FEDERATION_DEVTOOLS__,
|
|
253
|
+
JSON.stringify(devtoolsMessage2)
|
|
254
|
+
);
|
|
255
|
+
if (eagerShareInfo2.shouldReload) {
|
|
256
|
+
window.location.reload();
|
|
125
257
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
258
|
+
} else {
|
|
259
|
+
updateEagerShareInfo(
|
|
260
|
+
devtoolsMessage2,
|
|
261
|
+
pkgName,
|
|
262
|
+
shared.version,
|
|
263
|
+
shareScopes
|
|
264
|
+
);
|
|
265
|
+
localStorage.setItem(
|
|
266
|
+
import_constant.__FEDERATION_DEVTOOLS__,
|
|
267
|
+
JSON.stringify(devtoolsMessage2)
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (pkgName === "react-dom") {
|
|
271
|
+
shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
|
|
272
|
+
}
|
|
273
|
+
if (pkgName === "react") {
|
|
274
|
+
shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
|
|
275
|
+
}
|
|
276
|
+
return args;
|
|
277
|
+
}
|
|
278
|
+
let get;
|
|
279
|
+
if (pkgName === "react") {
|
|
280
|
+
get = () => loadUmdModule(supportPkgName, shared.version, shareScopes).then((moduleValue) => {
|
|
281
|
+
setScopeGlobals(supportPkgName, shareScopes, moduleValue);
|
|
282
|
+
return moduleValue;
|
|
283
|
+
}).then(() => {
|
|
284
|
+
orderResolve();
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (pkgName === "react-dom") {
|
|
288
|
+
get = () => orderPromise.then(
|
|
289
|
+
() => loadUmdModule(supportPkgName, shared.version, shareScopes)
|
|
290
|
+
).then((result) => {
|
|
291
|
+
setScopeGlobals(supportPkgName, shareScopes, result);
|
|
292
|
+
return result;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (typeof get === "function") {
|
|
296
|
+
const finalGet = get;
|
|
297
|
+
if (pkgName === "react") {
|
|
298
|
+
shared.get = () => __async(this, null, function* () {
|
|
299
|
+
if (!getScopeGlobal(supportPkgName, shareScopes)) {
|
|
300
|
+
yield finalGet();
|
|
301
|
+
console.warn(
|
|
302
|
+
"[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"
|
|
167
303
|
);
|
|
168
304
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
shared.lib = () => window.React;
|
|
179
|
-
return () => window.React;
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
if (share === "react-dom") {
|
|
183
|
-
shared.get = () => __async(this, null, function* () {
|
|
184
|
-
if (!window.ReactDOM) {
|
|
185
|
-
yield get();
|
|
186
|
-
}
|
|
187
|
-
shared.lib = () => window.ReactDOM;
|
|
188
|
-
return () => window.ReactDOM;
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
if (twinsShareInfo) {
|
|
192
|
-
twinsSharedArr[idx].get = shared.get;
|
|
193
|
-
}
|
|
305
|
+
shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
|
|
306
|
+
return () => getScopeGlobal(supportPkgName, shareScopes);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (pkgName === "react-dom") {
|
|
310
|
+
shared.get = () => __async(this, null, function* () {
|
|
311
|
+
if (!getScopeGlobal(supportPkgName, shareScopes)) {
|
|
312
|
+
yield finalGet();
|
|
194
313
|
}
|
|
314
|
+
shared.lib = () => getScopeGlobal(supportPkgName, shareScopes);
|
|
315
|
+
return () => getScopeGlobal(supportPkgName, shareScopes);
|
|
195
316
|
});
|
|
196
|
-
}
|
|
197
|
-
return __spreadValues({
|
|
198
|
-
userOptions
|
|
199
|
-
}, args);
|
|
200
|
-
} else {
|
|
201
|
-
return __spreadValues({
|
|
202
|
-
userOptions
|
|
203
|
-
}, args);
|
|
317
|
+
}
|
|
204
318
|
}
|
|
319
|
+
return args;
|
|
205
320
|
}
|
|
206
321
|
};
|
|
207
322
|
};
|
|
208
323
|
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
209
|
-
(0,
|
|
210
|
-
(0,
|
|
324
|
+
(0, import_sdk.definePropertyGlobalVal)(window, "__FEDERATION__", {});
|
|
325
|
+
(0, import_sdk.definePropertyGlobalVal)(window, "__VMOK__", window.__FEDERATION__);
|
|
211
326
|
}
|
|
212
327
|
if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
|
|
213
328
|
window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
@@ -105,10 +105,11 @@ const syncActiveTab = (tabId) => __async(void 0, null, function* () {
|
|
|
105
105
|
setTargetTab(tab);
|
|
106
106
|
return tab;
|
|
107
107
|
}
|
|
108
|
-
const
|
|
108
|
+
const tabs = yield getTabs({
|
|
109
109
|
active: true,
|
|
110
110
|
lastFocusedWindow: true
|
|
111
111
|
});
|
|
112
|
+
const activeTab = Array.isArray(tabs) ? tabs[0] : void 0;
|
|
112
113
|
setTargetTab(activeTab);
|
|
113
114
|
return activeTab;
|
|
114
115
|
} catch (error) {
|
|
@@ -131,9 +132,7 @@ function getInspectWindowTabId() {
|
|
|
131
132
|
function(info, error) {
|
|
132
133
|
const { tabId } = chrome.devtools.inspectedWindow;
|
|
133
134
|
getTabs().then((tabs) => {
|
|
134
|
-
const target = tabs.find(
|
|
135
|
-
(tab) => tab.id === tabId
|
|
136
|
-
);
|
|
135
|
+
const target = Array.isArray(tabs) ? tabs.find((tab) => tab.id === tabId) : void 0;
|
|
137
136
|
setTargetTab(target);
|
|
138
137
|
});
|
|
139
138
|
console.log(
|