Skip to content

Commit c8aa72e

Browse files
committed
ref: minor refactor
1 parent 7bb0926 commit c8aa72e

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

packages/nitro/src/config.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Options as SentryBundlerPluginOptions } from '@sentry/bundler-plugin-core';
2-
import { debug } from '@sentry/core';
32
import type { NitroConfig } from 'nitro/types';
43
import { createNitroModule } from './module';
4+
import { configureSourcemapSettings } from './sourceMaps';
55

66
export type SentryNitroOptions = Pick<
77
SentryBundlerPluginOptions,
@@ -40,33 +40,10 @@ export function setupSentryNitroModule(
4040
config.tracingChannel = true;
4141
}
4242

43-
const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true || moduleOptions?.disable === true;
44-
45-
if (!sourcemapUploadDisabled) {
46-
configureSourcemapSettings(config, moduleOptions);
47-
}
43+
configureSourcemapSettings(config, moduleOptions);
4844

4945
config.modules = config.modules || [];
5046
config.modules.push(createNitroModule(moduleOptions));
5147

5248
return config;
5349
}
54-
55-
function configureSourcemapSettings(config: NitroConfig, moduleOptions?: SentryNitroOptions): void {
56-
if (config.sourcemap === false) {
57-
debug.warn(
58-
'[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.',
59-
);
60-
}
61-
config.sourcemap = true;
62-
63-
// Nitro v3 has a `sourcemapMinify` plugin that destructively deletes `sourcesContent`,
64-
// `x_google_ignoreList`, and clears `mappings` for any chunk containing `node_modules`.
65-
// This makes sourcemaps unusable for Sentry.
66-
config.experimental = config.experimental || {};
67-
config.experimental.sourcemapMinify = false;
68-
69-
if (moduleOptions?.debug) {
70-
debug.log('[Sentry] Enabled source map generation and configured build settings for Sentry source map uploads.');
71-
}
72-
}

packages/nitro/src/sourceMaps.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Options } from '@sentry/bundler-plugin-core';
22
import { createSentryBuildPluginManager } from '@sentry/bundler-plugin-core';
3-
import type { Nitro } from 'nitro/types';
3+
import { debug } from '@sentry/core';
4+
import type { Nitro, NitroConfig } from 'nitro/types';
45
import type { SentryNitroOptions } from './config';
56

67
/**
@@ -89,3 +90,30 @@ export function getPluginOptions(options?: SentryNitroOptions): Options {
8990
},
9091
};
9192
}
93+
94+
/**
95+
* Configures the Nitro config to enable source map generation.
96+
*/
97+
export function configureSourcemapSettings(config: NitroConfig, moduleOptions?: SentryNitroOptions): void {
98+
const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true || moduleOptions?.disable === true;
99+
if (!sourcemapUploadDisabled) {
100+
return;
101+
}
102+
103+
if (config.sourcemap === false) {
104+
debug.warn(
105+
'[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.',
106+
);
107+
}
108+
config.sourcemap = true;
109+
110+
// Nitro v3 has a `sourcemapMinify` plugin that destructively deletes `sourcesContent`,
111+
// `x_google_ignoreList`, and clears `mappings` for any chunk containing `node_modules`.
112+
// This makes sourcemaps unusable for Sentry.
113+
config.experimental = config.experimental || {};
114+
config.experimental.sourcemapMinify = false;
115+
116+
if (moduleOptions?.debug) {
117+
debug.log('[Sentry] Enabled source map generation and configured build settings for Sentry source map uploads.');
118+
}
119+
}

0 commit comments

Comments
 (0)