@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.
Files changed (48) hide show
  1. package/README.md +3 -0
  2. package/dist/es/App.js +17 -2
  3. package/dist/es/App_module.css +3 -3
  4. package/dist/es/component/LoadingTrace/index.js +944 -0
  5. package/dist/es/component/LoadingTrace/index.module.js +5 -0
  6. package/dist/es/component/LoadingTrace/index_module.css +876 -0
  7. package/dist/es/i18n/index.js +178 -0
  8. package/dist/es/utils/chrome/fast-refresh.js +297 -173
  9. package/dist/es/utils/chrome/index.js +3 -4
  10. package/dist/es/utils/chrome/messages.js +7 -1
  11. package/dist/es/utils/chrome/observability-plugin.js +93 -0
  12. package/dist/es/utils/chrome/observability-shared.js +99 -0
  13. package/dist/es/utils/chrome/observability.js +208 -0
  14. package/dist/es/utils/chrome/override-remote.js +2 -42
  15. package/dist/es/utils/chrome/post-message-listener.js +14 -0
  16. package/dist/es/utils/chrome/snapshot-plugin.js +2 -36
  17. package/dist/es/utils/data/index.js +5 -25
  18. package/dist/es/vendor/basic-proxy-core.js +155 -0
  19. package/dist/es/worker/index.js +27 -8
  20. package/dist/lib/App.js +17 -2
  21. package/dist/lib/App_module.css +3 -3
  22. package/dist/lib/component/LoadingTrace/index.js +954 -0
  23. package/dist/lib/component/LoadingTrace/index.module.js +25 -0
  24. package/dist/lib/component/LoadingTrace/index_module.css +876 -0
  25. package/dist/lib/i18n/index.js +178 -0
  26. package/dist/lib/utils/chrome/fast-refresh.js +250 -135
  27. package/dist/lib/utils/chrome/index.js +3 -4
  28. package/dist/lib/utils/chrome/messages.js +11 -2
  29. package/dist/lib/utils/chrome/observability-plugin.js +86 -0
  30. package/dist/lib/utils/chrome/observability-shared.js +126 -0
  31. package/dist/lib/utils/chrome/observability.js +234 -0
  32. package/dist/lib/utils/chrome/override-remote.js +5 -52
  33. package/dist/lib/utils/chrome/post-message-listener.js +11 -0
  34. package/dist/lib/utils/chrome/snapshot-plugin.js +5 -46
  35. package/dist/lib/utils/data/index.js +6 -28
  36. package/dist/lib/vendor/basic-proxy-core.js +147 -0
  37. package/dist/lib/worker/index.js +27 -8
  38. package/dist/types/src/component/LoadingTrace/index.d.ts +6 -0
  39. package/dist/types/src/utils/chrome/messages.d.ts +3 -0
  40. package/dist/types/src/utils/chrome/observability-plugin.d.ts +1 -0
  41. package/dist/types/src/utils/chrome/observability-shared.d.ts +41 -0
  42. package/dist/types/src/utils/chrome/observability.d.ts +110 -0
  43. package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +0 -3
  44. package/dist/types/src/utils/data/index.d.ts +0 -1
  45. package/package.json +4 -3
  46. package/dist/es/utils/data/snapshot.js +0 -82
  47. package/dist/lib/utils/data/snapshot.js +0 -107
  48. package/dist/types/src/utils/data/snapshot.d.ts +0 -3
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ 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) => {
3
+ if (Object.prototype.hasOwnProperty.call(e, t)) {
4
+ e[t] = o;
5
+ return;
6
+ }
7
+ Object.defineProperty(e, t, { value: o, configurable: false, writable: true });
8
+ }, g = (e = l()) => {
9
+ !e.__FEDERATION__ && e.__VMOK__ && d(e, "__FEDERATION__", e.__VMOK__), e.__FEDERATION__ || d(e, "__FEDERATION__", {}), e.__VMOK__ || d(e, "__VMOK__", e.__FEDERATION__);
10
+ let t = e.__FEDERATION__;
11
+ return Array.isArray(t.__GLOBAL_PLUGIN__) || (t.__GLOBAL_PLUGIN__ = []), y(t.moduleInfo) || (t.moduleInfo = {}), t;
12
+ }, p = (e, t) => {
13
+ if (!e)
14
+ return t;
15
+ try {
16
+ return JSON.parse(e);
17
+ } catch (o) {
18
+ return t;
19
+ }
20
+ }, x = (e = l()) => {
21
+ var t;
22
+ return e.localStorage || ((t = e.window) == null ? void 0 : t.localStorage);
23
+ }, M = (e = l()) => {
24
+ let t = x(e);
25
+ return t ? p(t.getItem(P), null) : null;
26
+ }, I = (e) => {
27
+ let t = {};
28
+ return y(e) && Object.keys(e).forEach((o) => {
29
+ typeof e[o] == "string" && e[o] && (t[o] = e[o]);
30
+ }), t;
31
+ }, N = (e = l()) => {
32
+ let t = x(e);
33
+ if (!t)
34
+ return {};
35
+ let o = p(t.getItem(f), {});
36
+ return y(o.overrides) ? I(o.overrides) : I(o);
37
+ }, S = (e) => e.indexOf("http://") === 0 || e.indexOf("https://") === 0 || e.indexOf("//") === 0, m = (e, t) => {
38
+ Reflect.deleteProperty(e, t);
39
+ }, T = (e) => {
40
+ let t = {}, o = [];
41
+ return Object.keys(e || {}).forEach((s) => {
42
+ var r;
43
+ let i = (r = e[s]) == null ? void 0 : r.remotesInfo;
44
+ if (i) {
45
+ let n = Object.keys(i);
46
+ n.length && (n.forEach((c) => {
47
+ let a = c;
48
+ c.indexOf(":") !== -1 && (a = c.split(":").pop()), o.indexOf(a) === -1 && o.push(c);
49
+ }), t[s] = e[s]);
50
+ }
51
+ }), { consumers: t, producer: o };
52
+ }, R = (e, t) => {
53
+ let o = Object.keys(t || {}).reduce((i, r) => (r.indexOf(":") !== -1 && (i[r.split(":")[1]] = t[r]), i), {}), s = O(e);
54
+ return Object.keys(e || {}).forEach((i) => {
55
+ let r = e[i];
56
+ r != null && r.remotesInfo && Object.keys(r.remotesInfo).forEach((n) => {
57
+ let c = n.split(":")[1], a = t[n] || o[n] || t[c] || o[c];
58
+ a && (s[i].remotesInfo[n].matchedVersion = a, s[`${n}:${a}`] = { remoteEntry: a, version: a });
59
+ });
60
+ }), s;
61
+ }, v = (e, t) => {
62
+ let o = null, s = O(e);
63
+ if (Object.keys(e || {}).forEach((r) => {
64
+ let n = s[r];
65
+ n && Array.isArray(n.consumerList) && n.consumerList.length > 0 && (o = n);
66
+ }), !o)
67
+ return s;
68
+ let i = o.consumerList;
69
+ for (let r = 0; r < i.length; r++) {
70
+ let n = "", c = i[r];
71
+ if (Object.keys(t || {}).find((_) => {
72
+ let u = _;
73
+ return _.indexOf(":") !== -1 && (u = _.split(":")[1]), c.indexOf(u) !== -1 ? (n = _, true) : false;
74
+ })) {
75
+ let _ = t[n], u = c.split(":");
76
+ u[u.length - 1] = _, i[r] = u.join(":"), s[`${n}:${_}`] = { remoteEntry: _, version: _ };
77
+ }
78
+ }
79
+ return R(s, t);
80
+ }, F = (e = [], t) => {
81
+ var n;
82
+ let o = t || ((n = l().__FEDERATION__) == null ? void 0 : n.moduleInfo) || {}, s = {}, { consumers: i } = T(o), r = Object.keys(i).some((c) => {
83
+ var _;
84
+ let a = (_ = i[c]) == null ? void 0 : _.consumerList;
85
+ return Array.isArray(a) && a.length > 0;
86
+ });
87
+ return e.forEach((c) => {
88
+ c != null && c.key && (c != null && c.value) && (s[c.key] = c.value);
89
+ }), { status: "success", moduleInfo: r ? v(o, s) : R(o, s), overrides: s };
90
+ }, E = (e = l()) => {
91
+ let t = e, o = false;
92
+ return { name: h, beforeLoadRemoteSnapshot: (s) => {
93
+ var c;
94
+ let i = s == null ? void 0 : s.options;
95
+ if (i && i.inBrowser === false)
96
+ return;
97
+ let r = M(t);
98
+ if (!r || o)
99
+ return;
100
+ let n = g(t);
101
+ 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");
102
+ } };
103
+ }, B = (e = l()) => {
104
+ let t = e;
105
+ return { name: L, beforeRegisterRemote: (o) => {
106
+ var s;
107
+ try {
108
+ let i = o == null ? void 0 : o.remote;
109
+ if (!i)
110
+ return o;
111
+ let r = N(t), n = r[i.name] || r[i.alias || ""];
112
+ if (!n)
113
+ return o;
114
+ S(n) ? (m(i, "version"), i.entry = n) : (m(i, "entry"), i.version = n);
115
+ } catch (i) {
116
+ (s = t.console) == null || s.error(i);
117
+ }
118
+ return o;
119
+ } };
120
+ }, b = (e = l()) => {
121
+ let t = g(e);
122
+ return [B(e), E(e)].forEach((s) => {
123
+ var r, n;
124
+ ((r = t.__GLOBAL_PLUGIN__) == null ? void 0 : r.some((c) => c.name === s.name)) || (n = t.__GLOBAL_PLUGIN__) == null || n.push(s);
125
+ }), t.__GLOBAL_PLUGIN__ || [];
126
+ }, A = (e, t) => {
127
+ var r, n;
128
+ let o = g(e), s = t(e);
129
+ return ((r = o.__GLOBAL_PLUGIN__) == null ? void 0 : r.some((c) => c.name === s.name)) || (n = o.__GLOBAL_PLUGIN__) == null || n.push(s), s;
130
+ }, k = (e = l()) => A(e, B), D = (e = l()) => A(e, E), V = (e = l()) => {
131
+ let t = x(e);
132
+ if (!t)
133
+ return;
134
+ t.removeItem(P), t.removeItem(G);
135
+ let o = p(t.getItem(f), {});
136
+ y(o) && (m(o, "overrides"), Object.keys(o).length ? t.setItem(f, JSON.stringify(o)) : t.removeItem(f));
137
+ };
138
+ exports.calculateMicroAppSnapshot = v;
139
+ exports.calculateSnapshot = R;
140
+ exports.createOverridePlugin = B;
141
+ exports.createSnapshotPlugin = E;
142
+ exports.getModuleInfo = F;
143
+ exports.registerOverridePlugin = k;
144
+ exports.registerRuntimePlugins = b;
145
+ exports.registerSnapshotPlugin = D;
146
+ exports.resetProxyStorage = V;
147
+ exports.separateType = T;
@@ -1,4 +1,20 @@
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
+ };
2
18
  var __async = (__this, __arguments, generator) => {
3
19
  return new Promise((resolve, reject) => {
4
20
  var fulfilled = (value) => {
@@ -32,12 +48,12 @@ const resolveTabId = (tabId) => __async(exports, null, function* () {
32
48
  });
33
49
  return activeTab == null ? void 0 : activeTab.id;
34
50
  });
35
- const broadcastActiveTab = (tabId) => {
51
+ const broadcastActiveTab = (tabId, payload) => {
36
52
  try {
37
- chrome.runtime.sendMessage({
53
+ chrome.runtime.sendMessage(__spreadValues({
38
54
  type: import_messages.MESSAGE_ACTIVE_TAB_CHANGED,
39
55
  tabId
40
- });
56
+ }, payload));
41
57
  } catch (error) {
42
58
  console.warn(
43
59
  "[Module Federation Devtools] Failed to broadcast active tab",
@@ -62,11 +78,11 @@ const openSidePanel = (tabId) => __async(exports, null, function* () {
62
78
  if (sidePanel.open) {
63
79
  yield sidePanel.open({ tabId: targetTabId });
64
80
  }
65
- broadcastActiveTab(targetTabId);
81
+ broadcastActiveTab(targetTabId, { reason: "side-panel" });
66
82
  if (sidePanel.getOptions) {
67
83
  try {
68
84
  const options = yield sidePanel.getOptions({ tabId: targetTabId });
69
- broadcastActiveTab(targetTabId);
85
+ broadcastActiveTab(targetTabId, { reason: "side-panel" });
70
86
  return options;
71
87
  } catch (error) {
72
88
  console.warn("[Module Federation Devtools] getOptions failed", error);
@@ -113,7 +129,7 @@ chrome.tabs.onActivated.addListener((activeInfo) => __async(exports, null, funct
113
129
  return;
114
130
  }
115
131
  try {
116
- broadcastActiveTab(tabId);
132
+ broadcastActiveTab(tabId, { reason: "activated" });
117
133
  } catch (error) {
118
134
  console.warn(
119
135
  "[Module Federation Devtools] Failed to handle tab activation",
@@ -122,12 +138,15 @@ chrome.tabs.onActivated.addListener((activeInfo) => __async(exports, null, funct
122
138
  }
123
139
  }));
124
140
  chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
125
- if (changeInfo.status !== "complete") {
141
+ if (changeInfo.status !== "loading" && changeInfo.status !== "complete") {
126
142
  return;
127
143
  }
128
144
  if (tab == null ? void 0 : tab.active) {
129
145
  try {
130
- broadcastActiveTab(tabId);
146
+ broadcastActiveTab(tabId, {
147
+ reason: "updated",
148
+ status: changeInfo.status
149
+ });
131
150
  } catch (error) {
132
151
  console.warn(
133
152
  "[Module Federation Devtools] Failed to handle tab update",
@@ -0,0 +1,6 @@
1
+ interface LoadingTraceProps {
2
+ tabId?: number;
3
+ resetKey?: number;
4
+ }
5
+ declare const LoadingTrace: ({ tabId, resetKey }: LoadingTraceProps) => import("react").JSX.Element;
6
+ export default LoadingTrace;
@@ -1,2 +1,5 @@
1
1
  export declare const MESSAGE_OPEN_SIDE_PANEL = "mf-devtools/open-side-panel";
2
2
  export declare const MESSAGE_ACTIVE_TAB_CHANGED = "mf-devtools/active-tab-changed";
3
+ export declare const MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT = "mf-devtools/observability-event";
4
+ export declare const OBSERVABILITY_DEVTOOLS_SOURCE = "module-federation/observability";
5
+ export declare const OBSERVABILITY_DEVTOOLS_STORAGE_KEY = "__MF_DEVTOOLS_OBSERVABILITY_CONFIG__";
@@ -0,0 +1,41 @@
1
+ export type ObservabilityDevtoolsLevel = 'error' | 'summary' | 'verbose';
2
+ export type ObservabilityDevtoolsMode = 'development' | 'production';
3
+ export interface ObservabilityDevtoolsConfig {
4
+ enabled: boolean;
5
+ level: ObservabilityDevtoolsLevel;
6
+ maxEvents: number;
7
+ console: boolean;
8
+ browser: {
9
+ enabled: boolean;
10
+ scope: string;
11
+ mode: ObservabilityDevtoolsMode;
12
+ };
13
+ trace: {
14
+ printStart: boolean;
15
+ };
16
+ react: {
17
+ injectLoadedCallback: boolean;
18
+ remoteIds: string[];
19
+ };
20
+ }
21
+ export declare const CHROME_OBSERVABILITY_SCOPE = "chrome_extension";
22
+ export declare const DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG: ObservabilityDevtoolsConfig;
23
+ export declare const normalizeObservabilityDevtoolsConfig: (value?: Partial<ObservabilityDevtoolsConfig> | Record<string, unknown> | null) => ObservabilityDevtoolsConfig;
24
+ export declare const createObservabilityPluginOptions: (config: ObservabilityDevtoolsConfig) => {
25
+ enabled: boolean;
26
+ level: ObservabilityDevtoolsLevel;
27
+ maxEvents: number;
28
+ console: boolean;
29
+ browser: {
30
+ enabled: boolean;
31
+ scope: string;
32
+ mode: ObservabilityDevtoolsMode;
33
+ };
34
+ trace: {
35
+ printStart: boolean;
36
+ };
37
+ devtools: {
38
+ enabled: boolean;
39
+ source: string;
40
+ };
41
+ };
@@ -0,0 +1,110 @@
1
+ import { type ObservabilityDevtoolsConfig } from './observability-shared';
2
+ export interface ObservabilityDevtoolsEvent {
3
+ traceId: string;
4
+ timestamp: number;
5
+ phase: string;
6
+ status: string;
7
+ requestId?: string;
8
+ lifecycle?: string;
9
+ message?: string;
10
+ runtimeVersion?: string;
11
+ remote?: {
12
+ name?: string;
13
+ entry?: string;
14
+ alias?: string;
15
+ };
16
+ shared?: {
17
+ name?: string;
18
+ shareScope?: string[];
19
+ requiredVersion?: string | false;
20
+ selectedVersion?: string;
21
+ availableVersions?: string[];
22
+ provider?: string;
23
+ reason?: string;
24
+ };
25
+ expose?: string;
26
+ duration?: number;
27
+ errorCode?: string;
28
+ errorName?: string;
29
+ errorMessage?: string;
30
+ ownerHint?: string;
31
+ recovered?: boolean;
32
+ cached?: boolean;
33
+ loadedBefore?: ObservabilityDevtoolsLoadedBefore;
34
+ }
35
+ export interface ObservabilityDevtoolsLoadedBefore {
36
+ producer: boolean;
37
+ expose: boolean;
38
+ consumers: Array<{
39
+ name?: string;
40
+ remoteEntryExports?: boolean;
41
+ containerInitialized?: boolean;
42
+ exposes?: string[];
43
+ }>;
44
+ }
45
+ export interface ObservabilityDevtoolsReport {
46
+ traceId: string;
47
+ status: string;
48
+ requestId?: string;
49
+ hostName?: string;
50
+ runtimeVersion?: string;
51
+ remote?: {
52
+ name?: string;
53
+ entry?: string;
54
+ alias?: string;
55
+ };
56
+ shared?: {
57
+ name?: string;
58
+ shareScope?: string[];
59
+ requiredVersion?: string | false;
60
+ selectedVersion?: string;
61
+ availableVersions?: string[];
62
+ provider?: string;
63
+ reason?: string;
64
+ };
65
+ expose?: string;
66
+ startedAt: number;
67
+ updatedAt: number;
68
+ duration: number;
69
+ failedPhase?: string;
70
+ errorCode?: string;
71
+ errorName?: string;
72
+ errorMessage?: string;
73
+ ownerHint?: string;
74
+ loadedBefore?: ObservabilityDevtoolsLoadedBefore;
75
+ events: ObservabilityDevtoolsEvent[];
76
+ summary?: {
77
+ outcome?: string;
78
+ runtimeLoaded?: boolean;
79
+ sharedResolved?: boolean;
80
+ componentLoaded?: boolean;
81
+ loadCompleted?: boolean;
82
+ recovered?: boolean;
83
+ lastPhase?: string;
84
+ };
85
+ diagnosis?: {
86
+ title?: string;
87
+ ownerHint?: string;
88
+ errorCode?: string;
89
+ actions?: Array<{
90
+ title?: string;
91
+ detail?: string;
92
+ }>;
93
+ warnings?: string[];
94
+ };
95
+ __scope?: string;
96
+ }
97
+ export interface ObservabilityDevtoolsSnapshot {
98
+ config: ObservabilityDevtoolsConfig;
99
+ stored: boolean;
100
+ scopes: string[];
101
+ reports: ObservabilityDevtoolsReport[];
102
+ hasUserObservabilityPlugin: boolean;
103
+ }
104
+ export declare const readObservabilityConfig: () => Promise<ObservabilityDevtoolsConfig>;
105
+ export declare const applyObservabilityConfig: (config: ObservabilityDevtoolsConfig) => Promise<any>;
106
+ export declare const disableObservabilityConfig: () => Promise<any>;
107
+ export declare const reloadInspectedPage: () => Promise<any>;
108
+ export declare const readObservabilitySnapshot: () => Promise<ObservabilityDevtoolsSnapshot>;
109
+ export declare const mergeObservabilityReports: (currentReports: ObservabilityDevtoolsReport[], incomingReports: ObservabilityDevtoolsReport[]) => ObservabilityDevtoolsReport[];
110
+ export declare const getObservabilityReportScopeLabel: (report: Pick<ObservabilityDevtoolsReport, "__scope">) => string | undefined;
@@ -1,4 +1 @@
1
- declare global {
2
- var __INIT_VMOK_CHROME_DEVTOOL_PLUGIN__: boolean | undefined;
3
- }
4
1
  export {};
@@ -8,4 +8,3 @@ export declare const getModuleInfo: (proxyRules: Array<any>) => Promise<{
8
8
  moduleInfo: GlobalModuleInfo;
9
9
  overrides: Record<string, string>;
10
10
  }>;
11
- export * from './snapshot';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/devtools",
3
- "version": "2.3.3",
3
+ "version": "2.5.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,7 +47,8 @@
47
47
  "echarts-for-react": "3.0.5",
48
48
  "i18next": "23.0.0",
49
49
  "react-i18next": "15.0.0",
50
- "@module-federation/sdk": "2.3.3"
50
+ "@module-federation/observability-plugin": "2.5.0",
51
+ "@module-federation/sdk": "2.5.0"
51
52
  },
52
53
  "peerDependencies": {
53
54
  "react": "^18 || ^19",
@@ -82,7 +83,7 @@
82
83
  "typescript": "5.9.3",
83
84
  "rimraf": "~6.0.1",
84
85
  "vitest": "1.2.2",
85
- "@module-federation/runtime": "2.3.3"
86
+ "@module-federation/runtime": "2.5.0"
86
87
  },
87
88
  "scripts": {
88
89
  "build:storybook": "storybook build",
@@ -1,82 +0,0 @@
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
- };
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var snapshot_exports = {};
20
- __export(snapshot_exports, {
21
- calculateMicroAppSnapshot: () => calculateMicroAppSnapshot,
22
- calculateSnapshot: () => calculateSnapshot
23
- });
24
- module.exports = __toCommonJS(snapshot_exports);
25
- const calculateSnapshot = (originSnapshot, overrides) => {
26
- const overridesWithoutType = Object.keys(overrides).reduce(
27
- (memo, current) => {
28
- if (current.includes(":")) {
29
- const [, moduleId] = current.split(":");
30
- memo[moduleId] = overrides[current];
31
- }
32
- return memo;
33
- },
34
- {}
35
- );
36
- const newSnapshot = JSON.parse(JSON.stringify(originSnapshot));
37
- const moduleIds = Object.keys(originSnapshot);
38
- moduleIds.forEach((moduleId) => {
39
- const module2 = originSnapshot[moduleId];
40
- if ("remotesInfo" in module2) {
41
- const remoteIds = Object.keys(module2.remotesInfo);
42
- remoteIds.forEach((id) => {
43
- const [, splitId] = id.split(":");
44
- const entry = overrides[id] || overridesWithoutType[id] || overrides[splitId] || overridesWithoutType[splitId];
45
- if (entry) {
46
- newSnapshot[moduleId].remotesInfo[id].matchedVersion = entry;
47
- const customEntryId = `${id}:${entry}`;
48
- newSnapshot[customEntryId] = {
49
- remoteEntry: entry,
50
- version: entry
51
- };
52
- }
53
- });
54
- }
55
- });
56
- return newSnapshot;
57
- };
58
- const calculateMicroAppSnapshot = (originSnapshot, overrides) => {
59
- let masterApp = null;
60
- const newSnapshot = JSON.parse(JSON.stringify(originSnapshot));
61
- const moduleIds = Object.keys(originSnapshot);
62
- moduleIds.forEach((moduleId) => {
63
- const module2 = newSnapshot[moduleId];
64
- if ("consumerList" in module2 && Array.isArray(module2.consumerList) && module2.consumerList.length > 0) {
65
- masterApp = module2;
66
- }
67
- });
68
- if (!masterApp) {
69
- return newSnapshot;
70
- }
71
- const microApps = masterApp.consumerList;
72
- const microAppsCount = microApps.length;
73
- for (let i = 0; i < microAppsCount; i++) {
74
- let overrideTarget = "";
75
- const microApp = microApps[i];
76
- const idWithVersion = Object.keys(overrides).find((id) => {
77
- let target = id;
78
- if (id.includes(":")) {
79
- const [, name] = id.split(":");
80
- target = name;
81
- }
82
- if (microApp.includes(target)) {
83
- overrideTarget = id;
84
- return true;
85
- }
86
- return false;
87
- });
88
- if (idWithVersion) {
89
- const entry = overrides[overrideTarget];
90
- const idArray = microApp.split(":");
91
- idArray[idArray.length - 1] = entry;
92
- microApps[i] = idArray.join(":");
93
- const customEntryId = `${overrideTarget}:${entry}`;
94
- newSnapshot[customEntryId] = {
95
- remoteEntry: entry,
96
- version: entry
97
- };
98
- }
99
- }
100
- const snapshot = calculateSnapshot(newSnapshot, overrides);
101
- return snapshot;
102
- };
103
- // Annotate the CommonJS export names for ESM import in node:
104
- 0 && (module.exports = {
105
- calculateMicroAppSnapshot,
106
- calculateSnapshot
107
- });
@@ -1,3 +0,0 @@
1
- import { GlobalModuleInfo } from '@module-federation/sdk';
2
- export declare const calculateSnapshot: (originSnapshot: GlobalModuleInfo, overrides: Record<string, string>) => any;
3
- export declare const calculateMicroAppSnapshot: (originSnapshot: GlobalModuleInfo, overrides: Record<string, string>) => any;