From 4e2479bd1948f526f2ce5b31d2b5e7e7ba5e2b5a Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 4 Aug 2025 13:15:56 +0200 Subject: [PATCH 1/5] feat(astro): Streamline astro build logs --- packages/astro/src/integration/index.ts | 58 ++++++++----------- packages/astro/test/integration/index.test.ts | 47 ++++++++------- .../src/vite/makeEnableSourceMapsPlugin.ts | 4 +- .../react-router/test/vite/sourceMaps.test.ts | 12 ++-- packages/solidstart/src/vite/sourceMaps.ts | 4 +- .../solidstart/test/vite/sourceMaps.test.ts | 12 ++-- 6 files changed, 65 insertions(+), 72 deletions(-) diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 28092cad84be..dc6eddf21b4a 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -1,6 +1,5 @@ -import { consoleSandbox } from '@sentry/core'; import { sentryVitePlugin } from '@sentry/vite-plugin'; -import type { AstroConfig, AstroIntegration } from 'astro'; +import type { AstroConfig, AstroIntegration, AstroIntegrationLogger } from 'astro'; import * as fs from 'fs'; import * as path from 'path'; import { buildClientSnippet, buildSdkInitFileImportSnippet, buildServerSnippet } from './snippets'; @@ -36,14 +35,11 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { const otherOptionsKeys = Object.keys(otherOptions); if (otherOptionsKeys.length > 0) { - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.warn( - `[Sentry] You passed in additional options (${otherOptionsKeys.join( - ', ', - )}) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your \`sentry.client.config.(js|ts)\` or \`sentry.server.config.(js|ts)\` files.`, - ); - }); + logger.warn( + `You passed in additional options (${otherOptionsKeys.join( + ', ', + )}) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your \`sentry.client.config.(js|ts)\` or \`sentry.server.config.(js|ts)\` files.`, + ); } const sdkEnabled = { @@ -57,7 +53,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { // We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env if (shouldUploadSourcemaps && command !== 'dev') { - const computedSourceMapSettings = getUpdatedSourceMapSettings(config, options); + const computedSourceMapSettings = _getUpdatedSourceMapSettings(config, options, logger); let updatedFilesToDeleteAfterUpload: string[] | undefined = undefined; @@ -68,14 +64,12 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { // This also works for adapters, as the source maps are also copied to e.g. the .vercel folder updatedFilesToDeleteAfterUpload = ['./dist/**/client/**/*.map', './dist/**/server/**/*.map']; - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.log( + debug && + logger.info( `[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( updatedFilesToDeleteAfterUpload, )}\` to delete generated source maps after they were uploaded to Sentry.`, ); - }); } updateConfig({ @@ -222,9 +216,10 @@ export type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined; * * --> only exported for testing */ -export function getUpdatedSourceMapSettings( +export function _getUpdatedSourceMapSettings( astroConfig: AstroConfig, - sentryOptions?: SentryOptions, + sentryOptions: SentryOptions | undefined, + logger: AstroIntegrationLogger, ): { previousUserSourceMapSetting: UserSourceMapSetting; updatedSourceMapSetting: boolean | 'inline' | 'hidden' } { let previousUserSourceMapSetting: UserSourceMapSetting = undefined; @@ -234,39 +229,32 @@ export function getUpdatedSourceMapSettings( let updatedSourceMapSetting = viteSourceMap; const settingKey = 'vite.build.sourcemap'; + const debug = sentryOptions?.debug; if (viteSourceMap === false) { previousUserSourceMapSetting = 'disabled'; updatedSourceMapSetting = viteSourceMap; - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.warn( - `[Sentry] Source map generation is currently disabled in your Astro configuration (\`${settingKey}: false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, + debug && + logger.warn( + `Source map generation is currently disabled in your Astro configuration (\`${settingKey}: false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, ); - }); } else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { previousUserSourceMapSetting = 'enabled'; updatedSourceMapSetting = viteSourceMap; - if (sentryOptions?.debug) { - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.log( - `[Sentry] We discovered \`${settingKey}\` is set to \`${viteSourceMap.toString()}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`, - ); - }); - } + debug && + logger.info( + `We discovered \`${settingKey}\` is set to \`${viteSourceMap.toString()}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`, + ); } else { previousUserSourceMapSetting = 'unset'; updatedSourceMapSetting = 'hidden'; - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.log( - `[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`, + debug && + logger.info( + `Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`, ); - }); } return { previousUserSourceMapSetting, updatedSourceMapSetting }; diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index b98644f0b884..b1645d8b7348 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -1,6 +1,6 @@ -import type { AstroConfig } from 'astro'; +import type { AstroConfig, AstroIntegrationLogger } from 'astro'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { getUpdatedSourceMapSettings, sentryAstro } from '../../src/integration'; +import { _getUpdatedSourceMapSettings, sentryAstro } from '../../src/integration'; import type { SentryOptions } from '../../src/integration/types'; const sentryVitePluginSpy = vi.fn(() => 'sentryVitePlugin'); @@ -305,21 +305,25 @@ describe('sentryAstro integration', () => { }); it('injects runtime config into client and server init scripts and warns about deprecation', async () => { - const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const integration = sentryAstro({ environment: 'test', release: '1.0.0', dsn: 'https://test.sentry.io/123', - debug: true, bundleSizeOptimizations: {}, + // this also warns when debug is not enabled }); + const logger = { + warn: vi.fn(), + info: vi.fn(), + }; + 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, logger: { info: vi.fn() } }); + await integration.hooks['astro:config:setup']({ updateConfig, injectScript, config, logger }); - expect(consoleWarnSpy).toHaveBeenCalledWith( - '[Sentry] You passed in additional options (environment, release, dsn) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.', + expect(logger.warn).toHaveBeenCalledWith( + 'You passed in additional options (environment, release, dsn) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.', ); expect(injectScript).toHaveBeenCalledTimes(2); @@ -490,18 +494,23 @@ describe('sentryAstro integration', () => { }); }); -describe('getUpdatedSourceMapSettings', () => { +describe('_getUpdatedSourceMapSettings', () => { let astroConfig: Omit & { vite: { build: { sourcemap?: any } } }; let sentryOptions: SentryOptions; + let logger: AstroIntegrationLogger; beforeEach(() => { astroConfig = { vite: { build: {} } } as Omit & { vite: { build: { sourcemap?: any } } }; sentryOptions = {}; + logger = { + info: vi.fn(), + warn: vi.fn(), + } as unknown as AstroIntegrationLogger; }); it('should keep explicitly disabled source maps disabled', () => { astroConfig.vite.build.sourcemap = false; - const result = getUpdatedSourceMapSettings(astroConfig, sentryOptions); + const result = _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); expect(result.previousUserSourceMapSetting).toBe('disabled'); expect(result.updatedSourceMapSetting).toBe(false); }); @@ -515,7 +524,7 @@ describe('getUpdatedSourceMapSettings', () => { cases.forEach(({ sourcemap, expected }) => { astroConfig.vite.build.sourcemap = sourcemap; - const result = getUpdatedSourceMapSettings(astroConfig, sentryOptions); + const result = _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); expect(result.previousUserSourceMapSetting).toBe('enabled'); expect(result.updatedSourceMapSetting).toBe(expected); }); @@ -523,26 +532,22 @@ describe('getUpdatedSourceMapSettings', () => { it('should enable "hidden" source maps when unset', () => { astroConfig.vite.build.sourcemap = undefined; - const result = getUpdatedSourceMapSettings(astroConfig, sentryOptions); + const result = _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); expect(result.previousUserSourceMapSetting).toBe('unset'); expect(result.updatedSourceMapSetting).toBe('hidden'); }); it('should log warnings and messages when debug is enabled', () => { - const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); - const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); - sentryOptions = { debug: true }; astroConfig.vite.build.sourcemap = false; - getUpdatedSourceMapSettings(astroConfig, sentryOptions); - expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('Source map generation is currently disabled')); + _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); + // eslint-disable-next-line @typescript-eslint/unbound-method + expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Source map generation is currently disabled')); astroConfig.vite.build.sourcemap = 'hidden'; - getUpdatedSourceMapSettings(astroConfig, sentryOptions); - expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Sentry will keep this source map setting')); - - consoleWarnSpy.mockRestore(); - consoleLogSpy.mockRestore(); + _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); + // eslint-disable-next-line @typescript-eslint/unbound-method + expect(logger.info).toHaveBeenCalledWith(expect.stringContaining('Sentry will keep this source map setting')); }); }); diff --git a/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts b/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts index 63d1e4bd5779..7f9b58560f1d 100644 --- a/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts +++ b/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts @@ -15,7 +15,7 @@ export function makeEnableSourceMapsPlugin(options: SentryReactRouterBuildOption ...viteConfig, build: { ...viteConfig.build, - sourcemap: getUpdatedSourceMapSettings(viteConfig, options), + sourcemap: _getUpdatedSourceMapSettings(viteConfig, options), }, }; }, @@ -37,7 +37,7 @@ export function makeEnableSourceMapsPlugin(options: SentryReactRouterBuildOption * * --> only exported for testing */ -export function getUpdatedSourceMapSettings( +export function _getUpdatedSourceMapSettings( viteConfig: UserConfig, sentryPluginOptions?: SentryReactRouterBuildOptions, ): boolean | 'inline' | 'hidden' { diff --git a/packages/react-router/test/vite/sourceMaps.test.ts b/packages/react-router/test/vite/sourceMaps.test.ts index f59f7c5acf99..ddd69febf95f 100644 --- a/packages/react-router/test/vite/sourceMaps.test.ts +++ b/packages/react-router/test/vite/sourceMaps.test.ts @@ -1,6 +1,6 @@ import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { getUpdatedSourceMapSettings, makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin'; +import { _getUpdatedSourceMapSettings, makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin'; const mockedSentryVitePlugin = { name: 'sentry-vite-debug-id-upload-plugin', @@ -33,7 +33,7 @@ describe('makeEnableSourceMapsPlugin()', () => { }); }); -describe('getUpdatedSourceMapSettings', () => { +describe('_getUpdatedSourceMapSettings', () => { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -42,7 +42,7 @@ describe('getUpdatedSourceMapSettings', () => { describe('when sourcemap is false', () => { it('should keep sourcemap as false and show warning', () => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); // eslint-disable-next-line no-console @@ -58,7 +58,7 @@ describe('getUpdatedSourceMapSettings', () => { ['inline', 'inline'], [true, true], ] as ('inline' | 'hidden' | boolean)[][])('should keep sourcemap as %s when set to %s', (input, expected) => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); expect(result).toBe(expected); // eslint-disable-next-line no-console @@ -72,7 +72,7 @@ describe('getUpdatedSourceMapSettings', () => { it.each([[undefined], ['invalid'], ['something'], [null]])( 'should set sourcemap to hidden when value is %s', input => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console @@ -85,7 +85,7 @@ describe('getUpdatedSourceMapSettings', () => { ); it('should set sourcemap to hidden when build config is empty', () => { - const result = getUpdatedSourceMapSettings({}); + const result = _getUpdatedSourceMapSettings({}); expect(result).toBe('hidden'); // eslint-disable-next-line no-console diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index 285b3949bf93..f2d2df8dc6ed 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -70,7 +70,7 @@ export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOp ...viteConfig, build: { ...viteConfig.build, - sourcemap: getUpdatedSourceMapSettings(viteConfig, options), + sourcemap: _getUpdatedSourceMapSettings(viteConfig, options), }, }; }, @@ -93,7 +93,7 @@ export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOp * * --> only exported for testing */ -export function getUpdatedSourceMapSettings( +export function _getUpdatedSourceMapSettings( viteConfig: UserConfig, sentryPluginOptions?: SentrySolidStartPluginOptions, ): boolean | 'inline' | 'hidden' { diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index 7254b126ce93..0d4e5a8ee6e6 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -1,7 +1,7 @@ import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { - getUpdatedSourceMapSettings, + _getUpdatedSourceMapSettings, makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin, } from '../../src/vite/sourceMaps'; @@ -171,7 +171,7 @@ describe('makeAddSentryVitePlugin()', () => { }); }); -describe('getUpdatedSourceMapSettings', () => { +describe('_getUpdatedSourceMapSettings', () => { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -180,7 +180,7 @@ describe('getUpdatedSourceMapSettings', () => { describe('when sourcemap is false', () => { it('should keep sourcemap as false and show warning', () => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); // eslint-disable-next-line no-console @@ -196,7 +196,7 @@ describe('getUpdatedSourceMapSettings', () => { ['inline', 'inline'], [true, true], ] as ('inline' | 'hidden' | boolean)[][])('should keep sourcemap as %s when set to %s', (input, expected) => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); expect(result).toBe(expected); // eslint-disable-next-line no-console @@ -210,7 +210,7 @@ describe('getUpdatedSourceMapSettings', () => { it.each([[undefined], ['invalid'], ['something'], [null]])( 'should set sourcemap to hidden when value is %s', input => { - const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); + const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console @@ -223,7 +223,7 @@ describe('getUpdatedSourceMapSettings', () => { ); it('should set sourcemap to hidden when build config is empty', () => { - const result = getUpdatedSourceMapSettings({}); + const result = _getUpdatedSourceMapSettings({}); expect(result).toBe('hidden'); // eslint-disable-next-line no-console From eb32771490144644e6c3551e8e3bae49148766e4 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 4 Aug 2025 13:20:19 +0200 Subject: [PATCH 2/5] forgot one --- packages/astro/src/integration/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index dc6eddf21b4a..c2d6445df2de 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -66,7 +66,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { debug && logger.info( - `[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( + `Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( updatedFilesToDeleteAfterUpload, )}\` to delete generated source maps after they were uploaded to Sentry.`, ); From 58dd1dedef6ad2ae6139c8c7bb22a55610b72d9f Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 4 Aug 2025 13:27:33 +0200 Subject: [PATCH 3/5] revert other changes --- .../src/vite/makeEnableSourceMapsPlugin.ts | 4 ++-- packages/react-router/test/vite/sourceMaps.test.ts | 12 ++++++------ packages/solidstart/src/vite/sourceMaps.ts | 4 ++-- packages/solidstart/test/vite/sourceMaps.test.ts | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts b/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts index 7f9b58560f1d..63d1e4bd5779 100644 --- a/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts +++ b/packages/react-router/src/vite/makeEnableSourceMapsPlugin.ts @@ -15,7 +15,7 @@ export function makeEnableSourceMapsPlugin(options: SentryReactRouterBuildOption ...viteConfig, build: { ...viteConfig.build, - sourcemap: _getUpdatedSourceMapSettings(viteConfig, options), + sourcemap: getUpdatedSourceMapSettings(viteConfig, options), }, }; }, @@ -37,7 +37,7 @@ export function makeEnableSourceMapsPlugin(options: SentryReactRouterBuildOption * * --> only exported for testing */ -export function _getUpdatedSourceMapSettings( +export function getUpdatedSourceMapSettings( viteConfig: UserConfig, sentryPluginOptions?: SentryReactRouterBuildOptions, ): boolean | 'inline' | 'hidden' { diff --git a/packages/react-router/test/vite/sourceMaps.test.ts b/packages/react-router/test/vite/sourceMaps.test.ts index ddd69febf95f..f59f7c5acf99 100644 --- a/packages/react-router/test/vite/sourceMaps.test.ts +++ b/packages/react-router/test/vite/sourceMaps.test.ts @@ -1,6 +1,6 @@ import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { _getUpdatedSourceMapSettings, makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin'; +import { getUpdatedSourceMapSettings, makeEnableSourceMapsPlugin } from '../../src/vite/makeEnableSourceMapsPlugin'; const mockedSentryVitePlugin = { name: 'sentry-vite-debug-id-upload-plugin', @@ -33,7 +33,7 @@ describe('makeEnableSourceMapsPlugin()', () => { }); }); -describe('_getUpdatedSourceMapSettings', () => { +describe('getUpdatedSourceMapSettings', () => { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -42,7 +42,7 @@ describe('_getUpdatedSourceMapSettings', () => { describe('when sourcemap is false', () => { it('should keep sourcemap as false and show warning', () => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: false } }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); // eslint-disable-next-line no-console @@ -58,7 +58,7 @@ describe('_getUpdatedSourceMapSettings', () => { ['inline', 'inline'], [true, true], ] as ('inline' | 'hidden' | boolean)[][])('should keep sourcemap as %s when set to %s', (input, expected) => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); expect(result).toBe(expected); // eslint-disable-next-line no-console @@ -72,7 +72,7 @@ describe('_getUpdatedSourceMapSettings', () => { it.each([[undefined], ['invalid'], ['something'], [null]])( 'should set sourcemap to hidden when value is %s', input => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console @@ -85,7 +85,7 @@ describe('_getUpdatedSourceMapSettings', () => { ); it('should set sourcemap to hidden when build config is empty', () => { - const result = _getUpdatedSourceMapSettings({}); + const result = getUpdatedSourceMapSettings({}); expect(result).toBe('hidden'); // eslint-disable-next-line no-console diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index f2d2df8dc6ed..285b3949bf93 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -70,7 +70,7 @@ export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOp ...viteConfig, build: { ...viteConfig.build, - sourcemap: _getUpdatedSourceMapSettings(viteConfig, options), + sourcemap: getUpdatedSourceMapSettings(viteConfig, options), }, }; }, @@ -93,7 +93,7 @@ export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOp * * --> only exported for testing */ -export function _getUpdatedSourceMapSettings( +export function getUpdatedSourceMapSettings( viteConfig: UserConfig, sentryPluginOptions?: SentrySolidStartPluginOptions, ): boolean | 'inline' | 'hidden' { diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index 0d4e5a8ee6e6..7254b126ce93 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -1,7 +1,7 @@ import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { - _getUpdatedSourceMapSettings, + getUpdatedSourceMapSettings, makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin, } from '../../src/vite/sourceMaps'; @@ -171,7 +171,7 @@ describe('makeAddSentryVitePlugin()', () => { }); }); -describe('_getUpdatedSourceMapSettings', () => { +describe('getUpdatedSourceMapSettings', () => { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(console, 'warn').mockImplementation(() => {}); @@ -180,7 +180,7 @@ describe('_getUpdatedSourceMapSettings', () => { describe('when sourcemap is false', () => { it('should keep sourcemap as false and show warning', () => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: false } }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); // eslint-disable-next-line no-console @@ -196,7 +196,7 @@ describe('_getUpdatedSourceMapSettings', () => { ['inline', 'inline'], [true, true], ] as ('inline' | 'hidden' | boolean)[][])('should keep sourcemap as %s when set to %s', (input, expected) => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); expect(result).toBe(expected); // eslint-disable-next-line no-console @@ -210,7 +210,7 @@ describe('_getUpdatedSourceMapSettings', () => { it.each([[undefined], ['invalid'], ['something'], [null]])( 'should set sourcemap to hidden when value is %s', input => { - const result = _getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console @@ -223,7 +223,7 @@ describe('_getUpdatedSourceMapSettings', () => { ); it('should set sourcemap to hidden when build config is empty', () => { - const result = _getUpdatedSourceMapSettings({}); + const result = getUpdatedSourceMapSettings({}); expect(result).toBe('hidden'); // eslint-disable-next-line no-console From c025a445fb334bb88e01f16d68996bf06129575f Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 4 Aug 2025 13:35:35 +0200 Subject: [PATCH 4/5] short debug message when source maps disabled --- packages/astro/src/integration/index.ts | 6 +++++- packages/astro/test/integration/index.test.ts | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index c2d6445df2de..1a9eeaff8cd4 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -235,10 +235,14 @@ export function _getUpdatedSourceMapSettings( previousUserSourceMapSetting = 'disabled'; updatedSourceMapSetting = viteSourceMap; - debug && + if (debug) { + // Longer debug message with more details logger.warn( `Source map generation is currently disabled in your Astro configuration (\`${settingKey}: false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, ); + } else { + logger.warn('Source map generation is disabled in your Astro configuration.'); + } } else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { previousUserSourceMapSetting = 'enabled'; updatedSourceMapSetting = viteSourceMap; diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index b1645d8b7348..fc4bb1cc8f24 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -542,12 +542,33 @@ describe('_getUpdatedSourceMapSettings', () => { astroConfig.vite.build.sourcemap = false; _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); + // eslint-disable-next-line @typescript-eslint/unbound-method expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Source map generation is currently disabled')); + // eslint-disable-next-line @typescript-eslint/unbound-method + expect(logger.warn).toHaveBeenCalledWith( + expect.stringContaining('This setting is either a default setting or was explicitly set in your configuration.'), + ); astroConfig.vite.build.sourcemap = 'hidden'; _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); // eslint-disable-next-line @typescript-eslint/unbound-method expect(logger.info).toHaveBeenCalledWith(expect.stringContaining('Sentry will keep this source map setting')); }); + + it('should show short warnings debug is disabled', () => { + sentryOptions = { debug: false }; + + astroConfig.vite.build.sourcemap = false; + _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); + // eslint-disable-next-line @typescript-eslint/unbound-method + expect(logger.warn).toHaveBeenCalledWith( + 'Source map generation is disabled in your Astro configuration.', + ); + + astroConfig.vite.build.sourcemap = 'hidden'; + _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); + // eslint-disable-next-line @typescript-eslint/unbound-method + expect(logger.info).not.toHaveBeenCalled(); + }); }); From 991710fc1349269355accd2913fc929c927746a2 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 4 Aug 2025 13:58:52 +0200 Subject: [PATCH 5/5] fix linting --- packages/astro/test/integration/index.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index fc4bb1cc8f24..f7c0f2ec9e14 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -562,9 +562,7 @@ describe('_getUpdatedSourceMapSettings', () => { astroConfig.vite.build.sourcemap = false; _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger); // eslint-disable-next-line @typescript-eslint/unbound-method - expect(logger.warn).toHaveBeenCalledWith( - 'Source map generation is disabled in your Astro configuration.', - ); + expect(logger.warn).toHaveBeenCalledWith('Source map generation is disabled in your Astro configuration.'); astroConfig.vite.build.sourcemap = 'hidden'; _getUpdatedSourceMapSettings(astroConfig, sentryOptions, logger);