@module-federation/devtools 0.0.0-next-20240425091022
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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/es/App.js +31 -0
- package/dist/es/App.module.js +5 -0
- package/dist/es/App_module.css +19 -0
- package/dist/es/component/Form/index.js +283 -0
- package/dist/es/component/Form/index.module.js +5 -0
- package/dist/es/component/Form/index_module.css +43 -0
- package/dist/es/component/Graph/index.js +127 -0
- package/dist/es/component/Graph/index.module.js +5 -0
- package/dist/es/component/Graph/index_module.css +12 -0
- package/dist/es/component/GraphItem/index.js +73 -0
- package/dist/es/component/GraphItem/index.module.js +5 -0
- package/dist/es/component/GraphItem/index_module.css +56 -0
- package/dist/es/component/Layout/index.js +207 -0
- package/dist/es/component/Layout/index.module.js +5 -0
- package/dist/es/component/Layout/index_module.css +48 -0
- package/dist/es/init.js +8 -0
- package/dist/es/template/constant.js +65 -0
- package/dist/es/template/index.js +1 -0
- package/dist/es/utils/chrome/fast-refresh-init.js +5 -0
- package/dist/es/utils/chrome/fast-refresh.js +113 -0
- package/dist/es/utils/chrome/index.js +211 -0
- package/dist/es/utils/chrome/post-message-init.js +5 -0
- package/dist/es/utils/chrome/post-message-listener.js +20 -0
- package/dist/es/utils/chrome/post-message-start.js +8 -0
- package/dist/es/utils/chrome/post-message.js +62 -0
- package/dist/es/utils/chrome/snapshot-plugin-init.js +5 -0
- package/dist/es/utils/chrome/snapshot-plugin.js +36 -0
- package/dist/es/utils/chrome/storage.js +45 -0
- package/dist/es/utils/data/index.js +79 -0
- package/dist/es/utils/data/snapshot.js +82 -0
- package/dist/es/utils/index.js +4 -0
- package/dist/es/utils/sdk/graph.js +148 -0
- package/dist/es/utils/sdk/index.js +55 -0
- package/dist/es/utils/types/common.js +0 -0
- package/dist/es/utils/types/index.js +1 -0
- package/dist/es/worker/index.js +1 -0
- package/dist/lib/App.js +61 -0
- package/dist/lib/App.module.js +25 -0
- package/dist/lib/App_module.css +19 -0
- package/dist/lib/component/Form/index.js +295 -0
- package/dist/lib/component/Form/index.module.js +25 -0
- package/dist/lib/component/Form/index_module.css +43 -0
- package/dist/lib/component/Graph/index.js +149 -0
- package/dist/lib/component/Graph/index.module.js +25 -0
- package/dist/lib/component/Graph/index_module.css +12 -0
- package/dist/lib/component/GraphItem/index.js +103 -0
- package/dist/lib/component/GraphItem/index.module.js +25 -0
- package/dist/lib/component/GraphItem/index_module.css +56 -0
- package/dist/lib/component/Layout/index.js +214 -0
- package/dist/lib/component/Layout/index.module.js +25 -0
- package/dist/lib/component/Layout/index_module.css +48 -0
- package/dist/lib/init.js +9 -0
- package/dist/lib/template/constant.js +95 -0
- package/dist/lib/template/index.js +22 -0
- package/dist/lib/utils/chrome/fast-refresh-init.js +6 -0
- package/dist/lib/utils/chrome/fast-refresh.js +114 -0
- package/dist/lib/utils/chrome/index.js +245 -0
- package/dist/lib/utils/chrome/post-message-init.js +6 -0
- package/dist/lib/utils/chrome/post-message-listener.js +21 -0
- package/dist/lib/utils/chrome/post-message-start.js +9 -0
- package/dist/lib/utils/chrome/post-message.js +83 -0
- package/dist/lib/utils/chrome/snapshot-plugin-init.js +6 -0
- package/dist/lib/utils/chrome/snapshot-plugin.js +59 -0
- package/dist/lib/utils/chrome/storage.js +67 -0
- package/dist/lib/utils/data/index.js +106 -0
- package/dist/lib/utils/data/snapshot.js +107 -0
- package/dist/lib/utils/index.js +28 -0
- package/dist/lib/utils/sdk/graph.js +171 -0
- package/dist/lib/utils/sdk/index.js +89 -0
- package/dist/lib/utils/types/common.js +16 -0
- package/dist/lib/utils/types/index.js +22 -0
- package/dist/lib/worker/index.js +2 -0
- package/dist/types/src/App.d.ts +6 -0
- package/dist/types/src/component/Form/index.d.ts +18 -0
- package/dist/types/src/component/Graph/index.d.ts +7 -0
- package/dist/types/src/component/GraphItem/index.d.ts +10 -0
- package/dist/types/src/component/Layout/index.d.ts +7 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/init.d.ts +13 -0
- package/dist/types/src/template/constant.d.ts +23 -0
- package/dist/types/src/template/index.d.ts +1 -0
- package/dist/types/src/utils/chrome/fast-refresh-init.d.ts +1 -0
- package/dist/types/src/utils/chrome/fast-refresh.d.ts +1 -0
- package/dist/types/src/utils/chrome/index.d.ts +16 -0
- package/dist/types/src/utils/chrome/post-message-init.d.ts +1 -0
- package/dist/types/src/utils/chrome/post-message-listener.d.ts +0 -0
- package/dist/types/src/utils/chrome/post-message-start.d.ts +1 -0
- package/dist/types/src/utils/chrome/post-message.d.ts +1 -0
- package/dist/types/src/utils/chrome/snapshot-plugin-init.d.ts +1 -0
- package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +4 -0
- package/dist/types/src/utils/chrome/storage.d.ts +4 -0
- package/dist/types/src/utils/data/index.d.ts +11 -0
- package/dist/types/src/utils/data/snapshot.d.ts +3 -0
- package/dist/types/src/utils/index.d.ts +4 -0
- package/dist/types/src/utils/sdk/graph.d.ts +44 -0
- package/dist/types/src/utils/sdk/index.d.ts +10 -0
- package/dist/types/src/utils/types/common.d.ts +15 -0
- package/dist/types/src/utils/types/index.d.ts +1 -0
- package/dist/types/src/worker/index.d.ts +0 -0
- package/dist/types/stories/index.stories.d.ts +9 -0
- package/install-deps.bash +8 -0
- package/package.json +85 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { FormID } from "../../template/constant";
|
|
41
|
+
import { definePropertyGlobalVal } from "../sdk";
|
|
42
|
+
export * from "./storage";
|
|
43
|
+
const sleep = (num) => {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
resolve();
|
|
47
|
+
}, num);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const injectPostMessage = (postMessageUrl) => {
|
|
51
|
+
const script = document.createElement("script");
|
|
52
|
+
script.src = postMessageUrl;
|
|
53
|
+
document.getElementsByTagName("head")[0].appendChild(script);
|
|
54
|
+
};
|
|
55
|
+
const TabInfo = {
|
|
56
|
+
currentTabId: 0
|
|
57
|
+
};
|
|
58
|
+
function getCurrentTabId() {
|
|
59
|
+
return TabInfo.currentTabId;
|
|
60
|
+
}
|
|
61
|
+
function getInspectWindowTabId() {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
var _a;
|
|
64
|
+
if ((_a = chrome == null ? void 0 : chrome.devtools) == null ? void 0 : _a.inspectedWindow) {
|
|
65
|
+
if (chrome.isDevMode) {
|
|
66
|
+
resolve(0);
|
|
67
|
+
}
|
|
68
|
+
chrome.devtools.inspectedWindow.eval(
|
|
69
|
+
'typeof window.__FEDERATION__ !== "undefined" || typeof window.__VMOK__ !== "undefined"',
|
|
70
|
+
function(info, error) {
|
|
71
|
+
const { tabId } = chrome.devtools.inspectedWindow;
|
|
72
|
+
getTabs().then((tabs) => {
|
|
73
|
+
const target = tabs.find(
|
|
74
|
+
(tab) => tab.id === tabId
|
|
75
|
+
);
|
|
76
|
+
window.targetTab = target;
|
|
77
|
+
});
|
|
78
|
+
console.log(
|
|
79
|
+
"chrome.devtools.inspectedWindow.tabId",
|
|
80
|
+
chrome.devtools.inspectedWindow.tabId
|
|
81
|
+
);
|
|
82
|
+
TabInfo.currentTabId = tabId;
|
|
83
|
+
resolve(tabId);
|
|
84
|
+
if (error) {
|
|
85
|
+
reject(error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
if (window.targetTab && window.targetTab.id) {
|
|
91
|
+
const tabId = window.targetTab.id;
|
|
92
|
+
TabInfo.currentTabId = tabId;
|
|
93
|
+
resolve(tabId);
|
|
94
|
+
} else {
|
|
95
|
+
throw Error(`can't get active tab`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
|
|
101
|
+
yield sleep(300);
|
|
102
|
+
chrome.runtime.onMessage.addListener(
|
|
103
|
+
(message) => {
|
|
104
|
+
const { origin, data } = message;
|
|
105
|
+
if (!data || (data == null ? void 0 : data.appInfos)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
109
|
+
definePropertyGlobalVal(window, "__FEDERATION__", {});
|
|
110
|
+
definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
|
|
111
|
+
}
|
|
112
|
+
window.__FEDERATION__.originModuleInfo = JSON.parse(
|
|
113
|
+
JSON.stringify(data == null ? void 0 : data.moduleInfo)
|
|
114
|
+
);
|
|
115
|
+
if (data == null ? void 0 : data.updateModule) {
|
|
116
|
+
const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
|
|
117
|
+
const shouldUpdate = !moduleIds.some(
|
|
118
|
+
(id) => id.includes(data.updateModule.name)
|
|
119
|
+
);
|
|
120
|
+
if (shouldUpdate) {
|
|
121
|
+
const destination = data.updateModule.entry || data.updateModule.version;
|
|
122
|
+
window.__FEDERATION__.originModuleInfo[`${data.updateModule.name}:${destination}`] = {
|
|
123
|
+
remoteEntry: destination,
|
|
124
|
+
version: destination
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
window.__FEDERATION__.moduleInfo = JSON.parse(
|
|
129
|
+
JSON.stringify(window.__FEDERATION__.originModuleInfo)
|
|
130
|
+
);
|
|
131
|
+
callback(window.__FEDERATION__.moduleInfo);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
const postMessageStartUrl = getUrl("post-message-start.js");
|
|
135
|
+
yield injectScript(injectPostMessage, false, postMessageStartUrl);
|
|
136
|
+
});
|
|
137
|
+
const getTabs = (queryOptions = {}) => chrome.tabs.query(queryOptions);
|
|
138
|
+
const getScope = () => __async(void 0, null, function* () {
|
|
139
|
+
const activeTab = window.targetTab;
|
|
140
|
+
const favIconUrl = activeTab == null ? void 0 : activeTab.favIconUrl;
|
|
141
|
+
return favIconUrl || "noScope";
|
|
142
|
+
});
|
|
143
|
+
const injectScript = (excuteScript, world = false, ...args) => __async(void 0, null, function* () {
|
|
144
|
+
yield getInspectWindowTabId();
|
|
145
|
+
return chrome.scripting.executeScript({
|
|
146
|
+
target: {
|
|
147
|
+
tabId: getCurrentTabId()
|
|
148
|
+
},
|
|
149
|
+
func: excuteScript,
|
|
150
|
+
world: world ? "MAIN" : "ISOLATED",
|
|
151
|
+
args
|
|
152
|
+
}).then(() => {
|
|
153
|
+
console.log("InjectScript success, excuteScript:", args);
|
|
154
|
+
}).catch((e) => {
|
|
155
|
+
console.log(e, "InjectScript fail, excuteScript:", args);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
const getUrl = (file) => {
|
|
159
|
+
try {
|
|
160
|
+
const pathSet = chrome.runtime.getURL(file).split("/");
|
|
161
|
+
const fileName = pathSet.pop();
|
|
162
|
+
pathSet.push("static", "js", fileName);
|
|
163
|
+
return pathSet.join("/");
|
|
164
|
+
} catch (e) {
|
|
165
|
+
return "";
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const injectToast = (toastUtilUrl, e2eFlag) => {
|
|
169
|
+
const ele = document.querySelector(`[data-e2e=${e2eFlag}]`);
|
|
170
|
+
if (ele) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const scriptToast = document.createElement("script");
|
|
174
|
+
scriptToast.src = toastUtilUrl;
|
|
175
|
+
scriptToast.dataset.e2e = e2eFlag;
|
|
176
|
+
document.getElementsByTagName("head")[0].appendChild(scriptToast);
|
|
177
|
+
};
|
|
178
|
+
const setChromeStorage = (formData) => {
|
|
179
|
+
getScope().then((scope) => __async(void 0, null, function* () {
|
|
180
|
+
const data = yield chrome.storage.sync.get("FormID");
|
|
181
|
+
const storeData = data[FormID];
|
|
182
|
+
const scopes = Object.keys(storeData || {});
|
|
183
|
+
let filterOutDatedData = storeData || {};
|
|
184
|
+
const { length } = scopes;
|
|
185
|
+
if (length >= 10) {
|
|
186
|
+
filterOutDatedData = scopes.slice(0, length - 3).reduce((memo, cur) => {
|
|
187
|
+
memo[cur] = storeData[cur];
|
|
188
|
+
return memo;
|
|
189
|
+
}, {});
|
|
190
|
+
}
|
|
191
|
+
const existRules = storeData == null ? void 0 : storeData[scope];
|
|
192
|
+
chrome.storage.sync.set({
|
|
193
|
+
[FormID]: __spreadProps(__spreadValues({}, filterOutDatedData), {
|
|
194
|
+
[scope]: __spreadValues(__spreadValues({}, existRules), formData)
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
}));
|
|
198
|
+
};
|
|
199
|
+
export {
|
|
200
|
+
TabInfo,
|
|
201
|
+
getCurrentTabId,
|
|
202
|
+
getGlobalModuleInfo,
|
|
203
|
+
getInspectWindowTabId,
|
|
204
|
+
getScope,
|
|
205
|
+
getTabs,
|
|
206
|
+
getUrl,
|
|
207
|
+
injectPostMessage,
|
|
208
|
+
injectScript,
|
|
209
|
+
injectToast,
|
|
210
|
+
setChromeStorage
|
|
211
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
if (window.moduleHandler) {
|
|
2
|
+
window.removeEventListener("message", window.moduleHandler);
|
|
3
|
+
} else {
|
|
4
|
+
window.moduleHandler = (event) => {
|
|
5
|
+
const { origin, data } = event;
|
|
6
|
+
if (!data.moduleInfo) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
chrome.runtime.sendMessage({
|
|
10
|
+
origin,
|
|
11
|
+
data: {
|
|
12
|
+
moduleInfo: data.moduleInfo,
|
|
13
|
+
updateModule: data.updateModule
|
|
14
|
+
}
|
|
15
|
+
}).catch(() => {
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
window.addEventListener("message", window.moduleHandler);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
var _a;
|
|
30
|
+
import helpers from "@module-federation/runtime/helpers";
|
|
31
|
+
import { definePropertyGlobalVal } from "../sdk";
|
|
32
|
+
const getModuleInfo = () => {
|
|
33
|
+
return {
|
|
34
|
+
name: "mf-devtool-getModuleInfo-plugin",
|
|
35
|
+
loadRemoteSnapshot(_a2) {
|
|
36
|
+
var _b = _a2, { options, moduleInfo, remoteSnapshot } = _b, res = __objRest(_b, ["options", "moduleInfo", "remoteSnapshot"]);
|
|
37
|
+
const globalSnapshot = helpers.global.getGlobalSnapshot();
|
|
38
|
+
if (options.inBrowser) {
|
|
39
|
+
window.postMessage(
|
|
40
|
+
{
|
|
41
|
+
moduleInfo: globalSnapshot,
|
|
42
|
+
updateModule: moduleInfo
|
|
43
|
+
},
|
|
44
|
+
"*"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return __spreadValues({
|
|
48
|
+
options,
|
|
49
|
+
moduleInfo,
|
|
50
|
+
remoteSnapshot
|
|
51
|
+
}, res);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
56
|
+
definePropertyGlobalVal(window, "__FEDERATION__", {});
|
|
57
|
+
definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
|
|
58
|
+
}
|
|
59
|
+
if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
|
|
60
|
+
window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
61
|
+
}
|
|
62
|
+
(_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(getModuleInfo());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { MODULE_DEVTOOL_IDENTIFIER } from "@module-federation/sdk";
|
|
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.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());
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {
|
|
22
|
+
mergeLocalStorage,
|
|
23
|
+
removeLocalStorageKey,
|
|
24
|
+
removeLocalStorage,
|
|
25
|
+
setLocalStorage
|
|
26
|
+
} from "../sdk";
|
|
27
|
+
import { injectScript } from "./index";
|
|
28
|
+
const mergeStorage = (...args) => __async(void 0, null, function* () {
|
|
29
|
+
return injectScript(mergeLocalStorage, false, ...args);
|
|
30
|
+
});
|
|
31
|
+
const removeStorageKey = (...args) => __async(void 0, null, function* () {
|
|
32
|
+
return injectScript(removeLocalStorageKey, false, ...args);
|
|
33
|
+
});
|
|
34
|
+
const removeStorage = (...args) => __async(void 0, null, function* () {
|
|
35
|
+
return injectScript(removeLocalStorage, false, ...args);
|
|
36
|
+
});
|
|
37
|
+
const setStorage = (...args) => __async(void 0, null, function* () {
|
|
38
|
+
return injectScript(setLocalStorage, false, ...args);
|
|
39
|
+
});
|
|
40
|
+
export {
|
|
41
|
+
mergeStorage,
|
|
42
|
+
removeStorage,
|
|
43
|
+
removeStorageKey,
|
|
44
|
+
setStorage
|
|
45
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { calculateSnapshot, calculateMicroAppSnapshot } from "./snapshot";
|
|
22
|
+
const separateType = (moduleInfo) => {
|
|
23
|
+
const consumers = {};
|
|
24
|
+
const producer = [];
|
|
25
|
+
Object.keys(moduleInfo).forEach((key) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const remotesInfo = (_a = moduleInfo[key]) == null ? void 0 : _a.remotesInfo;
|
|
28
|
+
if (remotesInfo) {
|
|
29
|
+
const moduleIds = Object.keys(remotesInfo);
|
|
30
|
+
if (moduleIds.length) {
|
|
31
|
+
moduleIds.forEach((id) => {
|
|
32
|
+
let formatId = id;
|
|
33
|
+
if (id.includes(":")) {
|
|
34
|
+
formatId = id.split(":").pop();
|
|
35
|
+
}
|
|
36
|
+
const hasBeenAdded = producer.includes(formatId);
|
|
37
|
+
if (!hasBeenAdded) {
|
|
38
|
+
producer.push(id);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
consumers[key] = moduleInfo[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
consumers,
|
|
47
|
+
producer
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const getModuleInfo = (proxyRules) => __async(void 0, null, function* () {
|
|
51
|
+
let freshModuleInfo;
|
|
52
|
+
const { moduleInfo } = window.__FEDERATION__;
|
|
53
|
+
const { consumers } = separateType(moduleInfo);
|
|
54
|
+
const overrides = {};
|
|
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
|
+
};
|
|
74
|
+
});
|
|
75
|
+
export * from "./snapshot";
|
|
76
|
+
export {
|
|
77
|
+
getModuleInfo,
|
|
78
|
+
separateType
|
|
79
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const calculateSnapshot = (originSnapshot, overrides) => {
|
|
2
|
+
const overridesWithoutType = Object.keys(overrides).reduce(
|
|
3
|
+
(memo, current) => {
|
|
4
|
+
if (current.includes(":")) {
|
|
5
|
+
const [, moduleId] = current.split(":");
|
|
6
|
+
memo[moduleId] = overrides[current];
|
|
7
|
+
}
|
|
8
|
+
return memo;
|
|
9
|
+
},
|
|
10
|
+
{}
|
|
11
|
+
);
|
|
12
|
+
const newSnapshot = JSON.parse(JSON.stringify(originSnapshot));
|
|
13
|
+
const moduleIds = Object.keys(originSnapshot);
|
|
14
|
+
moduleIds.forEach((moduleId) => {
|
|
15
|
+
const module = originSnapshot[moduleId];
|
|
16
|
+
if ("remotesInfo" in module) {
|
|
17
|
+
const remoteIds = Object.keys(module.remotesInfo);
|
|
18
|
+
remoteIds.forEach((id) => {
|
|
19
|
+
const [, splitId] = id.split(":");
|
|
20
|
+
const entry = overrides[id] || overridesWithoutType[id] || overrides[splitId] || overridesWithoutType[splitId];
|
|
21
|
+
if (entry) {
|
|
22
|
+
newSnapshot[moduleId].remotesInfo[id].matchedVersion = entry;
|
|
23
|
+
const customEntryId = `${id}:${entry}`;
|
|
24
|
+
newSnapshot[customEntryId] = {
|
|
25
|
+
remoteEntry: entry,
|
|
26
|
+
version: entry
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return newSnapshot;
|
|
33
|
+
};
|
|
34
|
+
const calculateMicroAppSnapshot = (originSnapshot, overrides) => {
|
|
35
|
+
let masterApp = null;
|
|
36
|
+
const newSnapshot = JSON.parse(JSON.stringify(originSnapshot));
|
|
37
|
+
const moduleIds = Object.keys(originSnapshot);
|
|
38
|
+
moduleIds.forEach((moduleId) => {
|
|
39
|
+
const module = newSnapshot[moduleId];
|
|
40
|
+
if ("consumerList" in module && Array.isArray(module.consumerList) && module.consumerList.length > 0) {
|
|
41
|
+
masterApp = module;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (!masterApp) {
|
|
45
|
+
return newSnapshot;
|
|
46
|
+
}
|
|
47
|
+
const microApps = masterApp.consumerList;
|
|
48
|
+
const microAppsCount = microApps.length;
|
|
49
|
+
for (let i = 0; i < microAppsCount; i++) {
|
|
50
|
+
let overrideTarget = "";
|
|
51
|
+
const microApp = microApps[i];
|
|
52
|
+
const idWithVersion = Object.keys(overrides).find((id) => {
|
|
53
|
+
let target = id;
|
|
54
|
+
if (id.includes(":")) {
|
|
55
|
+
const [, name] = id.split(":");
|
|
56
|
+
target = name;
|
|
57
|
+
}
|
|
58
|
+
if (microApp.includes(target)) {
|
|
59
|
+
overrideTarget = id;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
64
|
+
if (idWithVersion) {
|
|
65
|
+
const entry = overrides[overrideTarget];
|
|
66
|
+
const idArray = microApp.split(":");
|
|
67
|
+
idArray[idArray.length - 1] = entry;
|
|
68
|
+
microApps[i] = idArray.join(":");
|
|
69
|
+
const customEntryId = `${overrideTarget}:${entry}`;
|
|
70
|
+
newSnapshot[customEntryId] = {
|
|
71
|
+
remoteEntry: entry,
|
|
72
|
+
version: entry
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const snapshot = calculateSnapshot(newSnapshot, overrides);
|
|
77
|
+
return snapshot;
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
calculateMicroAppSnapshot,
|
|
81
|
+
calculateSnapshot
|
|
82
|
+
};
|