Skip to content

Commit f896f36

Browse files
committed
review suggestions
1 parent ea795bc commit f896f36

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
@@ -248,7 +248,7 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
248248
*/
249249
export type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined;
250250

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

278278
const viteSourceMap = viteConfig.build.sourcemap;
279279

280+
const settingKey = 'vite.build.sourcemap';
281+
280282
if (viteSourceMap === false) {
281-
warnExplicitlyDisabledSourceMap('vite.build.sourcemap');
282283
previousUserSourceMapSetting = 'disabled';
284+
285+
consoleSandbox(() => {
286+
// eslint-disable-next-line no-console
287+
console.warn(
288+
`[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\`).`,
289+
);
290+
});
283291
} else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) {
284-
logKeepSourceMapSetting('vite.build.sourcemap', viteSourceMap.toString(), sentryPluginOptions);
285292
previousUserSourceMapSetting = 'enabled';
293+
294+
if (sentryPluginOptions?.debug) {
295+
consoleSandbox(() => {
296+
// eslint-disable-next-line no-console
297+
console.log(
298+
`[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.`,
299+
);
300+
});
301+
}
286302
} else {
287-
viteConfig.build.sourcemap = 'hidden';
288-
logSentryEnablesSourceMap('vite.build.sourcemap', 'hidden');
289303
previousUserSourceMapSetting = 'unset';
290-
}
291-
292-
return previousUserSourceMapSetting;
293-
}
304+
viteConfig.build.sourcemap = 'hidden';
294305

295-
function logKeepSourceMapSetting(
296-
settingKey: string,
297-
settingValue: string,
298-
sentryPluginOptions?: CustomSentryVitePluginOptions,
299-
): void {
300-
if (sentryPluginOptions?.debug) {
301306
consoleSandbox(() => {
302-
// eslint-disable-next-line no-console
303-
console.log(
304-
`[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.`,
305-
);
307+
// eslint-disable-next-line no-console
308+
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`.`);
306309
});
307310
}
308-
}
309-
310-
function warnExplicitlyDisabledSourceMap(settingKey: string): void {
311-
consoleSandbox(() => {
312-
// eslint-disable-next-line no-console
313-
console.warn(
314-
`[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\`).`,
315-
);
316-
});
317-
}
318311

319-
function logSentryEnablesSourceMap(settingKey: string, settingValue: string): void {
320-
consoleSandbox(() => {
321-
// eslint-disable-next-line no-console
322-
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: ${settingValue}\`.`);
323-
});
312+
return previousUserSourceMapSetting;
324313
}
325314

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

0 commit comments

Comments
 (0)