Skip to content

Commit 55e9775

Browse files
committed
review suggestions
1 parent a3903df commit 55e9775

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

packages/sveltekit/src/vite/sourceMaps.ts

+23-34
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
329329
*/
330330
export type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined;
331331

332-
/** There are 3 ways to set up source maps (https://github.com/getsentry/sentry-javascript/issues/13993)
332+
/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-javascript/issues/13993)
333333
*
334334
* 1. User explicitly disabled source maps
335335
* - keep this setting (emit a warning that errors won't be unminified in Sentry)
@@ -358,50 +358,39 @@ export function changeViteSourceMapSettings(
358358

359359
const viteSourceMap = viteConfig.build.sourcemap;
360360

361+
const settingKey = 'vite.build.sourcemap';
362+
361363
if (viteSourceMap === false) {
362-
warnExplicitlyDisabledSourceMap('vite.build.sourcemap');
363364
previousUserSourceMapSetting = 'disabled';
365+
366+
consoleSandbox(() => {
367+
// eslint-disable-next-line no-console
368+
console.warn(
369+
`[Sentry] Parts of source map generation are currently disabled in your Vite 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\`).`,
370+
);
371+
});
364372
} else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) {
365-
logKeepSourceMapSetting('vite.build.sourcemap', viteSourceMap.toString(), sentryPluginOptions);
366373
previousUserSourceMapSetting = 'enabled';
374+
375+
if (sentryPluginOptions?.debug) {
376+
consoleSandbox(() => {
377+
// eslint-disable-next-line no-console
378+
console.log(
379+
`[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.`,
380+
);
381+
});
382+
}
367383
} else {
368-
viteConfig.build.sourcemap = 'hidden';
369-
logSentryEnablesSourceMap('vite.build.sourcemap', 'hidden');
370384
previousUserSourceMapSetting = 'unset';
371-
}
372-
373-
return previousUserSourceMapSetting;
374-
}
385+
viteConfig.build.sourcemap = 'hidden';
375386

376-
function logKeepSourceMapSetting(
377-
settingKey: string,
378-
settingValue: string,
379-
sentryPluginOptions?: CustomSentryVitePluginOptions,
380-
): void {
381-
if (sentryPluginOptions?.debug) {
382387
consoleSandbox(() => {
383-
// eslint-disable-next-line no-console
384-
console.log(
385-
`[Sentry] We discovered \`${settingKey}\` is set to \`${settingValue}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`,
386-
);
388+
// eslint-disable-next-line no-console
389+
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`.`);
387390
});
388391
}
389-
}
390-
391-
function warnExplicitlyDisabledSourceMap(settingKey: string): void {
392-
consoleSandbox(() => {
393-
// eslint-disable-next-line no-console
394-
console.warn(
395-
`[Sentry] Parts of source map generation are currently disabled in your Nuxt 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\`).`,
396-
);
397-
});
398-
}
399392

400-
function logSentryEnablesSourceMap(settingKey: string, settingValue: string): void {
401-
consoleSandbox(() => {
402-
// eslint-disable-next-line no-console
403-
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: ${settingValue}\`.`);
404-
});
393+
return previousUserSourceMapSetting;
405394
}
406395

407396
function getFiles(dir: string): string[] {

0 commit comments

Comments
 (0)