miaoda-react-devkit 0.1.1-beta.15 → 0.1.1-beta.17

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.
@@ -1,7 +1,24 @@
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
+
1
5
  // src/stubs/sentry-react-noop-stub.ts
6
+ import { Component, createElement, isValidElement } from "react";
7
+ var INITIAL_ERROR_BOUNDARY_STATE = {
8
+ error: null,
9
+ componentStack: "",
10
+ hasError: false
11
+ };
2
12
  var init = (_options) => {
3
13
  };
14
+ var configureStubSubscribers = (_subscribers) => {
15
+ };
16
+ var getDefaultIntegrations = (_options) => [];
4
17
  var browserTracingIntegration = () => ({});
18
+ var breadcrumbsIntegration = (_options) => ({});
19
+ var httpContextIntegration = (_options) => ({});
20
+ var linkedErrorsIntegration = (_options) => ({});
21
+ var dedupeIntegration = (_options) => ({});
5
22
  var captureException = (_err) => "";
6
23
  var captureMessage = (_msg) => "";
7
24
  var captureEvent = (_event) => "";
@@ -19,26 +36,68 @@ var setExtra = (_key, _value) => {
19
36
  };
20
37
  var setExtras = (_extras) => {
21
38
  };
22
- var withScope = (cb) => {
23
- cb({});
24
- };
25
- var withIsolationScope = (cb) => {
26
- cb({});
27
- };
28
- var startSpan = (_opts, cb) => cb();
29
39
  var getClient = () => void 0;
30
40
  var flush = () => Promise.resolve(true);
31
41
  var close = () => Promise.resolve(true);
32
42
  var lastEventId = () => void 0;
33
43
  var SDK_VERSION = "0.0.0-stub";
34
- var ErrorBoundary = ({ children }) => children ?? null;
35
- var withErrorBoundary = (Component) => Component;
36
- var withProfiler = (Component) => Component;
44
+ var ErrorBoundary = class extends Component {
45
+ constructor() {
46
+ super(...arguments);
47
+ __publicField(this, "state", INITIAL_ERROR_BOUNDARY_STATE);
48
+ }
49
+ static getDerivedStateFromError(error) {
50
+ return { error, componentStack: "", hasError: true };
51
+ }
52
+ componentDidCatch(error, errorInfo) {
53
+ const componentStack = errorInfo.componentStack ?? "";
54
+ this.setState({ componentStack });
55
+ this.props.onError?.(error, componentStack, "");
56
+ }
57
+ componentDidMount() {
58
+ this.props.onMount?.();
59
+ }
60
+ componentWillUnmount() {
61
+ if (this.state.hasError) {
62
+ this.props.onUnmount?.(this.state.error, this.state.componentStack, "");
63
+ } else {
64
+ this.props.onUnmount?.(null, null, null);
65
+ }
66
+ }
67
+ resetErrorBoundary() {
68
+ if (this.state.hasError) {
69
+ this.props.onReset?.(this.state.error, this.state.componentStack, "");
70
+ }
71
+ this.setState(INITIAL_ERROR_BOUNDARY_STATE);
72
+ }
73
+ render() {
74
+ const { children, fallback } = this.props;
75
+ if (!this.state.hasError) return typeof children === "function" ? children() : children ?? null;
76
+ const fallbackElement = typeof fallback === "function" ? createElement(fallback, {
77
+ error: this.state.error,
78
+ componentStack: this.state.componentStack,
79
+ eventId: "",
80
+ resetError: () => this.resetErrorBoundary()
81
+ }) : fallback;
82
+ return isValidElement(fallbackElement) ? fallbackElement : null;
83
+ }
84
+ };
85
+ var withErrorBoundary = (WrappedComponent, errorBoundaryOptions) => {
86
+ const Wrapped = (props) => createElement(
87
+ ErrorBoundary,
88
+ errorBoundaryOptions,
89
+ createElement(WrappedComponent, props)
90
+ );
91
+ Object.assign(Wrapped, WrappedComponent);
92
+ Wrapped.displayName = `errorBoundary(${WrappedComponent.displayName || WrappedComponent.name || "unknown"})`;
93
+ return Wrapped;
94
+ };
95
+ var withProfiler = (Component2) => Component2;
37
96
  var useProfiler = (_name) => {
38
97
  };
39
98
  var Profiler = ({ children }) => children ?? null;
40
- var withSentryRouting = (Component) => Component;
41
- var withSentryReactRouterV6Routing = (Component) => Component;
99
+ var withSentryRouting = (Component2) => Component2;
100
+ var withSentryReactRouterV6Routing = (Component2) => Component2;
42
101
  var wrapCreateBrowserRouterV6 = (fn) => fn;
43
102
  var wrapCreateBrowserRouterV7 = (fn) => fn;
44
103
  var reactRouterV6BrowserTracingIntegration = () => ({});
