@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { OBSERVABILITY_DEVTOOLS_SOURCE } from "./messages";
|
|
2
|
+
const CHROME_OBSERVABILITY_SCOPE = "chrome_extension";
|
|
3
|
+
const MIN_EVENTS = 10;
|
|
4
|
+
const MAX_EVENTS = 1e3;
|
|
5
|
+
const DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG = {
|
|
6
|
+
enabled: true,
|
|
7
|
+
level: "verbose",
|
|
8
|
+
maxEvents: 300,
|
|
9
|
+
console: true,
|
|
10
|
+
browser: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
scope: CHROME_OBSERVABILITY_SCOPE,
|
|
13
|
+
mode: "development"
|
|
14
|
+
},
|
|
15
|
+
trace: {
|
|
16
|
+
printStart: true
|
|
17
|
+
},
|
|
18
|
+
react: {
|
|
19
|
+
injectLoadedCallback: false,
|
|
20
|
+
remoteIds: []
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
24
|
+
const normalizeBoolean = (value, fallback) => typeof value === "boolean" ? value : fallback;
|
|
25
|
+
const normalizeLevel = (value) => value === "error" || value === "summary" || value === "verbose" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.level;
|
|
26
|
+
const normalizeMode = (value) => value === "production" || value === "development" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.mode;
|
|
27
|
+
const normalizeMaxEvents = (value) => {
|
|
28
|
+
const parsed = Number(value);
|
|
29
|
+
if (!Number.isFinite(parsed)) {
|
|
30
|
+
return DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.maxEvents;
|
|
31
|
+
}
|
|
32
|
+
return Math.max(MIN_EVENTS, Math.min(MAX_EVENTS, Math.floor(parsed)));
|
|
33
|
+
};
|
|
34
|
+
const normalizeScope = (value) => {
|
|
35
|
+
if (typeof value !== "string") {
|
|
36
|
+
return CHROME_OBSERVABILITY_SCOPE;
|
|
37
|
+
}
|
|
38
|
+
const trimmed = value.trim().replace(/[^\w:@.-]+/g, "-");
|
|
39
|
+
return trimmed || CHROME_OBSERVABILITY_SCOPE;
|
|
40
|
+
};
|
|
41
|
+
const normalizeObservabilityDevtoolsConfig = (value) => {
|
|
42
|
+
const source = isObject(value) ? value : {};
|
|
43
|
+
const browser = isObject(source.browser) ? source.browser : {};
|
|
44
|
+
const trace = isObject(source.trace) ? source.trace : {};
|
|
45
|
+
return {
|
|
46
|
+
enabled: normalizeBoolean(
|
|
47
|
+
source.enabled,
|
|
48
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.enabled
|
|
49
|
+
),
|
|
50
|
+
level: normalizeLevel(source.level),
|
|
51
|
+
maxEvents: normalizeMaxEvents(source.maxEvents),
|
|
52
|
+
console: normalizeBoolean(
|
|
53
|
+
source.console,
|
|
54
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.console
|
|
55
|
+
),
|
|
56
|
+
browser: {
|
|
57
|
+
enabled: normalizeBoolean(
|
|
58
|
+
browser.enabled,
|
|
59
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.enabled
|
|
60
|
+
),
|
|
61
|
+
scope: normalizeScope(browser.scope),
|
|
62
|
+
mode: normalizeMode(browser.mode)
|
|
63
|
+
},
|
|
64
|
+
trace: {
|
|
65
|
+
printStart: normalizeBoolean(
|
|
66
|
+
trace.printStart,
|
|
67
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.trace.printStart
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
react: {
|
|
71
|
+
injectLoadedCallback: false,
|
|
72
|
+
remoteIds: []
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const createObservabilityPluginOptions = (config) => ({
|
|
77
|
+
enabled: config.enabled,
|
|
78
|
+
level: config.level,
|
|
79
|
+
maxEvents: config.maxEvents,
|
|
80
|
+
console: config.console,
|
|
81
|
+
browser: {
|
|
82
|
+
enabled: config.browser.enabled,
|
|
83
|
+
scope: config.browser.scope,
|
|
84
|
+
mode: config.browser.mode
|
|
85
|
+
},
|
|
86
|
+
trace: {
|
|
87
|
+
printStart: config.trace.printStart
|
|
88
|
+
},
|
|
89
|
+
devtools: {
|
|
90
|
+
enabled: true,
|
|
91
|
+
source: OBSERVABILITY_DEVTOOLS_SOURCE
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
export {
|
|
95
|
+
CHROME_OBSERVABILITY_SCOPE,
|
|
96
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
97
|
+
createObservabilityPluginOptions,
|
|
98
|
+
normalizeObservabilityDevtoolsConfig
|
|
99
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { injectScript } from "./index";
|
|
22
|
+
import { OBSERVABILITY_DEVTOOLS_STORAGE_KEY } from "./messages";
|
|
23
|
+
import {
|
|
24
|
+
CHROME_OBSERVABILITY_SCOPE,
|
|
25
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
26
|
+
normalizeObservabilityDevtoolsConfig
|
|
27
|
+
} from "./observability-shared";
|
|
28
|
+
const USER_OBSERVABILITY_PLUGIN_NAME = "observability-plugin";
|
|
29
|
+
const CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin:chrome-extension";
|
|
30
|
+
const LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin-devtools";
|
|
31
|
+
const OBSERVABILITY_SNAPSHOT_CONTEXT = {
|
|
32
|
+
chromeScope: CHROME_OBSERVABILITY_SCOPE,
|
|
33
|
+
userPluginName: USER_OBSERVABILITY_PLUGIN_NAME,
|
|
34
|
+
chromePluginNames: [
|
|
35
|
+
CHROME_OBSERVABILITY_PLUGIN_NAME,
|
|
36
|
+
LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const readConfigFromPage = (storageKey) => {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
|
|
43
|
+
return raw ? JSON.parse(raw) : null;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const writeConfigToPage = (storageKey, config) => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = window.localStorage) == null ? void 0 : _a.setItem(storageKey, JSON.stringify(config));
|
|
51
|
+
return config;
|
|
52
|
+
};
|
|
53
|
+
const removeConfigFromPage = (storageKey) => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = window.localStorage) == null ? void 0 : _a.removeItem(storageKey);
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
const reloadPage = () => {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = globalThis.location) == null ? void 0 : _a.reload();
|
|
61
|
+
};
|
|
62
|
+
const readSnapshotFromPage = (storageKey, context) => {
|
|
63
|
+
const chromeScope = typeof (context == null ? void 0 : context.chromeScope) === "string" ? context.chromeScope : "chrome_extension";
|
|
64
|
+
const userPluginName = typeof (context == null ? void 0 : context.userPluginName) === "string" ? context.userPluginName : "observability-plugin";
|
|
65
|
+
const chromePluginNames = Array.isArray(context == null ? void 0 : context.chromePluginNames) ? context.chromePluginNames : [
|
|
66
|
+
"observability-plugin:chrome-extension",
|
|
67
|
+
"observability-plugin-devtools"
|
|
68
|
+
];
|
|
69
|
+
const safeCopy = (value) => {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(JSON.stringify(value));
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const rawConfig = (() => {
|
|
77
|
+
var _a;
|
|
78
|
+
try {
|
|
79
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
|
|
80
|
+
return raw ? JSON.parse(raw) : null;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
const federation = window.__FEDERATION__ || window.__VMOK__;
|
|
86
|
+
const readers = (federation == null ? void 0 : federation.__OBSERVABILITY__) || {};
|
|
87
|
+
const reports = [];
|
|
88
|
+
const scopes = Object.keys(readers);
|
|
89
|
+
const isChromeObservabilityPluginName = (name) => chromePluginNames.includes(String(name));
|
|
90
|
+
const hasUserObservabilityPluginFromInstances = Array.isArray(
|
|
91
|
+
federation == null ? void 0 : federation.__INSTANCES__
|
|
92
|
+
) ? federation.__INSTANCES__.some((instance) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const plugins = (_a = instance == null ? void 0 : instance.options) == null ? void 0 : _a.plugins;
|
|
95
|
+
if (!Array.isArray(plugins)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return plugins.some(
|
|
99
|
+
(plugin) => (plugin == null ? void 0 : plugin.name) === userPluginName && !isChromeObservabilityPluginName(plugin == null ? void 0 : plugin.name)
|
|
100
|
+
);
|
|
101
|
+
}) : false;
|
|
102
|
+
const hasUserObservabilityPluginFromReaders = scopes.some(
|
|
103
|
+
(scope) => scope !== chromeScope
|
|
104
|
+
);
|
|
105
|
+
scopes.forEach((scope) => {
|
|
106
|
+
const reader = readers[scope];
|
|
107
|
+
if (!reader || typeof reader.getReports !== "function") {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const scopeReports = reader.getReports({ limit: 100 });
|
|
112
|
+
if (!Array.isArray(scopeReports)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
scopeReports.forEach((report) => {
|
|
116
|
+
const copied = safeCopy(report);
|
|
117
|
+
if (copied == null ? void 0 : copied.traceId) {
|
|
118
|
+
copied.__scope = scope;
|
|
119
|
+
reports.push(copied);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (e) {
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
config: rawConfig,
|
|
127
|
+
stored: Boolean(rawConfig),
|
|
128
|
+
scopes,
|
|
129
|
+
reports,
|
|
130
|
+
hasUserObservabilityPlugin: hasUserObservabilityPluginFromInstances || hasUserObservabilityPluginFromReaders
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const readObservabilityConfig = () => __async(void 0, null, function* () {
|
|
134
|
+
const config = yield injectScript(
|
|
135
|
+
readConfigFromPage,
|
|
136
|
+
false,
|
|
137
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
138
|
+
);
|
|
139
|
+
return normalizeObservabilityDevtoolsConfig(
|
|
140
|
+
config || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
const applyObservabilityConfig = (config) => __async(void 0, null, function* () {
|
|
144
|
+
return injectScript(
|
|
145
|
+
writeConfigToPage,
|
|
146
|
+
false,
|
|
147
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
|
|
148
|
+
normalizeObservabilityDevtoolsConfig(config)
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
const disableObservabilityConfig = () => __async(void 0, null, function* () {
|
|
152
|
+
return injectScript(removeConfigFromPage, false, OBSERVABILITY_DEVTOOLS_STORAGE_KEY);
|
|
153
|
+
});
|
|
154
|
+
const reloadInspectedPage = () => __async(void 0, null, function* () {
|
|
155
|
+
return injectScript(reloadPage, false);
|
|
156
|
+
});
|
|
157
|
+
const readObservabilitySnapshot = () => __async(void 0, null, function* () {
|
|
158
|
+
const snapshot = yield injectScript(
|
|
159
|
+
readSnapshotFromPage,
|
|
160
|
+
true,
|
|
161
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
|
|
162
|
+
OBSERVABILITY_SNAPSHOT_CONTEXT
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
config: normalizeObservabilityDevtoolsConfig(
|
|
166
|
+
(snapshot == null ? void 0 : snapshot.config) || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
|
|
167
|
+
),
|
|
168
|
+
stored: Boolean(snapshot == null ? void 0 : snapshot.stored),
|
|
169
|
+
scopes: Array.isArray(snapshot == null ? void 0 : snapshot.scopes) ? snapshot.scopes : [],
|
|
170
|
+
reports: Array.isArray(snapshot == null ? void 0 : snapshot.reports) ? snapshot.reports : [],
|
|
171
|
+
hasUserObservabilityPlugin: Boolean(snapshot == null ? void 0 : snapshot.hasUserObservabilityPlugin)
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const mergeObservabilityReports = (currentReports, incomingReports) => {
|
|
175
|
+
const merged = /* @__PURE__ */ new Map();
|
|
176
|
+
currentReports.forEach((report) => {
|
|
177
|
+
if (report.traceId) {
|
|
178
|
+
merged.set(report.traceId, report);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
incomingReports.forEach((report) => {
|
|
182
|
+
if (report.traceId) {
|
|
183
|
+
merged.set(report.traceId, report);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return Array.from(merged.values()).sort((left, right) => {
|
|
187
|
+
if ((right.updatedAt || 0) !== (left.updatedAt || 0)) {
|
|
188
|
+
return (right.updatedAt || 0) - (left.updatedAt || 0);
|
|
189
|
+
}
|
|
190
|
+
return (right.startedAt || 0) - (left.startedAt || 0);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const getObservabilityReportScopeLabel = (report) => {
|
|
194
|
+
const scope = report.__scope;
|
|
195
|
+
if (!scope || scope === CHROME_OBSERVABILITY_SCOPE) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
return `custom: ${scope}`;
|
|
199
|
+
};
|
|
200
|
+
export {
|
|
201
|
+
applyObservabilityConfig,
|
|
202
|
+
disableObservabilityConfig,
|
|
203
|
+
getObservabilityReportScopeLabel,
|
|
204
|
+
mergeObservabilityReports,
|
|
205
|
+
readObservabilityConfig,
|
|
206
|
+
readObservabilitySnapshot,
|
|
207
|
+
reloadInspectedPage
|
|
208
|
+
};
|
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { definePropertyGlobalVal } from "../sdk";
|
|
4
|
-
import { __FEDERATION_DEVTOOLS__ } from "../../template";
|
|
5
|
-
const chromeOverrideRemotesPlugin = function() {
|
|
6
|
-
return {
|
|
7
|
-
name: "mf-chrome-devtools-override-remotes-plugin",
|
|
8
|
-
beforeRegisterRemote(args) {
|
|
9
|
-
try {
|
|
10
|
-
const { remote } = args;
|
|
11
|
-
const overrideRemote = runtimeHelpers.global.nativeGlobal.localStorage.getItem(
|
|
12
|
-
__FEDERATION_DEVTOOLS__
|
|
13
|
-
);
|
|
14
|
-
if (!overrideRemote) {
|
|
15
|
-
return args;
|
|
16
|
-
}
|
|
17
|
-
const parsedOverrideRemote = JSON.parse(overrideRemote);
|
|
18
|
-
const overrideEntryOrVersion = parsedOverrideRemote[remote.name];
|
|
19
|
-
if (overrideEntryOrVersion) {
|
|
20
|
-
if (overrideEntryOrVersion.startsWith("http")) {
|
|
21
|
-
delete remote.version;
|
|
22
|
-
remote.entry = overrideEntryOrVersion;
|
|
23
|
-
} else {
|
|
24
|
-
delete remote.entry;
|
|
25
|
-
remote.version = overrideEntryOrVersion;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error(e);
|
|
30
|
-
}
|
|
31
|
-
return args;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
36
|
-
definePropertyGlobalVal(window, "__FEDERATION__", {});
|
|
37
|
-
definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
|
|
38
|
-
}
|
|
39
|
-
if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
|
|
40
|
-
window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
41
|
-
}
|
|
42
|
-
(_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(chromeOverrideRemotesPlugin());
|
|
1
|
+
const basicProxyCore = require("../../vendor/basic-proxy-core.js");
|
|
2
|
+
basicProxyCore.registerOverridePlugin(globalThis);
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { sanitizePostMessagePayload } from "./safe-post-message";
|
|
2
|
+
import {
|
|
3
|
+
MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
|
|
4
|
+
OBSERVABILITY_DEVTOOLS_SOURCE
|
|
5
|
+
} from "./messages";
|
|
2
6
|
if (window.moduleHandler) {
|
|
3
7
|
window.removeEventListener("message", window.moduleHandler);
|
|
4
8
|
} else {
|
|
5
9
|
window.moduleHandler = (event) => {
|
|
6
10
|
const { origin, data } = event;
|
|
11
|
+
if ((data == null ? void 0 : data.source) === OBSERVABILITY_DEVTOOLS_SOURCE) {
|
|
12
|
+
chrome.runtime.sendMessage({
|
|
13
|
+
type: MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
|
|
14
|
+
origin,
|
|
15
|
+
data: sanitizePostMessagePayload(data)
|
|
16
|
+
}).catch(() => {
|
|
17
|
+
return false;
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
7
21
|
if (!data.moduleInfo) {
|
|
8
22
|
return;
|
|
9
23
|
}
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import runtimeHelpers from "@module-federation/runtime/helpers";
|
|
4
|
-
import { definePropertyGlobalVal } from "../sdk";
|
|
5
|
-
const chromeDevtoolsPlugin = function() {
|
|
6
|
-
return {
|
|
7
|
-
name: "mf-chrome-devtools-inject-snapshot-plugin",
|
|
8
|
-
beforeLoadRemoteSnapshot({ options }) {
|
|
9
|
-
const { nativeGlobal } = runtimeHelpers.global;
|
|
10
|
-
if (!options || options.inBrowser) {
|
|
11
|
-
const realLocalStorage = nativeGlobal.localStorage || localStorage;
|
|
12
|
-
const debugModuleInfoStr = realLocalStorage.getItem(
|
|
13
|
-
MODULE_DEVTOOL_IDENTIFIER
|
|
14
|
-
);
|
|
15
|
-
if (debugModuleInfoStr && !nativeGlobal.__INIT_VMOK_CHROME_DEVTOOL_PLUGIN__) {
|
|
16
|
-
const chromeDevtoolSnapshot = JSON.parse(debugModuleInfoStr);
|
|
17
|
-
if (chromeDevtoolSnapshot) {
|
|
18
|
-
runtimeHelpers.global.addGlobalSnapshot(chromeDevtoolSnapshot);
|
|
19
|
-
nativeGlobal.__INIT_VMOK_CHROME_DEVTOOL_PLUGIN__ = true;
|
|
20
|
-
console.warn(
|
|
21
|
-
"[Module Federation Devtools]: You are using the chrome devtool to proxy online module"
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
30
|
-
definePropertyGlobalVal(window, "__FEDERATION__", {});
|
|
31
|
-
definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
|
|
32
|
-
}
|
|
33
|
-
if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
|
|
34
|
-
window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
35
|
-
}
|
|
36
|
-
(_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(chromeDevtoolsPlugin());
|
|
1
|
+
const basicProxyCore = require("../../vendor/basic-proxy-core.js");
|
|
2
|
+
basicProxyCore.registerSnapshotPlugin(globalThis);
|
|
@@ -18,7 +18,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
18
18
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const basicProxyCore = require("../../vendor/basic-proxy-core.js");
|
|
22
22
|
const separateType = (moduleInfo) => {
|
|
23
23
|
const consumers = {};
|
|
24
24
|
const producer = [];
|
|
@@ -48,31 +48,11 @@ const separateType = (moduleInfo) => {
|
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
const getModuleInfo = (proxyRules) => __async(void 0, null, function* () {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const isMicroMode = Object.keys(consumers).some((moduleId) => {
|
|
56
|
-
const subApps = consumers[moduleId].consumerList;
|
|
57
|
-
return Array.isArray(subApps) && subApps.length;
|
|
58
|
-
});
|
|
59
|
-
proxyRules.forEach((rule) => {
|
|
60
|
-
const { key, value } = rule;
|
|
61
|
-
overrides[key] = value;
|
|
62
|
-
});
|
|
63
|
-
if (isMicroMode) {
|
|
64
|
-
freshModuleInfo = calculateMicroAppSnapshot(moduleInfo, overrides);
|
|
65
|
-
} else {
|
|
66
|
-
freshModuleInfo = calculateSnapshot(moduleInfo, overrides);
|
|
67
|
-
}
|
|
68
|
-
console.debug("New Snapshot: ", freshModuleInfo);
|
|
69
|
-
return {
|
|
70
|
-
status: "success",
|
|
71
|
-
moduleInfo: freshModuleInfo,
|
|
72
|
-
overrides
|
|
73
|
-
};
|
|
51
|
+
return basicProxyCore.getModuleInfo(
|
|
52
|
+
proxyRules,
|
|
53
|
+
window.__FEDERATION__.moduleInfo
|
|
54
|
+
);
|
|
74
55
|
});
|
|
75
|
-
export * from "./snapshot";
|
|
76
56
|
export {
|
|
77
57
|
getModuleInfo,
|
|
78
58
|
separateType
|
|
@@ -0,0 +1,155 @@
|
|
|
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;
|
|
4
|
+
};
|
|
5
|
+
var require_basic_proxy_core = __commonJS({
|
|
6
|
+
"src/vendor/basic-proxy-core.js"(exports) {
|
|
7
|
+
var P = "__MF_DEVTOOLS_MODULE_INFO__", f = "__MF_DEVTOOLS__", G = "MF_ENV", h = "mf-chrome-devtools-inject-snapshot-plugin", L = "mf-chrome-devtools-override-remotes-plugin", l = () => globalThis, y = (e) => Object.prototype.toString.call(e) === "[object Object]", O = (e) => JSON.parse(JSON.stringify(e || {})), d = (e, t, o) => {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(e, t)) {
|
|
9
|
+
e[t] = o;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(e, t, { value: o, configurable: false, writable: true });
|
|
13
|
+
}, g = (e = l()) => {
|
|
14
|
+
!e.__FEDERATION__ && e.__VMOK__ && d(e, "__FEDERATION__", e.__VMOK__), e.__FEDERATION__ || d(e, "__FEDERATION__", {}), e.__VMOK__ || d(e, "__VMOK__", e.__FEDERATION__);
|
|
15
|
+
let t = e.__FEDERATION__;
|
|
16
|
+
return Array.isArray(t.__GLOBAL_PLUGIN__) || (t.__GLOBAL_PLUGIN__ = []), y(t.moduleInfo) || (t.moduleInfo = {}), t;
|
|
17
|
+
}, p = (e, t) => {
|
|
18
|
+
if (!e)
|
|
19
|
+
return t;
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(e);
|
|
22
|
+
} catch (o) {
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
}, x = (e = l()) => {
|
|
26
|
+
var t;
|
|
27
|
+
return e.localStorage || ((t = e.window) == null ? void 0 : t.localStorage);
|
|
28
|
+
}, M = (e = l()) => {
|
|
29
|
+
let t = x(e);
|
|
30
|
+
return t ? p(t.getItem(P), null) : null;
|
|
31
|
+
}, I = (e) => {
|
|
32
|
+
let t = {};
|
|
33
|
+
return y(e) && Object.keys(e).forEach((o) => {
|
|
34
|
+
typeof e[o] == "string" && e[o] && (t[o] = e[o]);
|
|
35
|
+
}), t;
|
|
36
|
+
}, N = (e = l()) => {
|
|
37
|
+
let t = x(e);
|
|
38
|
+
if (!t)
|
|
39
|
+
return {};
|
|
40
|
+
let o = p(t.getItem(f), {});
|
|
41
|
+
return y(o.overrides) ? I(o.overrides) : I(o);
|
|
42
|
+
}, S = (e) => e.indexOf("http://") === 0 || e.indexOf("https://") === 0 || e.indexOf("//") === 0, m = (e, t) => {
|
|
43
|
+
Reflect.deleteProperty(e, t);
|
|
44
|
+
}, T = (e) => {
|
|
45
|
+
let t = {}, o = [];
|
|
46
|
+
return Object.keys(e || {}).forEach((s) => {
|
|
47
|
+
var r;
|
|
48
|
+
let i = (r = e[s]) == null ? void 0 : r.remotesInfo;
|
|
49
|
+
if (i) {
|
|
50
|
+
let n = Object.keys(i);
|
|
51
|
+
n.length && (n.forEach((c) => {
|
|
52
|
+
let a = c;
|
|
53
|
+
c.indexOf(":") !== -1 && (a = c.split(":").pop()), o.indexOf(a) === -1 && o.push(c);
|
|
54
|
+
}), t[s] = e[s]);
|
|
55
|
+
}
|
|
56
|
+
}), { consumers: t, producer: o };
|
|
57
|
+
}, R = (e, t) => {
|
|
58
|
+
let o = Object.keys(t || {}).reduce((i, r) => (r.indexOf(":") !== -1 && (i[r.split(":")[1]] = t[r]), i), {}), s = O(e);
|
|
59
|
+
return Object.keys(e || {}).forEach((i) => {
|
|
60
|
+
let r = e[i];
|
|
61
|
+
r != null && r.remotesInfo && Object.keys(r.remotesInfo).forEach((n) => {
|
|
62
|
+
let c = n.split(":")[1], a = t[n] || o[n] || t[c] || o[c];
|
|
63
|
+
a && (s[i].remotesInfo[n].matchedVersion = a, s[`${n}:${a}`] = { remoteEntry: a, version: a });
|
|
64
|
+
});
|
|
65
|
+
}), s;
|
|
66
|
+
}, v = (e, t) => {
|
|
67
|
+
let o = null, s = O(e);
|
|
68
|
+
if (Object.keys(e || {}).forEach((r) => {
|
|
69
|
+
let n = s[r];
|
|
70
|
+
n && Array.isArray(n.consumerList) && n.consumerList.length > 0 && (o = n);
|
|
71
|
+
}), !o)
|
|
72
|
+
return s;
|
|
73
|
+
let i = o.consumerList;
|
|
74
|
+
for (let r = 0; r < i.length; r++) {
|
|
75
|
+
let n = "", c = i[r];
|
|
76
|
+
if (Object.keys(t || {}).find((_) => {
|
|
77
|
+
let u = _;
|
|
78
|
+
return _.indexOf(":") !== -1 && (u = _.split(":")[1]), c.indexOf(u) !== -1 ? (n = _, true) : false;
|
|
79
|
+
})) {
|
|
80
|
+
let _ = t[n], u = c.split(":");
|
|
81
|
+
u[u.length - 1] = _, i[r] = u.join(":"), s[`${n}:${_}`] = { remoteEntry: _, version: _ };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return R(s, t);
|
|
85
|
+
}, F = (e = [], t) => {
|
|
86
|
+
var n;
|
|
87
|
+
let o = t || ((n = l().__FEDERATION__) == null ? void 0 : n.moduleInfo) || {}, s = {}, { consumers: i } = T(o), r = Object.keys(i).some((c) => {
|
|
88
|
+
var _;
|
|
89
|
+
let a = (_ = i[c]) == null ? void 0 : _.consumerList;
|
|
90
|
+
return Array.isArray(a) && a.length > 0;
|
|
91
|
+
});
|
|
92
|
+
return e.forEach((c) => {
|
|
93
|
+
c != null && c.key && (c != null && c.value) && (s[c.key] = c.value);
|
|
94
|
+
}), { status: "success", moduleInfo: r ? v(o, s) : R(o, s), overrides: s };
|
|
95
|
+
}, E = (e = l()) => {
|
|
96
|
+
let t = e, o = false;
|
|
97
|
+
return { name: h, beforeLoadRemoteSnapshot: (s) => {
|
|
98
|
+
var c;
|
|
99
|
+
let i = s == null ? void 0 : s.options;
|
|
100
|
+
if (i && i.inBrowser === false)
|
|
101
|
+
return;
|
|
102
|
+
let r = M(t);
|
|
103
|
+
if (!r || o)
|
|
104
|
+
return;
|
|
105
|
+
let n = g(t);
|
|
106
|
+
n.moduleInfo = Object.assign({}, n.moduleInfo || {}, r), o = true, (c = t.console) == null || c.warn("[Module Federation Devtools]: You are using the chrome devtool to proxy online module");
|
|
107
|
+
} };
|
|
108
|
+
}, B = (e = l()) => {
|
|
109
|
+
let t = e;
|
|
110
|
+
return { name: L, beforeRegisterRemote: (o) => {
|
|
111
|
+
var s;
|
|
112
|
+
try {
|
|
113
|
+
let i = o == null ? void 0 : o.remote;
|
|
114
|
+
if (!i)
|
|
115
|
+
return o;
|
|
116
|
+
let r = N(t), n = r[i.name] || r[i.alias || ""];
|
|
117
|
+
if (!n)
|
|
118
|
+
return o;
|
|
119
|
+
S(n) ? (m(i, "version"), i.entry = n) : (m(i, "entry"), i.version = n);
|
|
120
|
+
} catch (i) {
|
|
121
|
+
(s = t.console) == null || s.error(i);
|
|
122
|
+
}
|
|
123
|
+
return o;
|
|
124
|
+
} };
|
|
125
|
+
}, b = (e = l()) => {
|
|
126
|
+
let t = g(e);
|
|
127
|
+
return [B(e), E(e)].forEach((s) => {
|
|
128
|
+
var r, n;
|
|
129
|
+
((r = t.__GLOBAL_PLUGIN__) == null ? void 0 : r.some((c) => c.name === s.name)) || (n = t.__GLOBAL_PLUGIN__) == null || n.push(s);
|
|
130
|
+
}), t.__GLOBAL_PLUGIN__ || [];
|
|
131
|
+
}, A = (e, t) => {
|
|
132
|
+
var r, n;
|
|
133
|
+
let o = g(e), s = t(e);
|
|
134
|
+
return ((r = o.__GLOBAL_PLUGIN__) == null ? void 0 : r.some((c) => c.name === s.name)) || (n = o.__GLOBAL_PLUGIN__) == null || n.push(s), s;
|
|
135
|
+
}, k = (e = l()) => A(e, B), D = (e = l()) => A(e, E), V = (e = l()) => {
|
|
136
|
+
let t = x(e);
|
|
137
|
+
if (!t)
|
|
138
|
+
return;
|
|
139
|
+
t.removeItem(P), t.removeItem(G);
|
|
140
|
+
let o = p(t.getItem(f), {});
|
|
141
|
+
y(o) && (m(o, "overrides"), Object.keys(o).length ? t.setItem(f, JSON.stringify(o)) : t.removeItem(f));
|
|
142
|
+
};
|
|
143
|
+
exports.calculateMicroAppSnapshot = v;
|
|
144
|
+
exports.calculateSnapshot = R;
|
|
145
|
+
exports.createOverridePlugin = B;
|
|
146
|
+
exports.createSnapshotPlugin = E;
|
|
147
|
+
exports.getModuleInfo = F;
|
|
148
|
+
exports.registerOverridePlugin = k;
|
|
149
|
+
exports.registerRuntimePlugins = b;
|
|
150
|
+
exports.registerSnapshotPlugin = D;
|
|
151
|
+
exports.resetProxyStorage = V;
|
|
152
|
+
exports.separateType = T;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
export default require_basic_proxy_core();
|
package/dist/es/worker/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
1
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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
|
+
};
|
|
2
18
|
var __commonJS = (cb, mod) => function __require() {
|
|
3
19
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
20
|
};
|
|
@@ -40,12 +56,12 @@ var require_worker = __commonJS({
|
|
|
40
56
|
});
|
|
41
57
|
return activeTab == null ? void 0 : activeTab.id;
|
|
42
58
|
});
|
|
43
|
-
const broadcastActiveTab = (tabId) => {
|
|
59
|
+
const broadcastActiveTab = (tabId, payload) => {
|
|
44
60
|
try {
|
|
45
|
-
chrome.runtime.sendMessage({
|
|
61
|
+
chrome.runtime.sendMessage(__spreadValues({
|
|
46
62
|
type: MESSAGE_ACTIVE_TAB_CHANGED,
|
|
47
63
|
tabId
|
|
48
|
-
});
|
|
64
|
+
}, payload));
|
|
49
65
|
} catch (error) {
|
|
50
66
|
console.warn(
|
|
51
67
|
"[Module Federation Devtools] Failed to broadcast active tab",
|
|
@@ -70,11 +86,11 @@ var require_worker = __commonJS({
|
|
|
70
86
|
if (sidePanel.open) {
|
|
71
87
|
yield sidePanel.open({ tabId: targetTabId });
|
|
72
88
|
}
|
|
73
|
-
broadcastActiveTab(targetTabId);
|
|
89
|
+
broadcastActiveTab(targetTabId, { reason: "side-panel" });
|
|
74
90
|
if (sidePanel.getOptions) {
|
|
75
91
|
try {
|
|
76
92
|
const options = yield sidePanel.getOptions({ tabId: targetTabId });
|
|
77
|
-
broadcastActiveTab(targetTabId);
|
|
93
|
+
broadcastActiveTab(targetTabId, { reason: "side-panel" });
|
|
78
94
|
return options;
|
|
79
95
|
} catch (error) {
|
|
80
96
|
console.warn("[Module Federation Devtools] getOptions failed", error);
|
|
@@ -121,7 +137,7 @@ var require_worker = __commonJS({
|
|
|
121
137
|
return;
|
|
122
138
|
}
|
|
123
139
|
try {
|
|
124
|
-
broadcastActiveTab(tabId);
|
|
140
|
+
broadcastActiveTab(tabId, { reason: "activated" });
|
|
125
141
|
} catch (error) {
|
|
126
142
|
console.warn(
|
|
127
143
|
"[Module Federation Devtools] Failed to handle tab activation",
|
|
@@ -130,12 +146,15 @@ var require_worker = __commonJS({
|
|
|
130
146
|
}
|
|
131
147
|
}));
|
|
132
148
|
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
133
|
-
if (changeInfo.status !== "complete") {
|
|
149
|
+
if (changeInfo.status !== "loading" && changeInfo.status !== "complete") {
|
|
134
150
|
return;
|
|
135
151
|
}
|
|
136
152
|
if (tab == null ? void 0 : tab.active) {
|
|
137
153
|
try {
|
|
138
|
-
broadcastActiveTab(tabId
|
|
154
|
+
broadcastActiveTab(tabId, {
|
|
155
|
+
reason: "updated",
|
|
156
|
+
status: changeInfo.status
|
|
157
|
+
});
|
|
139
158
|
} catch (error) {
|
|
140
159
|
console.warn(
|
|
141
160
|
"[Module Federation Devtools] Failed to handle tab update",
|