miaoda-react-devkit 0.1.1-beta.0 → 0.1.1-beta.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.
- package/README.md +145 -5
- package/cloud/vite.config.ts +156 -0
- package/dist/index.cjs +437 -46
- package/dist/index.d.cts +196 -41
- package/dist/index.d.ts +196 -41
- package/dist/index.js +431 -48
- package/dist/stubs/sentry-react-stub.js +427 -84
- package/dist/vite/index.cjs +60 -0
- package/dist/vite/index.d.cts +13 -1
- package/dist/vite/index.d.ts +13 -1
- package/dist/vite/index.js +59 -0
- package/package.json +6 -1
|
@@ -5,126 +5,469 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5
5
|
// src/stubs/sentry-react-stub.ts
|
|
6
6
|
import * as RealSentry from "@sentry/react";
|
|
7
7
|
|
|
8
|
-
// src/capture.ts
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// src/capture/console.ts
|
|
9
|
+
import { addConsoleInstrumentationHandler } from "@sentry/core";
|
|
10
|
+
var DEFAULT_CONSOLE_FILTER_KEYWORDS = [
|
|
11
|
+
"Sentry initialized successfully",
|
|
12
|
+
"[vite] ",
|
|
13
|
+
"Download the React DevTools for a better development experience"
|
|
14
|
+
];
|
|
15
|
+
function serializeArg(arg) {
|
|
16
|
+
if (typeof arg === "string") return arg;
|
|
17
|
+
if (arg instanceof Error) return arg.message;
|
|
18
|
+
try {
|
|
19
|
+
return JSON.stringify(arg);
|
|
20
|
+
} catch {
|
|
21
|
+
return String(arg);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function shouldFilterConsole(args, keywords) {
|
|
25
|
+
if (keywords.length === 0) return false;
|
|
26
|
+
const text = args.map(serializeArg).join(" ");
|
|
27
|
+
return keywords.some((kw) => text.includes(kw));
|
|
28
|
+
}
|
|
29
|
+
function shouldFilterConsoleMessage(message, keywords) {
|
|
30
|
+
return keywords.some((kw) => message.includes(kw));
|
|
31
|
+
}
|
|
32
|
+
function createConsoleObserver(keywords, subscribers) {
|
|
33
|
+
return {
|
|
34
|
+
install() {
|
|
35
|
+
if (subscribers.length === 0) return;
|
|
36
|
+
addConsoleInstrumentationHandler(({ args, level }) => {
|
|
37
|
+
if (shouldFilterConsole(args, keywords)) return;
|
|
38
|
+
const info = { level, args };
|
|
39
|
+
for (const sub of subscribers) sub.onConsole(info);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
beforeBreadcrumb(breadcrumb, _hint) {
|
|
43
|
+
if (breadcrumb.category === "console" && breadcrumb.message != null) {
|
|
44
|
+
if (shouldFilterConsoleMessage(breadcrumb.message, keywords)) return null;
|
|
45
|
+
}
|
|
46
|
+
return breadcrumb;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/capture/network.ts
|
|
52
|
+
import { getClient } from "@sentry/core";
|
|
53
|
+
|
|
54
|
+
// ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
|
|
55
|
+
var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/networkUtils.js
|
|
58
|
+
import { debug } from "@sentry/core";
|
|
59
|
+
function serializeFormData(formData) {
|
|
60
|
+
return new URLSearchParams(formData).toString();
|
|
61
|
+
}
|
|
62
|
+
function getBodyString(body, _debug = debug) {
|
|
63
|
+
try {
|
|
64
|
+
if (typeof body === "string") {
|
|
65
|
+
return [body];
|
|
66
|
+
}
|
|
67
|
+
if (body instanceof URLSearchParams) {
|
|
68
|
+
return [body.toString()];
|
|
69
|
+
}
|
|
70
|
+
if (body instanceof FormData) {
|
|
71
|
+
return [serializeFormData(body)];
|
|
72
|
+
}
|
|
73
|
+
if (!body) {
|
|
74
|
+
return [void 0];
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
DEBUG_BUILD && _debug.error(error, "Failed to serialize body", body);
|
|
78
|
+
return [void 0, "BODY_PARSE_ERROR"];
|
|
79
|
+
}
|
|
80
|
+
DEBUG_BUILD && _debug.log("Skipping network body because of body type", body);
|
|
81
|
+
return [void 0, "UNPARSEABLE_BODY_TYPE"];
|
|
82
|
+
}
|
|
83
|
+
function getFetchRequestArgBody(fetchArgs = []) {
|
|
84
|
+
if (fetchArgs.length !== 2 || typeof fetchArgs[1] !== "object") {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
return fetchArgs[1].body;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/capture/pgrest.ts
|
|
91
|
+
var DEFAULT_PGREST_URL_PATTERNS = [/\/rest\/v1\//];
|
|
92
|
+
var DEFAULT_PGREST_WHITELIST_CODES = [];
|
|
93
|
+
function isPgRestRequest(url, patterns) {
|
|
94
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
95
|
+
}
|
|
96
|
+
function parsePgRestErrorBody(body) {
|
|
97
|
+
if (!body) return null;
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(body);
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (typeof parsed !== "object") return null;
|
|
105
|
+
if (parsed === null) return null;
|
|
106
|
+
const p = parsed;
|
|
107
|
+
if (typeof p["code"] !== "string") return null;
|
|
108
|
+
if (typeof p["message"] !== "string") return null;
|
|
109
|
+
return {
|
|
110
|
+
code: p["code"],
|
|
111
|
+
message: p["message"],
|
|
112
|
+
details: typeof p["details"] === "string" ? p["details"] : null,
|
|
113
|
+
hint: typeof p["hint"] === "string" ? p["hint"] : null
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/capture/network.ts
|
|
118
|
+
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
119
|
+
var DEFAULT_IGNORE_URLS = [
|
|
120
|
+
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
121
|
+
/\.chunk\./,
|
|
122
|
+
/\/static\//,
|
|
123
|
+
/\/assets\//
|
|
124
|
+
];
|
|
125
|
+
function createUrlMatcher(patterns) {
|
|
126
|
+
const regexes = patterns.map((p) => typeof p === "string" ? new RegExp(p) : p);
|
|
127
|
+
return (url) => regexes.some((re) => re.test(url));
|
|
128
|
+
}
|
|
129
|
+
function truncateBody(body) {
|
|
130
|
+
return body.length > BODY_TRUNCATE_LIMIT ? body.slice(0, BODY_TRUNCATE_LIMIT) + "... (truncated)" : body;
|
|
131
|
+
}
|
|
132
|
+
function isStreamByContentType(contentType) {
|
|
133
|
+
return contentType.includes("text/event-stream") || contentType.includes("application/stream+json");
|
|
134
|
+
}
|
|
135
|
+
function handleXhrBreadcrumb(breadcrumb, hint, handler) {
|
|
136
|
+
const data = breadcrumb.data;
|
|
137
|
+
const method = data?.method ?? "GET";
|
|
138
|
+
const url = data?.url ?? "";
|
|
139
|
+
const statusCode = data?.status_code != null && data.status_code > 0 ? data.status_code : null;
|
|
140
|
+
const isError = statusCode === null;
|
|
141
|
+
const xhr = hint?.xhr;
|
|
142
|
+
const [rawRequestBody] = getBodyString(hint?.input);
|
|
143
|
+
const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
|
|
144
|
+
let responseBody;
|
|
145
|
+
if (xhr) {
|
|
146
|
+
const contentType = xhr.getResponseHeader("content-type") ?? "";
|
|
147
|
+
if (isStreamByContentType(contentType)) {
|
|
148
|
+
responseBody = "[streaming response - not captured]";
|
|
149
|
+
} else if (xhr.responseType === "" || xhr.responseType === "text") {
|
|
150
|
+
try {
|
|
151
|
+
responseBody = xhr.responseText != null ? truncateBody(xhr.responseText) : void 0;
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
} else if (xhr.responseType === "json") {
|
|
155
|
+
try {
|
|
156
|
+
responseBody = truncateBody(JSON.stringify(xhr.response));
|
|
157
|
+
} catch {
|
|
158
|
+
responseBody = "[json response parse failed]";
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
responseBody = "[non-text response]";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (breadcrumb.data) {
|
|
165
|
+
breadcrumb.data["requestBody"] = requestBody;
|
|
166
|
+
breadcrumb.data["responseBody"] = responseBody;
|
|
167
|
+
}
|
|
168
|
+
void handler({ type: "xhr", method, url, statusCode, requestBody, responseBody, isError });
|
|
169
|
+
}
|
|
170
|
+
async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
171
|
+
const data = breadcrumb.data;
|
|
172
|
+
const method = data?.method ?? "GET";
|
|
173
|
+
const url = data?.url ?? "";
|
|
174
|
+
const statusCode = data?.status_code ?? null;
|
|
175
|
+
const isError = hint?.data != null;
|
|
176
|
+
const response = hint?.response;
|
|
177
|
+
const cause = hint?.data instanceof Error ? hint.data : void 0;
|
|
178
|
+
const fetchArgs = hint?.input;
|
|
179
|
+
const reqBody = getFetchRequestArgBody(fetchArgs ?? []);
|
|
180
|
+
const [rawRequestBody] = getBodyString(reqBody);
|
|
181
|
+
const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
|
|
182
|
+
if (breadcrumb.data) {
|
|
183
|
+
breadcrumb.data["requestBody"] = requestBody;
|
|
184
|
+
}
|
|
185
|
+
const contentType = response?.headers?.get("content-type") ?? "";
|
|
186
|
+
if (isStreamByContentType(contentType)) {
|
|
187
|
+
if (breadcrumb.data) {
|
|
188
|
+
breadcrumb.data["responseBody"] = "[streaming response - not captured]";
|
|
189
|
+
}
|
|
190
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
let responseBody;
|
|
194
|
+
if (response) {
|
|
195
|
+
try {
|
|
196
|
+
const text = await Promise.race([
|
|
197
|
+
response.clone().text(),
|
|
198
|
+
new Promise(
|
|
199
|
+
(_, reject) => setTimeout(() => reject(new Error("timeout")), 500)
|
|
200
|
+
)
|
|
201
|
+
]);
|
|
202
|
+
responseBody = truncateBody(text);
|
|
203
|
+
} catch {
|
|
204
|
+
responseBody = void 0;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (breadcrumb.data) {
|
|
208
|
+
breadcrumb.data["responseBody"] = responseBody;
|
|
209
|
+
}
|
|
210
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause });
|
|
211
|
+
}
|
|
212
|
+
function createNetworkObserver(opts, subscribers) {
|
|
213
|
+
const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
|
|
214
|
+
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
215
|
+
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
216
|
+
function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
217
|
+
if (statusCode == null) return;
|
|
218
|
+
if (!isPgRestRequest(url, pgRestPatterns)) return;
|
|
219
|
+
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
220
|
+
if (!pgRestError) return;
|
|
221
|
+
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
222
|
+
const info = {
|
|
223
|
+
type: requestType,
|
|
224
|
+
method,
|
|
225
|
+
url,
|
|
226
|
+
statusCode,
|
|
227
|
+
pgRestError,
|
|
228
|
+
requestBody,
|
|
229
|
+
responseBody
|
|
230
|
+
};
|
|
231
|
+
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
232
|
+
}
|
|
233
|
+
function makeHandler(requestType) {
|
|
234
|
+
return (info) => {
|
|
235
|
+
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
236
|
+
tryDispatchPgRestWhitelistError(
|
|
237
|
+
requestType,
|
|
238
|
+
info.method,
|
|
239
|
+
info.url,
|
|
240
|
+
info.statusCode,
|
|
241
|
+
info.requestBody,
|
|
242
|
+
info.responseBody
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
shouldIgnore,
|
|
248
|
+
install() {
|
|
249
|
+
if (subscribers.length === 0) return;
|
|
250
|
+
const client = getClient();
|
|
251
|
+
if (!client) return;
|
|
252
|
+
const xhrHandler = makeHandler("xhr");
|
|
253
|
+
const fetchHandler = makeHandler("fetch");
|
|
254
|
+
client.on("beforeAddBreadcrumb", (breadcrumb, hint) => {
|
|
255
|
+
const url = breadcrumb.data?.url ?? "";
|
|
256
|
+
if (shouldIgnore(url)) return;
|
|
257
|
+
if (breadcrumb.category === "xhr") {
|
|
258
|
+
handleXhrBreadcrumb(breadcrumb, hint, xhrHandler);
|
|
259
|
+
} else if (breadcrumb.category === "fetch") {
|
|
260
|
+
void handleFetchBreadcrumb(breadcrumb, hint, fetchHandler);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/capture/capture.ts
|
|
12
268
|
var SentryCapture = class {
|
|
13
|
-
constructor(
|
|
14
|
-
__publicField(this, "
|
|
15
|
-
__publicField(this, "
|
|
16
|
-
__publicField(this, "
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
269
|
+
constructor(opts, subscribers = []) {
|
|
270
|
+
__publicField(this, "subscribers");
|
|
271
|
+
__publicField(this, "console");
|
|
272
|
+
__publicField(this, "network");
|
|
273
|
+
this.subscribers = subscribers;
|
|
274
|
+
this.console = createConsoleObserver(opts.consoleFilterKeywords, subscribers);
|
|
275
|
+
this.network = createNetworkObserver(opts, subscribers);
|
|
20
276
|
this.beforeSend = this.beforeSend.bind(this);
|
|
21
277
|
this.beforeBreadcrumb = this.beforeBreadcrumb.bind(this);
|
|
22
278
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
installFetchObserver() {
|
|
28
|
-
if (!this.onRequest) return;
|
|
29
|
-
const handler = this.onRequest;
|
|
30
|
-
addFetchInstrumentationHandler((data) => {
|
|
31
|
-
const { method, url } = data.fetchData;
|
|
32
|
-
const responseContentType = data.response?.headers?.get?.("content-type") ?? "";
|
|
33
|
-
if (responseContentType.includes("text/event-stream")) return;
|
|
34
|
-
if (!data.endTimestamp) {
|
|
35
|
-
handler({ method, url, statusCode: null, isEnd: false, isError: false });
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const statusCode = data.response?.status ?? null;
|
|
39
|
-
const isError = data.error != null;
|
|
40
|
-
handler({ method, url, statusCode, isEnd: true, isError });
|
|
41
|
-
});
|
|
279
|
+
/** 在 Sentry.init() 完成后调用一次,注册网络请求观测器。 */
|
|
280
|
+
installNetworkObserver() {
|
|
281
|
+
this.network.install();
|
|
42
282
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
283
|
+
/** 注册控制台日志观测器,可在 Sentry.init() 前后调用均可。 */
|
|
284
|
+
installConsoleObserver() {
|
|
285
|
+
this.console.install();
|
|
286
|
+
}
|
|
287
|
+
/** 传入 Sentry.init({ beforeSend }) —— 提取错误信息触发 onError 回调。 */
|
|
47
288
|
beforeSend(event, hint) {
|
|
48
|
-
const
|
|
289
|
+
const exceptionValue = event.exception?.values?.[0];
|
|
290
|
+
const message = exceptionValue?.value ?? event.message ?? "(unknown)";
|
|
49
291
|
const componentStack = event.contexts?.["react"]?.["componentStack"] ?? void 0;
|
|
50
|
-
const mechanismType =
|
|
292
|
+
const mechanismType = exceptionValue?.mechanism?.type ?? null;
|
|
51
293
|
const stack = hint.originalException instanceof Error ? hint.originalException.stack : void 0;
|
|
52
|
-
|
|
294
|
+
const errorName = exceptionValue?.type ?? (hint.originalException instanceof Error ? hint.originalException.name : void 0);
|
|
295
|
+
const frames = exceptionValue?.stacktrace?.frames;
|
|
296
|
+
const innerFrame = frames?.length ? frames[frames.length - 1] : void 0;
|
|
297
|
+
const fileName = innerFrame?.filename ?? innerFrame?.abs_path;
|
|
298
|
+
const lineNumber = innerFrame?.lineno;
|
|
299
|
+
const columnNumber = innerFrame?.colno;
|
|
300
|
+
const info = { message, stack, componentStack, mechanismType, errorName, fileName, lineNumber, columnNumber };
|
|
301
|
+
for (const sub of this.subscribers) sub.onError(info);
|
|
53
302
|
return event;
|
|
54
303
|
}
|
|
55
304
|
/**
|
|
56
|
-
*
|
|
305
|
+
* 传入 Sentry.init({ beforeBreadcrumb })。
|
|
306
|
+
* - console:过滤噪音关键词
|
|
307
|
+
* - fetch/xhr:过滤 ignoreUrls 匹配的静态资源请求
|
|
57
308
|
*/
|
|
58
|
-
beforeBreadcrumb(breadcrumb,
|
|
59
|
-
if (breadcrumb.
|
|
60
|
-
const
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
309
|
+
beforeBreadcrumb(breadcrumb, hint) {
|
|
310
|
+
if (breadcrumb.category === "fetch" || breadcrumb.category === "xhr") {
|
|
311
|
+
const url = breadcrumb.data?.url ?? "";
|
|
312
|
+
if (this.network.shouldIgnore(url)) return null;
|
|
313
|
+
}
|
|
314
|
+
return this.console.beforeBreadcrumb(breadcrumb, hint);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/subscribers/postMessageSubscriber.ts
|
|
319
|
+
function extractUrlPath(url) {
|
|
320
|
+
try {
|
|
321
|
+
const u = new URL(url);
|
|
322
|
+
return u.pathname + u.search + u.hash;
|
|
323
|
+
} catch {
|
|
324
|
+
return url;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
var PostMessageSubscriber = class {
|
|
328
|
+
constructor(send = (msg, origin) => window.parent.postMessage(msg, origin)) {
|
|
329
|
+
__publicField(this, "send");
|
|
330
|
+
this.send = send;
|
|
331
|
+
}
|
|
332
|
+
// postMessage 场景不需要上报 console 日志
|
|
333
|
+
onConsole(_info) {
|
|
334
|
+
}
|
|
335
|
+
onError({ message, stack, errorName, fileName, lineNumber, columnNumber }) {
|
|
336
|
+
const name = errorName ?? "Error";
|
|
337
|
+
const msg = {
|
|
338
|
+
type: "GLOBAL_ERROR",
|
|
339
|
+
message,
|
|
340
|
+
error: stack != null ? { name, message, stack } : null,
|
|
341
|
+
errorData: {
|
|
342
|
+
name,
|
|
343
|
+
message,
|
|
344
|
+
stack,
|
|
345
|
+
fileName: fileName ?? "unknown",
|
|
346
|
+
lineNumber: lineNumber ?? 0,
|
|
347
|
+
columnNumber: columnNumber ?? 0
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
this.send(msg, "*");
|
|
351
|
+
}
|
|
352
|
+
onNetworkRequest({ method, url, statusCode, requestBody, responseBody, isError, cause }) {
|
|
353
|
+
const isClientError = statusCode != null && statusCode >= 400 && statusCode < 500;
|
|
354
|
+
if (!isError && !isClientError) return;
|
|
355
|
+
const urlPath = extractUrlPath(url);
|
|
356
|
+
if (isError) {
|
|
357
|
+
const causeDesc = cause != null ? String(cause) : "NetworkError";
|
|
358
|
+
const errorMessage = `${method} ${urlPath} failed: ${causeDesc}`;
|
|
359
|
+
const msg = {
|
|
360
|
+
type: "GLOBAL_ERROR",
|
|
361
|
+
message: errorMessage,
|
|
362
|
+
error: cause != null ? { name: cause.name, message: cause.message, stack: cause.stack } : null,
|
|
363
|
+
errorData: {
|
|
364
|
+
name: cause?.name ?? "NetworkError",
|
|
365
|
+
message: cause?.message ?? causeDesc,
|
|
366
|
+
stack: cause?.stack ?? null,
|
|
367
|
+
fileName: url,
|
|
368
|
+
lineNumber: 0,
|
|
369
|
+
columnNumber: 0,
|
|
370
|
+
httpPath: urlPath,
|
|
371
|
+
httpStatus: 0,
|
|
372
|
+
httpMethod: method,
|
|
373
|
+
requestBody: requestBody ?? "",
|
|
374
|
+
responseBody: ""
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
this.send(msg, "*");
|
|
378
|
+
} else {
|
|
379
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode}`;
|
|
380
|
+
const msg = {
|
|
381
|
+
type: "GLOBAL_ERROR",
|
|
382
|
+
message: errorMessage,
|
|
383
|
+
error: null,
|
|
384
|
+
errorData: {
|
|
385
|
+
name: "HTTPClientError",
|
|
386
|
+
message: errorMessage,
|
|
387
|
+
stack: null,
|
|
388
|
+
fileName: url,
|
|
389
|
+
lineNumber: 0,
|
|
390
|
+
columnNumber: 0,
|
|
391
|
+
httpPath: urlPath,
|
|
392
|
+
httpStatus: statusCode,
|
|
393
|
+
httpMethod: method,
|
|
394
|
+
requestBody: requestBody ?? "",
|
|
395
|
+
responseBody: responseBody ?? ""
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
this.send(msg, "*");
|
|
66
399
|
}
|
|
67
|
-
|
|
400
|
+
}
|
|
401
|
+
onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody }) {
|
|
402
|
+
const urlPath = extractUrlPath(url);
|
|
403
|
+
const code = pgRestError.code;
|
|
404
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [PgRest:${code}]`;
|
|
405
|
+
const msg = {
|
|
406
|
+
type: "GLOBAL_ERROR",
|
|
407
|
+
message: errorMessage,
|
|
408
|
+
error: null,
|
|
409
|
+
errorData: {
|
|
410
|
+
name: "PgRestWhitelistError",
|
|
411
|
+
message: pgRestError.message,
|
|
412
|
+
stack: null,
|
|
413
|
+
fileName: url,
|
|
414
|
+
lineNumber: 0,
|
|
415
|
+
columnNumber: 0,
|
|
416
|
+
httpPath: urlPath,
|
|
417
|
+
httpStatus: statusCode,
|
|
418
|
+
httpMethod: method,
|
|
419
|
+
requestBody: requestBody ?? "",
|
|
420
|
+
responseBody,
|
|
421
|
+
pgRestCode: code,
|
|
422
|
+
pgRestDetails: pgRestError.details ?? void 0,
|
|
423
|
+
pgRestHint: pgRestError.hint ?? void 0,
|
|
424
|
+
requestType: type
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
this.send(msg, "*");
|
|
68
428
|
}
|
|
69
429
|
};
|
|
430
|
+
function createPostMessageSubscriber(send) {
|
|
431
|
+
return new PostMessageSubscriber(send);
|
|
432
|
+
}
|
|
70
433
|
|
|
71
434
|
// src/stubs/sentry-react-stub.ts
|
|
72
435
|
export * from "@sentry/react";
|
|
73
436
|
var STUB_DSN = "https://stubPublicKey@o0.ingest.sentry.io/0";
|
|
74
437
|
var OVERRIDE_DSN = typeof process !== "undefined" && process.env["SENTRY_OVERRIDE_DSN"] ? process.env["SENTRY_OVERRIDE_DSN"] : STUB_DSN;
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.warn(
|
|
80
|
-
"[SentryStub] \u8C03\u7528\u6808\uFF1A",
|
|
81
|
-
info.stack.split("\n").slice(0, 4).join("\n")
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
if (info.componentStack) {
|
|
85
|
-
console.warn(
|
|
86
|
-
"[SentryStub] \u7EC4\u4EF6\u6808\uFF1A",
|
|
87
|
-
info.componentStack.split("\n").slice(0, 4).join("\n")
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
onNetwork(info) {
|
|
92
|
-
if (info.statusCode != null && info.statusCode >= 400) {
|
|
93
|
-
console.warn(
|
|
94
|
-
`[SentryStub] \u7F51\u7EDC\u9519\u8BEF\uFF1A${info.method} ${info.url} \u2192 ${info.statusCode}`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
onRequest(info) {
|
|
99
|
-
if (!info.isEnd) return;
|
|
100
|
-
if (info.isError) {
|
|
101
|
-
console.warn(`[SentryStub] \u8BF7\u6C42\u5931\u8D25\uFF08\u7F51\u7EDC\u5C42\uFF09\uFF1A${info.method} ${info.url}`);
|
|
102
|
-
} else if (info.statusCode != null && info.statusCode >= 400) {
|
|
103
|
-
console.warn(`[SentryStub] \u8BF7\u6C42\u5F02\u5E38\uFF1A${info.method} ${info.url} \u2192 ${info.statusCode}`);
|
|
104
|
-
} else {
|
|
105
|
-
console.debug(`[SentryStub] \u8BF7\u6C42\u5B8C\u6210\uFF1A${info.method} ${info.url} \u2192 ${info.statusCode}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
438
|
+
var _subscribers = [createPostMessageSubscriber()];
|
|
439
|
+
function configureStubSubscribers(subscribers) {
|
|
440
|
+
_subscribers = subscribers;
|
|
441
|
+
}
|
|
109
442
|
var init2 = (options) => {
|
|
110
443
|
const upstreamBeforeSend = options?.beforeSend;
|
|
111
444
|
const upstreamBeforeBreadcrumb = options?.beforeBreadcrumb;
|
|
445
|
+
const capture = new SentryCapture(
|
|
446
|
+
{
|
|
447
|
+
consoleFilterKeywords: DEFAULT_CONSOLE_FILTER_KEYWORDS,
|
|
448
|
+
ignoreUrls: DEFAULT_IGNORE_URLS
|
|
449
|
+
},
|
|
450
|
+
_subscribers
|
|
451
|
+
);
|
|
112
452
|
const result = RealSentry.init({
|
|
113
453
|
...options,
|
|
114
454
|
dsn: OVERRIDE_DSN,
|
|
115
455
|
beforeSend(event, hint) {
|
|
116
|
-
const processed =
|
|
456
|
+
const processed = capture.beforeSend(event, hint);
|
|
117
457
|
return upstreamBeforeSend ? upstreamBeforeSend(processed, hint) : processed;
|
|
118
458
|
},
|
|
119
459
|
beforeBreadcrumb(breadcrumb, hint) {
|
|
120
|
-
const processed =
|
|
460
|
+
const processed = capture.beforeBreadcrumb(breadcrumb, hint);
|
|
461
|
+
if (processed === null) return null;
|
|
121
462
|
return upstreamBeforeBreadcrumb ? upstreamBeforeBreadcrumb(processed, hint) : processed;
|
|
122
463
|
}
|
|
123
464
|
});
|
|
124
|
-
|
|
465
|
+
capture.installNetworkObserver();
|
|
466
|
+
capture.installConsoleObserver();
|
|
125
467
|
return result;
|
|
126
468
|
};
|
|
127
469
|
export {
|
|
470
|
+
configureStubSubscribers,
|
|
128
471
|
init2 as init
|
|
129
472
|
};
|
|
130
473
|
//# sourceMappingURL=sentry-react-stub.js.map
|
package/dist/vite/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/vite/index.ts
|
|
31
31
|
var vite_exports = {};
|
|
32
32
|
__export(vite_exports, {
|
|
33
|
+
hmrTogglePlugin: () => hmrTogglePlugin,
|
|
33
34
|
withSentryStub: () => withSentryStub
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(vite_exports);
|
|
@@ -58,8 +59,67 @@ function withSentryStub() {
|
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
}
|
|
62
|
+
|
|
63
|
+
// src/vite/hmrTogglePlugin.ts
|
|
64
|
+
function hmrTogglePlugin() {
|
|
65
|
+
return {
|
|
66
|
+
name: "miaoda-devkit:hmr-toggle",
|
|
67
|
+
configureServer(server) {
|
|
68
|
+
let hmrEnabled = true;
|
|
69
|
+
const origSend = server.ws.send.bind(server.ws);
|
|
70
|
+
server.ws.send = (payload) => {
|
|
71
|
+
if (hmrEnabled) {
|
|
72
|
+
origSend(payload);
|
|
73
|
+
} else {
|
|
74
|
+
console.log("[HMR disabled] skipped payload:", payload.type);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_off", (_req, res) => {
|
|
78
|
+
hmrEnabled = false;
|
|
79
|
+
res.setHeader("Content-Type", "application/json");
|
|
80
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR disabled" }));
|
|
81
|
+
});
|
|
82
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_on", (_req, res) => {
|
|
83
|
+
hmrEnabled = true;
|
|
84
|
+
res.setHeader("Content-Type", "application/json");
|
|
85
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR enabled" }));
|
|
86
|
+
});
|
|
87
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_reload", (_req, res) => {
|
|
88
|
+
if (hmrEnabled) {
|
|
89
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
90
|
+
}
|
|
91
|
+
res.setHeader("Content-Type", "application/json");
|
|
92
|
+
res.end(JSON.stringify({ status: 0, msg: "Manual full reload triggered" }));
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
load(id) {
|
|
96
|
+
if (id === "virtual:after-update") {
|
|
97
|
+
return `
|
|
98
|
+
if (import.meta.hot) {
|
|
99
|
+
import.meta.hot.on('vite:afterUpdate', () => {
|
|
100
|
+
window.postMessage({ type: 'editor-update' }, '*');
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
transformIndexHtml(html) {
|
|
107
|
+
return {
|
|
108
|
+
html,
|
|
109
|
+
tags: [
|
|
110
|
+
{
|
|
111
|
+
tag: "script",
|
|
112
|
+
attrs: { type: "module", src: "/@id/virtual:after-update" },
|
|
113
|
+
injectTo: "body"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
61
120
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
121
|
0 && (module.exports = {
|
|
122
|
+
hmrTogglePlugin,
|
|
63
123
|
withSentryStub
|
|
64
124
|
});
|
|
65
125
|
//# sourceMappingURL=index.cjs.map
|
package/dist/vite/index.d.cts
CHANGED
|
@@ -9,4 +9,16 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 云端 dev server 专用:HMR 开关 + 手动 reload 控制接口。
|
|
14
|
+
*
|
|
15
|
+
* 暴露三个内部 HTTP 接口:
|
|
16
|
+
* POST /innerapi/v1/sourcecode/__hmr_off — 暂停 HMR 推送
|
|
17
|
+
* POST /innerapi/v1/sourcecode/__hmr_on — 恢复 HMR 推送
|
|
18
|
+
* POST /innerapi/v1/sourcecode/__hmr_reload — 触发一次全页 full-reload
|
|
19
|
+
*
|
|
20
|
+
* 同时注入 virtual:after-update 模块,使 vite:afterUpdate 事件可被宿主页面监听。
|
|
21
|
+
*/
|
|
22
|
+
declare function hmrTogglePlugin(): Plugin;
|
|
23
|
+
|
|
24
|
+
export { hmrTogglePlugin, withSentryStub };
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -9,4 +9,16 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 云端 dev server 专用:HMR 开关 + 手动 reload 控制接口。
|
|
14
|
+
*
|
|
15
|
+
* 暴露三个内部 HTTP 接口:
|
|
16
|
+
* POST /innerapi/v1/sourcecode/__hmr_off — 暂停 HMR 推送
|
|
17
|
+
* POST /innerapi/v1/sourcecode/__hmr_on — 恢复 HMR 推送
|
|
18
|
+
* POST /innerapi/v1/sourcecode/__hmr_reload — 触发一次全页 full-reload
|
|
19
|
+
*
|
|
20
|
+
* 同时注入 virtual:after-update 模块,使 vite:afterUpdate 事件可被宿主页面监听。
|
|
21
|
+
*/
|
|
22
|
+
declare function hmrTogglePlugin(): Plugin;
|
|
23
|
+
|
|
24
|
+
export { hmrTogglePlugin, withSentryStub };
|