Skip to content

Commit a34ad06

Browse files
committed
ref: minor refactor
1 parent 12f779a commit a34ad06

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,
@@ -42,33 +42,10 @@ export function setupSentryNitroModule(
4242
config.tracing = true;
4343
}
4444

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

5147
config.modules = config.modules || [];
5248
config.modules.push(createNitroModule(moduleOptions));
5349

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

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)