miaoda-react-devkit 0.1.1-beta.0 → 0.1.1-beta.10
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/cloud/vite.config.js +118 -0
- package/dist/index.cjs +622 -47
- package/dist/index.d.cts +305 -41
- package/dist/index.d.ts +305 -41
- package/dist/index.js +613 -49
- package/dist/stubs/sentry-react-noop-stub.js +78 -0
- package/dist/stubs/sentry-react-stub.js +547 -86
- package/dist/vite/index.cjs +80 -1
- package/dist/vite/index.d.cts +15 -1
- package/dist/vite/index.d.ts +15 -1
- package/dist/vite/index.js +78 -1
- package/package.json +8 -1
- package/README.md +0 -41
package/dist/vite/index.cjs
CHANGED
|
@@ -30,6 +30,8 @@ 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,
|
|
34
|
+
withSentryBuild: () => withSentryBuild,
|
|
33
35
|
withSentryStub: () => withSentryStub
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(vite_exports);
|
|
@@ -58,8 +60,85 @@ function withSentryStub() {
|
|
|
58
60
|
}
|
|
59
61
|
};
|
|
60
62
|
}
|
|
63
|
+
|
|
64
|
+
// src/vite/withSentryBuild.ts
|
|
65
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
66
|
+
var import_node_url2 = require("url");
|
|
67
|
+
var SENTRY_MODULE2 = "@sentry/react";
|
|
68
|
+
var _dirname2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
|
|
69
|
+
var STUB_PATH2 = import_node_path2.default.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
|
|
70
|
+
function withSentryBuild() {
|
|
71
|
+
return {
|
|
72
|
+
name: "miaoda-devkit:sentry-build",
|
|
73
|
+
enforce: "pre",
|
|
74
|
+
apply: "build",
|
|
75
|
+
resolveId(id) {
|
|
76
|
+
if (id === SENTRY_MODULE2) return STUB_PATH2;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/vite/hmrTogglePlugin.ts
|
|
83
|
+
function hmrTogglePlugin() {
|
|
84
|
+
return {
|
|
85
|
+
name: "miaoda-devkit:hmr-toggle",
|
|
86
|
+
configureServer(server) {
|
|
87
|
+
let hmrEnabled = true;
|
|
88
|
+
const origSend = server.ws.send.bind(server.ws);
|
|
89
|
+
server.ws.send = (payload) => {
|
|
90
|
+
if (hmrEnabled) {
|
|
91
|
+
origSend(payload);
|
|
92
|
+
} else {
|
|
93
|
+
console.log("[HMR disabled] skipped payload:", payload.type);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_off", (_req, res) => {
|
|
97
|
+
hmrEnabled = false;
|
|
98
|
+
res.setHeader("Content-Type", "application/json");
|
|
99
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR disabled" }));
|
|
100
|
+
});
|
|
101
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_on", (_req, res) => {
|
|
102
|
+
hmrEnabled = true;
|
|
103
|
+
res.setHeader("Content-Type", "application/json");
|
|
104
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR enabled" }));
|
|
105
|
+
});
|
|
106
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_reload", (_req, res) => {
|
|
107
|
+
if (hmrEnabled) {
|
|
108
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
109
|
+
}
|
|
110
|
+
res.setHeader("Content-Type", "application/json");
|
|
111
|
+
res.end(JSON.stringify({ status: 0, msg: "Manual full reload triggered" }));
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
load(id) {
|
|
115
|
+
if (id === "virtual:after-update") {
|
|
116
|
+
return `
|
|
117
|
+
if (import.meta.hot) {
|
|
118
|
+
import.meta.hot.on('vite:afterUpdate', () => {
|
|
119
|
+
window.postMessage({ type: 'editor-update' }, '*');
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
transformIndexHtml(html) {
|
|
126
|
+
return {
|
|
127
|
+
html,
|
|
128
|
+
tags: [
|
|
129
|
+
{
|
|
130
|
+
tag: "script",
|
|
131
|
+
attrs: { type: "module", src: "/@id/virtual:after-update" },
|
|
132
|
+
injectTo: "body"
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
61
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
140
|
0 && (module.exports = {
|
|
141
|
+
hmrTogglePlugin,
|
|
142
|
+
withSentryBuild,
|
|
63
143
|
withSentryStub
|
|
64
144
|
});
|
|
65
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/vite/index.d.cts
CHANGED
|
@@ -9,4 +9,18 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
declare function withSentryBuild(): Plugin;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 云端 dev server 专用:HMR 开关 + 手动 reload 控制接口。
|
|
16
|
+
*
|
|
17
|
+
* 暴露三个内部 HTTP 接口:
|
|
18
|
+
* POST /innerapi/v1/sourcecode/__hmr_off — 暂停 HMR 推送
|
|
19
|
+
* POST /innerapi/v1/sourcecode/__hmr_on — 恢复 HMR 推送
|
|
20
|
+
* POST /innerapi/v1/sourcecode/__hmr_reload — 触发一次全页 full-reload
|
|
21
|
+
*
|
|
22
|
+
* 同时注入 virtual:after-update 模块,使 vite:afterUpdate 事件可被宿主页面监听。
|
|
23
|
+
*/
|
|
24
|
+
declare function hmrTogglePlugin(): Plugin;
|
|
25
|
+
|
|
26
|
+
export { hmrTogglePlugin, withSentryBuild, withSentryStub };
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -9,4 +9,18 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
declare function withSentryBuild(): Plugin;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 云端 dev server 专用:HMR 开关 + 手动 reload 控制接口。
|
|
16
|
+
*
|
|
17
|
+
* 暴露三个内部 HTTP 接口:
|
|
18
|
+
* POST /innerapi/v1/sourcecode/__hmr_off — 暂停 HMR 推送
|
|
19
|
+
* POST /innerapi/v1/sourcecode/__hmr_on — 恢复 HMR 推送
|
|
20
|
+
* POST /innerapi/v1/sourcecode/__hmr_reload — 触发一次全页 full-reload
|
|
21
|
+
*
|
|
22
|
+
* 同时注入 virtual:after-update 模块,使 vite:afterUpdate 事件可被宿主页面监听。
|
|
23
|
+
*/
|
|
24
|
+
declare function hmrTogglePlugin(): Plugin;
|
|
25
|
+
|
|
26
|
+
export { hmrTogglePlugin, withSentryBuild, withSentryStub };
|
package/dist/vite/index.js
CHANGED
|
@@ -18,7 +18,84 @@ function withSentryStub() {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
// src/vite/withSentryBuild.ts
|
|
23
|
+
import path2 from "path";
|
|
24
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
25
|
+
var SENTRY_MODULE2 = "@sentry/react";
|
|
26
|
+
var _dirname2 = path2.dirname(fileURLToPath2(import.meta.url));
|
|
27
|
+
var STUB_PATH2 = path2.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
|
|
28
|
+
function withSentryBuild() {
|
|
29
|
+
return {
|
|
30
|
+
name: "miaoda-devkit:sentry-build",
|
|
31
|
+
enforce: "pre",
|
|
32
|
+
apply: "build",
|
|
33
|
+
resolveId(id) {
|
|
34
|
+
if (id === SENTRY_MODULE2) return STUB_PATH2;
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/vite/hmrTogglePlugin.ts
|
|
41
|
+
function hmrTogglePlugin() {
|
|
42
|
+
return {
|
|
43
|
+
name: "miaoda-devkit:hmr-toggle",
|
|
44
|
+
configureServer(server) {
|
|
45
|
+
let hmrEnabled = true;
|
|
46
|
+
const origSend = server.ws.send.bind(server.ws);
|
|
47
|
+
server.ws.send = (payload) => {
|
|
48
|
+
if (hmrEnabled) {
|
|
49
|
+
origSend(payload);
|
|
50
|
+
} else {
|
|
51
|
+
console.log("[HMR disabled] skipped payload:", payload.type);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_off", (_req, res) => {
|
|
55
|
+
hmrEnabled = false;
|
|
56
|
+
res.setHeader("Content-Type", "application/json");
|
|
57
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR disabled" }));
|
|
58
|
+
});
|
|
59
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_on", (_req, res) => {
|
|
60
|
+
hmrEnabled = true;
|
|
61
|
+
res.setHeader("Content-Type", "application/json");
|
|
62
|
+
res.end(JSON.stringify({ status: 0, msg: "HMR enabled" }));
|
|
63
|
+
});
|
|
64
|
+
server.middlewares.use("/innerapi/v1/sourcecode/__hmr_reload", (_req, res) => {
|
|
65
|
+
if (hmrEnabled) {
|
|
66
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
67
|
+
}
|
|
68
|
+
res.setHeader("Content-Type", "application/json");
|
|
69
|
+
res.end(JSON.stringify({ status: 0, msg: "Manual full reload triggered" }));
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
load(id) {
|
|
73
|
+
if (id === "virtual:after-update") {
|
|
74
|
+
return `
|
|
75
|
+
if (import.meta.hot) {
|
|
76
|
+
import.meta.hot.on('vite:afterUpdate', () => {
|
|
77
|
+
window.postMessage({ type: 'editor-update' }, '*');
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
transformIndexHtml(html) {
|
|
84
|
+
return {
|
|
85
|
+
html,
|
|
86
|
+
tags: [
|
|
87
|
+
{
|
|
88
|
+
tag: "script",
|
|
89
|
+
attrs: { type: "module", src: "/@id/virtual:after-update" },
|
|
90
|
+
injectTo: "body"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
21
97
|
export {
|
|
98
|
+
hmrTogglePlugin,
|
|
99
|
+
withSentryBuild,
|
|
22
100
|
withSentryStub
|
|
23
101
|
};
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miaoda-react-devkit",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.10",
|
|
4
4
|
"description": "React admin 应用开发工具集",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,16 +18,20 @@
|
|
|
18
18
|
"import": "./dist/vite/index.js",
|
|
19
19
|
"require": "./dist/vite/index.cjs"
|
|
20
20
|
},
|
|
21
|
+
"./cloud/vite.config": "./cloud/vite.config.js",
|
|
21
22
|
"./tsconfig-base": "./tsconfig-base.json"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
26
|
+
"cloud",
|
|
27
|
+
"!cloud/**/*.ts",
|
|
25
28
|
"tsconfig-base.json",
|
|
26
29
|
"!dist/**/*.map"
|
|
27
30
|
],
|
|
28
31
|
"peerDependencies": {
|
|
29
32
|
"@sentry/core": ">=8.0.0",
|
|
30
33
|
"@sentry/react": ">=8.0.0",
|
|
34
|
+
"miaoda-sc-plugin": ">=1.0.0",
|
|
31
35
|
"vite": ">=5.0.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependenciesMeta": {
|
|
@@ -37,6 +41,9 @@
|
|
|
37
41
|
"@sentry/react": {
|
|
38
42
|
"optional": true
|
|
39
43
|
},
|
|
44
|
+
"miaoda-sc-plugin": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
40
47
|
"vite": {
|
|
41
48
|
"optional": true
|
|
42
49
|
}
|
package/README.md
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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`。
|