Skip to content

Commit 52626ee

Browse files
committed
fix: skip sourcemap upload hooks early
1 parent 14b31ea commit 52626ee

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

packages/nitro/src/sourceMaps.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,7 @@ import type { SentryNitroOptions } from './config';
99
export function setupSourceMaps(nitro: Nitro, options?: SentryNitroOptions, sentryEnabledSourcemaps?: boolean): void {
1010
// The `compiled` hook fires on EVERY rebuild during `nitro dev` watch mode.
1111
// nitro.options.dev is reliably set by the time module setup runs.
12-
if (nitro.options.dev) {
13-
return;
14-
}
15-
16-
// Nitro spawns a nested Nitro instance for prerendering with the user's `modules` re-installed.
17-
// Uploading here would double-upload source maps and create a duplicate release.
18-
if (nitro.options.preset === 'nitro-prerender') {
19-
return;
20-
}
21-
22-
// Respect user's explicit disable
23-
if (options?.sourcemaps?.disable === true) {
12+
if (shouldSkipSourcemapUpload(nitro, options)) {
2413
return;
2514
}
2615

@@ -29,6 +18,18 @@ export function setupSourceMaps(nitro: Nitro, options?: SentryNitroOptions, sent
2918
});
3019
}
3120

21+
/**
22+
* Determines if sourcemap uploads should be skipped.
23+
*/
24+
function shouldSkipSourcemapUpload(nitro: Nitro, options?: SentryNitroOptions): boolean {
25+
return !!(
26+
nitro.options.dev ||
27+
nitro.options.preset === 'nitro-prerender' ||
28+
nitro.options.sourcemap === false ||
29+
options?.sourcemaps?.disable === true
30+
);
31+
}
32+
3233
/**
3334
* Handles the actual source map upload after the build completes.
3435
*/

packages/nitro/test/sourceMaps.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ describe('setupSourceMaps', () => {
274274
expect(hookFn).not.toHaveBeenCalled();
275275
});
276276

277+
it('does not register hook when nitro sourcemap is disabled', () => {
278+
const hookFn = vi.fn();
279+
const nitro = {
280+
options: { dev: false, sourcemap: false, output: { serverDir: '/output/server' } },
281+
hooks: { hook: hookFn },
282+
} as any;
283+
284+
setupSourceMaps(nitro);
285+
286+
expect(hookFn).not.toHaveBeenCalled();
287+
});
288+
277289
it('does not register hook in nitro-prerender preset', () => {
278290
const hookFn = vi.fn();
279291
const nitro = {

0 commit comments

Comments
 (0)