Skip to content

Commit 5bf9fd7

Browse files
authored
feat(solidstart): Streamline build logs (#17304)
Streamlines solidstart build logs: 1. Only show messages when `debug: true` 2. Show short message when sourcemaps: false and debug: false
1 parent f866c82 commit 5bf9fd7

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

packages/solidstart/src/vite/sourceMaps.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { consoleSandbox } from '@sentry/core';
21
import { sentryVitePlugin } from '@sentry/vite-plugin';
32
import type { Plugin, UserConfig } from 'vite';
43
import type { SentrySolidStartPluginOptions } from './types';
@@ -21,14 +20,13 @@ export function makeAddSentryVitePlugin(options: SentrySolidStartPluginOptions,
2120
// For .output, .vercel, .netlify etc.
2221
updatedFilesToDeleteAfterUpload = ['.*/**/*.map'];
2322

24-
consoleSandbox(() => {
23+
debug &&
2524
// eslint-disable-next-line no-console
2625
console.log(
2726
`[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify(
2827
updatedFilesToDeleteAfterUpload,
2928
)}\` to delete generated source maps after they were uploaded to Sentry.`,
3029
);
31-
});
3230
}
3331

3432
return [
@@ -103,36 +101,37 @@ export function getUpdatedSourceMapSettings(
103101
let updatedSourceMapSetting = viteSourceMap;
104102

105103
const settingKey = 'vite.build.sourcemap';
104+
const debug = sentryPluginOptions?.debug;
106105

107106
if (viteSourceMap === false) {
108107
updatedSourceMapSetting = viteSourceMap;
109108

110-
consoleSandbox(() => {
111-
// eslint-disable-next-line no-console
109+
if (debug) {
110+
// Longer debug message with more details
111+
// eslint-disable-next-line no-console
112112
console.warn(
113113
`[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\`).`,
114114
);
115-
});
115+
} else {
116+
// eslint-disable-next-line no-console
117+
console.warn('[Sentry] Source map generation is disabled in your SolidStart configuration.');
118+
}
116119
} else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) {
117120
updatedSourceMapSetting = viteSourceMap;
118121

119-
if (sentryPluginOptions?.debug) {
120-
consoleSandbox(() => {
121-
// eslint-disable-next-line no-console
122-
console.log(
123-
`[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.`,
124-
);
125-
});
126-
}
122+
debug &&
123+
// eslint-disable-next-line no-console
124+
console.log(
125+
`[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.`,
126+
);
127127
} else {
128128
updatedSourceMapSetting = 'hidden';
129129

130-
consoleSandbox(() => {
130+
debug &&
131131
// eslint-disable-next-line no-console
132132
console.log(
133133
`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`,
134134
);
135-
});
136135
}
137136

138137
return updatedSourceMapSetting;

packages/solidstart/test/vite/sourceMaps.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,31 @@ describe('getUpdatedSourceMapSettings', () => {
179179
});
180180

181181
describe('when sourcemap is false', () => {
182-
it('should keep sourcemap as false and show warning', () => {
182+
it('should keep sourcemap as false and show short warning when debug is disabled', () => {
183183
const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } });
184184

185185
expect(result).toBe(false);
186186
// eslint-disable-next-line no-console
187187
expect(console.warn).toHaveBeenCalledWith(
188-
expect.stringContaining('[Sentry] Source map generation is currently disabled'),
188+
'[Sentry] Source map generation is disabled in your SolidStart configuration.',
189+
);
190+
});
191+
192+
it('should keep sourcemap as false and show long warning when debug is enabled', () => {
193+
const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }, { debug: true });
194+
195+
expect(result).toBe(false);
196+
// eslint-disable-next-line no-console
197+
expect(console.warn).toHaveBeenCalledWith(
198+
expect.stringContaining(
199+
'[Sentry] Source map generation is currently disabled in your SolidStart configuration',
200+
),
201+
);
202+
// eslint-disable-next-line no-console
203+
expect(console.warn).toHaveBeenCalledWith(
204+
expect.stringContaining(
205+
'This setting is either a default setting or was explicitly set in your configuration.',
206+
),
189207
);
190208
});
191209
});
@@ -210,7 +228,7 @@ describe('getUpdatedSourceMapSettings', () => {
210228
it.each([[undefined], ['invalid'], ['something'], [null]])(
211229
'should set sourcemap to hidden when value is %s',
212230
input => {
213-
const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } });
231+
const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }, { debug: true });
214232

215233
expect(result).toBe('hidden');
216234
// eslint-disable-next-line no-console
@@ -223,7 +241,7 @@ describe('getUpdatedSourceMapSettings', () => {
223241
);
224242

225243
it('should set sourcemap to hidden when build config is empty', () => {
226-
const result = getUpdatedSourceMapSettings({});
244+
const result = getUpdatedSourceMapSettings({}, { debug: true });
227245

228246
expect(result).toBe('hidden');
229247
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)