From 5cbfdca116eb62fbda785f9a1a69650e42d46887 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 8 May 2023 14:10:32 +0200 Subject: [PATCH] fix(sveltekit): Avoid creating the Sentry Vite plugin in dev mode --- packages/sveltekit/src/vite/sentryVitePlugins.ts | 2 +- .../test/vite/sentrySvelteKitPlugins.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index 0f2461a419de..1f983d7a9653 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -78,7 +78,7 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} ); } - if (mergedOptions.autoUploadSourceMaps) { + if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') { const pluginOptions = { ...mergedOptions.sourceMapsUploadOptions, debug: mergedOptions.debug, // override the plugin's debug flag with the one from the top-level options diff --git a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts index f606b5ee6e9a..963844bdef70 100644 --- a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts +++ b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts @@ -38,6 +38,19 @@ describe('sentryVite()', () => { expect(plugins).toHaveLength(1); }); + it("doesn't return the custom sentry source maps plugin if `NODE_ENV` is development", async () => { + const previousEnv = process.env.NODE_ENV; + + process.env.NODE_ENV = 'development'; + const plugins = await sentrySvelteKit({ autoUploadSourceMaps: true, autoInstrument: true }); + const instrumentPlugin = plugins[0]; + + expect(plugins).toHaveLength(1); + expect(instrumentPlugin.name).toEqual('sentry-auto-instrumentation'); + + process.env.NODE_ENV = previousEnv; + }); + it("doesn't return the auto instrument plugin if autoInstrument is `false`", async () => { const plugins = await sentrySvelteKit({ autoInstrument: false }); expect(plugins).toHaveLength(1);