miaoda-react-devkit 0.1.1-beta.14 → 0.1.1-beta.16

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