|
1 |
| -import { readFileSync, writeFileSync } from 'node:fs'; |
2 |
| -import { consoleSandbox, debug } from '@sentry/core'; |
| 1 | +import { consoleSandbox } from '@sentry/core'; |
3 | 2 | import { sentryVitePlugin } from '@sentry/vite-plugin';
|
4 |
| -import type { AstroConfig, AstroIntegration, RoutePart } from 'astro'; |
| 3 | +import type { AstroConfig, AstroIntegration } from 'astro'; |
5 | 4 | import * as fs from 'fs';
|
6 | 5 | import * as path from 'path';
|
7 | 6 | import { buildClientSnippet, buildSdkInitFileImportSnippet, buildServerSnippet } from './snippets';
|
8 |
| -import type { IntegrationResolvedRoute, SentryOptions } from './types'; |
| 7 | +import type { SentryOptions } from './types'; |
9 | 8 |
|
10 | 9 | const PKG_NAME = '@sentry/astro';
|
11 | 10 |
|
12 | 11 | export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
|
13 |
| - let sentryServerInitPath: string | undefined; |
14 |
| - let didSaveRouteData = false; |
15 |
| - |
16 | 12 | return {
|
17 | 13 | name: PKG_NAME,
|
18 | 14 | hooks: {
|
@@ -138,8 +134,6 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
|
138 | 134 | injectScript('page-ssr', buildServerSnippet(options || {}));
|
139 | 135 | }
|
140 | 136 |
|
141 |
| - sentryServerInitPath = pathToServerInit; |
142 |
| - |
143 | 137 | // Prevent Sentry from being externalized for SSR.
|
144 | 138 | // Cloudflare like environments have Node.js APIs are available under `node:` prefix.
|
145 | 139 | // Ref: https://developers.cloudflare.com/workers/runtime-apis/nodejs/
|
@@ -171,36 +165,6 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
|
171 | 165 | });
|
172 | 166 | }
|
173 | 167 | },
|
174 |
| - |
175 |
| - // @ts-expect-error - This hook is available in Astro 5+ |
176 |
| - 'astro:routes:resolved': ({ routes }: { routes: IntegrationResolvedRoute[] }) => { |
177 |
| - if (!sentryServerInitPath || didSaveRouteData) { |
178 |
| - return; |
179 |
| - } |
180 |
| - |
181 |
| - try { |
182 |
| - const serverInitContent = readFileSync(sentryServerInitPath, 'utf8'); |
183 |
| - |
184 |
| - const updatedServerInitContent = `${serverInitContent}\nglobalThis["__sentryRouteInfo"] = ${JSON.stringify( |
185 |
| - routes.map(route => { |
186 |
| - return { |
187 |
| - ...route, |
188 |
| - patternCaseSensitive: joinRouteSegments(route.segments), // Store parametrized routes with correct casing on `globalThis` to be able to use them on the server during runtime |
189 |
| - patternRegex: route.patternRegex.source, // using `source` to be able to serialize the regex |
190 |
| - }; |
191 |
| - }), |
192 |
| - null, |
193 |
| - 2, |
194 |
| - )};`; |
195 |
| - |
196 |
| - writeFileSync(sentryServerInitPath, updatedServerInitContent, 'utf8'); |
197 |
| - |
198 |
| - didSaveRouteData = true; // Prevents writing the file multiple times during runtime |
199 |
| - debug.log('Successfully added route pattern information to Sentry config file:', sentryServerInitPath); |
200 |
| - } catch (error) { |
201 |
| - debug.warn(`Failed to write to Sentry config file at ${sentryServerInitPath}:`, error); |
202 |
| - } |
203 |
| - }, |
204 | 168 | },
|
205 | 169 | };
|
206 | 170 | };
|
@@ -307,18 +271,3 @@ export function getUpdatedSourceMapSettings(
|
307 | 271 |
|
308 | 272 | return { previousUserSourceMapSetting, updatedSourceMapSetting };
|
309 | 273 | }
|
310 |
| - |
311 |
| -/** |
312 |
| - * Join Astro route segments into a case-sensitive single path string. |
313 |
| - * |
314 |
| - * Astro lowercases the parametrized route. Joining segments manually is recommended to get the correct casing of the routes. |
315 |
| - * Recommendation in comment: https://github.com/withastro/astro/issues/13885#issuecomment-2934203029 |
316 |
| - * Function Reference: https://github.com/joanrieu/astro-typed-links/blob/b3dc12c6fe8d672a2bc2ae2ccc57c8071bbd09fa/package/src/integration.ts#L16 |
317 |
| - */ |
318 |
| -function joinRouteSegments(segments: RoutePart[][]): string { |
319 |
| - const parthArray = segments.map(segment => |
320 |
| - segment.map(routePart => (routePart.dynamic ? `[${routePart.content}]` : routePart.content)).join(''), |
321 |
| - ); |
322 |
| - |
323 |
| - return `/${parthArray.join('/')}`; |
324 |
| -} |
0 commit comments