Skip to content

Commit 5464865

Browse files
logaretmclaude
andcommitted
fix(nitro): Respect user's explicit sourcemap setting instead of forcing true
Previously, `configureSourcemapSettings` unconditionally set `config.sourcemap = true`, overriding the user's explicit `false`. This could expose source maps publicly when users intentionally disabled them. Now follows the same 3-case pattern as other meta-framework SDKs (Nuxt): 1. User disabled (false) → keep their setting, warn about unminified errors 2. User enabled (true) → keep their setting 3. User didn't set (undefined) → enable for Sentry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9ca8a96 commit 5464865

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

packages/nitro/src/sourceMaps.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ export function getPluginOptions(options?: SentryNitroOptions): BundlerPluginOpt
9090
};
9191
}
9292

93-
/**
94-
* Configures the Nitro config to enable source map generation.
95-
*/
93+
/* Source map configuration rules:
94+
1. User explicitly disabled source maps (sourcemap: false)
95+
- Keep their setting, emit a warning that errors won't be unminified in Sentry
96+
- We will not upload anything
97+
2. User enabled source map generation (true)
98+
- Keep their setting (don't modify besides uploading)
99+
3. User did not set source maps (undefined)
100+
- We enable source maps for Sentry
101+
- Configure `filesToDeleteAfterUpload` to clean up .map files after upload
102+
*/
96103
export function configureSourcemapSettings(config: NitroConfig, moduleOptions?: SentryNitroOptions): void {
97104
const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true;
98105
if (sourcemapUploadDisabled) {
@@ -101,20 +108,26 @@ export function configureSourcemapSettings(config: NitroConfig, moduleOptions?:
101108

102109
if (config.sourcemap === false) {
103110
debug.warn(
104-
'[Sentry] You have explicitly disabled source maps (`sourcemap: false`). Sentry is overriding this to `true` so that errors can be un-minified in Sentry. To disable Sentry source map uploads entirely, use `sourcemaps: { disable: true }` in your Sentry options instead.',
111+
'[Sentry] You have explicitly disabled source maps (`sourcemap: false`). Sentry will not upload source maps, and errors will not be unminified. To let Sentry handle source maps, remove the `sourcemap` option from your Nitro config, or use `sourcemaps: { disable: true }` in your Sentry options to silence this warning.',
105112
);
113+
return;
106114
}
107115

108-
config.sourcemap = true;
116+
if (config.sourcemap === true) {
117+
if (moduleOptions?.debug) {
118+
debug.log('[Sentry] Source maps are already enabled. Sentry will upload them for error unminification.');
119+
}
120+
} else {
121+
// User did not explicitly set sourcemap — enable it for Sentry
122+
config.sourcemap = true;
123+
if (moduleOptions?.debug) {
124+
debug.log('[Sentry] Enabled source map generation for Sentry. Source map files will be deleted after upload.');
125+
}
126+
}
109127

110128
// Nitro v3 has a `sourcemapMinify` plugin that destructively deletes `sourcesContent`,
111129
// `x_google_ignoreList`, and clears `mappings` for any chunk containing `node_modules`.
112130
// This makes sourcemaps unusable for Sentry.
113-
// FIXME: Not sure about this one, it works either way?
114131
config.experimental = config.experimental || {};
115132
config.experimental.sourcemapMinify = false;
116-
117-
if (moduleOptions?.debug) {
118-
debug.log('[Sentry] Enabled source map generation and configured build settings for Sentry source map uploads.');
119-
}
120133
}

packages/nitro/test/sourceMaps.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,25 @@ describe('configureSourcemapSettings', () => {
142142
expect(config.sourcemap).toBe(true);
143143
});
144144

145-
it('forces sourcemap to true even when user set it to false', () => {
145+
it('respects user explicitly disabling sourcemaps and warns', () => {
146146
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
147147
const config: NitroConfig = { sourcemap: false };
148148
configureSourcemapSettings(config);
149149

150-
expect(config.sourcemap).toBe(true);
151-
expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining('overriding this to `true`'));
150+
expect(config.sourcemap).toBe(false);
151+
expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining('explicitly disabled source maps'));
152152
debugSpy.mockRestore();
153153
});
154154

155+
it('does not modify experimental config when user disabled sourcemaps', () => {
156+
vi.spyOn(debug, 'warn').mockImplementation(() => {});
157+
const config: NitroConfig = { sourcemap: false };
158+
configureSourcemapSettings(config);
159+
160+
expect(config.experimental).toBeUndefined();
161+
vi.restoreAllMocks();
162+
});
163+
155164
it('keeps sourcemap true when user already set it', () => {
156165
const config: NitroConfig = { sourcemap: true };
157166
configureSourcemapSettings(config);

0 commit comments

Comments
 (0)