Skip to content

Commit 7264677

Browse files
authored
feat(nuxt): Streamline build logs (#17308)
This updates nuxt build logs a bit: 1. Make sure everything is gated behind `debug: true` 2. Show short message when sourceMaps: false without `debug: true` 3. Adjust messages to align with other SDKs a bit more. 4. Avoid `consoleSandbox` which we do not need there
1 parent 64d1a46 commit 7264677

File tree

2 files changed

+52
-65
lines changed

2 files changed

+52
-65
lines changed

packages/nuxt/src/vite/sourceMaps.ts

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Nuxt } from '@nuxt/schema';
2-
import { consoleSandbox } from '@sentry/core';
32
import { type SentryRollupPluginOptions, sentryRollupPlugin } from '@sentry/rollup-plugin';
43
import { type SentryVitePluginOptions, sentryVitePlugin } from '@sentry/vite-plugin';
54
import type { NitroConfig } from 'nitropack';
@@ -57,11 +56,9 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
5756
!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload &&
5857
(shouldDeleteFilesFallback.client || shouldDeleteFilesFallback.server)
5958
) {
60-
consoleSandbox(() =>
61-
// eslint-disable-next-line no-console
62-
console.log(
63-
"[Sentry] As Sentry enabled `'hidden'` source maps, source maps will be automatically deleted after uploading them to Sentry.",
64-
),
59+
// eslint-disable-next-line no-console
60+
console.log(
61+
"[Sentry] As Sentry enabled `'hidden'` source maps, source maps will be automatically deleted after uploading them to Sentry.",
6562
);
6663
}
6764
}
@@ -84,15 +81,13 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
8481
});
8582

8683
if (isDebug) {
87-
consoleSandbox(() => {
88-
if (!runtime) {
89-
// eslint-disable-next-line no-console
90-
console.log("[Sentry] Cannot detect runtime (client/server) inside hook 'vite:extendConfig'.");
91-
} else {
92-
// eslint-disable-next-line no-console
93-
console.log(`[Sentry] Adding Sentry Vite plugin to the ${runtime} runtime.`);
94-
}
95-
});
84+
if (!runtime) {
85+
// eslint-disable-next-line no-console
86+
console.log("[Sentry] Cannot detect runtime (client/server) inside hook 'vite:extendConfig'.");
87+
} else {
88+
// eslint-disable-next-line no-console
89+
console.log(`[Sentry] Adding Sentry Vite plugin to the ${runtime} runtime.`);
90+
}
9691
}
9792

9893
// Add Sentry plugin
@@ -119,10 +114,8 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
119114
validateNitroSourceMapSettings(nuxt, nitroConfig, moduleOptions);
120115

121116
if (isDebug) {
122-
consoleSandbox(() => {
123-
// eslint-disable-next-line no-console
124-
console.log('[Sentry] Adding Sentry Rollup plugin to the server runtime.');
125-
});
117+
// eslint-disable-next-line no-console
118+
console.log('[Sentry] Adding Sentry Rollup plugin to the server runtime.');
126119
}
127120

