diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index 285b3949bf93..0cd44e6a61c7 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -1,4 +1,3 @@ -import { consoleSandbox } from '@sentry/core'; import { sentryVitePlugin } from '@sentry/vite-plugin'; import type { Plugin, UserConfig } from 'vite'; import type { SentrySolidStartPluginOptions } from './types'; @@ -21,14 +20,13 @@ export function makeAddSentryVitePlugin(options: SentrySolidStartPluginOptions, // For .output, .vercel, .netlify etc. updatedFilesToDeleteAfterUpload = ['.*/**/*.map']; - consoleSandbox(() => { + debug && // eslint-disable-next-line no-console console.log( `[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( updatedFilesToDeleteAfterUpload, )}\` to delete generated source maps after they were uploaded to Sentry.`, ); - }); } return [ @@ -103,36 +101,37 @@ export function getUpdatedSourceMapSettings( let updatedSourceMapSetting = viteSourceMap; const settingKey = 'vite.build.sourcemap'; + const debug = sentryPluginOptions?.debug; if (viteSourceMap === false) { updatedSourceMapSetting = viteSourceMap; - consoleSandbox(() => { - // eslint-disable-next-line no-console + if (debug) { + // Longer debug message with more details + // eslint-disable-next-line no-console console.warn( `[Sentry] Source map generation is currently disabled in your SolidStart 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 { + // eslint-disable-next-line no-console + console.warn('[Sentry] Source map generation is disabled in your SolidStart configuration.'); + } } else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { updatedSourceMapSetting = viteSourceMap; - if (sentryPluginOptions?.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 && + // 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.`, + ); } else { updatedSourceMapSetting = 'hidden'; - consoleSandbox(() => { + debug && // 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.`, ); - }); } return updatedSourceMapSetting; diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index 7254b126ce93..a3fba62c1eda 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -179,13 +179,31 @@ describe('getUpdatedSourceMapSettings', () => { }); describe('when sourcemap is false', () => { - it('should keep sourcemap as false and show warning', () => { + it('should keep sourcemap as false and show short warning when debug is disabled', () => { const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); // eslint-disable-next-line no-console expect(console.warn).toHaveBeenCalledWith( - expect.stringContaining('[Sentry] Source map generation is currently disabled'), + '[Sentry] Source map generation is disabled in your SolidStart configuration.', + ); + }); + + it('should keep sourcemap as false and show long warning when debug is enabled', () => { + const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }, { debug: true }); + + expect(result).toBe(false); + // eslint-disable-next-line no-console + expect(console.warn).toHaveBeenCalledWith( + expect.stringContaining( + '[Sentry] Source map generation is currently disabled in your SolidStart configuration', + ), + ); + // eslint-disable-next-line no-console + expect(console.warn).toHaveBeenCalledWith( + expect.stringContaining( + 'This setting is either a default setting or was explicitly set in your configuration.', + ), ); }); }); @@ -210,7 +228,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 } }, { debug: true }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console @@ -223,7 +241,7 @@ describe('getUpdatedSourceMapSettings', () => { ); it('should set sourcemap to hidden when build config is empty', () => { - const result = getUpdatedSourceMapSettings({}); + const result = getUpdatedSourceMapSettings({}, { debug: true }); expect(result).toBe('hidden'); // eslint-disable-next-line no-console