miaoda-react-devkit 0.1.1-beta.2 → 0.1.1-beta.4

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.
@@ -0,0 +1,106 @@
1
+ // cloud/vite.config.ts
2
+ import * as vite from "vite";
3
+ import { loadConfigFromFile, mergeConfig } from "vite";
4
+ import { withSentryStub, hmrTogglePlugin } from "../dist/vite/index.js";
5
+ import {
6
+ makeTagger,
7
+ injectedGuiListenerPlugin,
8
+ injectOnErrorPlugin,
9
+ monitorPlugin,
10
+ fontsCodePlugin,
11
+ mdClickPlugin,
12
+ extractRouterPlugin,
13
+ patchSupabasePlugins
14
+ } from "miaoda-sc-plugin";
15
+ import path from "path";
16
+ import fs from "fs";
17
+ var projectRoot = process.cwd();
18
+ var appType = process.env.DEVKIT_APP_TYPE ?? "freestyle";
19
+ var cdnHost = process.env.DEVKIT_CDN_HOST ?? "resource-static.cdn.bcebos.com";
20
+ var env = process.env.DEVKIT_ENV ?? "";
21
+ var sentryDsn = process.env.DEVKIT_SENTRY_DSN ?? "";
22
+ var miaodaEnv = process.env.DEVKIT_MIAODA_ENV ?? "";
23
+ var appId = process.env.DEVKIT_APP_ID ?? "";
24
+ var isOnline = env === "online";
25
+ var loaded = await loadConfigFromFile(
26
+ { command: "serve", mode: "development" },
27
+ path.join(projectRoot, "vite.config.ts"),
28
+ projectRoot
29
+ );
30
+ var projectConfig = loaded?.config ?? {};
31
+ var configPath = path.join(projectRoot, "vite.config.ts");
32
+ if (!loaded) {
33
+ throw new Error(
34
+ `[miaoda-devkit] \u627E\u4E0D\u5230\u9879\u76EE vite \u914D\u7F6E\uFF1A${configPath}
35
+ \u8BF7\u786E\u8BA4\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u5B58\u5728 vite.config.ts`
36
+ );
37
+ }
38
+ var plugins = (projectConfig.plugins ?? []).flat(Infinity).filter((p) => !!p);
39
+ var hasReact = plugins.some((p) => p.name === "vite:react-babel" || p.name === "vite:react-swc");
40
+ if (!hasReact) {
41
+ throw new Error(
42
+ `[miaoda-devkit] \u9879\u76EE vite \u914D\u7F6E\u7F3A\u5C11 React \u63D2\u4EF6\u3002
43
+ \u8BF7\u5728 ${configPath} \u7684 plugins \u4E2D\u6DFB\u52A0 react()\uFF08@vitejs/plugin-react \u6216 @vitejs/plugin-react-swc\uFF09`
44
+ );
45
+ }
46
+ var possibleEntries = ["./src/main.tsx", "./src/main.ts", "./src/index.tsx", "./src/index.ts"];
47
+ var warmupFiles = possibleEntries.filter((e) => fs.existsSync(path.join(projectRoot, e)));
48
+ var SENTRY_IMPORT_RE = /from\s+['"]@sentry\/react['"]/;
49
+ function entryHasSentryImport(root, entries) {
50
+ for (const entry of entries) {
51
+ const fullPath = path.join(root, entry);
52
+ if (!fs.existsSync(fullPath)) {
53
+ continue;
54
+ }
55
+ try {
56
+ if (SENTRY_IMPORT_RE.test(fs.readFileSync(fullPath, "utf-8"))) {
57
+ return true;
58
+ }
59
+ } catch {
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+ var hasSentryReact = entryHasSentryImport(projectRoot, possibleEntries);
65
+ var viteVersionInfo = {
66
+ version: vite.version,
67
+ rollupVersion: vite.rollupVersion ?? null,
68
+ rolldownVersion: vite.rolldownVersion ?? null,
69
+ isRolldownVite: "rolldownVersion" in vite
70
+ };
71
+ var injectedGuiUrl = `https://${cdnHost}/common/v2/${isOnline ? "" : `${env}/`}injected.js`;
72
+ var cloudPlugins = [
73
+ ...hasSentryReact ? [withSentryStub()] : [monitorPlugin({
74
+ scriptSrc: `https://${cdnHost}/sentry/browser.sentry.min.js`,
75
+ sentryDsn,
76
+ environment: miaodaEnv,
77
+ appId
78
+ })],
79
+ // web 类型需要 DOM 节点打标(GUI使用)
80
+ ...appType === "web" ? [
81
+ makeTagger(),
82
+ mdClickPlugin({ appType }),
83
+ fontsCodePlugin(),
84
+ injectedGuiListenerPlugin({ path: injectedGuiUrl })
85
+ ] : [],
86
+ injectedGuiListenerPlugin({ path: injectedGuiUrl }),
87
+ injectOnErrorPlugin(),
88
+ hmrTogglePlugin(),
89
+ extractRouterPlugin(),
90
+ patchSupabasePlugins()
91
+ ];
92
+ var cloudConfig = {
93
+ define: {
94
+ __VITE_INFO__: JSON.stringify(viteVersionInfo)
95
+ },
96
+ // 将缓存目录固定到项目本地,避免在 /workspace/node_modules/ 下创建
97
+ cacheDir: path.resolve(projectRoot, "node_modules/.vite"),
98
+ server: {
99
+ warmup: warmupFiles.length > 0 ? { clientFiles: warmupFiles } : {}
100
+ },
101
+ plugins: cloudPlugins
102
+ };
103
+ var vite_config_default = mergeConfig(projectConfig, cloudConfig);
104
+ export {
105
+ vite_config_default as default
106
+ };
package/dist/index.cjs CHANGED
@@ -240,12 +240,15 @@ function createNetworkObserver(opts, subscribers) {
240
240
  const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
241
241
  const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
242
242
  const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
243
+ const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
243
244
  function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
244
245
  if (statusCode == null) return;
245
246
  if (!isPgRestRequest(url, pgRestPatterns)) return;
246
247
  const pgRestError = parsePgRestErrorBody(responseBody);
247
248
  if (!pgRestError) return;
248
249
  if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
250
+ const allBreadcrumbs = (0, import_core3.getIsolationScope)().getScopeData().breadcrumbs;
251
+ const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
249
252
  const info = {
250
253
  type: requestType,
251
254
  method,
@@ -253,7 +256,8 @@ function createNetworkObserver(opts, subscribers) {
253
256
  statusCode,
254
257
  pgRestError,
255
258
  requestBody,
256
- responseBody
259
+ responseBody,
260
+ precedingBreadcrumbs
257
261
  };
258
262
  for (const sub of subscribers) sub.onPgRestWhitelistError(info);
259
263
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
1
+ import { Breadcrumb, ErrorEvent, EventHint, BreadcrumbHint } from '@sentry/react';
2
2
 
3
3
  /** PostgREST 响应检测与错误体解析。 */
4
4
  /**
@@ -85,6 +85,12 @@ interface IPgRestWhitelistErrorInfo {
85
85
  requestBody: string | undefined;
86
86
  /** 原始响应体文本 */
87
87
  responseBody: string;
88
+ /**
89
+ * 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。
90
+ * 包含导航(navigation)、点击(ui.click)、历史网络请求(fetch/xhr)、控制台日志等。
91
+ * 取自 Sentry isolation scope,时序上早于当前这条 pgrest 请求。
92
+ */
93
+ precedingBreadcrumbs: Breadcrumb[];
88
94
  }
89
95
  /** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
90
96
  interface ISentryCaptureOptions {
@@ -114,6 +120,12 @@ interface ISentryCaptureOptions {
114
120
  * '23505'(唯一键冲突)、'23503'(外键约束失败)
115
121
  */
116
122
  pgRestWhitelistCodes?: string[];
123
+ /**
124
+ * `onPgRestWhitelistError` 回调中 `precedingBreadcrumbs` 的最大条数(可选)。
125
+ * 取 scope 中最新的 N 条,超出部分(更早的操作)被丢弃。
126
+ * 未配置时取全部(受 Sentry `maxBreadcrumbs` 上限约束,默认最多 100 条)。
127
+ */
128
+ precedingBreadcrumbsLimit?: number;
117
129
  }
118
130
 
119
131
  /** 捕获事件订阅者接口与消息类型定义。 */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
1
+ import { Breadcrumb, ErrorEvent, EventHint, BreadcrumbHint } from '@sentry/react';
2
2
 
3
3
  /** PostgREST 响应检测与错误体解析。 */
4
4
  /**
@@ -85,6 +85,12 @@ interface IPgRestWhitelistErrorInfo {
85
85
  requestBody: string | undefined;
86
86
  /** 原始响应体文本 */
87
87
  responseBody: string;
88
+ /**
89
+ * 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。
90
+ * 包含导航(navigation)、点击(ui.click)、历史网络请求(fetch/xhr)、控制台日志等。
91
+ * 取自 Sentry isolation scope,时序上早于当前这条 pgrest 请求。
92
+ */
93
+ precedingBreadcrumbs: Breadcrumb[];
88
94
  }
89
95
  /** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
90
96
  interface ISentryCaptureOptions {
@@ -114,6 +120,12 @@ interface ISentryCaptureOptions {
114
120
  * '23505'(唯一键冲突)、'23503'(外键约束失败)
115
121
  */
116
122
  pgRestWhitelistCodes?: string[];
123
+ /**
124
+ * `onPgRestWhitelistError` 回调中 `precedingBreadcrumbs` 的最大条数(可选)。
125
+ * 取 scope 中最新的 N 条,超出部分(更早的操作)被丢弃。
126
+ * 未配置时取全部(受 Sentry `maxBreadcrumbs` 上限约束,默认最多 100 条)。
127
+ */
128
+ precedingBreadcrumbsLimit?: number;
117
129
  }
118
130
 
119
131
  /** 捕获事件订阅者接口与消息类型定义。 */
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ function createConsoleObserver(keywords, subscribers) {
46
46
  }
47
47
 
48
48
  // src/capture/network.ts
49
- import { getClient } from "@sentry/core";
49
+ import { getClient, getIsolationScope } from "@sentry/core";
50
50
 
51
51
  // ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
52
52
  var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
@@ -210,12 +210,15 @@ function createNetworkObserver(opts, subscribers) {
210
210
  const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
211
211
  const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
212
212
  const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
213
+ const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
213
214
  function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
214
215
  if (statusCode == null) return;
215
216
  if (!isPgRestRequest(url, pgRestPatterns)) return;
216
217
  const pgRestError = parsePgRestErrorBody(responseBody);
217
218
  if (!pgRestError) return;
218
219
  if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
220
+ const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
221
+ const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
219
222
  const info = {
220
223
  type: requestType,
221
224
  method,
@@ -223,7 +226,8 @@ function createNetworkObserver(opts, subscribers) {
223
226
  statusCode,
224
227
  pgRestError,
225
228
  requestBody,
226
- responseBody
229
+ responseBody,
230
+ precedingBreadcrumbs
227
231
  };
228
232
  for (const sub of subscribers) sub.onPgRestWhitelistError(info);
229
233
  }
@@ -49,7 +49,7 @@ function createConsoleObserver(keywords, subscribers) {
49
49
  }
50
50
 
51
51
  // src/capture/network.ts
52
- import { getClient } from "@sentry/core";
52
+ import { getClient, getIsolationScope } from "@sentry/core";
53
53
 
54
54
  // ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
55
55
  var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
@@ -213,12 +213,15 @@ function createNetworkObserver(opts, subscribers) {
213
213
  const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
214
214
  const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
215
215
  const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
216
+ const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
216
217
  function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
217
218
  if (statusCode == null) return;
218
219
  if (!isPgRestRequest(url, pgRestPatterns)) return;
219
220
  const pgRestError = parsePgRestErrorBody(responseBody);
220
221
  if (!pgRestError) return;
221
222
  if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
223
+ const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
224
+ const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
222
225
  const info = {
223
226
  type: requestType,
224
227
  method,
@@ -226,7 +229,8 @@ function createNetworkObserver(opts, subscribers) {
226
229
  statusCode,
227
230
  pgRestError,
228
231
  requestBody,
229
- responseBody
232
+ responseBody,
233
+ precedingBreadcrumbs
230
234
  };
231
235
  for (const sub of subscribers) sub.onPgRestWhitelistError(info);
232
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-react-devkit",
3
- "version": "0.1.1-beta.2",
3
+ "version": "0.1.1-beta.4",
4
4
  "description": "React admin 应用开发工具集",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,6 +18,7 @@
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": [