128121
// Add Sentry plugin
@@ -173,16 +166,14 @@ export function getPluginOptions(
173166
// eslint-disable-next-line deprecation/deprecation
174167
deprecatedSourcemapsOptions.filesToDeleteAfterUpload;
175168

176-
if (typeof filesToDeleteAfterUpload === 'undefined' && shouldDeleteFilesAfterUpload) {
177-
consoleSandbox(() => {
178-
// eslint-disable-next-line no-console
179-
console.log(
180-
`[Sentry] Setting \`sentry.sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload: [${fallbackFilesToDelete
181-
// Logging it as strings in the array
182-
.map(path => `"${path}"`)
183-
.join(', ')}]\` to delete generated source maps after they were uploaded to Sentry.`,
184-
);
185-
});
169+
if (typeof filesToDeleteAfterUpload === 'undefined' && shouldDeleteFilesAfterUpload && moduleOptions.debug) {
170+
// eslint-disable-next-line no-console
171+
console.log(
172+
`[Sentry] Setting \`sentry.sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload: [${fallbackFilesToDelete
173+
// Logging it as strings in the array
174+
.map(path => `"${path}"`)
175+
.join(', ')}]\` to delete generated source maps after they were uploaded to Sentry.`,
176+
);
186177
}
187178

188179
return {
@@ -277,11 +268,12 @@ export function changeNuxtSourceMapSettings(
277268
};
278269

279270
const nuxtSourceMap = nuxt.options.sourcemap;
271+
const isDebug = sentryModuleOptions.debug;
280272

281273
if (typeof nuxtSourceMap === 'string' || typeof nuxtSourceMap === 'boolean' || typeof nuxtSourceMap === 'undefined') {
282274
switch (nuxtSourceMap) {
283275
case false:
284-
warnExplicitlyDisabledSourceMap('sourcemap');
276+
warnExplicitlyDisabledSourceMap('sourcemap', isDebug);
285277
previousUserSourceMapSetting = { client: 'disabled', server: 'disabled' };
286278
break;
287279

@@ -292,33 +284,33 @@ export function changeNuxtSourceMapSettings(
292284
break;
293285
case undefined:
294286
nuxt.options.sourcemap = { server: 'hidden', client: 'hidden' };
295-
logSentryEnablesSourceMap('sourcemap.client', 'hidden');
296-
logSentryEnablesSourceMap('sourcemap.server', 'hidden');
287+
isDebug && logSentryEnablesSourceMap('sourcemap.client', 'hidden');
288+
isDebug && logSentryEnablesSourceMap('sourcemap.server', 'hidden');
297289
previousUserSourceMapSetting = { client: 'unset', server: 'unset' };
298290
break;
299291
}
300292
} else {
301293
if (nuxtSourceMap.client === false) {
302-
warnExplicitlyDisabledSourceMap('sourcemap.client');
294+
warnExplicitlyDisabledSourceMap('sourcemap.client', isDebug);
303295
previousUserSourceMapSetting.client = 'disabled';
304296
} else if (['hidden', true].includes(nuxtSourceMap.client)) {
305297
logKeepEnabledSourceMapSetting(sentryModuleOptions, 'sourcemap.client', nuxtSourceMap.client.toString());
306298
previousUserSourceMapSetting.client = 'enabled';
307299
} else {
308300
nuxt.options.sourcemap.client = 'hidden';
309-
logSentryEnablesSourceMap('sourcemap.client', 'hidden');
301+
isDebug && logSentryEnablesSourceMap('sourcemap.client', 'hidden');
310302
previousUserSourceMapSetting.client = 'unset';
311303
}
312304

313305
if (nuxtSourceMap.server === false) {
314-
warnExplicitlyDisabledSourceMap('sourcemap.server');
306+
warnExplicitlyDisabledSourceMap('sourcemap.server', isDebug);
315307
previousUserSourceMapSetting.server = 'disabled';
316308
} else if (['hidden', true].includes(nuxtSourceMap.server)) {
317309
logKeepEnabledSourceMapSetting(sentryModuleOptions, 'sourcemap.server', nuxtSourceMap.server.toString());
318310
previousUserSourceMapSetting.server = 'enabled';
319311
} else {
320312
nuxt.options.sourcemap.server = 'hidden';
321-
logSentryEnablesSourceMap('sourcemap.server', 'hidden');
313+
isDebug && logSentryEnablesSourceMap('sourcemap.server', 'hidden');
322314
previousUserSourceMapSetting.server = 'unset';
323315
}
324316
}
@@ -368,12 +360,10 @@ export function validateNitroSourceMapSettings(
368360

369361
nitroConfig.rollupConfig.output.sourcemapExcludeSources = false;
370362
if (isDebug) {
371-
consoleSandbox(() => {
372-
// eslint-disable-next-line no-console
373-
console.log(
374-
'[Sentry] Set `sourcemapExcludeSources: false` in the Nuxt config (`nitro.rollupConfig.output`). Source maps will now include the actual code to be able to un-minify code snippets in Sentry.',
375-
);
376-
});
363+
// eslint-disable-next-line no-console
364+
console.log(
365+
'[Sentry] Set `sourcemapExcludeSources: false` in the Nuxt config (`nitro.rollupConfig.output`). Source maps will now include the actual code to be able to un-minify code snippets in Sentry.',
366+
);
377367
}
378368
}
379369

@@ -389,12 +379,10 @@ function validateDifferentSourceMapSettings({
389379
otherSettingValue?: SourceMapSetting;
390380
}): void {
391381
if (nuxtSettingValue !== otherSettingValue) {
392-
consoleSandbox(() => {
393-
// eslint-disable-next-line no-console
394-
console.warn(
395-
`[Sentry] Source map generation settings are conflicting. Sentry uses \`${nuxtSettingKey}: ${nuxtSettingValue}\`. However, a conflicting setting was discovered (\`${otherSettingKey}: ${otherSettingValue}\`). This setting was probably explicitly set in your configuration. Sentry won't override this setting but it may affect source maps generation and upload. Without source maps, code snippets on the Sentry Issues page will remain minified.`,
396-
);
397-
});
382+
// eslint-disable-next-line no-console
383+
console.warn(
384+
`[Sentry] Source map generation settings are conflicting. Sentry uses \`${nuxtSettingKey}: ${nuxtSettingValue}\`. However, a conflicting setting was discovered (\`${otherSettingKey}: ${otherSettingValue}\`). This setting was probably explicitly set in your configuration. Sentry won't override this setting but it may affect source maps generation and upload. Without source maps, code snippets on the Sentry Issues page will remain minified.`,
385+
);
398386
}
399387
}
400388

@@ -404,27 +392,26 @@ function logKeepEnabledSourceMapSetting(
404392
settingValue: string,
405393
): void {
406394
if (sentryNuxtModuleOptions.debug) {
407-
consoleSandbox(() => {
408-
// eslint-disable-next-line no-console
409-
console.log(
410-
`[Sentry] \`${settingKey}\` is enabled with \`${settingValue}\`. This will correctly un-minify the code snippet on the Sentry Issue Details page.`,
411-
);
412-
});
395+
// eslint-disable-next-line no-console
396+
console.log(
397+
`[Sentry] \`${settingKey}\` is enabled with \`${settingValue}\`. This will correctly un-minify the code snippet on the Sentry Issue Details page.`,
398+
);
413399
}
414400
}
415401

416-
function warnExplicitlyDisabledSourceMap(settingKey: string): void {
417-
consoleSandbox(() => {
402+
function warnExplicitlyDisabledSourceMap(settingKey: string, isDebug: boolean | undefined): void {
403+
if (isDebug) {
418404
// eslint-disable-next-line no-console
419405
console.warn(
420-
`[Sentry] We discovered \`${settingKey}\` is set to \`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'\`).`,
406+
`[Sentry] Source map generation is 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\`).`,
421407
);
422-
});
408+
} else {
409+
// eslint-disable-next-line no-console
410+
console.warn(`[Sentry] Source map generation (\`${settingKey}\`) is disabled in your Vite configuration.`);
411+
}
423412
}
424413

425414
function logSentryEnablesSourceMap(settingKey: string, settingValue: string): void {
426-
consoleSandbox(() => {
427-
// eslint-disable-next-line no-console
428-
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: ${settingValue}\`.`);
429-
});
415+
// eslint-disable-next-line no-console
416+
console.log(`[Sentry] Enabled source map generation in the build options with \`${settingKey}: ${settingValue}\`.`);
430417
}

packages/nuxt/test/vite/sourceMaps.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ describe('change Nuxt source map settings', () => {
482482
);
483483
});
484484

485-
it('should log a message when debug is false and one of the source maps are unset', () => {
485+
it('should log a message when one of the source maps are unset', () => {
486486
nuxt.options.sourcemap.server = true;
487487

488-
const { client, server } = changeNuxtSourceMapSettings(nuxt as Nuxt, { debug: false });
488+
const { client, server } = changeNuxtSourceMapSettings(nuxt as Nuxt, { debug: true });
489489

490490
expect(client).toBe('unset');
491491
expect(server).toBe('enabled');
@@ -495,7 +495,7 @@ describe('change Nuxt source map settings', () => {
495495
);
496496
});
497497

498-
it('should not log a message when debug is false and client/server source maps are defined', () => {
498+
it('should not log a message when client/server source maps are defined and debug is false', () => {
499499
nuxt.options.sourcemap.client = false;
500500
nuxt.options.sourcemap.server = true;
501501

0 commit comments

Comments
 (0)