@sentry/tanstackstart-react 10.53.1 → 10.55.0
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/README.md +3 -2
- package/build/cjs/client/index.js +5 -26
- package/build/cjs/client/index.js.map +1 -1
- package/build/cjs/client/sdk.js +12 -9
- package/build/cjs/client/sdk.js.map +1 -1
- package/build/cjs/client/tunnelRoute.js +2 -13
- package/build/cjs/client/tunnelRoute.js.map +1 -1
- package/build/cjs/index.server.js +1 -0
- package/build/cjs/index.server.js.map +1 -1
- package/build/cjs/server/globalMiddleware.js +38 -22
- package/build/cjs/server/globalMiddleware.js.map +1 -1
- package/build/cjs/server/index.js +16 -29
- package/build/cjs/server/index.js.map +1 -1
- package/build/cjs/server/middleware.js +10 -66
- package/build/cjs/server/middleware.js.map +1 -1
- package/build/cjs/server/routeParametrization.js +47 -0
- package/build/cjs/server/routeParametrization.js.map +1 -0
- package/build/cjs/server/sdk.js +9 -7
- package/build/cjs/server/sdk.js.map +1 -1
- package/build/cjs/server/tunnelRoute.js +11 -31
- package/build/cjs/server/tunnelRoute.js.map +1 -1
- package/build/cjs/server/utils.js +4 -21
- package/build/cjs/server/utils.js.map +1 -1
- package/build/cjs/server/wrapFetchWithSentry.js +88 -44
- package/build/cjs/server/wrapFetchWithSentry.js.map +1 -1
- package/build/cjs/vite/autoInstrumentMiddleware.js +15 -97
- package/build/cjs/vite/autoInstrumentMiddleware.js.map +1 -1
- package/build/cjs/vite/routePatterns.js +60 -0
- package/build/cjs/vite/routePatterns.js.map +1 -0
- package/build/cjs/vite/sentryTanstackStart.js +8 -44
- package/build/cjs/vite/sentryTanstackStart.js.map +1 -1
- package/build/cjs/vite/sourceMaps.js +34 -75
- package/build/cjs/vite/sourceMaps.js.map +1 -1
- package/build/cjs/vite/tunnelRoute.js +30 -63
- package/build/cjs/vite/tunnelRoute.js.map +1 -1
- package/build/esm/client/index.js +5 -26
- package/build/esm/client/index.js.map +1 -1
- package/build/esm/client/sdk.js +12 -9
- package/build/esm/client/sdk.js.map +1 -1
- package/build/esm/client/tunnelRoute.js +2 -13
- package/build/esm/client/tunnelRoute.js.map +1 -1
- package/build/esm/index.server.js +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/server/globalMiddleware.js +39 -23
- package/build/esm/server/globalMiddleware.js.map +1 -1
- package/build/esm/server/index.js +16 -30
- package/build/esm/server/index.js.map +1 -1
- package/build/esm/server/middleware.js +10 -66
- package/build/esm/server/middleware.js.map +1 -1
- package/build/esm/server/routeParametrization.js +44 -0
- package/build/esm/server/routeParametrization.js.map +1 -0
- package/build/esm/server/sdk.js +9 -7
- package/build/esm/server/sdk.js.map +1 -1
- package/build/esm/server/tunnelRoute.js +11 -31
- package/build/esm/server/tunnelRoute.js.map +1 -1
- package/build/esm/server/utils.js +5 -21
- package/build/esm/server/utils.js.map +1 -1
- package/build/esm/server/wrapFetchWithSentry.js +90 -46
- package/build/esm/server/wrapFetchWithSentry.js.map +1 -1
- package/build/esm/vite/autoInstrumentMiddleware.js +15 -97
- package/build/esm/vite/autoInstrumentMiddleware.js.map +1 -1
- package/build/esm/vite/routePatterns.js +57 -0
- package/build/esm/vite/routePatterns.js.map +1 -0
- package/build/esm/vite/sentryTanstackStart.js +8 -44
- package/build/esm/vite/sentryTanstackStart.js.map +1 -1
- package/build/esm/vite/sourceMaps.js +34 -75
- package/build/esm/vite/sourceMaps.js.map +1 -1
- package/build/esm/vite/tunnelRoute.js +30 -63
- package/build/esm/vite/tunnelRoute.js.map +1 -1
- package/build/types/client/sdk.d.ts.map +1 -1
- package/build/types/index.types.d.ts +1 -0
- package/build/types/index.types.d.ts.map +1 -1
- package/build/types/server/globalMiddleware.d.ts.map +1 -1
- package/build/types/server/index.d.ts +5 -0
- package/build/types/server/index.d.ts.map +1 -1
- package/build/types/server/routeParametrization.d.ts +12 -0
- package/build/types/server/routeParametrization.d.ts.map +1 -0
- package/build/types/server/sdk.d.ts.map +1 -1
- package/build/types/server/utils.d.ts +0 -9
- package/build/types/server/utils.d.ts.map +1 -1
- package/build/types/server/wrapFetchWithSentry.d.ts.map +1 -1
- package/build/types/vite/routePatterns.d.ts +18 -0
- package/build/types/vite/routePatterns.d.ts.map +1 -0
- package/build/types/vite/sentryTanstackStart.d.ts +17 -0
- package/build/types/vite/sentryTanstackStart.d.ts.map +1 -1
- package/build/types/vite/sourceMaps.d.ts +4 -4
- package/build/types/vite/sourceMaps.d.ts.map +1 -1
- package/build/types-ts3.8/index.types.d.ts +1 -0
- package/build/types-ts3.8/server/index.d.ts +5 -0
- package/build/types-ts3.8/server/routeParametrization.d.ts +12 -0
- package/build/types-ts3.8/server/utils.d.ts +0 -9
- package/build/types-ts3.8/vite/routePatterns.d.ts +18 -0
- package/build/types-ts3.8/vite/sentryTanstackStart.d.ts +17 -0
- package/build/types-ts3.8/vite/sourceMaps.d.ts +4 -4
- package/package.json +5 -5
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
function makeRoutePatternPlugin() {
|
|
5
|
+
let resolvedRoot = "";
|
|
6
|
+
return {
|
|
7
|
+
name: "sentry-tanstackstart-route-patterns",
|
|
8
|
+
enforce: "post",
|
|
9
|
+
configResolved(config) {
|
|
10
|
+
resolvedRoot = config.root || process.cwd();
|
|
11
|
+
},
|
|
12
|
+
transform(code, id) {
|
|
13
|
+
if (!code.includes("__SENTRY_ROUTE_PATTERNS__")) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const routeTreePath = path.resolve(resolvedRoot, "src/routeTree.gen.ts");
|
|
17
|
+
let patterns = [];
|
|
18
|
+
try {
|
|
19
|
+
if (fs.existsSync(routeTreePath)) {
|
|
20
|
+
patterns = extractRoutePatterns(fs.readFileSync(routeTreePath, "utf-8"));
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
code: code.replace(/__SENTRY_ROUTE_PATTERNS__/g, JSON.stringify(patterns)),
|
|
26
|
+
map: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function extractRoutePatterns(content) {
|
|
32
|
+
const fullPathsMatch = content.match(/fullPaths:\s*([\s\S]*?)(?:\n\s*\w|\n\})/);
|
|
33
|
+
if (!fullPathsMatch) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const patterns = [];
|
|
37
|
+
const pathRegex = /['"]([^'"]+)['"]/g;
|
|
38
|
+
let match;
|
|
39
|
+
while ((match = pathRegex.exec(fullPathsMatch[1] || "")) !== null) {
|
|
40
|
+
if (match[1]) {
|
|
41
|
+
patterns.push(match[1]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...new Set(patterns)].sort((a, b) => {
|
|
45
|
+
const aSegments = a.split("/");
|
|
46
|
+
const bSegments = b.split("/");
|
|
47
|
+
if (bSegments.length !== aSegments.length) {
|
|
48
|
+
return bSegments.length - aSegments.length;
|
|
49
|
+
}
|
|
50
|
+
const aDynamic = aSegments.filter((s) => s.startsWith("$")).length;
|
|
51
|
+
const bDynamic = bSegments.filter((s) => s.startsWith("$")).length;
|
|
52
|
+
return aDynamic - bDynamic;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { extractRoutePatterns, makeRoutePatternPlugin };
|
|
57
|
+
//# sourceMappingURL=routePatterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routePatterns.js","sources":["../../../src/vite/routePatterns.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type { Plugin } from 'vite';\n\n/**\n * Extracts route patterns from TanStack Start's generated routeTree.gen.ts\n * and replaces `__SENTRY_ROUTE_PATTERNS__` references with the extracted patterns.\n *\n * The route tree file is read during `transform` rather than `config` because\n * TanStack Start generates it during the build.\n */\nexport function makeRoutePatternPlugin(): Plugin {\n let resolvedRoot = '';\n\n return {\n name: 'sentry-tanstackstart-route-patterns',\n enforce: 'post',\n\n configResolved(config) {\n resolvedRoot = config.root || process.cwd();\n },\n\n transform(code, id) {\n // this is set in the `wrapFetchWithSentry` where the paths are getting replaced by their parametrized counterparts\n // so this extraction should only happen once during the build (for the `wrapFetchWithSentry` file)\n if (!code.includes('__SENTRY_ROUTE_PATTERNS__')) {\n return null;\n }\n\n // extract the patterns from the route tree file\n const routeTreePath = path.resolve(resolvedRoot, 'src/routeTree.gen.ts');\n let patterns: string[] = [];\n try {\n if (fs.existsSync(routeTreePath)) {\n patterns = extractRoutePatterns(fs.readFileSync(routeTreePath, 'utf-8'));\n }\n } catch {\n // skip\n }\n\n return {\n code: code.replace(/__SENTRY_ROUTE_PATTERNS__/g, JSON.stringify(patterns)),\n map: null,\n };\n },\n };\n}\n\n/**\n * Extracts full route path patterns from the content of routeTree.gen.ts.\n *\n * Parses the `fullPaths` type union which contains the resolved full paths\n * (e.g., `fullPaths: '/' | '/page-a' | '/users/$userId'`).\n * This is more reliable than `path:` properties which can be relative for nested routes.\n */\nexport function extractRoutePatterns(content: string): string[] {\n const fullPathsMatch = content.match(/fullPaths:\\s*([\\s\\S]*?)(?:\\n\\s*\\w|\\n\\})/);\n if (!fullPathsMatch) {\n return [];\n }\n\n const patterns: string[] = [];\n const pathRegex = /['\"]([^'\"]+)['\"]/g;\n let match;\n while ((match = pathRegex.exec(fullPathsMatch[1] || '')) !== null) {\n if (match[1]) {\n patterns.push(match[1]);\n }\n }\n\n return [...new Set(patterns)].sort((a, b) => {\n const aSegments = a.split('/');\n const bSegments = b.split('/');\n if (bSegments.length !== aSegments.length) {\n return bSegments.length - aSegments.length;\n }\n const aDynamic = aSegments.filter(s => s.startsWith('$')).length;\n const bDynamic = bSegments.filter(s => s.startsWith('$')).length;\n return aDynamic - bDynamic;\n });\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,sBAAA,GAAiC;AAC/C,EAAA,IAAI,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IAAK,EAAE,OAAO,IAAA,EAAM;AACjE,IAAA,IAAI,KAAA,CAAM,CAAC,CAAA,EAAG;AACZ,MAAA,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AAAA,IACxB;AAAA,EACF;AAEA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,QAAQ,CAAC,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM;AAC3C,IAAA,MAAM,SAAA,GAAY,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA;AAC7B,IAAA,MAAM,SAAA,GAAY,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA;AAC7B,IAAA,IAAI,SAAA,CAAU,MAAA,KAAW,SAAA,CAAU,MAAA,EAAQ;AACzC,MAAA,OAAO,SAAA,CAAU,SAAS,SAAA,CAAU,MAAA;AAAA,IACtC;AACA,IAAA,MAAM,QAAA,GAAW,UAAU,MAAA,CAAO,CAAA,CAAA,KAAK,EAAE,UAAA,CAAW,GAAG,CAAC,CAAA,CAAE,MAAA;AAC1D,IAAA,MAAM,QAAA,GAAW,UAAU,MAAA,CAAO,CAAA,CAAA,KAAK,EAAE,UAAA,CAAW,GAAG,CAAC,CAAA,CAAE,MAAA;AAC1D,IAAA,OAAO,QAAA,GAAW,QAAA;AAAA,EACpB,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,60 +1,24 @@
|
|
|
1
1
|
import { makeAutoInstrumentMiddlewarePlugin } from './autoInstrumentMiddleware.js';
|
|
2
|
+
import { makeRoutePatternPlugin } from './routePatterns.js';
|
|
2
3
|
import { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps.js';
|
|
3
4
|
import { makeTunnelRoutePlugin } from './tunnelRoute.js';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Build-time options for the Sentry TanStack Start SDK.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Vite plugins for the Sentry TanStack Start SDK.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // vite.config.ts
|
|
15
|
-
* import { defineConfig } from 'vite';
|
|
16
|
-
* import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite';
|
|
17
|
-
* import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
18
|
-
*
|
|
19
|
-
* export default defineConfig({
|
|
20
|
-
* plugins: [
|
|
21
|
-
* tanstackStart(),
|
|
22
|
-
* sentryTanstackStart({
|
|
23
|
-
* org: 'your-org',
|
|
24
|
-
* project: 'your-project',
|
|
25
|
-
* }),
|
|
26
|
-
* ],
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param options - Options to configure the Sentry Vite plugins
|
|
31
|
-
* @returns An array of Vite plugins
|
|
32
|
-
*/
|
|
33
6
|
function sentryTanstackStart(options = {}) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (process.env.NODE_ENV === 'development') {
|
|
38
|
-
return tunnelRoutePlugin ? [tunnelRoutePlugin] : [];
|
|
7
|
+
const plugins = [makeRoutePatternPlugin()];
|
|
8
|
+
if (options.tunnelRoute) {
|
|
9
|
+
plugins.push(makeTunnelRoutePlugin(options.tunnelRoute, options.debug));
|
|
39
10
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (tunnelRoutePlugin) {
|
|
44
|
-
plugins.push(tunnelRoutePlugin);
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
return plugins;
|
|
45
13
|
}
|
|
46
|
-
|
|
47
|
-
// middleware auto-instrumentation
|
|
14
|
+
plugins.push(...makeAddSentryVitePlugin(options));
|
|
48
15
|
if (options.autoInstrumentMiddleware !== false) {
|
|
49
16
|
plugins.push(makeAutoInstrumentMiddlewarePlugin({ enabled: true, debug: options.debug }));
|
|
50
17
|
}
|
|
51
|
-
|
|
52
|
-
// source maps
|
|
53
|
-
const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === 'disable-upload';
|
|
18
|
+
const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === "disable-upload";
|
|
54
19
|
if (!sourceMapsDisabled) {
|
|
55
20
|
plugins.push(...makeEnableSourceMapsVitePlugin(options));
|
|
56
21
|
}
|
|
57
|
-
|
|
58
22
|
return plugins;
|
|
59
23
|
}
|
|
60
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryTanstackStart.js","sources":["../../../src/vite/sentryTanstackStart.ts"],"sourcesContent":["import type { BuildTimeOptionsBase } from '@sentry/core';\nimport type { Plugin } from 'vite';\nimport { makeAutoInstrumentMiddlewarePlugin } from './autoInstrumentMiddleware';\nimport { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps';\nimport type { TunnelRouteOptions } from './tunnelRoute';\nimport { makeTunnelRoutePlugin } from './tunnelRoute';\n\n/**\n * Build-time options for the Sentry TanStack Start SDK.\n */\nexport interface SentryTanstackStartOptions extends BuildTimeOptionsBase {\n /**\n * If this flag is `true`, the Sentry plugins will automatically instrument TanStack Start middlewares.\n *\n * This wraps global middlewares (`requestMiddleware` and `functionMiddleware`) in `createStart()` with Sentry\n * instrumentation to capture performance data.\n *\n * Set to `false` to disable automatic middleware instrumentation if you prefer to wrap middlewares manually\n * using `wrapMiddlewaresWithSentry`.\n *\n * @default true\n */\n autoInstrumentMiddleware?: boolean;\n\n /**\n * Configures a framework-managed same-origin tunnel route for Sentry envelopes.\n *\n * This creates a TanStack Start server route backed by `createSentryTunnelRoute()` and applies the resulting path\n * as the default `tunnel` option on the client.\n *\n * You can pass:\n * - `true` to generate an opaque route path per dev session or production build.\n * - `'/custom-path'` to use a fixed static route path.\n * - `{ allowedDsns, path }` for full control. If `allowedDsns` is omitted or empty, the tunnel route derives the DSN\n * from the active server Sentry client at runtime.\n *\n * If you also pass `tunnel` to `Sentry.init()`, that explicit runtime option wins and a warning is emitted because\n * the managed tunnel route is being bypassed.\n */\n tunnelRoute?: TunnelRouteOptions;\n}\n\n/**\n * Vite plugins for the Sentry TanStack Start SDK.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite';\n * import { tanstackStart } from '@tanstack/react-start/plugin/vite';\n *\n * export default defineConfig({\n * plugins: [\n * tanstackStart(),\n * sentryTanstackStart({\n * org: 'your-org',\n * project: 'your-project',\n * }),\n * ],\n * });\n * ```\n *\n * @param options - Options to configure the Sentry Vite plugins\n * @returns An array of Vite plugins\n */\nexport function sentryTanstackStart(options: SentryTanstackStartOptions = {}): Plugin[] {\n const
|
|
1
|
+
{"version":3,"file":"sentryTanstackStart.js","sources":["../../../src/vite/sentryTanstackStart.ts"],"sourcesContent":["import type { BuildTimeOptionsBase } from '@sentry/core';\nimport type { Plugin } from 'vite';\nimport { makeAutoInstrumentMiddlewarePlugin } from './autoInstrumentMiddleware';\nimport { makeRoutePatternPlugin } from './routePatterns';\nimport { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps';\nimport type { TunnelRouteOptions } from './tunnelRoute';\nimport { makeTunnelRoutePlugin } from './tunnelRoute';\n\n/**\n * Build-time options for the Sentry TanStack Start SDK.\n */\nexport interface SentryTanstackStartOptions extends BuildTimeOptionsBase {\n /**\n * If this flag is `true`, the Sentry plugins will automatically instrument TanStack Start middlewares.\n *\n * This wraps global middlewares (`requestMiddleware` and `functionMiddleware`) in `createStart()` with Sentry\n * instrumentation to capture performance data.\n *\n * Set to `false` to disable automatic middleware instrumentation if you prefer to wrap middlewares manually\n * using `wrapMiddlewaresWithSentry`.\n *\n * @default true\n */\n autoInstrumentMiddleware?: boolean;\n\n /**\n * Options related to react component name annotations.\n * Disabled by default, unless a value is set for this option.\n * When enabled, your app's DOM will automatically be annotated during build-time with their respective component names.\n * This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring.\n * Please note that this feature is not currently supported by the esbuild bundler plugins, and will only annotate React components\n */\n reactComponentAnnotation?: {\n /**\n * Whether the component name annotate plugin should be enabled or not.\n */\n enabled?: boolean;\n\n /**\n * A list of strings representing the names of components to ignore. The plugin will not apply `data-sentry` annotations on the DOM element for these components.\n */\n ignoredComponents?: string[];\n };\n\n /**\n * Configures a framework-managed same-origin tunnel route for Sentry envelopes.\n *\n * This creates a TanStack Start server route backed by `createSentryTunnelRoute()` and applies the resulting path\n * as the default `tunnel` option on the client.\n *\n * You can pass:\n * - `true` to generate an opaque route path per dev session or production build.\n * - `'/custom-path'` to use a fixed static route path.\n * - `{ allowedDsns, path }` for full control. If `allowedDsns` is omitted or empty, the tunnel route derives the DSN\n * from the active server Sentry client at runtime.\n *\n * If you also pass `tunnel` to `Sentry.init()`, that explicit runtime option wins and a warning is emitted because\n * the managed tunnel route is being bypassed.\n */\n tunnelRoute?: TunnelRouteOptions;\n}\n\n/**\n * Vite plugins for the Sentry TanStack Start SDK.\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite';\n * import { tanstackStart } from '@tanstack/react-start/plugin/vite';\n *\n * export default defineConfig({\n * plugins: [\n * tanstackStart(),\n * sentryTanstackStart({\n * org: 'your-org',\n * project: 'your-project',\n * }),\n * ],\n * });\n * ```\n *\n * @param options - Options to configure the Sentry Vite plugins\n * @returns An array of Vite plugins\n */\nexport function sentryTanstackStart(options: SentryTanstackStartOptions = {}): Plugin[] {\n const plugins: Plugin[] = [makeRoutePatternPlugin()];\n\n if (options.tunnelRoute) {\n plugins.push(makeTunnelRoutePlugin(options.tunnelRoute, options.debug));\n }\n\n // only add build-time plugins in production builds\n if (process.env.NODE_ENV === 'development') {\n return plugins;\n }\n\n plugins.push(...makeAddSentryVitePlugin(options));\n\n // middleware auto-instrumentation\n if (options.autoInstrumentMiddleware !== false) {\n plugins.push(makeAutoInstrumentMiddlewarePlugin({ enabled: true, debug: options.debug }));\n }\n\n // source maps\n const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === 'disable-upload';\n if (!sourceMapsDisabled) {\n plugins.push(...makeEnableSourceMapsVitePlugin(options));\n }\n\n return plugins;\n}\n"],"names":[],"mappings":";;;;;AAsFO,SAAS,mBAAA,CAAoB,OAAA,GAAsC,EAAC,EAAa;AACtF,EAAA,MAAM,OAAA,GAAoB,CAAC,sBAAA,EAAwB,CAAA;AAEnD,EAAA,IAAI,QAAQ,WAAA,EAAa;AACvB,IAAA,OAAA,CAAQ,KAAK,qBAAA,CAAsB,OAAA,CAAQ,WAAA,EAAa,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EACxE;AAGA,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,aAAA,EAAe;AAC1C,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,OAAA,CAAQ,IAAA,CAAK,GAAG,uBAAA,CAAwB,OAAO,CAAC,CAAA;AAGhD,EAAA,IAAI,OAAA,CAAQ,6BAA6B,KAAA,EAAO;AAC9C,IAAA,OAAA,CAAQ,IAAA,CAAK,mCAAmC,EAAE,OAAA,EAAS,MAAM,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAO,CAAC,CAAA;AAAA,EAC1F;AAGA,EAAA,MAAM,qBAAqB,OAAA,CAAQ,UAAA,EAAY,YAAY,IAAA,IAAQ,OAAA,CAAQ,YAAY,OAAA,KAAY,gBAAA;AACnG,EAAA,IAAI,CAAC,kBAAA,EAAoB;AACvB,IAAA,OAAA,CAAQ,IAAA,CAAK,GAAG,8BAAA,CAA+B,OAAO,CAAC,CAAA;AAAA,EACzD;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { sentryVitePlugin } from '@sentry/vite-plugin';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* A Sentry plugin for adding the @sentry/vite-plugin to automatically upload source maps to Sentry.
|
|
5
|
-
*/
|
|
6
3
|
function makeAddSentryVitePlugin(options) {
|
|
7
4
|
const {
|
|
8
5
|
applicationKey,
|
|
@@ -18,40 +15,34 @@ function makeAddSentryVitePlugin(options) {
|
|
|
18
15
|
silent,
|
|
19
16
|
sourcemaps,
|
|
20
17
|
telemetry,
|
|
18
|
+
reactComponentAnnotation
|
|
21
19
|
} = options;
|
|
22
|
-
|
|
23
|
-
// defer resolving the filesToDeleteAfterUpload until we got access to the Vite config
|
|
24
20
|
let resolveFilesToDeleteAfterUpload;
|
|
25
|
-
const filesToDeleteAfterUploadPromise = new Promise(resolve => {
|
|
21
|
+
const filesToDeleteAfterUploadPromise = new Promise((resolve) => {
|
|
26
22
|
resolveFilesToDeleteAfterUpload = resolve;
|
|
27
23
|
});
|
|
28
|
-
|
|
29
24
|
const configPlugin = {
|
|
30
|
-
name:
|
|
31
|
-
apply:
|
|
32
|
-
enforce:
|
|
25
|
+
name: "sentry-tanstackstart-files-to-delete-after-upload-plugin",
|
|
26
|
+
apply: "build",
|
|
27
|
+
enforce: "post",
|
|
33
28
|
config(config) {
|
|
34
29
|
const userFilesToDelete = sourcemaps?.filesToDeleteAfterUpload;
|
|
35
|
-
|
|
36
|
-
// Only auto-delete source maps if the user didn't configure sourcemaps at all
|
|
37
|
-
if (typeof userFilesToDelete === 'undefined' && typeof config.build?.sourcemap === 'undefined') {
|
|
30
|
+
if (typeof userFilesToDelete === "undefined" && typeof config.build?.sourcemap === "undefined") {
|
|
38
31
|
if (debug) {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
32
|
console.log(
|
|
41
|
-
'[Sentry] Automatically setting `sourcemaps.filesToDeleteAfterUpload: ["./**/*.map"]` to delete generated source maps after they were uploaded to Sentry.'
|
|
33
|
+
'[Sentry] Automatically setting `sourcemaps.filesToDeleteAfterUpload: ["./**/*.map"]` to delete generated source maps after they were uploaded to Sentry.'
|
|
42
34
|
);
|
|
43
35
|
}
|
|
44
|
-
resolveFilesToDeleteAfterUpload?.([
|
|
36
|
+
resolveFilesToDeleteAfterUpload?.(["./**/*.map"]);
|
|
45
37
|
} else {
|
|
46
38
|
resolveFilesToDeleteAfterUpload?.(userFilesToDelete);
|
|
47
39
|
}
|
|
48
|
-
}
|
|
40
|
+
}
|
|
49
41
|
};
|
|
50
|
-
|
|
51
42
|
const sentryPlugins = sentryVitePlugin({
|
|
52
43
|
applicationKey,
|
|
53
44
|
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
|
|
54
|
-
bundleSizeOptimizations: bundleSizeOptimizations ??
|
|
45
|
+
bundleSizeOptimizations: bundleSizeOptimizations ?? void 0,
|
|
55
46
|
debug: debug ?? false,
|
|
56
47
|
errorHandler,
|
|
57
48
|
headers,
|
|
@@ -65,101 +56,69 @@ function makeAddSentryVitePlugin(options) {
|
|
|
65
56
|
ignore: sourcemaps?.ignore,
|
|
66
57
|
// BuildTimeOptionsBase types can lag behind bundler plugin options in some local setups.
|
|
67
58
|
// Keep runtime support while staying resilient to type version skew.
|
|
68
|
-
rewriteSources:
|
|
69
|
-
filesToDeleteAfterUpload: filesToDeleteAfterUploadPromise
|
|
59
|
+
rewriteSources: sourcemaps?.rewriteSources,
|
|
60
|
+
filesToDeleteAfterUpload: filesToDeleteAfterUploadPromise
|
|
61
|
+
},
|
|
62
|
+
reactComponentAnnotation: {
|
|
63
|
+
enabled: reactComponentAnnotation?.enabled ?? void 0,
|
|
64
|
+
ignoredComponents: reactComponentAnnotation?.ignoredComponents ?? void 0
|
|
70
65
|
},
|
|
71
66
|
telemetry: telemetry ?? true,
|
|
72
67
|
url: sentryUrl,
|
|
73
68
|
_metaOptions: {
|
|
74
69
|
telemetry: {
|
|
75
|
-
metaFramework:
|
|
76
|
-
}
|
|
77
|
-
}
|
|
70
|
+
metaFramework: "tanstackstart-react"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
78
73
|
});
|
|
79
|
-
|
|
80
74
|
return [configPlugin, ...sentryPlugins];
|
|
81
75
|
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A Sentry plugin for TanStack Start React to enable "hidden" source maps if they are unset.
|
|
85
|
-
*/
|
|
86
76
|
function makeEnableSourceMapsVitePlugin(options) {
|
|
87
77
|
return [
|
|
88
78
|
{
|
|
89
|
-
name:
|
|
90
|
-
apply:
|
|
91
|
-
enforce:
|
|
79
|
+
name: "sentry-tanstackstart-react-source-maps",
|
|
80
|
+
apply: "build",
|
|
81
|
+
enforce: "post",
|
|
92
82
|
config(viteConfig) {
|
|
93
83
|
return {
|
|
94
84
|
...viteConfig,
|
|
95
85
|
build: {
|
|
96
86
|
...viteConfig.build,
|
|
97
|
-
sourcemap: getUpdatedSourceMapSettings(viteConfig, options)
|
|
98
|
-
}
|
|
87
|
+
sourcemap: getUpdatedSourceMapSettings(viteConfig, options)
|
|
88
|
+
}
|
|
99
89
|
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
102
92
|
];
|
|
103
93
|
}
|
|
104
|
-
|
|
105
|
-
/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-javascript/issues/13993)
|
|
106
|
-
*
|
|
107
|
-
* 1. User explicitly disabled source maps
|
|
108
|
-
* - keep this setting (emit a warning that errors won't be unminified in Sentry)
|
|
109
|
-
* - We won't upload anything
|
|
110
|
-
*
|
|
111
|
-
* 2. Users enabled source map generation (true, 'hidden', 'inline').
|
|
112
|
-
* - keep this setting (don't do anything - like deletion - besides uploading)
|
|
113
|
-
*
|
|
114
|
-
* 3. Users didn't set source maps generation
|
|
115
|
-
* - we enable 'hidden' source maps generation
|
|
116
|
-
* - configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this)
|
|
117
|
-
*
|
|
118
|
-
* --> only exported for testing
|
|
119
|
-
*/
|
|
120
|
-
function getUpdatedSourceMapSettings(
|
|
121
|
-
viteConfig,
|
|
122
|
-
sentryPluginOptions,
|
|
123
|
-
) {
|
|
94
|
+
function getUpdatedSourceMapSettings(viteConfig, sentryPluginOptions) {
|
|
124
95
|
viteConfig.build = viteConfig.build || {};
|
|
125
|
-
|
|
126
96
|
const viteUserSourceMapSetting = viteConfig.build?.sourcemap;
|
|
127
|
-
const settingKey =
|
|
97
|
+
const settingKey = "vite.build.sourcemap";
|
|
128
98
|
const debug = sentryPluginOptions?.debug;
|
|
129
|
-
|
|
130
|
-
// Respect user source map setting if it is explicitly set
|
|
131
99
|
if (viteUserSourceMapSetting === false) {
|
|
132
100
|
if (debug) {
|
|
133
|
-
// eslint-disable-next-line no-console
|
|
134
101
|
console.warn(
|
|
135
|
-
`[Sentry] Source map generation is currently disabled in your TanStack Start configuration (\`${settingKey}: false\`). Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified
|
|
102
|
+
`[Sentry] Source map generation is currently disabled in your TanStack Start configuration (\`${settingKey}: false\`). Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified.`
|
|
136
103
|
);
|
|
137
104
|
} else {
|
|
138
|
-
|
|
139
|
-
console.warn('[Sentry] Source map generation is disabled in your TanStack Start configuration.');
|
|
105
|
+
console.warn("[Sentry] Source map generation is disabled in your TanStack Start configuration.");
|
|
140
106
|
}
|
|
141
|
-
|
|
142
107
|
return viteUserSourceMapSetting;
|
|
143
|
-
} else if (viteUserSourceMapSetting && [
|
|
108
|
+
} else if (viteUserSourceMapSetting && ["hidden", "inline", true].includes(viteUserSourceMapSetting)) {
|
|
144
109
|
if (debug) {
|
|
145
|
-
// eslint-disable-next-line no-console
|
|
146
110
|
console.log(
|
|
147
|
-
`[Sentry] We discovered \`${settingKey}\` is set to \`${viteUserSourceMapSetting.toString()}\`. Sentry will keep this source map setting
|
|
111
|
+
`[Sentry] We discovered \`${settingKey}\` is set to \`${viteUserSourceMapSetting.toString()}\`. Sentry will keep this source map setting.`
|
|
148
112
|
);
|
|
149
113
|
}
|
|
150
|
-
|
|
151
114
|
return viteUserSourceMapSetting;
|
|
152
115
|
}
|
|
153
|
-
|
|
154
|
-
// If the user did not specify a source map setting, we enable 'hidden' by default
|
|
155
116
|
if (debug) {
|
|
156
|
-
// eslint-disable-next-line no-console
|
|
157
117
|
console.log(
|
|
158
|
-
`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry
|
|
118
|
+
`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`
|
|
159
119
|
);
|
|
160
120
|
}
|
|
161
|
-
|
|
162
|
-
return 'hidden';
|
|
121
|
+
return "hidden";
|
|
163
122
|
}
|
|
164
123
|
|
|
165
124
|
export { getUpdatedSourceMapSettings, makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceMaps.js","sources":["../../../src/vite/sourceMaps.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"sourceMaps.js","sources":["../../../src/vite/sourceMaps.ts"],"sourcesContent":["import { sentryVitePlugin } from '@sentry/vite-plugin';\nimport type { Plugin, UserConfig } from 'vite';\nimport type { SentryTanstackStartOptions } from './sentryTanstackStart';\n\ntype FilesToDeleteAfterUpload = string | string[] | undefined;\n\n/**\n * A Sentry plugin for adding the @sentry/vite-plugin to automatically upload source maps to Sentry.\n */\nexport function makeAddSentryVitePlugin(options: SentryTanstackStartOptions): Plugin[] {\n const {\n applicationKey,\n authToken,\n bundleSizeOptimizations,\n debug,\n errorHandler,\n headers,\n org,\n project,\n release,\n sentryUrl,\n silent,\n sourcemaps,\n telemetry,\n reactComponentAnnotation,\n } = options;\n\n // defer resolving the filesToDeleteAfterUpload until we got access to the Vite config\n let resolveFilesToDeleteAfterUpload: ((value: FilesToDeleteAfterUpload) => void) | undefined;\n const filesToDeleteAfterUploadPromise = new Promise<FilesToDeleteAfterUpload>(resolve => {\n resolveFilesToDeleteAfterUpload = resolve;\n });\n\n const configPlugin: Plugin = {\n name: 'sentry-tanstackstart-files-to-delete-after-upload-plugin',\n apply: 'build',\n enforce: 'post',\n config(config) {\n const userFilesToDelete = sourcemaps?.filesToDeleteAfterUpload;\n\n // Only auto-delete source maps if the user didn't configure sourcemaps at all\n if (typeof userFilesToDelete === 'undefined' && typeof config.build?.sourcemap === 'undefined') {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Automatically setting `sourcemaps.filesToDeleteAfterUpload: [\"./**/*.map\"]` to delete generated source maps after they were uploaded to Sentry.',\n );\n }\n resolveFilesToDeleteAfterUpload?.(['./**/*.map']);\n } else {\n resolveFilesToDeleteAfterUpload?.(userFilesToDelete);\n }\n },\n };\n\n const sentryPlugins = sentryVitePlugin({\n applicationKey,\n authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,\n bundleSizeOptimizations: bundleSizeOptimizations ?? undefined,\n debug: debug ?? false,\n errorHandler,\n headers,\n org: org ?? process.env.SENTRY_ORG,\n project: project ?? process.env.SENTRY_PROJECT,\n release,\n silent,\n sourcemaps: {\n assets: sourcemaps?.assets,\n disable: sourcemaps?.disable,\n ignore: sourcemaps?.ignore,\n // BuildTimeOptionsBase types can lag behind bundler plugin options in some local setups.\n // Keep runtime support while staying resilient to type version skew.\n rewriteSources: (sourcemaps as unknown as { rewriteSources?: unknown } | undefined)?.rewriteSources as never,\n filesToDeleteAfterUpload: filesToDeleteAfterUploadPromise,\n },\n reactComponentAnnotation: {\n enabled: reactComponentAnnotation?.enabled ?? undefined,\n ignoredComponents: reactComponentAnnotation?.ignoredComponents ?? undefined,\n },\n telemetry: telemetry ?? true,\n url: sentryUrl,\n _metaOptions: {\n telemetry: {\n metaFramework: 'tanstackstart-react',\n },\n },\n });\n\n return [configPlugin, ...sentryPlugins];\n}\n\n/**\n * A Sentry plugin for TanStack Start React to enable \"hidden\" source maps if they are unset.\n */\nexport function makeEnableSourceMapsVitePlugin(options: SentryTanstackStartOptions): Plugin[] {\n return [\n {\n name: 'sentry-tanstackstart-react-source-maps',\n apply: 'build',\n enforce: 'post',\n config(viteConfig) {\n return {\n ...viteConfig,\n build: {\n ...viteConfig.build,\n sourcemap: getUpdatedSourceMapSettings(viteConfig, options),\n },\n };\n },\n },\n ];\n}\n\n/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-javascript/issues/13993)\n *\n * 1. User explicitly disabled source maps\n * - keep this setting (emit a warning that errors won't be unminified in Sentry)\n * - We won't upload anything\n *\n * 2. Users enabled source map generation (true, 'hidden', 'inline').\n * - keep this setting (don't do anything - like deletion - besides uploading)\n *\n * 3. Users didn't set source maps generation\n * - we enable 'hidden' source maps generation\n * - configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this)\n *\n * --> only exported for testing\n */\nexport function getUpdatedSourceMapSettings(\n viteConfig: UserConfig,\n sentryPluginOptions?: SentryTanstackStartOptions,\n): boolean | 'inline' | 'hidden' {\n viteConfig.build = viteConfig.build || {};\n\n const viteUserSourceMapSetting = viteConfig.build?.sourcemap;\n const settingKey = 'vite.build.sourcemap';\n const debug = sentryPluginOptions?.debug;\n\n // Respect user source map setting if it is explicitly set\n if (viteUserSourceMapSetting === false) {\n if (debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] Source map generation is currently disabled in your TanStack Start configuration (\\`${settingKey}: false\\`). Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.warn('[Sentry] Source map generation is disabled in your TanStack Start configuration.');\n }\n\n return viteUserSourceMapSetting;\n } else if (viteUserSourceMapSetting && ['hidden', 'inline', true].includes(viteUserSourceMapSetting)) {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] We discovered \\`${settingKey}\\` is set to \\`${viteUserSourceMapSetting.toString()}\\`. Sentry will keep this source map setting.`,\n );\n }\n\n return viteUserSourceMapSetting;\n }\n\n // If the user did not specify a source map setting, we enable 'hidden' by default\n if (debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Enabled source map generation in the build options with \\`${settingKey}: 'hidden'\\`. The source maps will be deleted after they were uploaded to Sentry.`,\n );\n }\n\n return 'hidden';\n}\n"],"names":[],"mappings":";;AASO,SAAS,wBAAwB,OAAA,EAA+C;AACrF,EAAA,MAAM;AAAA,IACJ,cAAA;AAAA,IACA,SAAA;AAAA,IACA,uBAAA;AAAA,IACA,KAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAGJ,EAAA,IAAI,+BAAA;AACJ,EAAA,MAAM,+BAAA,GAAkC,IAAI,OAAA,CAAkC,CAAA,OAAA,KAAW;AACvF,IAAA,+BAAA,GAAkC,OAAA;AAAA,EACpC,CAAC,CAAA;AAED,EAAA,MAAM,YAAA,GAAuB;AAAA,IAC3B,IAAA,EAAM,0DAAA;AAAA,IACN,KAAA,EAAO,OAAA;AAAA,IACP,OAAA,EAAS,MAAA;AAAA,IACT,OAAO,MAAA,EAAQ;AACb,MAAA,MAAM,oBAAoB,UAAA,EAAY,wBAAA;AAGtC,MAAA,IAAI,OAAO,iBAAA,KAAsB,WAAA,IAAe,OAAO,MAAA,CAAO,KAAA,EAAO,cAAc,WAAA,EAAa;AAC9F,QAAA,IAAI,KAAA,EAAO;AAET,UAAA,OAAA,CAAQ,GAAA;AAAA,YACN;AAAA,WACF;AAAA,QACF;AACA,QAAA,+BAAA,GAAkC,CAAC,YAAY,CAAC,CAAA;AAAA,MAClD,CAAA,MAAO;AACL,QAAA,+BAAA,GAAkC,iBAAiB,CAAA;AAAA,MACrD;AAAA,IACF;AAAA,GACF;AAEA,EAAA,MAAM,gBAAgB,gBAAA,CAAiB;AAAA,IACrC,cAAA;AAAA,IACA,SAAA,EAAW,SAAA,IA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const VIRTUAL_TUNNEL_ROUTE_ID = 'virtual:sentry-tanstackstart-react/tunnel-route';
|
|
1
|
+
const MANAGED_TUNNEL_ROUTE_IMPORT = "SentryManagedTunnelRouteImport";
|
|
2
|
+
const MANAGED_TUNNEL_ROUTE_NAME = "SentryManagedTunnelRoute";
|
|
3
|
+
const MANAGED_TUNNEL_ROUTE_PATH_ENV_KEY = "__SENTRY_INTERNAL_TANSTACKSTART_TUNNEL_ROUTE__";
|
|
4
|
+
const VIRTUAL_TUNNEL_ROUTE_ID = "virtual:sentry-tanstackstart-react/tunnel-route";
|
|
6
5
|
const RESOLVED_VIRTUAL_TUNNEL_ROUTE_ID = `\0${VIRTUAL_TUNNEL_ROUTE_ID}`;
|
|
7
|
-
|
|
8
6
|
function generateRandomTunnelRoute() {
|
|
9
|
-
const randomPath = Array.from({ length: 8 }, () => Math.floor(Math.random() * 36).toString(36)).join(
|
|
10
|
-
|
|
7
|
+
const randomPath = Array.from({ length: 8 }, () => Math.floor(Math.random() * 36).toString(36)).join("");
|
|
11
8
|
return `/${randomPath}`;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
10
|
function resolveTunnelRoute(tunnel) {
|
|
15
|
-
if (typeof tunnel ===
|
|
11
|
+
if (typeof tunnel === "string") {
|
|
16
12
|
return tunnel;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
if (process.env[MANAGED_TUNNEL_ROUTE_PATH_ENV_KEY]) {
|
|
20
15
|
return process.env[MANAGED_TUNNEL_ROUTE_PATH_ENV_KEY];
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
const resolvedTunnelRoute = generateRandomTunnelRoute();
|
|
24
18
|
process.env[MANAGED_TUNNEL_ROUTE_PATH_ENV_KEY] = resolvedTunnelRoute;
|
|
25
19
|
return resolvedTunnelRoute;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function validateStaticPath(path) {
|
|
29
|
-
if (!path.startsWith(
|
|
22
|
+
if (!path.startsWith("/") || path.includes("?") || path.includes("#")) {
|
|
30
23
|
throw new Error(
|
|
31
|
-
|
|
24
|
+
"[@sentry/tanstackstart-react] `tunnelRoute` static paths must start with `/` and must not contain query or hash segments."
|
|
32
25
|
);
|
|
33
26
|
}
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
function normalizeTunnelRouteOptions(options) {
|
|
37
29
|
if (options === true) {
|
|
38
|
-
return { resolvedPath: resolveTunnelRoute(true), allowedDsns:
|
|
30
|
+
return { resolvedPath: resolveTunnelRoute(true), allowedDsns: void 0 };
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
if (typeof options === 'string') {
|
|
32
|
+
if (typeof options === "string") {
|
|
42
33
|
validateStaticPath(options);
|
|
43
34
|
return {
|
|
44
35
|
resolvedPath: resolveTunnelRoute(options),
|
|
45
|
-
allowedDsns:
|
|
36
|
+
allowedDsns: void 0
|
|
46
37
|
};
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
const allowedDsns = options.allowedDsns && options.allowedDsns.length > 0 ? options.allowedDsns : undefined;
|
|
39
|
+
const allowedDsns = options.allowedDsns && options.allowedDsns.length > 0 ? options.allowedDsns : void 0;
|
|
50
40
|
const path = options.path;
|
|
51
|
-
|
|
52
41
|
if (path) {
|
|
53
42
|
validateStaticPath(path);
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
return { resolvedPath: resolveTunnelRoute(path || true), allowedDsns };
|
|
57
45
|
}
|
|
58
|
-
|
|
59
|
-
// `routeTree.gen.ts` quote style follows `tsr.config.json#quoteStyle` (`single` | `double`),
|
|
60
|
-
// so we check both forms for each route-identifying key.
|
|
61
|
-
const ROUTE_CONFLICT_KEYS = ['fullPath', 'path', 'id'] ;
|
|
62
|
-
|
|
46
|
+
const ROUTE_CONFLICT_KEYS = ["fullPath", "path", "id"];
|
|
63
47
|
function hasRouteConflict(source, resolvedTunnelRoute) {
|
|
64
48
|
const literals = [`'${resolvedTunnelRoute}'`, `"${resolvedTunnelRoute}"`];
|
|
65
|
-
return ROUTE_CONFLICT_KEYS.some(key => literals.some(literal => source.includes(`${key}: ${literal}`)));
|
|
49
|
+
return ROUTE_CONFLICT_KEYS.some((key) => literals.some((literal) => source.includes(`${key}: ${literal}`)));
|
|
66
50
|
}
|
|
67
|
-
|
|
68
51
|
function injectAfterLastImport(source, statement) {
|
|
69
52
|
const importMatches = [...source.matchAll(/^import .+$/gm)];
|
|
70
53
|
const lastImport = importMatches.at(-1);
|
|
71
|
-
|
|
72
|
-
if (lastImport?.index === undefined) {
|
|
54
|
+
if (lastImport?.index === void 0) {
|
|
73
55
|
throw new Error(
|
|
74
|
-
|
|
56
|
+
"[@sentry/tanstackstart-react] Failed to inject the managed tunnel route because `routeTree.gen.ts` imports could not be located."
|
|
75
57
|
);
|
|
76
58
|
}
|
|
77
|
-
|
|
78
59
|
const insertIndex = lastImport.index + lastImport[0].length;
|
|
79
|
-
return `${source.slice(0, insertIndex)}
|
|
60
|
+
return `${source.slice(0, insertIndex)}
|
|
61
|
+
${statement}${source.slice(insertIndex)}`;
|
|
80
62
|
}
|
|
81
|
-
|
|
82
63
|
function injectManagedTunnelRoute(source, resolvedTunnelRoute) {
|
|
83
64
|
if (source.includes(VIRTUAL_TUNNEL_ROUTE_ID)) {
|
|
84
65
|
return source;
|
|
85
66
|
}
|
|
86
|
-
|
|
87
67
|
if (hasRouteConflict(source, resolvedTunnelRoute)) {
|
|
88
68
|
throw new Error(
|
|
89
|
-
`[@sentry/tanstackstart-react] Cannot register managed tunnel route "${resolvedTunnelRoute}" because an existing TanStack Start route already uses that path
|
|
69
|
+
`[@sentry/tanstackstart-react] Cannot register managed tunnel route "${resolvedTunnelRoute}" because an existing TanStack Start route already uses that path.`
|
|
90
70
|
);
|
|
91
71
|
}
|
|
92
|
-
|
|
93
72
|
const serializedTunnelRoute = JSON.stringify(resolvedTunnelRoute);
|
|
94
|
-
|
|
95
73
|
let transformedSource = injectAfterLastImport(
|
|
96
74
|
source,
|
|
97
|
-
`import { Route as ${MANAGED_TUNNEL_ROUTE_IMPORT} } from '${VIRTUAL_TUNNEL_ROUTE_ID}'
|
|
75
|
+
`import { Route as ${MANAGED_TUNNEL_ROUTE_IMPORT} } from '${VIRTUAL_TUNNEL_ROUTE_ID}'`
|
|
98
76
|
);
|
|
99
|
-
|
|
100
77
|
const rootRouteChildrenMatch = transformedSource.match(
|
|
101
|
-
/const rootRouteChildren(?:\s*:\s*RootRouteChildren)?\s*=\s*\{
|
|
78
|
+
/const rootRouteChildren(?:\s*:\s*RootRouteChildren)?\s*=\s*\{/
|
|
102
79
|
);
|
|
103
|
-
|
|
104
|
-
if (rootRouteChildrenMatch?.index === undefined) {
|
|
80
|
+
if (rootRouteChildrenMatch?.index === void 0) {
|
|
105
81
|
throw new Error(
|
|
106
|
-
|
|
82
|
+
"[@sentry/tanstackstart-react] Failed to inject the managed tunnel route because the generated TanStack route tree did not contain `rootRouteChildren`."
|
|
107
83
|
);
|
|
108
84
|
}
|
|
109
|
-
|
|
110
85
|
const injectedRootRouteChildrenDeclaration = `const ${MANAGED_TUNNEL_ROUTE_NAME} = ${MANAGED_TUNNEL_ROUTE_IMPORT}.update({
|
|
111
86
|
id: ${serializedTunnelRoute},
|
|
112
87
|
path: ${serializedTunnelRoute},
|
|
@@ -116,31 +91,25 @@ function injectManagedTunnelRoute(source, resolvedTunnelRoute) {
|
|
|
116
91
|
${rootRouteChildrenMatch[0]}
|
|
117
92
|
${MANAGED_TUNNEL_ROUTE_NAME}: ${MANAGED_TUNNEL_ROUTE_NAME},
|
|
118
93
|
`;
|
|
119
|
-
|
|
120
94
|
transformedSource = `${transformedSource.slice(0, rootRouteChildrenMatch.index)}${injectedRootRouteChildrenDeclaration}${transformedSource.slice(rootRouteChildrenMatch.index + rootRouteChildrenMatch[0].length)}`;
|
|
121
|
-
|
|
122
95
|
return transformedSource;
|
|
123
96
|
}
|
|
124
|
-
|
|
125
97
|
function makeTunnelRoutePlugin(options, debug) {
|
|
126
98
|
const normalized = normalizeTunnelRouteOptions(options);
|
|
127
99
|
const resolvedTunnelRoute = normalized.resolvedPath;
|
|
128
100
|
const serializedTunnelRoute = JSON.stringify(resolvedTunnelRoute);
|
|
129
|
-
const serializedAllowedDsns = normalized.allowedDsns ? JSON.stringify(normalized.allowedDsns) :
|
|
130
|
-
|
|
101
|
+
const serializedAllowedDsns = normalized.allowedDsns ? JSON.stringify(normalized.allowedDsns) : void 0;
|
|
131
102
|
if (debug) {
|
|
132
|
-
// eslint-disable-next-line no-console
|
|
133
103
|
console.log(`[@sentry/tanstackstart-react] Registered tunnel route: ${resolvedTunnelRoute}`);
|
|
134
104
|
}
|
|
135
|
-
|
|
136
105
|
return {
|
|
137
|
-
name:
|
|
138
|
-
enforce:
|
|
106
|
+
name: "sentry-tanstackstart-tunnel-route",
|
|
107
|
+
enforce: "pre",
|
|
139
108
|
config() {
|
|
140
109
|
return {
|
|
141
110
|
define: {
|
|
142
|
-
__SENTRY_TANSTACKSTART_TUNNEL_ROUTE__: serializedTunnelRoute
|
|
143
|
-
}
|
|
111
|
+
__SENTRY_TANSTACKSTART_TUNNEL_ROUTE__: serializedTunnelRoute
|
|
112
|
+
}
|
|
144
113
|
};
|
|
145
114
|
},
|
|
146
115
|
resolveId(source) {
|
|
@@ -150,7 +119,6 @@ function makeTunnelRoutePlugin(options, debug) {
|
|
|
150
119
|
if (id !== RESOLVED_VIRTUAL_TUNNEL_ROUTE_ID) {
|
|
151
120
|
return null;
|
|
152
121
|
}
|
|
153
|
-
|
|
154
122
|
return `import { createFileRoute } from '@tanstack/react-router';
|
|
155
123
|
|
|
156
124
|
export const Route = createFileRoute(${serializedTunnelRoute})({
|
|
@@ -166,12 +134,11 @@ export const Route = createFileRoute(${serializedTunnelRoute})({
|
|
|
166
134
|
`;
|
|
167
135
|
},
|
|
168
136
|
transform(source, id) {
|
|
169
|
-
if (!id.endsWith(
|
|
137
|
+
if (!id.endsWith("/routeTree.gen.ts") && !id.endsWith("\\routeTree.gen.ts")) {
|
|
170
138
|
return null;
|
|
171
139
|
}
|
|
172
|
-
|
|
173
140
|
return injectManagedTunnelRoute(source, resolvedTunnelRoute);
|
|
174
|
-
}
|
|
141
|
+
}
|
|
175
142
|
};
|
|
176
143
|
}
|
|
177
144
|
|