Skip to content

Commit 03032ed

Browse files
committed
fix: correct hook for nitro
1 parent aaef3cf commit 03032ed

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

packages/nitro/src/setup/setupSourceMaps.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function setupSourceMaps(nitro: Nitro, moduleOptions: SentryNitroOptions)
3030
// In case we overwrite the source map settings, we default to deleting the files
3131
let shouldDeleteFilesFallback = true;
3232

33-
nitro.hooks.hook('compiled', () => {
33+
nitro.hooks.hook('build:before', () => {
3434
if (sourceMapsEnabled && !nitro.options.dev) {
3535
// Changing this setting will propagate:
3636
// - for client to viteConfig.build.sourceMap
@@ -179,32 +179,17 @@ export function getPluginOptions(
179179
};
180180
}
181181

182-
/* There are multiple ways to set up source maps (https://github.com/getsentry/sentry-javascript/issues/13993 and https://github.com/getsentry/sentry-javascript/pull/15859)
183-
1. User explicitly disabled source maps
184-
- keep this setting (emit a warning that errors won't be unminified in Sentry)
185-
- We will not upload anything
186-
2. users enabled source map generation (true, hidden, inline).
187-
- keep this setting (don't do anything - like deletion - besides uploading)
188-
3. users did not set source maps generation
189-
- we enable 'hidden' source maps generation
190-
- configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this)
191-
192-
Users only have to explicitly enable client source maps. Sentry only overwrites the base Nuxt source map settings as they propagate.
182+
/**
183+
* Changes the Nitro source map settings.
184+
* Exported for testing purposes.
193185
*/
194-
195-
/** only exported for tests */
196-
export function getSourceMapSettings(nitro: Nitro): SourceMapSetting | undefined {
197-
return nitro.options.sourceMap;
198-
}
199-
200-
/** only exported for testing */
201186
export function changeNitroSourceMapSettings(
202187
nitro: Nitro,
203188
sentryModuleOptions: SentryNitroOptions,
204189
): UserSourceMapSetting {
205190
let previousUserSetting: UserSourceMapSetting;
206191

207-
const nitroSourceMap = getSourceMapSettings(nitro);
192+
const nitroSourceMap = nitro.options.sourceMap;
208193
const isDebug = sentryModuleOptions.debug;
209194

210195
if (
@@ -233,8 +218,6 @@ export function changeNitroSourceMapSettings(
233218
break;
234219
}
235220
} else {
236-
// TODO: Should we do something for client?
237-
238221
if (nitroSourceMap === false) {
239222
warnExplicitlyDisabledSourceMap('sourceMap', isDebug);
240223
previousUserSetting = 'disabled';
@@ -262,10 +245,6 @@ export function validateNitroSourceMapSettings(
262245
): void {
263246
const isDebug = sentryModuleOptions.debug;
264247

265-
// NITRO CONFIG ---
266-
267-
// TODO: Frameworks using this could conflict with nitro, figure something out for them.
268-
269248
// Check conflicts with rollup config
270249
const nitroSourceMap = nitroConfig.sourceMap;
271250
nitroConfig.rollupConfig = nitroConfig.rollupConfig || {};

packages/nitro/test/rollup/setupSourceMaps.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { Nitro, RollupConfig } from 'nitropack/types';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
33
import type { SentryNitroOptions } from '../../src/common/types';
4-
import type { SourceMapSetting } from '../../src/rollup/setupSourceMaps';
4+
import type { SourceMapSetting } from '../../src/setup/setupSourceMaps';
55
import {
66
changeNitroSourceMapSettings,
77
getPluginOptions,
88
validateNitroSourceMapSettings,
9-
} from '../../src/rollup/setupSourceMaps';
9+
} from '../../src/setup/setupSourceMaps';
1010

1111
vi.mock('@sentry/core', () => ({
1212
consoleSandbox: (callback: () => void) => callback(),

0 commit comments

Comments
 (0)