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