@@ -48,15 +107,21 @@ export {
48
107
  Profiler,
49
108
  SDK_VERSION,
50
109
  addBreadcrumb,
110
+ breadcrumbsIntegration,
51
111
  browserTracingIntegration,
52
112
  captureEvent,
53
113
  captureException,
54
114
  captureMessage,
55
115
  close,
116
+ configureStubSubscribers,
117
+ dedupeIntegration,
56
118
  flush,
57
119
  getClient,
120
+ getDefaultIntegrations,
121
+ httpContextIntegration,
58
122
  init,
59
123
  lastEventId,
124
+ linkedErrorsIntegration,
60
125
  reactRouterV6BrowserTracingIntegration,
61
126
  reactRouterV7BrowserTracingIntegration,
62
127
  setContext,
@@ -65,12 +130,9 @@ export {
65
130
  setTag,
66
131
  setTags,
67
132
  setUser,
68
- startSpan,
69
133
  useProfiler,
70
134
  withErrorBoundary,
71
- withIsolationScope,
72
135
  withProfiler,
73
- withScope,
74
136
  withSentryReactRouterV6Routing,
75
137
  withSentryRouting,
76
138
  wrapCreateBrowserRouterV6,
@@ -65,16 +65,297 @@ function withSentryStub() {
65
65
  // src/vite/withSentryBuild.ts
66
66
  var import_node_path2 = __toESM(require("path"), 1);
67
67
  var import_node_url2 = require("url");
68
+
69
+ // src/vite/sentryApiValidator.ts
70
+ var t2 = __toESM(require("@babel/types"), 1);
71
+
72
+ // src/vite/extractRouterPlugin/babelHelpers.ts
73
+ var import_traverse = __toESM(require("@babel/traverse"), 1);
74
+ var import_parser = require("@babel/parser");
75
+ var t = __toESM(require("@babel/types"), 1);
76
+
77
+ // src/vite/extractRouterPlugin/constants.ts
78
+ var SOURCE_TYPE = "module";
79
+ var PLUGINS = ["jsx", "typescript"];
80
+ var EXCLUDE_MODULE = ["react", "react-dom", "react-router-dom"];
81
+ var JS_SUFFIXES = [".ts", ".tsx", ".jsx", ".js"];
82
+
83
+ // src/vite/extractRouterPlugin/babelHelpers.ts
84
+ var resolveBabelModule = (mod) => {
85
+ if (typeof mod === "function") return mod;
86
+ if (typeof mod.default === "function") return mod.default;
87
+ throw new Error("Cannot resolve babel module");
88
+ };
89
+ var traverse = resolveBabelModule(import_traverse.default);
90
+ var parseCode = (code, id) => (0, import_parser.parse)(code, { sourceType: SOURCE_TYPE, plugins: PLUGINS, sourceFilename: id });
91
+ var isLazyCallee = (callee) => {
92
+ if (t.isIdentifier(callee) && callee.name === "lazy") return true;
93
+ if (t.isMemberExpression(callee) && t.isIdentifier(callee.property) && callee.property.name === "lazy") return true;
94
+ return false;
95
+ };
96
+ var createImportVisitors = (importMap, lazyImportMap) => ({
97
+ /** 收集 import 声明:import Foo from './Foo' → importMap.set('Foo', './Foo') */
98
+ ImportDeclaration(nodePath) {
99
+ const source = nodePath.node.source.value;
100
+ if (EXCLUDE_MODULE.includes(source)) return;
101
+ for (const spec of nodePath.node.specifiers) {
102
+ if (t.isImportSpecifier(spec) || t.isImportDefaultSpecifier(spec)) {
103
+ importMap.set(spec.local.name, source);
104
+ }
105
+ }
106
+ },
107
+ /**
108
+ * 收集 lazy 声明:const Foo = lazy(() => import('./Foo'))
109
+ * → lazyImportMap.set('Foo', './Foo')
110
+ */
111
+ VariableDeclarator(nodePath) {
112
+ if (!t.isIdentifier(nodePath.node.id) || !nodePath.node.init) return;
113
+ if (!t.isCallExpression(nodePath.node.init) || !isLazyCallee(nodePath.node.init.callee)) return;
114
+ const arg0 = nodePath.node.init.arguments[0];
115
+ if (t.isArrowFunctionExpression(arg0) && t.isCallExpression(arg0.body) && t.isImport(arg0.body.callee) && arg0.body.arguments.length > 0 && t.isStringLiteral(arg0.body.arguments[0])) {
116
+ lazyImportMap.set(nodePath.node.id.name, arg0.body.arguments[0].value);
117
+ }
118
+ }
119
+ });
120
+ var getOriginalArrayName = (objectPath) => {
121
+ if (objectPath.isIdentifier()) return objectPath.node.name;
122
+ if (objectPath.isCallExpression()) {
123
+ const callee = objectPath.get("callee");
124
+ if (callee.isMemberExpression()) return getOriginalArrayName(callee.get("object"));
125
+ }
126
+ if (objectPath.isMemberExpression()) {
127
+ const property = objectPath.get("property");
128
+ if (property.isIdentifier()) return property.node.name;
129
+ return getOriginalArrayName(objectPath.get("object"));
130
+ }
131
+ return "";
132
+ };
133
+ var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
134
+ if (!mod?.id || seen.has(mod.id) || mod.id.includes("node_modules")) return [];
135
+ seen.add(mod.id);
136
+ const deps = [mod.id];
137
+ for (const m of mod.importedModules ?? []) {
138
+ deps.push(...collectDeps(m, seen));
139
+ }
140
+ return deps;
141
+ };
142
+
143
+ // src/vite/sentryApiContract.ts
144
+ var SUPPORTED_SENTRY_APIS = [
145
+ "ErrorBoundary",
146
+ "Profiler",
147
+ "SDK_VERSION",
148
+ "addBreadcrumb",
149
+ "breadcrumbsIntegration",
150
+ "browserTracingIntegration",
151
+ "captureEvent",
152
+ "captureException",
153
+ "captureMessage",
154
+ "close",
155
+ "configureStubSubscribers",
156
+ "dedupeIntegration",
157
+ "flush",
158
+ "getClient",
159
+ "getDefaultIntegrations",
160
+ "httpContextIntegration",
161
+ "init",
162
+ "lastEventId",
163
+ "linkedErrorsIntegration",
164
+ "reactRouterV6BrowserTracingIntegration",
165
+ "reactRouterV7BrowserTracingIntegration",
166
+ "setContext",
167
+ "setExtra",
168
+ "setExtras",
169
+ "setTag",
170
+ "setTags",
171
+ "setUser",
172
+ "useProfiler",
173
+ "withErrorBoundary",
174
+ "withProfiler",
175
+ "withSentryReactRouterV6Routing",
176
+ "withSentryRouting",
177
+ "wrapCreateBrowserRouterV6",
178
+ "wrapCreateBrowserRouterV7"
179
+ ];
180
+ var SUPPORTED_SENTRY_API_SET = new Set(SUPPORTED_SENTRY_APIS);
181
+
182
+ // src/vite/sentryApiValidator.ts
68
183
  var SENTRY_MODULE2 = "@sentry/react";
184
+ function issueAt(path6, message) {
185
+ return {
186
+ message,
187
+ line: path6.node.loc?.start.line ?? 1,
188
+ column: (path6.node.loc?.start.column ?? 0) + 1
189
+ };
190
+ }
191
+ function unsupportedApi(path6, api) {
192
+ if (SUPPORTED_SENTRY_API_SET.has(api)) return null;
193
+ return issueAt(path6, `The production Sentry stub does not implement Sentry.${api}.`);
194
+ }
195
+ function memberApiName(path6) {
196
+ const { computed, property } = path6.node;
197
+ if (!computed && t2.isIdentifier(property)) return property.name;
198
+ if (computed && t2.isStringLiteral(property)) return property.value;
199
+ return null;
200
+ }
201
+ function importedApiName(specifier) {
202
+ const imported = t2.isImportSpecifier(specifier) ? specifier.imported : specifier.local;
203
+ if (t2.isIdentifier(imported)) return imported.name;
204
+ if (t2.isStringLiteral(imported)) return imported.value;
205
+ return null;
206
+ }
207
+ function validateObjectPattern(path6, issues) {
208
+ for (const propertyPath of path6.get("properties")) {
209
+ if (propertyPath.isRestElement()) {
210
+ issues.push(issueAt(propertyPath, "Rest destructuring of the Sentry namespace is not supported in production builds."));
211
+ continue;
212
+ }
213
+ if (!propertyPath.isObjectProperty()) continue;
214
+ const key = propertyPath.node.key;
215
+ const api = !propertyPath.node.computed && t2.isIdentifier(key) ? key.name : t2.isStringLiteral(key) ? key.value : null;
216
+ if (!api) {
217
+ issues.push(issueAt(propertyPath, "Dynamic Sentry API destructuring is not supported in production builds."));
218
+ continue;
219
+ }
220
+ const issue = unsupportedApi(propertyPath, api);
221
+ if (issue) issues.push(issue);
222
+ }
223
+ }
224
+ function validateNamespaceReference(path6, issues) {
225
+ if (path6.findParent((parent2) => parent2.isTSType())) return;
226
+ let expressionPath = path6;
227
+ let parent = expressionPath.parentPath;
228
+ while (parent && (parent.isTSAsExpression() || parent.isTSTypeAssertion() || parent.isTSNonNullExpression() || parent.isParenthesizedExpression()) && parent.node.expression === expressionPath.node) {
229
+ expressionPath = parent;
230
+ parent = expressionPath.parentPath;
231
+ }
232
+ if (!parent) {
233
+ issues.push(issueAt(path6, "Unable to statically validate the Sentry namespace reference."));
234
+ return;
235
+ }
236
+ if ((parent.isMemberExpression() || parent.isOptionalMemberExpression()) && parent.node.object === expressionPath.node) {
237
+ const api = memberApiName(parent);
238
+ if (!api) {
239
+ issues.push(issueAt(parent, "Dynamic Sentry API access is not supported in production builds."));
240
+ return;
241
+ }
242
+ const issue = unsupportedApi(parent, api);
243
+ if (issue) issues.push(issue);
244
+ return;
245
+ }
246
+ if (parent.isJSXMemberExpression() && parent.node.object === path6.node) {
247
+ const api = t2.isJSXIdentifier(parent.node.property) ? parent.node.property.name : null;
248
+ if (!api) {
249
+ issues.push(issueAt(parent, "Dynamic Sentry JSX access is not supported in production builds."));
250
+ return;
251
+ }
252
+ const issue = unsupportedApi(parent, api);
253
+ if (issue) issues.push(issue);
254
+ return;
255
+ }
256
+ if (parent.isVariableDeclarator() && parent.node.init === expressionPath.node) {
257
+ const idPath = parent.get("id");
258
+ if (idPath.isObjectPattern()) {
259
+ validateObjectPattern(idPath, issues);
260
+ return;
261
+ }
262
+ }
263
+ issues.push(issueAt(path6, "Passing or aliasing the Sentry namespace is not supported in production builds. Use a static Sentry.api call."));
264
+ }
265
+ function findUnsupportedSentryApiUsages(code, id) {
266
+ if (!code.includes(SENTRY_MODULE2)) return [];
267
+ const ast = parseCode(code, id);
268
+ const issues = [];
269
+ const namespaceImports = [];
270
+ traverse(ast, {
271
+ ImportDeclaration(path6) {
272
+ if (path6.node.source.value !== SENTRY_MODULE2 || path6.node.importKind === "type") return;
273
+ for (const specifierPath of path6.get("specifiers")) {
274
+ const specifier = specifierPath.node;
275
+ if (t2.isImportNamespaceSpecifier(specifier)) {
276
+ namespaceImports.push({ localName: specifier.local.name, path: path6 });
277
+ continue;
278
+ }
279
+ if (t2.isImportDefaultSpecifier(specifier)) {
280
+ issues.push(issueAt(specifierPath, "Default imports from @sentry/react are not supported in production builds."));
281
+ continue;
282
+ }
283
+ if (specifier.importKind === "type") continue;
284
+ const api = importedApiName(specifier);
285
+ if (!api) continue;
286
+ const issue = unsupportedApi(specifierPath, api);
287
+ if (issue) issues.push(issue);
288
+ }
289
+ },
290
+ ExportNamedDeclaration(path6) {
291
+ if (path6.node.source?.value !== SENTRY_MODULE2 || path6.node.exportKind === "type") return;
292
+ for (const specifierPath of path6.get("specifiers")) {
293
+ if (specifierPath.isExportNamespaceSpecifier()) {
294
+ issues.push(issueAt(specifierPath, "Namespace re-exports from @sentry/react are not supported in production builds."));
295
+ continue;
296
+ }
297
+ if (!specifierPath.isExportSpecifier() || specifierPath.node.exportKind === "type") continue;
298
+ const api = importedApiName(specifierPath.node);
299
+ if (!api) continue;
300
+ const issue = unsupportedApi(specifierPath, api);
301
+ if (issue) issues.push(issue);
302
+ }
303
+ },
304
+ ExportAllDeclaration(path6) {
305
+ if (path6.node.source.value === SENTRY_MODULE2 && path6.node.exportKind !== "type") {
306
+ issues.push(issueAt(path6, "export * from @sentry/react is not supported with the production Sentry stub."));
307
+ }
308
+ },
309
+ CallExpression(path6) {
310
+ const [firstArgument] = path6.node.arguments;
311
+ if (!t2.isStringLiteral(firstArgument) || firstArgument.value !== SENTRY_MODULE2) return;
312
+ if (t2.isImport(path6.node.callee)) {
313
+ issues.push(issueAt(path6, "Dynamic imports of @sentry/react are not supported in production builds."));
314
+ } else if (t2.isIdentifier(path6.node.callee, { name: "require" })) {
315
+ issues.push(issueAt(path6, "CommonJS require() of @sentry/react is not supported in production builds."));
316
+ }
317
+ },
318
+ TSImportEqualsDeclaration(path6) {
319
+ const reference = path6.node.moduleReference;
320
+ if (t2.isTSExternalModuleReference(reference) && t2.isStringLiteral(reference.expression, { value: SENTRY_MODULE2 })) {
321
+ issues.push(issueAt(path6, "TypeScript import-equals for @sentry/react is not supported in production builds."));
322
+ }
323
+ }
324
+ });
325
+ for (const namespaceImport of namespaceImports) {
326
+ const binding = namespaceImport.path.scope.getBinding(namespaceImport.localName);
327
+ if (!binding) continue;
328
+ for (const referencePath of binding.referencePaths) {
329
+ validateNamespaceReference(referencePath, issues);
330
+ }
331
+ }
332
+ return issues;
333
+ }
334
+
335
+ // src/vite/withSentryBuild.ts
336
+ var SENTRY_MODULE3 = "@sentry/react";
69
337
  var _dirname2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
70
338
  var STUB_PATH2 = import_node_path2.default.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
339
+ var SOURCE_FILE_RE = /\.[cm]?[jt]sx?$/;
71
340
  function withSentryBuild() {
72
341
  return {
73
342
  name: "miaoda-devkit:sentry-build",
74
343
  enforce: "pre",
75
344
  apply: "build",
76
345
  resolveId(id) {
77
- if (id === SENTRY_MODULE2) return STUB_PATH2;
346
+ if (id === SENTRY_MODULE3) return STUB_PATH2;
347
+ return null;
348
+ },
349
+ transform(code, id) {
350
+ const cleanId = id.split("?", 1)[0];
351
+ if (!SOURCE_FILE_RE.test(cleanId)) return null;
352
+ const [issue] = findUnsupportedSentryApiUsages(code, cleanId);
353
+ if (issue) {
354
+ this.error(
355
+ `[miaoda-devkit:sentry-build] ${issue.message}
356
+ File: ${cleanId}:${issue.line}:${issue.column}`
357
+ );
358
+ }
78
359
  return null;
79
360
  }
80
361
  };
@@ -141,92 +422,21 @@ function hmrTogglePlugin() {
141
422
  // src/vite/extractRouterPlugin/index.ts
142
423
  var import_path3 = __toESM(require("path"), 1);
143
424
 
144
- // src/vite/extractRouterPlugin/babelHelpers.ts
145
- var import_traverse = __toESM(require("@babel/traverse"), 1);
146
- var import_parser = require("@babel/parser");
147
- var t = __toESM(require("@babel/types"), 1);
148
-
149
- // src/vite/extractRouterPlugin/constants.ts
150
- var SOURCE_TYPE = "module";
151
- var PLUGINS = ["jsx", "typescript"];
152
- var EXCLUDE_MODULE = ["react", "react-dom", "react-router-dom"];
153
- var JS_SUFFIXES = [".ts", ".tsx", ".jsx", ".js"];
154
-
155
- // src/vite/extractRouterPlugin/babelHelpers.ts
156
- var resolveBabelModule = (mod) => {
157
- if (typeof mod === "function") return mod;
158
- if (typeof mod.default === "function") return mod.default;
159
- throw new Error("Cannot resolve babel module");
160
- };
161
- var traverse = resolveBabelModule(import_traverse.default);
162
- var parseCode = (code, id) => (0, import_parser.parse)(code, { sourceType: SOURCE_TYPE, plugins: PLUGINS, sourceFilename: id });
163
- var isLazyCallee = (callee) => {
164
- if (t.isIdentifier(callee) && callee.name === "lazy") return true;
165
- if (t.isMemberExpression(callee) && t.isIdentifier(callee.property) && callee.property.name === "lazy") return true;
166
- return false;
167
- };
168
- var createImportVisitors = (importMap, lazyImportMap) => ({
169
- /** 收集 import 声明:import Foo from './Foo' → importMap.set('Foo', './Foo') */
170
- ImportDeclaration(nodePath) {
171
- const source = nodePath.node.source.value;
172
- if (EXCLUDE_MODULE.includes(source)) return;
173
- for (const spec of nodePath.node.specifiers) {
174
- if (t.isImportSpecifier(spec) || t.isImportDefaultSpecifier(spec)) {
175
- importMap.set(spec.local.name, source);
176
- }
177
- }
178
- },
179
- /**
180
- * 收集 lazy 声明:const Foo = lazy(() => import('./Foo'))
181
- * → lazyImportMap.set('Foo', './Foo')
182
- */
183
- VariableDeclarator(nodePath) {
184
- if (!t.isIdentifier(nodePath.node.id) || !nodePath.node.init) return;
185
- if (!t.isCallExpression(nodePath.node.init) || !isLazyCallee(nodePath.node.init.callee)) return;
186
- const arg0 = nodePath.node.init.arguments[0];
187
- if (t.isArrowFunctionExpression(arg0) && t.isCallExpression(arg0.body) && t.isImport(arg0.body.callee) && arg0.body.arguments.length > 0 && t.isStringLiteral(arg0.body.arguments[0])) {
188
- lazyImportMap.set(nodePath.node.id.name, arg0.body.arguments[0].value);
189
- }
190
- }
191
- });
192
- var getOriginalArrayName = (objectPath) => {
193
- if (objectPath.isIdentifier()) return objectPath.node.name;
194
- if (objectPath.isCallExpression()) {
195
- const callee = objectPath.get("callee");
196
- if (callee.isMemberExpression()) return getOriginalArrayName(callee.get("object"));
197
- }
198
- if (objectPath.isMemberExpression()) {
199
- const property = objectPath.get("property");
200
- if (property.isIdentifier()) return property.node.name;
201
- return getOriginalArrayName(objectPath.get("object"));
202
- }
203
- return "";
204
- };
205
- var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
206
- if (!mod?.id || seen.has(mod.id) || mod.id.includes("node_modules")) return [];
207
- seen.add(mod.id);
208
- const deps = [mod.id];
209
- for (const m of mod.importedModules ?? []) {
210
- deps.push(...collectDeps(m, seen));
211
- }
212
- return deps;
213
- };
214
-
215
425
  // src/vite/extractRouterPlugin/routeTransform.ts
216
- var t2 = __toESM(require("@babel/types"), 1);
426
+ var t3 = __toESM(require("@babel/types"), 1);
217
427
  var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
218
428
  const dfs = (el, map) => {
219
429
  const nameNode = el.openingElement.name;
220
- if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
430
+ if (t3.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
221
431
  for (const child of el.children) {
222
- if (t2.isJSXElement(child)) {
432
+ if (t3.isJSXElement(child)) {
223
433
  const found = dfs(child, map);
224
434
  if (found) return found;
225
435
  }
226
436
  }
227
437
  return "";
228
438
  };
229
- return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
439
+ return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t3.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
230
440
  };
231
441
  var eachTree = (tree, iterator, level = 1, parents = []) => {
232
442
  for (let i = 0; i < tree.length; i++) {
@@ -256,7 +466,7 @@ var flattenRouteTree = (routes) => {
256
466
  };
257
467
 
258
468
  // src/vite/extractRouterPlugin/valueResolver.ts
259
- var t3 = __toESM(require("@babel/types"), 1);
469
+ var t4 = __toESM(require("@babel/types"), 1);
260
470
  var import_fs2 = __toESM(require("fs"), 1);
261
471
  var import_path2 = __toESM(require("path"), 1);
262
472
 
@@ -356,7 +566,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
356
566
  const declaration = nodePath.get("declaration");
357
567
  if (declaration.isVariableDeclaration()) {
358
568
  for (const dec of declaration.node.declarations) {
359
- if (t3.isIdentifier(dec.id) && dec.id.name === exportName) {
569
+ if (t4.isIdentifier(dec.id) && dec.id.name === exportName) {
360
570
  exportBinding = nodePath.scope.getBinding(dec.id.name);
361
571
  exportNodePath = nodePath;
362
572
  break;
@@ -364,7 +574,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
364
574
  }
365
575
  }
366
576
  for (const specifier of nodePath.node.specifiers) {
367
- if (t3.isExportSpecifier(specifier) && specifier.local.name === exportName) {
577
+ if (t4.isExportSpecifier(specifier) && specifier.local.name === exportName) {
368
578
  exportBinding = nodePath.scope.getBinding(specifier.local.name);
369
579
  exportNodePath = nodePath;
370
580
  break;
@@ -415,7 +625,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
415
625
  };
416
626
  var resolveModuleBinding = async (binding, currentFilePath, option, context, parentPath) => {
417
627
  const importDeclaration = binding.path.parent;
418
- if (!t3.isImportDeclaration(importDeclaration)) return null;
628
+ if (!t4.isImportDeclaration(importDeclaration)) return null;
419
629
  const importPath = resolveAlias(importDeclaration.source.value, option.aliasMap);
420
630
  const absolutePath = import_path2.default.resolve(import_path2.default.dirname(currentFilePath), importPath);
421
631
  const resolvedPath = await resolveFilePath(absolutePath);
@@ -423,7 +633,7 @@ var resolveModuleBinding = async (binding, currentFilePath, option, context, par
423
633
  let exportName = null;
424
634
  if (binding.path.isImportSpecifier()) {
425
635
  const imp = binding.path.node;
426
- exportName = t3.isIdentifier(imp.imported) ? imp.imported.name : null;
636
+ exportName = t4.isIdentifier(imp.imported) ? imp.imported.name : null;
427
637
  }
428
638
  return resolveFromFile(resolvedPath, exportName, option, context, parentPath);
429
639
  };
@@ -457,11 +667,11 @@ var resolveCallInit = async (init, binding, option, currentFilePath, context, pa
457
667
  }
458
668
  if (body.isBlockStatement()) {
459
669
  for (const stmt of body.node.body) {
460
- if (!t3.isReturnStatement(stmt) || !stmt.argument) continue;
461
- if (t3.isArrayExpression(stmt.argument)) {
670
+ if (!t4.isReturnStatement(stmt) || !stmt.argument) continue;
671
+ if (t4.isArrayExpression(stmt.argument)) {
462
672
  return resolveArrayExpression(stmt.argument, currentFilePath, context, option, parentPath);
463
673
  }
464
- if (t3.isIdentifier(stmt.argument)) {
674
+ if (t4.isIdentifier(stmt.argument)) {
465
675
  const refBinding = binding.scope.getBinding(stmt.argument.name);
466
676
  if (refBinding) return resolveImportedValue(refBinding, currentFilePath, option, context, parentPath);
467
677
  }
@@ -492,10 +702,10 @@ var resolveParamBinding = async (binding, currentFilePath, option, context) => {
492
702
  const functionPath = binding.path.getFunctionParent();
493
703
  if (!functionPath) return null;
494
704
  const node = functionPath.node;
495
- const functionName = t3.isFunctionDeclaration(node) ? node.id?.name : t3.isVariableDeclarator(functionPath.parent) && t3.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
705
+ const functionName = t4.isFunctionDeclaration(node) ? node.id?.name : t4.isVariableDeclarator(functionPath.parent) && t4.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
496
706
  if (!functionName) return null;
497
707
  const paramIndex = functionPath.node.params.findIndex(
498
- (param) => t3.isIdentifier(param) && param.name === binding.identifier.name
708
+ (param) => t4.isIdentifier(param) && param.name === binding.identifier.name
499
709
  );
500
710
  if (paramIndex < 0) return null;
501
711
  const programPath = functionPath.findParent((p) => p.isProgram());
@@ -528,8 +738,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
528
738
  const spreadRoutes = [];
529
739
  for (const element of arrayExpression.elements) {
530
740
  if (!element) continue;
531
- if (t3.isSpreadElement(element)) {
532
- if (t3.isIdentifier(element.argument)) {
741
+ if (t4.isSpreadElement(element)) {
742
+ if (t4.isIdentifier(element.argument)) {
533
743
  const binding = context.scope.getBinding(element.argument.name);
534
744
  if (binding) {
535
745
  const value = await resolveImportedValue(binding, currentFilePath, option, context, parentPath);
@@ -538,20 +748,20 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
538
748
  }
539
749
  continue;
540
750
  }
541
- if (!t3.isObjectExpression(element)) continue;
751
+ if (!t4.isObjectExpression(element)) continue;
542
752
  const obj = {};
543
753
  for (const property of element.properties) {
544
- if (!t3.isObjectProperty(property)) continue;
545
- const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
754
+ if (!t4.isObjectProperty(property)) continue;
755
+ const key = t4.isIdentifier(property.key) ? property.key.name : t4.isStringLiteral(property.key) ? property.key.value : null;
546
756
  if (!key || !["path", "name", "title", "children"].includes(key)) continue;
547
- if (t3.isStringLiteral(property.value)) {
757
+ if (t4.isStringLiteral(property.value)) {
548
758
  obj[key] = property.value.value;
549
- } else if (t3.isIdentifier(property.value)) {
759
+ } else if (t4.isIdentifier(property.value)) {
550
760
  const propBinding = context.scope.getBinding(property.value.name);
551
761
  if (propBinding) {
552
762
  obj[key] = await resolveImportedValue(propBinding, currentFilePath, option, context);
553
763
  }
554
- } else if (parentPath && t3.isArrayExpression(property.value) && key === "children") {
764
+ } else if (parentPath && t4.isArrayExpression(property.value) && key === "children") {
555
765
  const rawPath = obj.path;
556
766
  const currentPath = rawPath ? rawPath.startsWith("/") ? rawPath : joinPaths(parentPath, rawPath) : parentPath;
557
767
  const trimmedPath = currentPath?.replace(/\*+$/g, "").replace(/\/+$/g, "");
@@ -571,11 +781,11 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
571
781
  return [...spreadRoutes, ...flattenRouteTree(result)];
572
782
  };
573
783
  var resolveExpressionValue = async (nodePath, expression, id, option) => {
574
- if (t3.isStringLiteral(expression)) return expression.value;
575
- if (t3.isTemplateLiteral(expression) && expression.expressions.length === 0) {
784
+ if (t4.isStringLiteral(expression)) return expression.value;
785
+ if (t4.isTemplateLiteral(expression) && expression.expressions.length === 0) {
576
786
  return expression.quasis[0].value.raw;
577
787
  }
578
- if (t3.isIdentifier(expression)) {
788
+ if (t4.isIdentifier(expression)) {
579
789
  const binding = nodePath.scope.getBinding(expression.name);
580
790
  const value = await resolveImportedValue(binding, id, option, nodePath);
581
791
  return typeof value === "string" ? value : null;
@@ -768,7 +978,7 @@ var resolveAllRoute = async (code, id, option, outWildcardMounts) => {
768
978
  };
769
979
 
770
980
  // src/vite/extractRouterPlugin/hooksParser.ts
771
- var t4 = __toESM(require("@babel/types"), 1);
981
+ var t5 = __toESM(require("@babel/types"), 1);
772
982
  var resolveHooksRoute = async (code, id, option) => {
773
983
  try {
774
984
  const ast = parseCode(code, id);
@@ -779,7 +989,7 @@ var resolveHooksRoute = async (code, id, option) => {
779
989
  ...createImportVisitors(importMap, lazyImportMap),
780
990
  CallExpression(nodePath) {
781
991
  const callee = nodePath.node.callee;
782
- if (t4.isIdentifier(callee) && callee.name === "useRoutes") {
992
+ if (t5.isIdentifier(callee) && callee.name === "useRoutes") {
783
993
  useRoutesCalls.push(nodePath);
784
994
  }
785
995
  }
@@ -22,16 +22,297 @@ function withSentryStub() {
22
22
  // src/vite/withSentryBuild.ts
23
23
  import path2 from "path";
24
24
  import { fileURLToPath as fileURLToPath2 } from "url";
25
+
26
+ // src/vite/sentryApiValidator.ts
27
+ import * as t2 from "@babel/types";
28
+
29
+ // src/vite/extractRouterPlugin/babelHelpers.ts
30
+ import _traverse from "@babel/traverse";
31
+ import { parse } from "@babel/parser";
32
+ import * as t from "@babel/types";
33
+
34
+ // src/vite/extractRouterPlugin/constants.ts
35
+ var SOURCE_TYPE = "module";
36
+ var PLUGINS = ["jsx", "typescript"];
37
+ var EXCLUDE_MODULE = ["react", "react-dom", "react-router-dom"];
38
+ var JS_SUFFIXES = [".ts", ".tsx", ".jsx", ".js"];
39
+
40
+ // src/vite/extractRouterPlugin/babelHelpers.ts
41
+ var resolveBabelModule = (mod) => {
42
+ if (typeof mod === "function") return mod;
43
+ if (typeof mod.default === "function") return mod.default;
44
+ throw new Error("Cannot resolve babel module");
45
+ };
46
+ var traverse = resolveBabelModule(_traverse);
47
+ var parseCode = (code, id) => parse(code, { sourceType: SOURCE_TYPE, plugins: PLUGINS, sourceFilename: id });
48
+ var isLazyCallee = (callee) => {
49
+ if (t.isIdentifier(callee) && callee.name === "lazy") return true;
50
+ if (t.isMemberExpression(callee) && t.isIdentifier(callee.property) && callee.property.name === "lazy") return true;
51
+ return false;
52
+ };
53
+ var createImportVisitors = (importMap, lazyImportMap) => ({
54
+ /** 收集 import 声明:import Foo from './Foo' → importMap.set('Foo', './Foo') */
55
+ ImportDeclaration(nodePath) {
56
+ const source = nodePath.node.source.value;
57
+ if (EXCLUDE_MODULE.includes(source)) return;
58
+ for (const spec of nodePath.node.specifiers) {
59
+ if (t.isImportSpecifier(spec) || t.isImportDefaultSpecifier(spec)) {
60
+ importMap.set(spec.local.name, source);
61
+ }
62
+ }
63
+ },
64
+ /**
65
+ * 收集 lazy 声明:const Foo = lazy(() => import('./Foo'))
66
+ * → lazyImportMap.set('Foo', './Foo')
67
+ */
68
+ VariableDeclarator(nodePath) {
69
+ if (!t.isIdentifier(nodePath.node.id) || !nodePath.node.init) return;
70
+ if (!t.isCallExpression(nodePath.node.init) || !isLazyCallee(nodePath.node.init.callee)) return;
71
+ const arg0 = nodePath.node.init.arguments[0];
72
+ if (t.isArrowFunctionExpression(arg0) && t.isCallExpression(arg0.body) && t.isImport(arg0.body.callee) && arg0.body.arguments.length > 0 && t.isStringLiteral(arg0.body.arguments[0])) {
73
+ lazyImportMap.set(nodePath.node.id.name, arg0.body.arguments[0].value);
74
+ }
75
+ }
76
+ });
77
+ var getOriginalArrayName = (objectPath) => {
78
+ if (objectPath.isIdentifier()) return objectPath.node.name;
79
+ if (objectPath.isCallExpression()) {
80
+ const callee = objectPath.get("callee");
81
+ if (callee.isMemberExpression()) return getOriginalArrayName(callee.get("object"));
82
+ }
83
+ if (objectPath.isMemberExpression()) {
84
+ const property = objectPath.get("property");
85
+ if (property.isIdentifier()) return property.node.name;
86
+ return getOriginalArrayName(objectPath.get("object"));
87
+ }
88
+ return "";
89
+ };
90
+ var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
91
+ if (!mod?.id || seen.has(mod.id) || mod.id.includes("node_modules")) return [];
92
+ seen.add(mod.id);
93
+ const deps = [mod.id];
94
+ for (const m of mod.importedModules ?? []) {
95
+ deps.push(...collectDeps(m, seen));
96
+ }
97
+ return deps;
98
+ };
99
+
100
+ // src/vite/sentryApiContract.ts
101
+ var SUPPORTED_SENTRY_APIS = [
102
+ "ErrorBoundary",
103
+ "Profiler",
104
+ "SDK_VERSION",
105
+ "addBreadcrumb",
106
+ "breadcrumbsIntegration",
107
+ "browserTracingIntegration",
108
+ "captureEvent",
109
+ "captureException",
110
+ "captureMessage",
111
+ "close",
112
+ "configureStubSubscribers",
113
+ "dedupeIntegration",
114
+ "flush",
115
+ "getClient",
116
+ "getDefaultIntegrations",
117
+ "httpContextIntegration",
118
+ "init",
119
+ "lastEventId",
120
+ "linkedErrorsIntegration",
121
+ "reactRouterV6BrowserTracingIntegration",
122
+ "reactRouterV7BrowserTracingIntegration",
123
+ "setContext",
124
+ "setExtra",
125
+ "setExtras",
126
+ "setTag",
127
+ "setTags",
128
+ "setUser",
129
+ "useProfiler",
130
+ "withErrorBoundary",
131
+ "withProfiler",
132
+ "withSentryReactRouterV6Routing",
133
+ "withSentryRouting",
134
+ "wrapCreateBrowserRouterV6",
135
+ "wrapCreateBrowserRouterV7"
136
+ ];
137
+ var SUPPORTED_SENTRY_API_SET = new Set(SUPPORTED_SENTRY_APIS);
138
+
139
+ // src/vite/sentryApiValidator.ts
25
140
  var SENTRY_MODULE2 = "@sentry/react";
141
+ function issueAt(path6, message) {
142
+ return {
143
+ message,
144
+ line: path6.node.loc?.start.line ?? 1,
145
+ column: (path6.node.loc?.start.column ?? 0) + 1
146
+ };
147
+ }
148
+ function unsupportedApi(path6, api) {
149
+ if (SUPPORTED_SENTRY_API_SET.has(api)) return null;
150
+ return issueAt(path6, `The production Sentry stub does not implement Sentry.${api}.`);
151
+ }
152
+ function memberApiName(path6) {
153
+ const { computed, property } = path6.node;
154
+ if (!computed && t2.isIdentifier(property)) return property.name;
155
+ if (computed && t2.isStringLiteral(property)) return property.value;
156
+ return null;
157
+ }
158
+ function importedApiName(specifier) {
159
+ const imported = t2.isImportSpecifier(specifier) ? specifier.imported : specifier.local;
160
+ if (t2.isIdentifier(imported)) return imported.name;
161
+ if (t2.isStringLiteral(imported)) return imported.value;
162
+ return null;
163
+ }
164
+ function validateObjectPattern(path6, issues) {
165
+ for (const propertyPath of path6.get("properties")) {
166
+ if (propertyPath.isRestElement()) {
167
+ issues.push(issueAt(propertyPath, "Rest destructuring of the Sentry namespace is not supported in production builds."));
168
+ continue;
169
+ }
170
+ if (!propertyPath.isObjectProperty()) continue;
171
+ const key = propertyPath.node.key;
172
+ const api = !propertyPath.node.computed && t2.isIdentifier(key) ? key.name : t2.isStringLiteral(key) ? key.value : null;
173
+ if (!api) {
174
+ issues.push(issueAt(propertyPath, "Dynamic Sentry API destructuring is not supported in production builds."));
175
+ continue;
176
+ }
177
+ const issue = unsupportedApi(propertyPath, api);
178
+ if (issue) issues.push(issue);
179
+ }
180
+ }
181
+ function validateNamespaceReference(path6, issues) {
182
+ if (path6.findParent((parent2) => parent2.isTSType())) return;
183
+ let expressionPath = path6;
184
+ let parent = expressionPath.parentPath;
185
+ while (parent && (parent.isTSAsExpression() || parent.isTSTypeAssertion() || parent.isTSNonNullExpression() || parent.isParenthesizedExpression()) && parent.node.expression === expressionPath.node) {
186
+ expressionPath = parent;
187
+ parent = expressionPath.parentPath;
188
+ }
189
+ if (!parent) {
190
+ issues.push(issueAt(path6, "Unable to statically validate the Sentry namespace reference."));
191
+ return;
192
+ }
193
+ if ((parent.isMemberExpression() || parent.isOptionalMemberExpression()) && parent.node.object === expressionPath.node) {
194
+ const api = memberApiName(parent);
195
+ if (!api) {
196
+ issues.push(issueAt(parent, "Dynamic Sentry API access is not supported in production builds."));
197
+ return;
198
+ }
199
+ const issue = unsupportedApi(parent, api);
200
+ if (issue) issues.push(issue);
201
+ return;
202
+ }
203
+ if (parent.isJSXMemberExpression() && parent.node.object === path6.node) {
204
+ const api = t2.isJSXIdentifier(parent.node.property) ? parent.node.property.name : null;
205
+ if (!api) {
206
+ issues.push(issueAt(parent, "Dynamic Sentry JSX access is not supported in production builds."));
207
+ return;
208
+ }
209
+ const issue = unsupportedApi(parent, api);
210
+ if (issue) issues.push(issue);
211
+ return;
212
+ }
213
+ if (parent.isVariableDeclarator() && parent.node.init === expressionPath.node) {
214
+ const idPath = parent.get("id");
215
+ if (idPath.isObjectPattern()) {
216
+ validateObjectPattern(idPath, issues);
217
+ return;
218
+ }
219
+ }
220
+ issues.push(issueAt(path6, "Passing or aliasing the Sentry namespace is not supported in production builds. Use a static Sentry.api call."));
221
+ }
222
+ function findUnsupportedSentryApiUsages(code, id) {
223
+ if (!code.includes(SENTRY_MODULE2)) return [];
224
+ const ast = parseCode(code, id);
225
+ const issues = [];
226
+ const namespaceImports = [];
227
+ traverse(ast, {
228
+ ImportDeclaration(path6) {
229
+ if (path6.node.source.value !== SENTRY_MODULE2 || path6.node.importKind === "type") return;
230
+ for (const specifierPath of path6.get("specifiers")) {
231
+ const specifier = specifierPath.node;
232
+ if (t2.isImportNamespaceSpecifier(specifier)) {
233
+ namespaceImports.push({ localName: specifier.local.name, path: path6 });
234
+ continue;
235
+ }
236
+ if (t2.isImportDefaultSpecifier(specifier)) {
237
+ issues.push(issueAt(specifierPath, "Default imports from @sentry/react are not supported in production builds."));
238
+ continue;
239
+ }
240
+ if (specifier.importKind === "type") continue;
241
+ const api = importedApiName(specifier);
242
+ if (!api) continue;
243
+ const issue = unsupportedApi(specifierPath, api);
244
+ if (issue) issues.push(issue);
245
+ }
246
+ },
247
+ ExportNamedDeclaration(path6) {
248
+ if (path6.node.source?.value !== SENTRY_MODULE2 || path6.node.exportKind === "type") return;
249
+ for (const specifierPath of path6.get("specifiers")) {
250
+ if (specifierPath.isExportNamespaceSpecifier()) {
251
+ issues.push(issueAt(specifierPath, "Namespace re-exports from @sentry/react are not supported in production builds."));
252
+ continue;
253
+ }
254
+ if (!specifierPath.isExportSpecifier() || specifierPath.node.exportKind === "type") continue;
255
+ const api = importedApiName(specifierPath.node);
256
+ if (!api) continue;
257
+ const issue = unsupportedApi(specifierPath, api);
258
+ if (issue) issues.push(issue);
259
+ }
260
+ },
261
+ ExportAllDeclaration(path6) {
262
+ if (path6.node.source.value === SENTRY_MODULE2 && path6.node.exportKind !== "type") {
263
+ issues.push(issueAt(path6, "export * from @sentry/react is not supported with the production Sentry stub."));
264
+ }
265
+ },
266
+ CallExpression(path6) {
267
+ const [firstArgument] = path6.node.arguments;
268
+ if (!t2.isStringLiteral(firstArgument) || firstArgument.value !== SENTRY_MODULE2) return;
269
+ if (t2.isImport(path6.node.callee)) {
270
+ issues.push(issueAt(path6, "Dynamic imports of @sentry/react are not supported in production builds."));
271
+ } else if (t2.isIdentifier(path6.node.callee, { name: "require" })) {
272
+ issues.push(issueAt(path6, "CommonJS require() of @sentry/react is not supported in production builds."));
273
+ }
274
+ },
275
+ TSImportEqualsDeclaration(path6) {
276
+ const reference = path6.node.moduleReference;
277
+ if (t2.isTSExternalModuleReference(reference) && t2.isStringLiteral(reference.expression, { value: SENTRY_MODULE2 })) {
278
+ issues.push(issueAt(path6, "TypeScript import-equals for @sentry/react is not supported in production builds."));
279
+ }
280
+ }
281
+ });
282
+ for (const namespaceImport of namespaceImports) {
283
+ const binding = namespaceImport.path.scope.getBinding(namespaceImport.localName);
284
+ if (!binding) continue;
285
+ for (const referencePath of binding.referencePaths) {
286
+ validateNamespaceReference(referencePath, issues);
287
+ }
288
+ }
289
+ return issues;
290
+ }
291
+
292
+ // src/vite/withSentryBuild.ts
293
+ var SENTRY_MODULE3 = "@sentry/react";
26
294
  var _dirname2 = path2.dirname(fileURLToPath2(import.meta.url));
27
295
  var STUB_PATH2 = path2.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
296
+ var SOURCE_FILE_RE = /\.[cm]?[jt]sx?$/;
28
297
  function withSentryBuild() {
29
298
  return {
30
299
  name: "miaoda-devkit:sentry-build",
31
300
  enforce: "pre",
32
301
  apply: "build",
33
302
  resolveId(id) {
34
- if (id === SENTRY_MODULE2) return STUB_PATH2;
303
+ if (id === SENTRY_MODULE3) return STUB_PATH2;
304
+ return null;
305
+ },
306
+ transform(code, id) {
307
+ const cleanId = id.split("?", 1)[0];
308
+ if (!SOURCE_FILE_RE.test(cleanId)) return null;
309
+ const [issue] = findUnsupportedSentryApiUsages(code, cleanId);
310
+ if (issue) {
311
+ this.error(
312
+ `[miaoda-devkit:sentry-build] ${issue.message}
313
+ File: ${cleanId}:${issue.line}:${issue.column}`
314
+ );
315
+ }
35
316
  return null;
36
317
  }
37
318
  };
@@ -98,92 +379,21 @@ function hmrTogglePlugin() {
98
379
  // src/vite/extractRouterPlugin/index.ts
99
380
  import path5 from "path";
100
381
 
101
- // src/vite/extractRouterPlugin/babelHelpers.ts
102
- import _traverse from "@babel/traverse";
103
- import { parse } from "@babel/parser";
104
- import * as t from "@babel/types";
105
-
106
- // src/vite/extractRouterPlugin/constants.ts
107
- var SOURCE_TYPE = "module";
108
- var PLUGINS = ["jsx", "typescript"];
109
- var EXCLUDE_MODULE = ["react", "react-dom", "react-router-dom"];
110
- var JS_SUFFIXES = [".ts", ".tsx", ".jsx", ".js"];
111
-
112
- // src/vite/extractRouterPlugin/babelHelpers.ts
113
- var resolveBabelModule = (mod) => {
114
- if (typeof mod === "function") return mod;
115
- if (typeof mod.default === "function") return mod.default;
116
- throw new Error("Cannot resolve babel module");
117
- };
118
- var traverse = resolveBabelModule(_traverse);
119
- var parseCode = (code, id) => parse(code, { sourceType: SOURCE_TYPE, plugins: PLUGINS, sourceFilename: id });
120
- var isLazyCallee = (callee) => {
121
- if (t.isIdentifier(callee) && callee.name === "lazy") return true;
122
- if (t.isMemberExpression(callee) && t.isIdentifier(callee.property) && callee.property.name === "lazy") return true;
123
- return false;
124
- };
125
- var createImportVisitors = (importMap, lazyImportMap) => ({
126
- /** 收集 import 声明:import Foo from './Foo' → importMap.set('Foo', './Foo') */
127
- ImportDeclaration(nodePath) {
128
- const source = nodePath.node.source.value;
129
- if (EXCLUDE_MODULE.includes(source)) return;
130
- for (const spec of nodePath.node.specifiers) {
131
- if (t.isImportSpecifier(spec) || t.isImportDefaultSpecifier(spec)) {
132
- importMap.set(spec.local.name, source);
133
- }
134
- }
135
- },
136
- /**
137
- * 收集 lazy 声明:const Foo = lazy(() => import('./Foo'))
138
- * → lazyImportMap.set('Foo', './Foo')
139
- */
140
- VariableDeclarator(nodePath) {
141
- if (!t.isIdentifier(nodePath.node.id) || !nodePath.node.init) return;
142
- if (!t.isCallExpression(nodePath.node.init) || !isLazyCallee(nodePath.node.init.callee)) return;
143
- const arg0 = nodePath.node.init.arguments[0];
144
- if (t.isArrowFunctionExpression(arg0) && t.isCallExpression(arg0.body) && t.isImport(arg0.body.callee) && arg0.body.arguments.length > 0 && t.isStringLiteral(arg0.body.arguments[0])) {
145
- lazyImportMap.set(nodePath.node.id.name, arg0.body.arguments[0].value);
146
- }
147
- }
148
- });
149
- var getOriginalArrayName = (objectPath) => {
150
- if (objectPath.isIdentifier()) return objectPath.node.name;
151
- if (objectPath.isCallExpression()) {
152
- const callee = objectPath.get("callee");
153
- if (callee.isMemberExpression()) return getOriginalArrayName(callee.get("object"));
154
- }
155
- if (objectPath.isMemberExpression()) {
156
- const property = objectPath.get("property");
157
- if (property.isIdentifier()) return property.node.name;
158
- return getOriginalArrayName(objectPath.get("object"));
159
- }
160
- return "";
161
- };
162
- var collectDeps = (mod, seen = /* @__PURE__ */ new Set()) => {
163
- if (!mod?.id || seen.has(mod.id) || mod.id.includes("node_modules")) return [];
164
- seen.add(mod.id);
165
- const deps = [mod.id];
166
- for (const m of mod.importedModules ?? []) {
167
- deps.push(...collectDeps(m, seen));
168
- }
169
- return deps;
170
- };
171
-
172
382
  // src/vite/extractRouterPlugin/routeTransform.ts
173
- import * as t2 from "@babel/types";
383
+ import * as t3 from "@babel/types";
174
384
  var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
175
385
  const dfs = (el, map) => {
176
386
  const nameNode = el.openingElement.name;
177
- if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
387
+ if (t3.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
178
388
  for (const child of el.children) {
179
- if (t2.isJSXElement(child)) {
389
+ if (t3.isJSXElement(child)) {
180
390
  const found = dfs(child, map);
181
391
  if (found) return found;
182
392
  }
183
393
  }
184
394
  return "";
185
395
  };
186
- return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
396
+ return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t3.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
187
397
  };
188
398
  var eachTree = (tree, iterator, level = 1, parents = []) => {
189
399
  for (let i = 0; i < tree.length; i++) {
@@ -213,7 +423,7 @@ var flattenRouteTree = (routes) => {
213
423
  };
214
424
 
215
425
  // src/vite/extractRouterPlugin/valueResolver.ts
216
- import * as t3 from "@babel/types";
426
+ import * as t4 from "@babel/types";
217
427
  import fs2 from "fs";
218
428
  import path4 from "path";
219
429
 
@@ -313,7 +523,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
313
523
  const declaration = nodePath.get("declaration");
314
524
  if (declaration.isVariableDeclaration()) {
315
525
  for (const dec of declaration.node.declarations) {
316
- if (t3.isIdentifier(dec.id) && dec.id.name === exportName) {
526
+ if (t4.isIdentifier(dec.id) && dec.id.name === exportName) {
317
527
  exportBinding = nodePath.scope.getBinding(dec.id.name);
318
528
  exportNodePath = nodePath;
319
529
  break;
@@ -321,7 +531,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
321
531
  }
322
532
  }
323
533
  for (const specifier of nodePath.node.specifiers) {
324
- if (t3.isExportSpecifier(specifier) && specifier.local.name === exportName) {
534
+ if (t4.isExportSpecifier(specifier) && specifier.local.name === exportName) {
325
535
  exportBinding = nodePath.scope.getBinding(specifier.local.name);
326
536
  exportNodePath = nodePath;
327
537
  break;
@@ -372,7 +582,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
372
582
  };
373
583
  var resolveModuleBinding = async (binding, currentFilePath, option, context, parentPath) => {
374
584
  const importDeclaration = binding.path.parent;
375
- if (!t3.isImportDeclaration(importDeclaration)) return null;
585
+ if (!t4.isImportDeclaration(importDeclaration)) return null;
376
586
  const importPath = resolveAlias(importDeclaration.source.value, option.aliasMap);
377
587
  const absolutePath = path4.resolve(path4.dirname(currentFilePath), importPath);
378
588
  const resolvedPath = await resolveFilePath(absolutePath);
@@ -380,7 +590,7 @@ var resolveModuleBinding = async (binding, currentFilePath, option, context, par
380
590
  let exportName = null;
381
591
  if (binding.path.isImportSpecifier()) {
382
592
  const imp = binding.path.node;
383
- exportName = t3.isIdentifier(imp.imported) ? imp.imported.name : null;
593
+ exportName = t4.isIdentifier(imp.imported) ? imp.imported.name : null;
384
594
  }
385
595
  return resolveFromFile(resolvedPath, exportName, option, context, parentPath);
386
596
  };
@@ -414,11 +624,11 @@ var resolveCallInit = async (init, binding, option, currentFilePath, context, pa
414
624
  }
415
625
  if (body.isBlockStatement()) {
416
626
  for (const stmt of body.node.body) {
417
- if (!t3.isReturnStatement(stmt) || !stmt.argument) continue;
418
- if (t3.isArrayExpression(stmt.argument)) {
627
+ if (!t4.isReturnStatement(stmt) || !stmt.argument) continue;
628
+ if (t4.isArrayExpression(stmt.argument)) {
419
629
  return resolveArrayExpression(stmt.argument, currentFilePath, context, option, parentPath);
420
630
  }
421
- if (t3.isIdentifier(stmt.argument)) {
631
+ if (t4.isIdentifier(stmt.argument)) {
422
632
  const refBinding = binding.scope.getBinding(stmt.argument.name);
423
633
  if (refBinding) return resolveImportedValue(refBinding, currentFilePath, option, context, parentPath);
424
634
  }
@@ -449,10 +659,10 @@ var resolveParamBinding = async (binding, currentFilePath, option, context) => {
449
659
  const functionPath = binding.path.getFunctionParent();
450
660
  if (!functionPath) return null;
451
661
  const node = functionPath.node;
452
- const functionName = t3.isFunctionDeclaration(node) ? node.id?.name : t3.isVariableDeclarator(functionPath.parent) && t3.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
662
+ const functionName = t4.isFunctionDeclaration(node) ? node.id?.name : t4.isVariableDeclarator(functionPath.parent) && t4.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
453
663
  if (!functionName) return null;
454
664
  const paramIndex = functionPath.node.params.findIndex(
455
- (param) => t3.isIdentifier(param) && param.name === binding.identifier.name
665
+ (param) => t4.isIdentifier(param) && param.name === binding.identifier.name
456
666
  );
457
667
  if (paramIndex < 0) return null;
458
668
  const programPath = functionPath.findParent((p) => p.isProgram());
@@ -485,8 +695,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
485
695
  const spreadRoutes = [];
486
696
  for (const element of arrayExpression.elements) {
487
697
  if (!element) continue;
488
- if (t3.isSpreadElement(element)) {
489
- if (t3.isIdentifier(element.argument)) {
698
+ if (t4.isSpreadElement(element)) {
699
+ if (t4.isIdentifier(element.argument)) {
490
700
  const binding = context.scope.getBinding(element.argument.name);
491
701
  if (binding) {
492
702
  const value = await resolveImportedValue(binding, currentFilePath, option, context, parentPath);
@@ -495,20 +705,20 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
495
705
  }
496
706
  continue;
497
707
  }
498
- if (!t3.isObjectExpression(element)) continue;
708
+ if (!t4.isObjectExpression(element)) continue;
499
709
  const obj = {};
500
710
  for (const property of element.properties) {
501
- if (!t3.isObjectProperty(property)) continue;
502
- const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
711
+ if (!t4.isObjectProperty(property)) continue;
712
+ const key = t4.isIdentifier(property.key) ? property.key.name : t4.isStringLiteral(property.key) ? property.key.value : null;
503
713
  if (!key || !["path", "name", "title", "children"].includes(key)) continue;
504
- if (t3.isStringLiteral(property.value)) {
714
+ if (t4.isStringLiteral(property.value)) {
505
715
  obj[key] = property.value.value;
506
- } else if (t3.isIdentifier(property.value)) {
716
+ } else if (t4.isIdentifier(property.value)) {
507
717
  const propBinding = context.scope.getBinding(property.value.name);
508
718
  if (propBinding) {
509
719
  obj[key] = await resolveImportedValue(propBinding, currentFilePath, option, context);
510
720
  }
511
- } else if (parentPath && t3.isArrayExpression(property.value) && key === "children") {
721
+ } else if (parentPath && t4.isArrayExpression(property.value) && key === "children") {
512
722
  const rawPath = obj.path;
513
723
  const currentPath = rawPath ? rawPath.startsWith("/") ? rawPath : joinPaths(parentPath, rawPath) : parentPath;
514
724
  const trimmedPath = currentPath?.replace(/\*+$/g, "").replace(/\/+$/g, "");
@@ -528,11 +738,11 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
528
738
  return [...spreadRoutes, ...flattenRouteTree(result)];
529
739
  };
530
740
  var resolveExpressionValue = async (nodePath, expression, id, option) => {
531
- if (t3.isStringLiteral(expression)) return expression.value;
532
- if (t3.isTemplateLiteral(expression) && expression.expressions.length === 0) {
741
+ if (t4.isStringLiteral(expression)) return expression.value;
742
+ if (t4.isTemplateLiteral(expression) && expression.expressions.length === 0) {
533
743
  return expression.quasis[0].value.raw;
534
744
  }
535
- if (t3.isIdentifier(expression)) {
745
+ if (t4.isIdentifier(expression)) {
536
746
  const binding = nodePath.scope.getBinding(expression.name);
537
747
  const value = await resolveImportedValue(binding, id, option, nodePath);
538
748
  return typeof value === "string" ? value : null;
@@ -725,7 +935,7 @@ var resolveAllRoute = async (code, id, option, outWildcardMounts) => {
725
935
  };
726
936
 
727
937
  // src/vite/extractRouterPlugin/hooksParser.ts
728
- import * as t4 from "@babel/types";
938
+ import * as t5 from "@babel/types";
729
939
  var resolveHooksRoute = async (code, id, option) => {
730
940
  try {
731
941
  const ast = parseCode(code, id);
@@ -736,7 +946,7 @@ var resolveHooksRoute = async (code, id, option) => {
736
946
  ...createImportVisitors(importMap, lazyImportMap),
737
947
  CallExpression(nodePath) {
738
948
  const callee = nodePath.node.callee;
739
- if (t4.isIdentifier(callee) && callee.name === "useRoutes") {
949
+ if (t5.isIdentifier(callee) && callee.name === "useRoutes") {
740
950
  useRoutesCalls.push(nodePath);
741
951
  }
742
952
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-react-devkit",
3
- "version": "0.1.1-beta.15",
3
+ "version": "0.1.1-beta.17",
4
4
  "description": "React admin 应用开发工具集",
5
5
  "license": "MIT",
6
6
  "type": "module",