miaoda-react-devkit 0.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.cts +71 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +70 -0
- package/dist/stubs/sentry-react-stub.js +130 -0
- package/dist/vite/index.cjs +65 -0
- package/dist/vite/index.d.cts +12 -0
- package/dist/vite/index.d.ts +12 -0
- package/dist/vite/index.js +24 -0
- package/package.json +48 -0
- package/tsconfig-base.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# miaoda-react-devkit
|
|
2
|
+
|
|
3
|
+
React 管理后台开发工具集,目前提供 Sentry 开发环境 stub。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
开发模式下,`@sentry/react` 会被自动替换为 stub:
|
|
8
|
+
|
|
9
|
+
- DSN 替换为无害的 stub 端点(project id = 0),错误不会上报到真实 Sentry
|
|
10
|
+
- 捕获到错误时在控制台打印 `[SentryStub]` 前缀的 warn,含错误消息和调用栈
|
|
11
|
+
- 4xx/5xx 网络请求同样会打印 warn
|
|
12
|
+
- 用户传入的 `beforeSend` / `beforeBreadcrumb` 回调仍会被链式调用
|
|
13
|
+
- 生产构建时插件不生效,恢复正常上报
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
在 `vite.config.ts` 中加入插件(需放在第一位):
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { withSentryStub } from 'miaoda-react-devkit/vite';
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
plugins: [withSentryStub(), react()],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
应用代码中正常使用 `@sentry/react`,无需任何改动。
|
|
28
|
+
|
|
29
|
+
## 环境变量
|
|
30
|
+
|
|
31
|
+
| 变量 | 说明 |
|
|
32
|
+
|------|------|
|
|
33
|
+
| `SENTRY_OVERRIDE_DSN` | 覆盖 stub DSN,可指向本地 Sentry Relay |
|
|
34
|
+
|
|
35
|
+
## 构建
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
E2E 测试见 `../devkit-e2e`。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
25
|
+
SentryCapture: () => SentryCapture
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
|
|
29
|
+
// src/capture.ts
|
|
30
|
+
var import_core = require("@sentry/core");
|
|
31
|
+
var SentryCapture = class {
|
|
32
|
+
constructor({ onError, onNetwork, onRequest } = {}) {
|
|
33
|
+
__publicField(this, "onError");
|
|
34
|
+
__publicField(this, "onNetwork");
|
|
35
|
+
__publicField(this, "onRequest");
|
|
36
|
+
this.onError = onError;
|
|
37
|
+
this.onNetwork = onNetwork;
|
|
38
|
+
this.onRequest = onRequest;
|
|
39
|
+
this.beforeSend = this.beforeSend.bind(this);
|
|
40
|
+
this.beforeBreadcrumb = this.beforeBreadcrumb.bind(this);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 注册 Sentry fetch 监听器,观测所有非 SSE 请求的开始与结束。
|
|
44
|
+
* 在 Sentry.init() 后调用一次,复用 Sentry 已打补丁的 fetch,不会二次代理。
|
|
45
|
+
*/
|
|
46
|
+
installFetchObserver() {
|
|
47
|
+
if (!this.onRequest) return;
|
|
48
|
+
const handler = this.onRequest;
|
|
49
|
+
(0, import_core.addFetchInstrumentationHandler)((data) => {
|
|
50
|
+
const { method, url } = data.fetchData;
|
|
51
|
+
const responseContentType = data.response?.headers?.get?.("content-type") ?? "";
|
|
52
|
+
if (responseContentType.includes("text/event-stream")) return;
|
|
53
|
+
if (!data.endTimestamp) {
|
|
54
|
+
handler({ method, url, statusCode: null, isEnd: false, isError: false });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const statusCode = data.response?.status ?? null;
|
|
58
|
+
const isError = data.error != null;
|
|
59
|
+
handler({ method, url, statusCode, isEnd: true, isError });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 在 Sentry 上报前调用,提取错误信息触发 onError 回调。
|
|
64
|
+
* BrowserOptions.beforeSend 要求 ErrorEvent(Event & { type: undefined }),类型需精确匹配。
|
|
65
|
+
*/
|
|
66
|
+
beforeSend(event, hint) {
|
|
67
|
+
const message = event.exception?.values?.[0]?.value ?? event.message ?? "(unknown)";
|
|
68
|
+
const componentStack = event.contexts?.["react"]?.["componentStack"] ?? void 0;
|
|
69
|
+
const mechanismType = event.exception?.values?.[0]?.mechanism?.type ?? null;
|
|
70
|
+
const stack = hint.originalException instanceof Error ? hint.originalException.stack : void 0;
|
|
71
|
+
this.onError?.({ message, stack, componentStack, mechanismType });
|
|
72
|
+
return event;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 在 Sentry 记录面包屑前调用,提取网络请求信息触发 onNetwork 回调。
|
|
76
|
+
*/
|
|
77
|
+
beforeBreadcrumb(breadcrumb, _hint) {
|
|
78
|
+
if (breadcrumb.type === "http") {
|
|
79
|
+
const data = breadcrumb.data;
|
|
80
|
+
this.onNetwork?.({
|
|
81
|
+
method: data?.method ?? null,
|
|
82
|
+
url: data?.url ?? null,
|
|
83
|
+
statusCode: data?.status_code ?? null
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return breadcrumb;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
SentryCapture
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sentry 事件捕获封装。
|
|
5
|
+
*
|
|
6
|
+
* 提供三类观测能力:
|
|
7
|
+
* - 错误捕获:通过 beforeSend 钩子提取异常信息
|
|
8
|
+
* - 网络面包屑:通过 beforeBreadcrumb 钩子提取 HTTP 请求记录
|
|
9
|
+
* - 请求观测:通过 installFetchObserver 在请求开始/结束时触发回调
|
|
10
|
+
*
|
|
11
|
+
* 典型用法:实例化后将 beforeSend / beforeBreadcrumb 传入 Sentry.init(),
|
|
12
|
+
* 并在 init 完成后调用 installFetchObserver()。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** onError 回调接收的错误信息 */
|
|
16
|
+
interface ErrorCaptureInfo {
|
|
17
|
+
message: string;
|
|
18
|
+
stack?: string;
|
|
19
|
+
/** React 组件调用栈,由 ErrorBoundary 提供 */
|
|
20
|
+
componentStack?: string;
|
|
21
|
+
/** 错误捕获方式,如 'instrument'、'onerror' 等 */
|
|
22
|
+
mechanismType?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** onNetwork 回调接收的 HTTP 面包屑信息 */
|
|
25
|
+
interface NetworkCaptureInfo {
|
|
26
|
+
method: string | null;
|
|
27
|
+
url: string | null;
|
|
28
|
+
statusCode: number | null;
|
|
29
|
+
}
|
|
30
|
+
/** onRequest 回调接收的请求观测信息 */
|
|
31
|
+
interface RequestObserveInfo {
|
|
32
|
+
method: string;
|
|
33
|
+
url: string;
|
|
34
|
+
/** HTTP 状态码,网络层失败(无响应)时为 null */
|
|
35
|
+
statusCode: number | null;
|
|
36
|
+
/** 请求已结束(成功或失败)时为 true,请求开始时为 false */
|
|
37
|
+
isEnd: boolean;
|
|
38
|
+
/** 网络层失败(未收到 HTTP 响应)时为 true */
|
|
39
|
+
isError: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** SentryCapture 构造选项 */
|
|
42
|
+
interface SentryCaptureOptions {
|
|
43
|
+
/** 有错误事件上报时触发 */
|
|
44
|
+
onError?: (info: ErrorCaptureInfo) => void;
|
|
45
|
+
/** Sentry 记录 HTTP 面包屑时触发 */
|
|
46
|
+
onNetwork?: (info: NetworkCaptureInfo) => void;
|
|
47
|
+
/** 每个非 SSE 的 fetch 请求在开始和结束时均会触发 */
|
|
48
|
+
onRequest?: (info: RequestObserveInfo) => void;
|
|
49
|
+
}
|
|
50
|
+
declare class SentryCapture {
|
|
51
|
+
private readonly onError;
|
|
52
|
+
private readonly onNetwork;
|
|
53
|
+
private readonly onRequest;
|
|
54
|
+
constructor({ onError, onNetwork, onRequest }?: SentryCaptureOptions);
|
|
55
|
+
/**
|
|
56
|
+
* 注册 Sentry fetch 监听器,观测所有非 SSE 请求的开始与结束。
|
|
57
|
+
* 在 Sentry.init() 后调用一次,复用 Sentry 已打补丁的 fetch,不会二次代理。
|
|
58
|
+
*/
|
|
59
|
+
installFetchObserver(): void;
|
|
60
|
+
/**
|
|
61
|
+
* 在 Sentry 上报前调用,提取错误信息触发 onError 回调。
|
|
62
|
+
* BrowserOptions.beforeSend 要求 ErrorEvent(Event & { type: undefined }),类型需精确匹配。
|
|
63
|
+
*/
|
|
64
|
+
beforeSend(event: ErrorEvent, hint: EventHint): ErrorEvent;
|
|
65
|
+
/**
|
|
66
|
+
* 在 Sentry 记录面包屑前调用,提取网络请求信息触发 onNetwork 回调。
|
|
67
|
+
*/
|
|
68
|
+
beforeBreadcrumb(breadcrumb: Breadcrumb, _hint?: BreadcrumbHint): Breadcrumb;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type ErrorCaptureInfo, type NetworkCaptureInfo, type RequestObserveInfo, SentryCapture, type SentryCaptureOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sentry 事件捕获封装。
|
|
5
|
+
*
|
|
6
|
+
* 提供三类观测能力:
|
|
7
|
+
* - 错误捕获:通过 beforeSend 钩子提取异常信息
|
|
8
|
+
* - 网络面包屑:通过 beforeBreadcrumb 钩子提取 HTTP 请求记录
|
|
9
|
+
* - 请求观测:通过 installFetchObserver 在请求开始/结束时触发回调
|
|
10
|
+
*
|
|
11
|
+
* 典型用法:实例化后将 beforeSend / beforeBreadcrumb 传入 Sentry.init(),
|
|
12
|
+
* 并在 init 完成后调用 installFetchObserver()。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** onError 回调接收的错误信息 */
|
|
16
|
+
interface ErrorCaptureInfo {
|
|
17
|
+
message: string;
|
|
18
|
+
stack?: string;
|
|
19
|
+
/** React 组件调用栈,由 ErrorBoundary 提供 */
|
|
20
|
+
componentStack?: string;
|
|
21
|
+
/** 错误捕获方式,如 'instrument'、'onerror' 等 */
|
|
22
|
+
mechanismType?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** onNetwork 回调接收的 HTTP 面包屑信息 */
|
|
25
|
+
interface NetworkCaptureInfo {
|
|
26
|
+
method: string | null;
|
|
27
|
+
url: string | null;
|
|
28
|
+
statusCode: number | null;
|
|
29
|
+
}
|
|
30
|
+
/** onRequest 回调接收的请求观测信息 */
|
|
31
|
+
interface RequestObserveInfo {
|
|
32
|
+
method: string;
|
|
33
|
+
url: string;
|
|
34
|
+
/** HTTP 状态码,网络层失败(无响应)时为 null */
|
|
35
|
+
statusCode: number | null;
|
|
36
|
+
/** 请求已结束(成功或失败)时为 true,请求开始时为 false */
|
|
37
|
+
isEnd: boolean;
|
|
38
|
+
/** 网络层失败(未收到 HTTP 响应)时为 true */
|
|
39
|
+
isError: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** SentryCapture 构造选项 */
|
|
42
|
+
interface SentryCaptureOptions {
|
|
43
|
+
/** 有错误事件上报时触发 */
|
|
44
|
+
onError?: (info: ErrorCaptureInfo) => void;
|
|
45
|
+
/** Sentry 记录 HTTP 面包屑时触发 */
|
|
46
|
+
onNetwork?: (info: NetworkCaptureInfo) => void;
|
|
47
|
+
/** 每个非 SSE 的 fetch 请求在开始和结束时均会触发 */
|
|
48
|
+
onRequest?: (info: RequestObserveInfo) => void;
|
|
49
|
+
}
|
|
50
|
+
declare class SentryCapture {
|
|
51
|
+
private readonly onError;
|
|
52
|
+
private readonly onNetwork;
|
|
53
|
+
private readonly onRequest;
|
|
54
|
+
constructor({ onError, onNetwork, onRequest }?: SentryCaptureOptions);
|
|
55
|
+
/**
|
|
56
|
+
* 注册 Sentry fetch 监听器,观测所有非 SSE 请求的开始与结束。
|
|
57
|
+
* 在 Sentry.init() 后调用一次,复用 Sentry 已打补丁的 fetch,不会二次代理。
|
|
58
|
+
*/
|
|
59
|
+
installFetchObserver(): void;
|
|
60
|
+
/**
|
|
61
|
+
* 在 Sentry 上报前调用,提取错误信息触发 onError 回调。
|
|
62
|
+
* BrowserOptions.beforeSend 要求 ErrorEvent(Event & { type: undefined }),类型需精确匹配。
|
|
63
|
+
*/
|
|
64
|
+
beforeSend(event: ErrorEvent, hint: EventHint): ErrorEvent;
|
|
65
|
+
/**
|
|
66
|
+
* 在 Sentry 记录面包屑前调用,提取网络请求信息触发 onNetwork 回调。
|
|
67
|
+
*/
|
|
68
|
+
beforeBreadcrumb(breadcrumb: Breadcrumb, _hint?: BreadcrumbHint): Breadcrumb;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { type ErrorCaptureInfo, type NetworkCaptureInfo, type RequestObserveInfo, SentryCapture, type SentryCaptureOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/capture.ts
|
|
6
|
+
import {
|
|
7
|
+
addFetchInstrumentationHandler
|
|
8
|
+
} from "@sentry/core";
|
|
9
|
+
var SentryCapture = class {
|
|
10
|
+
constructor({ onError, onNetwork, onRequest } = {}) {
|
|
11
|
+
__publicField(this, "onError");
|
|
12
|
+
__publicField(this, "onNetwork");
|
|
13
|
+
__publicField(this, "onRequest");
|
|
14
|
+
this.onError = onError;
|
|
15
|
+
this.onNetwork = onNetwork;
|
|
16
|
+
this.onRequest = onRequest;
|
|
17
|
+
this.beforeSend = this.beforeSend.bind(this);
|
|
18
|
+
this.beforeBreadcrumb = this.beforeBreadcrumb.bind(this);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 注册 Sentry fetch 监听器,观测所有非 SSE 请求的开始与结束。
|
|
22
|
+
* 在 Sentry.init() 后调用一次,复用 Sentry 已打补丁的 fetch,不会二次代理。
|
|
23
|
+
*/
|
|
24
|
+
installFetchObserver() {
|
|
25
|
+
if (!this.onRequest) return;
|
|
26
|
+
const handler = this.onRequest;
|
|
27
|
+
addFetchInstrumentationHandler((data) => {
|
|
28
|
+
const { method, url } = data.fetchData;
|
|
29
|
+
const responseContentType = data.response?.headers?.get?.("content-type") ?? "";
|
|
30
|
+
if (responseContentType.includes("text/event-stream")) return;
|
|
31
|
+
if (!data.endTimestamp) {
|
|
32
|
+
handler({ method, url, statusCode: null, isEnd: false, isError: false });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const statusCode = data.response?.status ?? null;
|
|
36
|
+
const isError = data.error != null;
|
|
37
|
+
handler({ method, url, statusCode, isEnd: true, isError });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 在 Sentry 上报前调用,提取错误信息触发 onError 回调。
|
|
42
|
+
* BrowserOptions.beforeSend 要求 ErrorEvent(Event & { type: undefined }),类型需精确匹配。
|
|
43
|
+
*/
|
|
44
|
+
beforeSend(event, hint) {
|
|
45
|
+
const message = event.exception?.values?.[0]?.value ?? event.message ?? "(unknown)";
|
|
46
|
+
const componentStack = event.contexts?.["react"]?.["componentStack"] ?? void 0;
|
|
47
|
+
const mechanismType = event.exception?.values?.[0]?.mechanism?.type ?? null;
|
|
48
|
+
const stack = hint.originalException instanceof Error ? hint.originalException.stack : void 0;
|
|
49
|
+
this.onError?.({ message, stack, componentStack, mechanismType });
|
|
50
|
+
return event;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 在 Sentry 记录面包屑前调用,提取网络请求信息触发 onNetwork 回调。
|
|
54
|
+
*/
|
|
55
|
+
beforeBreadcrumb(breadcrumb, _hint) {
|
|
56
|
+
if (breadcrumb.type === "http") {
|
|
57
|
+
const data = breadcrumb.data;
|
|
58
|
+
this.onNetwork?.({
|
|
59
|
+
method: data?.method ?? null,
|
|
60
|
+
url: data?.url ?? null,
|
|
61
|
+
statusCode: data?.status_code ?? null
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return breadcrumb;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
SentryCapture
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/stubs/sentry-react-stub.ts
|
|
6
|
+
import * as RealSentry from "@sentry/react";
|
|
7
|
+
|
|
8
|
+
// src/capture.ts
|
|
9
|
+
import {
|
|
10
|
+
addFetchInstrumentationHandler
|
|
11
|
+
} from "@sentry/core";
|
|
12
|
+
var SentryCapture = class {
|
|
13
|
+
constructor({ onError, onNetwork, onRequest } = {}) {
|
|
14
|
+
__publicField(this, "onError");
|
|
15
|
+
__publicField(this, "onNetwork");
|
|
16
|
+
__publicField(this, "onRequest");
|
|
17
|
+
this.onError = onError;
|
|
18
|
+
this.onNetwork = onNetwork;
|
|
19
|
+
this.onRequest = onRequest;
|
|
20
|
+
this.beforeSend = this.beforeSend.bind(this);
|
|
21
|
+
this.beforeBreadcrumb = this.beforeBreadcrumb.bind(this);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 注册 Sentry fetch 监听器,观测所有非 SSE 请求的开始与结束。
|
|
25
|
+
* 在 Sentry.init() 后调用一次,复用 Sentry 已打补丁的 fetch,不会二次代理。
|
|
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
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 在 Sentry 上报前调用,提取错误信息触发 onError 回调。
|
|
45
|
+
* BrowserOptions.beforeSend 要求 ErrorEvent(Event & { type: undefined }),类型需精确匹配。
|
|
46
|
+
*/
|
|
47
|
+
beforeSend(event, hint) {
|
|
48
|
+
const message = event.exception?.values?.[0]?.value ?? event.message ?? "(unknown)";
|
|
49
|
+
const componentStack = event.contexts?.["react"]?.["componentStack"] ?? void 0;
|
|
50
|
+
const mechanismType = event.exception?.values?.[0]?.mechanism?.type ?? null;
|
|
51
|
+
const stack = hint.originalException instanceof Error ? hint.originalException.stack : void 0;
|
|
52
|
+
this.onError?.({ message, stack, componentStack, mechanismType });
|
|
53
|
+
return event;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 在 Sentry 记录面包屑前调用,提取网络请求信息触发 onNetwork 回调。
|
|
57
|
+
*/
|
|
58
|
+
beforeBreadcrumb(breadcrumb, _hint) {
|
|
59
|
+
if (breadcrumb.type === "http") {
|
|
60
|
+
const data = breadcrumb.data;
|
|
61
|
+
this.onNetwork?.({
|
|
62
|
+
method: data?.method ?? null,
|
|
63
|
+
url: data?.url ?? null,
|
|
64
|
+
statusCode: data?.status_code ?? null
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return breadcrumb;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/stubs/sentry-react-stub.ts
|
|
72
|
+
export * from "@sentry/react";
|
|
73
|
+
var STUB_DSN = "https://stubPublicKey@o0.ingest.sentry.io/0";
|
|
74
|
+
var OVERRIDE_DSN = typeof process !== "undefined" && process.env["SENTRY_OVERRIDE_DSN"] ? process.env["SENTRY_OVERRIDE_DSN"] : STUB_DSN;
|
|
75
|
+
var _capture = new SentryCapture({
|
|
76
|
+
onError(info) {
|
|
77
|
+
console.warn("[SentryStub] \u6355\u83B7\u5230\u9519\u8BEF\uFF1A", info.message);
|
|
78
|
+
if (info.stack) {
|
|
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
|
+
});
|
|
109
|
+
var init2 = (options) => {
|
|
110
|
+
const upstreamBeforeSend = options?.beforeSend;
|
|
111
|
+
const upstreamBeforeBreadcrumb = options?.beforeBreadcrumb;
|
|
112
|
+
const result = RealSentry.init({
|
|
113
|
+
...options,
|
|
114
|
+
dsn: OVERRIDE_DSN,
|
|
115
|
+
beforeSend(event, hint) {
|
|
116
|
+
const processed = _capture.beforeSend(event, hint);
|
|
117
|
+
return upstreamBeforeSend ? upstreamBeforeSend(processed, hint) : processed;
|
|
118
|
+
},
|
|
119
|
+
beforeBreadcrumb(breadcrumb, hint) {
|
|
120
|
+
const processed = _capture.beforeBreadcrumb(breadcrumb, hint);
|
|
121
|
+
return upstreamBeforeBreadcrumb ? upstreamBeforeBreadcrumb(processed, hint) : processed;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
_capture.installFetchObserver();
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
export {
|
|
128
|
+
init2 as init
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=sentry-react-stub.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/vite/index.ts
|
|
31
|
+
var vite_exports = {};
|
|
32
|
+
__export(vite_exports, {
|
|
33
|
+
withSentryStub: () => withSentryStub
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(vite_exports);
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
41
|
+
// src/vite/withSentryStub.ts
|
|
42
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
43
|
+
var import_node_url = require("url");
|
|
44
|
+
var SENTRY_MODULE = "@sentry/react";
|
|
45
|
+
var _dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
46
|
+
var STUB_PATH = import_node_path.default.resolve(_dirname, "../stubs/sentry-react-stub.js");
|
|
47
|
+
function withSentryStub() {
|
|
48
|
+
return {
|
|
49
|
+
name: "miaoda-devkit:sentry-stub",
|
|
50
|
+
enforce: "pre",
|
|
51
|
+
apply: "serve",
|
|
52
|
+
resolveId(id, importer) {
|
|
53
|
+
if (importer && importer.includes("sentry-react-stub")) return null;
|
|
54
|
+
if (id === SENTRY_MODULE) {
|
|
55
|
+
return STUB_PATH;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
withSentryStub
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite 插件:在 `vite dev` 期间将 @sentry/react 重定向到 stub。
|
|
5
|
+
*
|
|
6
|
+
* - apply: 'serve' → 仅在开发服务器模式下生效
|
|
7
|
+
* - 生产构建时 @sentry/react 正常解析,使用真实 DSN 上报
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare function withSentryStub(): Plugin;
|
|
11
|
+
|
|
12
|
+
export { withSentryStub };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite 插件:在 `vite dev` 期间将 @sentry/react 重定向到 stub。
|
|
5
|
+
*
|
|
6
|
+
* - apply: 'serve' → 仅在开发服务器模式下生效
|
|
7
|
+
* - 生产构建时 @sentry/react 正常解析,使用真实 DSN 上报
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare function withSentryStub(): Plugin;
|
|
11
|
+
|
|
12
|
+
export { withSentryStub };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/vite/withSentryStub.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
var SENTRY_MODULE = "@sentry/react";
|
|
5
|
+
var _dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
var STUB_PATH = path.resolve(_dirname, "../stubs/sentry-react-stub.js");
|
|
7
|
+
function withSentryStub() {
|
|
8
|
+
return {
|
|
9
|
+
name: "miaoda-devkit:sentry-stub",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
apply: "serve",
|
|
12
|
+
resolveId(id, importer) {
|
|
13
|
+
if (importer && importer.includes("sentry-react-stub")) return null;
|
|
14
|
+
if (id === SENTRY_MODULE) {
|
|
15
|
+
return STUB_PATH;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
withSentryStub
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "miaoda-react-devkit",
|
|
3
|
+
"version": "0.1.1-beta.0",
|
|
4
|
+
"description": "React admin 应用开发工具集",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./vite": {
|
|
17
|
+
"types": "./dist/vite/index.d.ts",
|
|
18
|
+
"import": "./dist/vite/index.js",
|
|
19
|
+
"require": "./dist/vite/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./tsconfig-base": "./tsconfig-base.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"tsconfig-base.json",
|
|
26
|
+
"!dist/**/*.map"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@sentry/core": ">=8.0.0",
|
|
30
|
+
"@sentry/react": ">=8.0.0",
|
|
31
|
+
"vite": ">=5.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependenciesMeta": {
|
|
34
|
+
"@sentry/core": {
|
|
35
|
+
"optional": true
|
|
36
|
+
},
|
|
37
|
+
"@sentry/react": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"vite": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"registry": "https://registry.npmjs.org/",
|
|
46
|
+
"access": "public"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"useDefineForClassFields": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noUncheckedSideEffectImports": true
|
|
19
|
+
}
|
|
20
|
+
}
|