miaoda-react-devkit 0.1.1-beta.16 → 0.1.1-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stubs/sentry-react-noop-stub.js +76 -15
- package/dist/vite/index.cjs +99 -308
- package/dist/vite/index.d.cts +6 -0
- package/dist/vite/index.d.ts +6 -0
- package/dist/vite/index.js +99 -308
- package/package.json +1 -1
|
@@ -1,10 +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
|
};
|
|
4
14
|
var configureStubSubscribers = (_subscribers) => {
|
|
5
15
|
};
|
|
6
16
|
var getDefaultIntegrations = (_options) => [];
|
|
7
17
|
var browserTracingIntegration = () => ({});
|
|
18
|
+
var breadcrumbsIntegration = (_options) => ({});
|
|
19
|
+
var httpContextIntegration = (_options) => ({});
|
|
20
|
+
var linkedErrorsIntegration = (_options) => ({});
|
|
21
|
+
var dedupeIntegration = (_options) => ({});
|
|
8
22
|
var captureException = (_err) => "";
|
|
9
23
|
var captureMessage = (_msg) => "";
|
|
10
24
|
var captureEvent = (_event) => "";
|
|
@@ -22,60 +36,107 @@ var setExtra = (_key, _value) => {
|
|
|
22
36
|
};
|
|
23
37
|
var setExtras = (_extras) => {
|
|
24
38
|
};
|
|
25
|
-
var withScope = (cb) => {
|
|
26
|
-
cb({});
|
|
27
|
-
};
|
|
28
|
-
var withIsolationScope = (cb) => {
|
|
29
|
-
cb({});
|
|
30
|
-
};
|
|
31
|
-
var startSpan = (_opts, cb) => cb();
|
|
32
39
|
var getClient = () => void 0;
|
|
33
40
|
var flush = () => Promise.resolve(true);
|
|
34
41
|
var close = () => Promise.resolve(true);
|
|
35
42
|
var lastEventId = () => void 0;
|
|
36
43
|
var SDK_VERSION = "0.0.0-stub";
|
|
37
|
-
var ErrorBoundary =
|
|
38
|
-
|
|
39
|
-
|
|
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;
|
|
40
96
|
var useProfiler = (_name) => {
|
|
41
97
|
};
|
|
42
98
|
var Profiler = ({ children }) => children ?? null;
|
|
43
|
-
var withSentryRouting = (
|
|
44
|
-
var withSentryReactRouterV6Routing = (
|
|
99
|
+
var withSentryRouting = (Component2) => Component2;
|
|
100
|
+
var withSentryReactRouterV6Routing = (Component2) => Component2;
|
|
45
101
|
var wrapCreateBrowserRouterV6 = (fn) => fn;
|
|
46
102
|
var wrapCreateBrowserRouterV7 = (fn) => fn;
|
|
47
103
|
var reactRouterV6BrowserTracingIntegration = () => ({});
|
|
48
104
|
var reactRouterV7BrowserTracingIntegration = () => ({});
|
|
105
|
+
var getCurrentScope = () => ({});
|
|
106
|
+
var replayIntegration = (_options) => ({});
|
|
49
107
|
export {
|
|
50
108
|
ErrorBoundary,
|
|
51
109
|
Profiler,
|
|
52
110
|
SDK_VERSION,
|
|
53
111
|
addBreadcrumb,
|
|
112
|
+
breadcrumbsIntegration,
|
|
54
113
|
browserTracingIntegration,
|
|
55
114
|
captureEvent,
|
|
56
115
|
captureException,
|
|
57
116
|
captureMessage,
|
|
58
117
|
close,
|
|
59
118
|
configureStubSubscribers,
|
|
119
|
+
dedupeIntegration,
|
|
60
120
|
flush,
|
|
61
121
|
getClient,
|
|
122
|
+
getCurrentScope,
|
|
62
123
|
getDefaultIntegrations,
|
|
124
|
+
httpContextIntegration,
|
|
63
125
|
init,
|
|
64
126
|
lastEventId,
|
|
127
|
+
linkedErrorsIntegration,
|
|
65
128
|
reactRouterV6BrowserTracingIntegration,
|
|
66
129
|
reactRouterV7BrowserTracingIntegration,
|
|
130
|
+
replayIntegration,
|
|
67
131
|
setContext,
|
|
68
132
|
setExtra,
|
|
69
133
|
setExtras,
|
|
70
134
|
setTag,
|
|
71
135
|
setTags,
|
|
72
136
|
setUser,
|
|
73
|
-
startSpan,
|
|
74
137
|
useProfiler,
|
|
75
138
|
withErrorBoundary,
|
|
76
|
-
withIsolationScope,
|
|
77
139
|
withProfiler,
|
|
78
|
-
withScope,
|
|
79
140
|
withSentryReactRouterV6Routing,
|
|
80
141
|
withSentryRouting,
|
|
81
142
|
wrapCreateBrowserRouterV6,
|
package/dist/vite/index.cjs
CHANGED
|
@@ -65,296 +65,16 @@ 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
|
|
182
68
|
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";
|
|
336
69
|
var _dirname2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
|
|
337
70
|
var STUB_PATH2 = import_node_path2.default.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
|
|
338
|
-
var SOURCE_FILE_RE = /\.[cm]?[jt]sx?$/;
|
|
339
71
|
function withSentryBuild() {
|
|
340
72
|
return {
|
|
341
73
|
name: "miaoda-devkit:sentry-build",
|
|
342
74
|
enforce: "pre",
|
|
343
75
|
apply: "build",
|
|
344
76
|
resolveId(id) {
|
|
345
|
-
if (id ===
|
|
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
|
-
}
|
|
77
|
+
if (id === SENTRY_MODULE2) return STUB_PATH2;
|
|
358
78
|
return null;
|
|
359
79
|
}
|
|
360
80
|
};
|
|
@@ -421,21 +141,92 @@ function hmrTogglePlugin() {
|
|
|
421
141
|
// src/vite/extractRouterPlugin/index.ts
|
|
422
142
|
var import_path3 = __toESM(require("path"), 1);
|
|
423
143
|
|
|
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
|
+
|
|
424
215
|
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
425
|
-
var
|
|
216
|
+
var t2 = __toESM(require("@babel/types"), 1);
|
|
426
217
|
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
427
218
|
const dfs = (el, map) => {
|
|
428
219
|
const nameNode = el.openingElement.name;
|
|
429
|
-
if (
|
|
220
|
+
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
430
221
|
for (const child of el.children) {
|
|
431
|
-
if (
|
|
222
|
+
if (t2.isJSXElement(child)) {
|
|
432
223
|
const found = dfs(child, map);
|
|
433
224
|
if (found) return found;
|
|
434
225
|
}
|
|
435
226
|
}
|
|
436
227
|
return "";
|
|
437
228
|
};
|
|
438
|
-
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (
|
|
229
|
+
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
439
230
|
};
|
|
440
231
|
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
441
232
|
for (let i = 0; i < tree.length; i++) {
|
|
@@ -465,7 +256,7 @@ var flattenRouteTree = (routes) => {
|
|
|
465
256
|
};
|
|
466
257
|
|
|
467
258
|
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
468
|
-
var
|
|
259
|
+
var t3 = __toESM(require("@babel/types"), 1);
|
|
469
260
|
var import_fs2 = __toESM(require("fs"), 1);
|
|
470
261
|
var import_path2 = __toESM(require("path"), 1);
|
|
471
262
|
|
|
@@ -565,7 +356,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
565
356
|
const declaration = nodePath.get("declaration");
|
|
566
357
|
if (declaration.isVariableDeclaration()) {
|
|
567
358
|
for (const dec of declaration.node.declarations) {
|
|
568
|
-
if (
|
|
359
|
+
if (t3.isIdentifier(dec.id) && dec.id.name === exportName) {
|
|
569
360
|
exportBinding = nodePath.scope.getBinding(dec.id.name);
|
|
570
361
|
exportNodePath = nodePath;
|
|
571
362
|
break;
|
|
@@ -573,7 +364,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
573
364
|
}
|
|
574
365
|
}
|
|
575
366
|
for (const specifier of nodePath.node.specifiers) {
|
|
576
|
-
if (
|
|
367
|
+
if (t3.isExportSpecifier(specifier) && specifier.local.name === exportName) {
|
|
577
368
|
exportBinding = nodePath.scope.getBinding(specifier.local.name);
|
|
578
369
|
exportNodePath = nodePath;
|
|
579
370
|
break;
|
|
@@ -624,7 +415,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
624
415
|
};
|
|
625
416
|
var resolveModuleBinding = async (binding, currentFilePath, option, context, parentPath) => {
|
|
626
417
|
const importDeclaration = binding.path.parent;
|
|
627
|
-
if (!
|
|
418
|
+
if (!t3.isImportDeclaration(importDeclaration)) return null;
|
|
628
419
|
const importPath = resolveAlias(importDeclaration.source.value, option.aliasMap);
|
|
629
420
|
const absolutePath = import_path2.default.resolve(import_path2.default.dirname(currentFilePath), importPath);
|
|
630
421
|
const resolvedPath = await resolveFilePath(absolutePath);
|
|
@@ -632,7 +423,7 @@ var resolveModuleBinding = async (binding, currentFilePath, option, context, par
|
|
|
632
423
|
let exportName = null;
|
|
633
424
|
if (binding.path.isImportSpecifier()) {
|
|
634
425
|
const imp = binding.path.node;
|
|
635
|
-
exportName =
|
|
426
|
+
exportName = t3.isIdentifier(imp.imported) ? imp.imported.name : null;
|
|
636
427
|
}
|
|
637
428
|
return resolveFromFile(resolvedPath, exportName, option, context, parentPath);
|
|
638
429
|
};
|
|
@@ -666,11 +457,11 @@ var resolveCallInit = async (init, binding, option, currentFilePath, context, pa
|
|
|
666
457
|
}
|
|
667
458
|
if (body.isBlockStatement()) {
|
|
668
459
|
for (const stmt of body.node.body) {
|
|
669
|
-
if (!
|
|
670
|
-
if (
|
|
460
|
+
if (!t3.isReturnStatement(stmt) || !stmt.argument) continue;
|
|
461
|
+
if (t3.isArrayExpression(stmt.argument)) {
|
|
671
462
|
return resolveArrayExpression(stmt.argument, currentFilePath, context, option, parentPath);
|
|
672
463
|
}
|
|
673
|
-
if (
|
|
464
|
+
if (t3.isIdentifier(stmt.argument)) {
|
|
674
465
|
const refBinding = binding.scope.getBinding(stmt.argument.name);
|
|
675
466
|
if (refBinding) return resolveImportedValue(refBinding, currentFilePath, option, context, parentPath);
|
|
676
467
|
}
|
|
@@ -701,10 +492,10 @@ var resolveParamBinding = async (binding, currentFilePath, option, context) => {
|
|
|
701
492
|
const functionPath = binding.path.getFunctionParent();
|
|
702
493
|
if (!functionPath) return null;
|
|
703
494
|
const node = functionPath.node;
|
|
704
|
-
const functionName =
|
|
495
|
+
const functionName = t3.isFunctionDeclaration(node) ? node.id?.name : t3.isVariableDeclarator(functionPath.parent) && t3.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
|
|
705
496
|
if (!functionName) return null;
|
|
706
497
|
const paramIndex = functionPath.node.params.findIndex(
|
|
707
|
-
(param) =>
|
|
498
|
+
(param) => t3.isIdentifier(param) && param.name === binding.identifier.name
|
|
708
499
|
);
|
|
709
500
|
if (paramIndex < 0) return null;
|
|
710
501
|
const programPath = functionPath.findParent((p) => p.isProgram());
|
|
@@ -737,8 +528,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
737
528
|
const spreadRoutes = [];
|
|
738
529
|
for (const element of arrayExpression.elements) {
|
|
739
530
|
if (!element) continue;
|
|
740
|
-
if (
|
|
741
|
-
if (
|
|
531
|
+
if (t3.isSpreadElement(element)) {
|
|
532
|
+
if (t3.isIdentifier(element.argument)) {
|
|
742
533
|
const binding = context.scope.getBinding(element.argument.name);
|
|
743
534
|
if (binding) {
|
|
744
535
|
const value = await resolveImportedValue(binding, currentFilePath, option, context, parentPath);
|
|
@@ -747,20 +538,20 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
747
538
|
}
|
|
748
539
|
continue;
|
|
749
540
|
}
|
|
750
|
-
if (!
|
|
541
|
+
if (!t3.isObjectExpression(element)) continue;
|
|
751
542
|
const obj = {};
|
|
752
543
|
for (const property of element.properties) {
|
|
753
|
-
if (!
|
|
754
|
-
const key =
|
|
544
|
+
if (!t3.isObjectProperty(property)) continue;
|
|
545
|
+
const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
|
|
755
546
|
if (!key || !["path", "name", "title", "children"].includes(key)) continue;
|
|
756
|
-
if (
|
|
547
|
+
if (t3.isStringLiteral(property.value)) {
|
|
757
548
|
obj[key] = property.value.value;
|
|
758
|
-
} else if (
|
|
549
|
+
} else if (t3.isIdentifier(property.value)) {
|
|
759
550
|
const propBinding = context.scope.getBinding(property.value.name);
|
|
760
551
|
if (propBinding) {
|
|
761
552
|
obj[key] = await resolveImportedValue(propBinding, currentFilePath, option, context);
|
|
762
553
|
}
|
|
763
|
-
} else if (parentPath &&
|
|
554
|
+
} else if (parentPath && t3.isArrayExpression(property.value) && key === "children") {
|
|
764
555
|
const rawPath = obj.path;
|
|
765
556
|
const currentPath = rawPath ? rawPath.startsWith("/") ? rawPath : joinPaths(parentPath, rawPath) : parentPath;
|
|
766
557
|
const trimmedPath = currentPath?.replace(/\*+$/g, "").replace(/\/+$/g, "");
|
|
@@ -780,11 +571,11 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
780
571
|
return [...spreadRoutes, ...flattenRouteTree(result)];
|
|
781
572
|
};
|
|
782
573
|
var resolveExpressionValue = async (nodePath, expression, id, option) => {
|
|
783
|
-
if (
|
|
784
|
-
if (
|
|
574
|
+
if (t3.isStringLiteral(expression)) return expression.value;
|
|
575
|
+
if (t3.isTemplateLiteral(expression) && expression.expressions.length === 0) {
|
|
785
576
|
return expression.quasis[0].value.raw;
|
|
786
577
|
}
|
|
787
|
-
if (
|
|
578
|
+
if (t3.isIdentifier(expression)) {
|
|
788
579
|
const binding = nodePath.scope.getBinding(expression.name);
|
|
789
580
|
const value = await resolveImportedValue(binding, id, option, nodePath);
|
|
790
581
|
return typeof value === "string" ? value : null;
|
|
@@ -977,7 +768,7 @@ var resolveAllRoute = async (code, id, option, outWildcardMounts) => {
|
|
|
977
768
|
};
|
|
978
769
|
|
|
979
770
|
// src/vite/extractRouterPlugin/hooksParser.ts
|
|
980
|
-
var
|
|
771
|
+
var t4 = __toESM(require("@babel/types"), 1);
|
|
981
772
|
var resolveHooksRoute = async (code, id, option) => {
|
|
982
773
|
try {
|
|
983
774
|
const ast = parseCode(code, id);
|
|
@@ -988,7 +779,7 @@ var resolveHooksRoute = async (code, id, option) => {
|
|
|
988
779
|
...createImportVisitors(importMap, lazyImportMap),
|
|
989
780
|
CallExpression(nodePath) {
|
|
990
781
|
const callee = nodePath.node.callee;
|
|
991
|
-
if (
|
|
782
|
+
if (t4.isIdentifier(callee) && callee.name === "useRoutes") {
|
|
992
783
|
useRoutesCalls.push(nodePath);
|
|
993
784
|
}
|
|
994
785
|
}
|
package/dist/vite/index.d.cts
CHANGED
|
@@ -9,6 +9,12 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 生产构建使用的 Sentry 替换插件。
|
|
14
|
+
*
|
|
15
|
+
* 只负责在模块解析阶段把 `@sentry/react` 指向 noop stub,不扫描或限制业务代码
|
|
16
|
+
* 使用的 Sentry API,避免监控代码的写法变化阻塞应用发布。
|
|
17
|
+
*/
|
|
12
18
|
declare function withSentryBuild(): Plugin;
|
|
13
19
|
|
|
14
20
|
/**
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ import { Plugin } from 'vite';
|
|
|
9
9
|
|
|
10
10
|
declare function withSentryStub(): Plugin;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* 生产构建使用的 Sentry 替换插件。
|
|
14
|
+
*
|
|
15
|
+
* 只负责在模块解析阶段把 `@sentry/react` 指向 noop stub,不扫描或限制业务代码
|
|
16
|
+
* 使用的 Sentry API,避免监控代码的写法变化阻塞应用发布。
|
|
17
|
+
*/
|
|
12
18
|
declare function withSentryBuild(): Plugin;
|
|
13
19
|
|
|
14
20
|
/**
|
package/dist/vite/index.js
CHANGED
|
@@ -22,296 +22,16 @@ 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
|
|
139
25
|
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";
|
|
293
26
|
var _dirname2 = path2.dirname(fileURLToPath2(import.meta.url));
|
|
294
27
|
var STUB_PATH2 = path2.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
|
|
295
|
-
var SOURCE_FILE_RE = /\.[cm]?[jt]sx?$/;
|
|
296
28
|
function withSentryBuild() {
|
|
297
29
|
return {
|
|
298
30
|
name: "miaoda-devkit:sentry-build",
|
|
299
31
|
enforce: "pre",
|
|
300
32
|
apply: "build",
|
|
301
33
|
resolveId(id) {
|
|
302
|
-
if (id ===
|
|
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
|
-
}
|
|
34
|
+
if (id === SENTRY_MODULE2) return STUB_PATH2;
|
|
315
35
|
return null;
|
|
316
36
|
}
|
|
317
37
|
};
|
|
@@ -378,21 +98,92 @@ function hmrTogglePlugin() {
|
|
|
378
98
|
// src/vite/extractRouterPlugin/index.ts
|
|
379
99
|
import path5 from "path";
|
|
380
100
|
|
|
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
|
+
|
|
381
172
|
// src/vite/extractRouterPlugin/routeTransform.ts
|
|
382
|
-
import * as
|
|
173
|
+
import * as t2 from "@babel/types";
|
|
383
174
|
var findResolvableJSXComponent = (jsxEl, importMap, lazyImportMap) => {
|
|
384
175
|
const dfs = (el, map) => {
|
|
385
176
|
const nameNode = el.openingElement.name;
|
|
386
|
-
if (
|
|
177
|
+
if (t2.isJSXIdentifier(nameNode) && map.has(nameNode.name)) return nameNode.name;
|
|
387
178
|
for (const child of el.children) {
|
|
388
|
-
if (
|
|
179
|
+
if (t2.isJSXElement(child)) {
|
|
389
180
|
const found = dfs(child, map);
|
|
390
181
|
if (found) return found;
|
|
391
182
|
}
|
|
392
183
|
}
|
|
393
184
|
return "";
|
|
394
185
|
};
|
|
395
|
-
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (
|
|
186
|
+
return dfs(jsxEl, lazyImportMap) || dfs(jsxEl, importMap) || (t2.isJSXIdentifier(jsxEl.openingElement.name) ? jsxEl.openingElement.name.name : "");
|
|
396
187
|
};
|
|
397
188
|
var eachTree = (tree, iterator, level = 1, parents = []) => {
|
|
398
189
|
for (let i = 0; i < tree.length; i++) {
|
|
@@ -422,7 +213,7 @@ var flattenRouteTree = (routes) => {
|
|
|
422
213
|
};
|
|
423
214
|
|
|
424
215
|
// src/vite/extractRouterPlugin/valueResolver.ts
|
|
425
|
-
import * as
|
|
216
|
+
import * as t3 from "@babel/types";
|
|
426
217
|
import fs2 from "fs";
|
|
427
218
|
import path4 from "path";
|
|
428
219
|
|
|
@@ -522,7 +313,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
522
313
|
const declaration = nodePath.get("declaration");
|
|
523
314
|
if (declaration.isVariableDeclaration()) {
|
|
524
315
|
for (const dec of declaration.node.declarations) {
|
|
525
|
-
if (
|
|
316
|
+
if (t3.isIdentifier(dec.id) && dec.id.name === exportName) {
|
|
526
317
|
exportBinding = nodePath.scope.getBinding(dec.id.name);
|
|
527
318
|
exportNodePath = nodePath;
|
|
528
319
|
break;
|
|
@@ -530,7 +321,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
530
321
|
}
|
|
531
322
|
}
|
|
532
323
|
for (const specifier of nodePath.node.specifiers) {
|
|
533
|
-
if (
|
|
324
|
+
if (t3.isExportSpecifier(specifier) && specifier.local.name === exportName) {
|
|
534
325
|
exportBinding = nodePath.scope.getBinding(specifier.local.name);
|
|
535
326
|
exportNodePath = nodePath;
|
|
536
327
|
break;
|
|
@@ -581,7 +372,7 @@ var resolveFromFile = async (filePath, exportName, option, context, parentPath,
|
|
|
581
372
|
};
|
|
582
373
|
var resolveModuleBinding = async (binding, currentFilePath, option, context, parentPath) => {
|
|
583
374
|
const importDeclaration = binding.path.parent;
|
|
584
|
-
if (!
|
|
375
|
+
if (!t3.isImportDeclaration(importDeclaration)) return null;
|
|
585
376
|
const importPath = resolveAlias(importDeclaration.source.value, option.aliasMap);
|
|
586
377
|
const absolutePath = path4.resolve(path4.dirname(currentFilePath), importPath);
|
|
587
378
|
const resolvedPath = await resolveFilePath(absolutePath);
|
|
@@ -589,7 +380,7 @@ var resolveModuleBinding = async (binding, currentFilePath, option, context, par
|
|
|
589
380
|
let exportName = null;
|
|
590
381
|
if (binding.path.isImportSpecifier()) {
|
|
591
382
|
const imp = binding.path.node;
|
|
592
|
-
exportName =
|
|
383
|
+
exportName = t3.isIdentifier(imp.imported) ? imp.imported.name : null;
|
|
593
384
|
}
|
|
594
385
|
return resolveFromFile(resolvedPath, exportName, option, context, parentPath);
|
|
595
386
|
};
|
|
@@ -623,11 +414,11 @@ var resolveCallInit = async (init, binding, option, currentFilePath, context, pa
|
|
|
623
414
|
}
|
|
624
415
|
if (body.isBlockStatement()) {
|
|
625
416
|
for (const stmt of body.node.body) {
|
|
626
|
-
if (!
|
|
627
|
-
if (
|
|
417
|
+
if (!t3.isReturnStatement(stmt) || !stmt.argument) continue;
|
|
418
|
+
if (t3.isArrayExpression(stmt.argument)) {
|
|
628
419
|
return resolveArrayExpression(stmt.argument, currentFilePath, context, option, parentPath);
|
|
629
420
|
}
|
|
630
|
-
if (
|
|
421
|
+
if (t3.isIdentifier(stmt.argument)) {
|
|
631
422
|
const refBinding = binding.scope.getBinding(stmt.argument.name);
|
|
632
423
|
if (refBinding) return resolveImportedValue(refBinding, currentFilePath, option, context, parentPath);
|
|
633
424
|
}
|
|
@@ -658,10 +449,10 @@ var resolveParamBinding = async (binding, currentFilePath, option, context) => {
|
|
|
658
449
|
const functionPath = binding.path.getFunctionParent();
|
|
659
450
|
if (!functionPath) return null;
|
|
660
451
|
const node = functionPath.node;
|
|
661
|
-
const functionName =
|
|
452
|
+
const functionName = t3.isFunctionDeclaration(node) ? node.id?.name : t3.isVariableDeclarator(functionPath.parent) && t3.isIdentifier(functionPath.parent.id) ? functionPath.parent.id.name : null;
|
|
662
453
|
if (!functionName) return null;
|
|
663
454
|
const paramIndex = functionPath.node.params.findIndex(
|
|
664
|
-
(param) =>
|
|
455
|
+
(param) => t3.isIdentifier(param) && param.name === binding.identifier.name
|
|
665
456
|
);
|
|
666
457
|
if (paramIndex < 0) return null;
|
|
667
458
|
const programPath = functionPath.findParent((p) => p.isProgram());
|
|
@@ -694,8 +485,8 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
694
485
|
const spreadRoutes = [];
|
|
695
486
|
for (const element of arrayExpression.elements) {
|
|
696
487
|
if (!element) continue;
|
|
697
|
-
if (
|
|
698
|
-
if (
|
|
488
|
+
if (t3.isSpreadElement(element)) {
|
|
489
|
+
if (t3.isIdentifier(element.argument)) {
|
|
699
490
|
const binding = context.scope.getBinding(element.argument.name);
|
|
700
491
|
if (binding) {
|
|
701
492
|
const value = await resolveImportedValue(binding, currentFilePath, option, context, parentPath);
|
|
@@ -704,20 +495,20 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
704
495
|
}
|
|
705
496
|
continue;
|
|
706
497
|
}
|
|
707
|
-
if (!
|
|
498
|
+
if (!t3.isObjectExpression(element)) continue;
|
|
708
499
|
const obj = {};
|
|
709
500
|
for (const property of element.properties) {
|
|
710
|
-
if (!
|
|
711
|
-
const key =
|
|
501
|
+
if (!t3.isObjectProperty(property)) continue;
|
|
502
|
+
const key = t3.isIdentifier(property.key) ? property.key.name : t3.isStringLiteral(property.key) ? property.key.value : null;
|
|
712
503
|
if (!key || !["path", "name", "title", "children"].includes(key)) continue;
|
|
713
|
-
if (
|
|
504
|
+
if (t3.isStringLiteral(property.value)) {
|
|
714
505
|
obj[key] = property.value.value;
|
|
715
|
-
} else if (
|
|
506
|
+
} else if (t3.isIdentifier(property.value)) {
|
|
716
507
|
const propBinding = context.scope.getBinding(property.value.name);
|
|
717
508
|
if (propBinding) {
|
|
718
509
|
obj[key] = await resolveImportedValue(propBinding, currentFilePath, option, context);
|
|
719
510
|
}
|
|
720
|
-
} else if (parentPath &&
|
|
511
|
+
} else if (parentPath && t3.isArrayExpression(property.value) && key === "children") {
|
|
721
512
|
const rawPath = obj.path;
|
|
722
513
|
const currentPath = rawPath ? rawPath.startsWith("/") ? rawPath : joinPaths(parentPath, rawPath) : parentPath;
|
|
723
514
|
const trimmedPath = currentPath?.replace(/\*+$/g, "").replace(/\/+$/g, "");
|
|
@@ -737,11 +528,11 @@ var resolveArrayExpression = async (arrayExpression, currentFilePath, context, o
|
|
|
737
528
|
return [...spreadRoutes, ...flattenRouteTree(result)];
|
|
738
529
|
};
|
|
739
530
|
var resolveExpressionValue = async (nodePath, expression, id, option) => {
|
|
740
|
-
if (
|
|
741
|
-
if (
|
|
531
|
+
if (t3.isStringLiteral(expression)) return expression.value;
|
|
532
|
+
if (t3.isTemplateLiteral(expression) && expression.expressions.length === 0) {
|
|
742
533
|
return expression.quasis[0].value.raw;
|
|
743
534
|
}
|
|
744
|
-
if (
|
|
535
|
+
if (t3.isIdentifier(expression)) {
|
|
745
536
|
const binding = nodePath.scope.getBinding(expression.name);
|
|
746
537
|
const value = await resolveImportedValue(binding, id, option, nodePath);
|
|
747
538
|
return typeof value === "string" ? value : null;
|
|
@@ -934,7 +725,7 @@ var resolveAllRoute = async (code, id, option, outWildcardMounts) => {
|
|
|
934
725
|
};
|
|
935
726
|
|
|
936
727
|
// src/vite/extractRouterPlugin/hooksParser.ts
|
|
937
|
-
import * as
|
|
728
|
+
import * as t4 from "@babel/types";
|
|
938
729
|
var resolveHooksRoute = async (code, id, option) => {
|
|
939
730
|
try {
|
|
940
731
|
const ast = parseCode(code, id);
|
|
@@ -945,7 +736,7 @@ var resolveHooksRoute = async (code, id, option) => {
|
|
|
945
736
|
...createImportVisitors(importMap, lazyImportMap),
|
|
946
737
|
CallExpression(nodePath) {
|
|
947
738
|
const callee = nodePath.node.callee;
|
|
948
|
-
if (
|
|
739
|
+
if (t4.isIdentifier(callee) && callee.name === "useRoutes") {
|
|
949
740
|
useRoutesCalls.push(nodePath);
|
|
950
741
|
}
|
|
951
742
|
}
|