@module-federation/devtools 2.2.3 → 2.3.1

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.
@@ -39,6 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import { FormID } from "../../template/constant";
41
41
  import { definePropertyGlobalVal } from "../sdk";
42
+ import { sanitizePostMessagePayload } from "./safe-post-message";
42
43
  export * from "./storage";
43
44
  const sleep = (num) => {
44
45
  return new Promise((resolve) => {
@@ -134,8 +135,8 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
134
135
  var _a, _b;
135
136
  if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
136
137
  callback(
137
- JSON.parse(
138
- JSON.stringify((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo)
138
+ sanitizePostMessagePayload(
139
+ (_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo
139
140
  )
140
141
  );
141
142
  }
@@ -149,8 +150,8 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
149
150
  definePropertyGlobalVal(window, "__FEDERATION__", {});
150
151
  definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
151
152
  }
152
- window.__FEDERATION__.originModuleInfo = JSON.parse(
153
- JSON.stringify(data == null ? void 0 : data.moduleInfo)
153
+ window.__FEDERATION__.originModuleInfo = sanitizePostMessagePayload(
154
+ data == null ? void 0 : data.moduleInfo
154
155
  );
155
156
  if (data == null ? void 0 : data.updateModule) {
156
157
  const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
@@ -166,10 +167,10 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
166
167
  }
167
168
  }
168
169
  if (data == null ? void 0 : data.share) {
169
- window.__FEDERATION__.__SHARE__ = data.share;
170
+ window.__FEDERATION__.__SHARE__ = sanitizePostMessagePayload(data.share);
170
171
  }
171
- window.__FEDERATION__.moduleInfo = JSON.parse(
172
- JSON.stringify(window.__FEDERATION__.originModuleInfo)
172
+ window.__FEDERATION__.moduleInfo = sanitizePostMessagePayload(
173
+ window.__FEDERATION__.originModuleInfo
173
174
  );
174
175
  console.log("getGlobalModuleInfo window", window.__FEDERATION__);
175
176
  callback(window.__FEDERATION__.moduleInfo);
@@ -1,3 +1,4 @@
1
+ import { sanitizePostMessagePayload } from "./safe-post-message";
1
2
  if (window.moduleHandler) {
2
3
  window.removeEventListener("message", window.moduleHandler);
3
4
  } else {
@@ -8,11 +9,11 @@ if (window.moduleHandler) {
8
9
  }
9
10
  chrome.runtime.sendMessage({
10
11
  origin,
11
- data: {
12
+ data: sanitizePostMessagePayload({
12
13
  moduleInfo: data.moduleInfo,
13
14
  updateModule: data.updateModule,
14
15
  share: data.share
15
- }
16
+ })
16
17
  }).catch(() => {
17
18
  return false;
18
19
  });
@@ -1,16 +1,10 @@
1
1
  var _a, _b;
2
+ import { sanitizePostMessagePayload } from "./safe-post-message";
2
3
  const moduleInfo = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.moduleInfo;
3
4
  window.postMessage(
4
- {
5
+ sanitizePostMessagePayload({
5
6
  moduleInfo,
6
- share: JSON.parse(
7
- JSON.stringify((_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__, (_key, value) => {
8
- if (typeof value === "function") {
9
- return "Function";
10
- }
11
- return value;
12
- })
13
- )
14
- },
7
+ share: (_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__
8
+ }),
15
9
  "*"
16
10
  );
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  var _a;
30
30
  import helpers from "@module-federation/runtime/helpers";
31
31
  import { definePropertyGlobalVal } from "../sdk";
32
+ import { sanitizePostMessagePayload } from "./safe-post-message";
32
33
  const getModuleInfo = () => {
33
34
  return {
34
35
  name: "mf-devtool-getModuleInfo-plugin",
@@ -45,10 +46,10 @@ const getModuleInfo = () => {
45
46
  const globalSnapshot = helpers.global.getGlobalSnapshot();
46
47
  if (!options || options.inBrowser) {
47
48
  window.postMessage(
48
- {
49
+ sanitizePostMessagePayload({
49
50
  moduleInfo: globalSnapshot,
50
51
  updateModule: moduleInfo
51
- },
52
+ }),
52
53
  "*"
53
54
  );
54
55
  }
@@ -0,0 +1,124 @@
1
+ const FUNCTION_PLACEHOLDER = "function(){}";
2
+ const UNDEFINED_PLACEHOLDER = "[undefined]";
3
+ const CIRCULAR_PLACEHOLDER = "[circular]";
4
+ const NON_SERIALIZABLE_PLACEHOLDER = "[unserializable]";
5
+ const toStringTag = (value) => Object.prototype.toString.call(value).slice(8, -1);
6
+ const isPlainObject = (value) => {
7
+ if (!value || typeof value !== "object") {
8
+ return false;
9
+ }
10
+ const proto = Object.getPrototypeOf(value);
11
+ return proto === Object.prototype || proto === null;
12
+ };
13
+ const sanitizeValue = (value, seen) => {
14
+ if (value === null || typeof value === "string" || typeof value === "number") {
15
+ return Number.isNaN(value) ? "[NaN]" : value;
16
+ }
17
+ if (typeof value === "boolean") {
18
+ return value;
19
+ }
20
+ if (typeof value === "function") {
21
+ return FUNCTION_PLACEHOLDER;
22
+ }
23
+ if (typeof value === "undefined") {
24
+ return UNDEFINED_PLACEHOLDER;
25
+ }
26
+ if (typeof value === "bigint" || typeof value === "symbol") {
27
+ return String(value);
28
+ }
29
+ if (!(value instanceof Object)) {
30
+ return NON_SERIALIZABLE_PLACEHOLDER;
31
+ }
32
+ if (seen.has(value)) {
33
+ return CIRCULAR_PLACEHOLDER;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ const next2 = [];
37
+ seen.set(value, next2);
38
+ value.forEach((item, index) => {
39
+ next2[index] = sanitizeValue(item, seen);
40
+ });
41
+ return next2;
42
+ }
43
+ if (value instanceof Date) {
44
+ return value.toISOString();
45
+ }
46
+ if (value instanceof RegExp) {
47
+ return value.toString();
48
+ }
49
+ if (value instanceof Error) {
50
+ const next2 = {
51
+ name: value.name,
52
+ message: value.message,
53
+ stack: value.stack || ""
54
+ };
55
+ seen.set(value, next2);
56
+ return next2;
57
+ }
58
+ if (value instanceof Map) {
59
+ const next2 = [];
60
+ seen.set(value, next2);
61
+ next2.push(
62
+ ...Array.from(value.entries()).map(([key, item]) => [
63
+ sanitizeValue(key, seen),
64
+ sanitizeValue(item, seen)
65
+ ])
66
+ );
67
+ return next2;
68
+ }
69
+ if (value instanceof Set) {
70
+ const next2 = [];
71
+ seen.set(value, next2);
72
+ next2.push(
73
+ ...Array.from(value.values()).map((item) => sanitizeValue(item, seen))
74
+ );
75
+ return next2;
76
+ }
77
+ if (ArrayBuffer.isView(value)) {
78
+ return Array.from(new Uint8Array(value.buffer));
79
+ }
80
+ if (value instanceof ArrayBuffer) {
81
+ return Array.from(new Uint8Array(value));
82
+ }
83
+ if (typeof Node !== "undefined" && value instanceof Node) {
84
+ return `[${toStringTag(value)}]`;
85
+ }
86
+ if (typeof Window !== "undefined" && value instanceof Window) {
87
+ return "[Window]";
88
+ }
89
+ if (typeof Document !== "undefined" && value instanceof Document) {
90
+ return "[Document]";
91
+ }
92
+ const next = {};
93
+ seen.set(value, next);
94
+ const entries = isPlainObject(value) ? Object.keys(value).map((key) => {
95
+ try {
96
+ return [key, value[key]];
97
+ } catch (_error) {
98
+ return [key, NON_SERIALIZABLE_PLACEHOLDER];
99
+ }
100
+ }) : Reflect.ownKeys(value).map((key) => {
101
+ try {
102
+ return [
103
+ String(key),
104
+ value[key]
105
+ ];
106
+ } catch (_error) {
107
+ return [String(key), NON_SERIALIZABLE_PLACEHOLDER];
108
+ }
109
+ });
110
+ entries.forEach(([key, item]) => {
111
+ try {
112
+ next[key] = sanitizeValue(item, seen);
113
+ } catch (_error) {
114
+ next[key] = NON_SERIALIZABLE_PLACEHOLDER;
115
+ }
116
+ });
117
+ return next;
118
+ };
119
+ const sanitizePostMessagePayload = (payload) => {
120
+ return sanitizeValue(payload, /* @__PURE__ */ new WeakMap());
121
+ };
122
+ export {
123
+ sanitizePostMessagePayload
124
+ };
@@ -74,6 +74,7 @@ __export(chrome_exports, {
74
74
  module.exports = __toCommonJS(chrome_exports);
75
75
  var import_constant = require("../../template/constant");
76
76
  var import_sdk2 = require("../sdk");
77
+ var import_safe_post_message = require("./safe-post-message");
77
78
  __reExport(chrome_exports, require("./storage"), module.exports);
78
79
  const sleep = (num) => {
79
80
  return new Promise((resolve) => {
@@ -169,8 +170,8 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
169
170
  var _a, _b;
170
171
  if (typeof window !== "undefined" && ((_a = window.__FEDERATION__) == null ? void 0 : _a.moduleInfo)) {
171
172
  callback(
172
- JSON.parse(
173
- JSON.stringify((_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo)
173
+ (0, import_safe_post_message.sanitizePostMessagePayload)(
174
+ (_b = window.__FEDERATION__) == null ? void 0 : _b.moduleInfo
174
175
  )
175
176
  );
176
177
  }
@@ -184,8 +185,8 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
184
185
  (0, import_sdk2.definePropertyGlobalVal)(window, "__FEDERATION__", {});
185
186
  (0, import_sdk2.definePropertyGlobalVal)(window, "__VMOK__", window.__FEDERATION__);
186
187
  }
187
- window.__FEDERATION__.originModuleInfo = JSON.parse(
188
- JSON.stringify(data == null ? void 0 : data.moduleInfo)
188
+ window.__FEDERATION__.originModuleInfo = (0, import_safe_post_message.sanitizePostMessagePayload)(
189
+ data == null ? void 0 : data.moduleInfo
189
190
  );
190
191
  if (data == null ? void 0 : data.updateModule) {
191
192
  const moduleIds = Object.keys(window.__FEDERATION__.originModuleInfo);
@@ -201,10 +202,10 @@ const getGlobalModuleInfo = (callback) => __async(void 0, null, function* () {
201
202
  }
202
203
  }
203
204
  if (data == null ? void 0 : data.share) {
204
- window.__FEDERATION__.__SHARE__ = data.share;
205
+ window.__FEDERATION__.__SHARE__ = (0, import_safe_post_message.sanitizePostMessagePayload)(data.share);
205
206
  }
206
- window.__FEDERATION__.moduleInfo = JSON.parse(
207
- JSON.stringify(window.__FEDERATION__.originModuleInfo)
207
+ window.__FEDERATION__.moduleInfo = (0, import_safe_post_message.sanitizePostMessagePayload)(
208
+ window.__FEDERATION__.originModuleInfo
208
209
  );
209
210
  console.log("getGlobalModuleInfo window", window.__FEDERATION__);
210
211
  callback(window.__FEDERATION__.moduleInfo);
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var import_safe_post_message = require("./safe-post-message");
2
3
  if (window.moduleHandler) {
3
4
  window.removeEventListener("message", window.moduleHandler);
4
5
  } else {
@@ -9,11 +10,11 @@ if (window.moduleHandler) {
9
10
  }
10
11
  chrome.runtime.sendMessage({
11
12
  origin,
12
- data: {
13
+ data: (0, import_safe_post_message.sanitizePostMessagePayload)({
13
14
  moduleInfo: data.moduleInfo,
14
15
  updateModule: data.updateModule,
15
16
  share: data.share
16
- }
17
+ })
17
18
  }).catch(() => {
18
19
  return false;
19
20
  });
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
+ var import_safe_post_message = require("./safe-post-message");
2
3
  var _a, _b;
3
4
  const moduleInfo = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.moduleInfo;
4
5
  window.postMessage(
5
- {
6
+ (0, import_safe_post_message.sanitizePostMessagePayload)({
6
7
  moduleInfo,
7
- share: JSON.parse(
8
- JSON.stringify((_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__, (_key, value) => {
9
- if (typeof value === "function") {
10
- return "Function";
11
- }
12
- return value;
13
- })
14
- )
15
- },
8
+ share: (_b = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _b.__SHARE__
9
+ }),
16
10
  "*"
17
11
  );
@@ -49,6 +49,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
49
49
  ));
50
50
  var import_helpers = __toESM(require("@module-federation/runtime/helpers"));
51
51
  var import_sdk = require("../sdk");
52
+ var import_safe_post_message = require("./safe-post-message");
52
53
  var _a;
53
54
  const getModuleInfo = () => {
54
55
  return {
@@ -66,10 +67,10 @@ const getModuleInfo = () => {
66
67
  const globalSnapshot = import_helpers.default.global.getGlobalSnapshot();
67
68
  if (!options || options.inBrowser) {
68
69
  window.postMessage(
69
- {
70
+ (0, import_safe_post_message.sanitizePostMessagePayload)({
70
71
  moduleInfo: globalSnapshot,
71
72
  updateModule: moduleInfo
72
- },
73
+ }),
73
74
  "*"
74
75
  );
75
76
  }
@@ -0,0 +1,148 @@
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 safe_post_message_exports = {};
20
+ __export(safe_post_message_exports, {
21
+ sanitizePostMessagePayload: () => sanitizePostMessagePayload
22
+ });
23
+ module.exports = __toCommonJS(safe_post_message_exports);
24
+ const FUNCTION_PLACEHOLDER = "function(){}";
25
+ const UNDEFINED_PLACEHOLDER = "[undefined]";
26
+ const CIRCULAR_PLACEHOLDER = "[circular]";
27
+ const NON_SERIALIZABLE_PLACEHOLDER = "[unserializable]";
28
+ const toStringTag = (value) => Object.prototype.toString.call(value).slice(8, -1);
29
+ const isPlainObject = (value) => {
30
+ if (!value || typeof value !== "object") {
31
+ return false;
32
+ }
33
+ const proto = Object.getPrototypeOf(value);
34
+ return proto === Object.prototype || proto === null;
35
+ };
36
+ const sanitizeValue = (value, seen) => {
37
+ if (value === null || typeof value === "string" || typeof value === "number") {
38
+ return Number.isNaN(value) ? "[NaN]" : value;
39
+ }
40
+ if (typeof value === "boolean") {
41
+ return value;
42
+ }
43
+ if (typeof value === "function") {
44
+ return FUNCTION_PLACEHOLDER;
45
+ }
46
+ if (typeof value === "undefined") {
47
+ return UNDEFINED_PLACEHOLDER;
48
+ }
49
+ if (typeof value === "bigint" || typeof value === "symbol") {
50
+ return String(value);
51
+ }
52
+ if (!(value instanceof Object)) {
53
+ return NON_SERIALIZABLE_PLACEHOLDER;
54
+ }
55
+ if (seen.has(value)) {
56
+ return CIRCULAR_PLACEHOLDER;
57
+ }
58
+ if (Array.isArray(value)) {
59
+ const next2 = [];
60
+ seen.set(value, next2);
61
+ value.forEach((item, index) => {
62
+ next2[index] = sanitizeValue(item, seen);
63
+ });
64
+ return next2;
65
+ }
66
+ if (value instanceof Date) {
67
+ return value.toISOString();
68
+ }
69
+ if (value instanceof RegExp) {
70
+ return value.toString();
71
+ }
72
+ if (value instanceof Error) {
73
+ const next2 = {
74
+ name: value.name,
75
+ message: value.message,
76
+ stack: value.stack || ""
77
+ };
78
+ seen.set(value, next2);
79
+ return next2;
80
+ }
81
+ if (value instanceof Map) {
82
+ const next2 = [];
83
+ seen.set(value, next2);
84
+ next2.push(
85
+ ...Array.from(value.entries()).map(([key, item]) => [
86
+ sanitizeValue(key, seen),
87
+ sanitizeValue(item, seen)
88
+ ])
89
+ );
90
+ return next2;
91
+ }
92
+ if (value instanceof Set) {
93
+ const next2 = [];
94
+ seen.set(value, next2);
95
+ next2.push(
96
+ ...Array.from(value.values()).map((item) => sanitizeValue(item, seen))
97
+ );
98
+ return next2;
99
+ }
100
+ if (ArrayBuffer.isView(value)) {
101
+ return Array.from(new Uint8Array(value.buffer));
102
+ }
103
+ if (value instanceof ArrayBuffer) {
104
+ return Array.from(new Uint8Array(value));
105
+ }
106
+ if (typeof Node !== "undefined" && value instanceof Node) {
107
+ return `[${toStringTag(value)}]`;
108
+ }
109
+ if (typeof Window !== "undefined" && value instanceof Window) {
110
+ return "[Window]";
111
+ }
112
+ if (typeof Document !== "undefined" && value instanceof Document) {
113
+ return "[Document]";
114
+ }
115
+ const next = {};
116
+ seen.set(value, next);
117
+ const entries = isPlainObject(value) ? Object.keys(value).map((key) => {
118
+ try {
119
+ return [key, value[key]];
120
+ } catch (_error) {
121
+ return [key, NON_SERIALIZABLE_PLACEHOLDER];
122
+ }
123
+ }) : Reflect.ownKeys(value).map((key) => {
124
+ try {
125
+ return [
126
+ String(key),
127
+ value[key]
128
+ ];
129
+ } catch (_error) {
130
+ return [String(key), NON_SERIALIZABLE_PLACEHOLDER];
131
+ }
132
+ });
133
+ entries.forEach(([key, item]) => {
134
+ try {
135
+ next[key] = sanitizeValue(item, seen);
136
+ } catch (_error) {
137
+ next[key] = NON_SERIALIZABLE_PLACEHOLDER;
138
+ }
139
+ });
140
+ return next;
141
+ };
142
+ const sanitizePostMessagePayload = (payload) => {
143
+ return sanitizeValue(payload, /* @__PURE__ */ new WeakMap());
144
+ };
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ sanitizePostMessagePayload
148
+ });
@@ -1 +1 @@
1
- declare const moduleInfo: import("@module-federation/sdk/.").GlobalModuleInfo;
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const sanitizePostMessagePayload: <T>(payload: T) => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/devtools",
3
- "version": "2.2.3",
3
+ "version": "2.3.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,7 +47,7 @@
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.2.3"
50
+ "@module-federation/sdk": "2.3.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "react": "^18 || ^19",
@@ -82,7 +82,7 @@
82
82
  "typescript": "5.9.3",
83
83
  "rimraf": "~6.0.1",
84
84
  "vitest": "1.2.2",
85
- "@module-federation/runtime": "2.2.3"
85
+ "@module-federation/runtime": "2.3.1"
86
86
  },
87
87
  "scripts": {
88
88
  "build:storybook": "storybook build",