From 4b61f328896061eb865115ceab9d17c6cb49412c Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 28 Nov 2023 16:07:42 +0100 Subject: [PATCH 1/2] fix(astro): Avoid adding the Sentry Vite plugin in dev mode --- packages/astro/src/integration/index.ts | 4 ++-- packages/astro/src/integration/types.ts | 1 + packages/astro/test/integration/index.test.ts | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 213fae64ed7a..e2d177e2b575 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -14,7 +14,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { name: PKG_NAME, hooks: { // eslint-disable-next-line complexity - 'astro:config:setup': async ({ updateConfig, injectScript, addMiddleware, config }) => { + 'astro:config:setup': async ({ updateConfig, injectScript, addMiddleware, config, command }) => { // The third param here enables loading of all env vars, regardless of prefix // see: https://main.vitejs.dev/config/#using-environment-variables-in-config @@ -29,7 +29,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { const shouldUploadSourcemaps = uploadOptions?.enabled ?? true; // We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env - if (shouldUploadSourcemaps) { + if (shouldUploadSourcemaps && command !== 'dev') { updateConfig({ vite: { build: { diff --git a/packages/astro/src/integration/types.ts b/packages/astro/src/integration/types.ts index 8c069a2516a7..b742a4fb3e08 100644 --- a/packages/astro/src/integration/types.ts +++ b/packages/astro/src/integration/types.ts @@ -1,4 +1,5 @@ import type { BrowserOptions } from '@sentry/browser'; +import { NodeOptions } from '@sentry/node'; import type { Options } from '@sentry/types'; type SdkInitPaths = { diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index 7dba9a0ef347..5b8be17496c0 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -155,6 +155,19 @@ describe('sentryAstro integration', () => { expect(sentryVitePluginSpy).toHaveBeenCalledTimes(0); }); + it("doesn't add the Vite plugin in dev mode", async () => { + const integration = sentryAstro({ + sourceMapsUploadOptions: { enabled: true }, + }); + + expect(integration.hooks['astro:config:setup']).toBeDefined(); + // @ts-expect-error - the hook exists and we only need to pass what we actually use + await integration.hooks['astro:config:setup']({ updateConfig, injectScript, config, command: 'dev' }); + + expect(updateConfig).toHaveBeenCalledTimes(0); + expect(sentryVitePluginSpy).toHaveBeenCalledTimes(0); + }); + it('injects client and server init scripts', async () => { const integration = sentryAstro({}); From e03e4b4754d3c205d00d2951cb7f34a4945e48f4 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 28 Nov 2023 16:17:49 +0100 Subject: [PATCH 2/2] remove import --- packages/astro/src/integration/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/astro/src/integration/types.ts b/packages/astro/src/integration/types.ts index b742a4fb3e08..8c069a2516a7 100644 --- a/packages/astro/src/integration/types.ts +++ b/packages/astro/src/integration/types.ts @@ -1,5 +1,4 @@ import type { BrowserOptions } from '@sentry/browser'; -import { NodeOptions } from '@sentry/node'; import type { Options } from '@sentry/types'; type SdkInitPaths = {