MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / configureSourcemapSettings

Function configureSourcemapSettings

packages/nitro/src/sourceMaps.ts:136–192  ·  view source on GitHub ↗
(
  config: NitroConfig,
  moduleOptions?: SentryNitroOptions,
)

Source from the content-addressed store, hash-verified

134 - Configure `filesToDeleteAfterUpload` to clean up .map files after upload
135*/
136export function configureSourcemapSettings(
137 config: NitroConfig,
138 moduleOptions?: SentryNitroOptions,
139): { sentryEnabledSourcemaps: boolean } {
140 const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true;
141 if (sourcemapUploadDisabled) {
142 return { sentryEnabledSourcemaps: false };
143 }
144
145 // Nitro types `sourcemap` as `boolean`, but it forwards the value to Vite which also accepts `'hidden'` and `'inline'`.
146 const userSourcemap = (config as { sourcemap?: boolean | 'hidden' | 'inline' }).sourcemap;
147
148 if (userSourcemap === false) {
149 // eslint-disable-next-line no-console
150 console.warn(
151 '[@sentry/nitro] 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.',
152 );
153 return { sentryEnabledSourcemaps: false };
154 }
155
156 if (userSourcemap === 'inline') {
157 // eslint-disable-next-line no-console
158 console.warn(
159 '[@sentry/nitro] You have set `sourcemap: "inline"`. Inline source maps are embedded in the output bundle, so there are no `.map` files to upload. Sentry will not upload source maps. Set `sourcemap: "hidden"` (or leave it unset) to let Sentry upload source maps and un-minify errors.',
160 );
161 return { sentryEnabledSourcemaps: false };
162 }
163
164 let sentryEnabledSourcemaps = false;
165 if (userSourcemap === true || userSourcemap === 'hidden') {
166 if (moduleOptions?.debug) {
167 // eslint-disable-next-line no-console
168 console.log(
169 `[@sentry/nitro] Source maps are already enabled (\`sourcemap: ${JSON.stringify(userSourcemap)}\`). Sentry will upload them for error unminification.`,
170 );
171 }
172 } else {
173 // User did not explicitly set sourcemap, enable hidden source maps for Sentry.
174 // `'hidden'` emits .map files without adding a `//# sourceMappingURL=` comment to the output, avoiding public exposure.
175 (config as { sourcemap?: unknown }).sourcemap = 'hidden';
176 sentryEnabledSourcemaps = true;
177 if (moduleOptions?.debug) {
178 // eslint-disable-next-line no-console
179 console.log(
180 '[@sentry/nitro] Enabled hidden source map generation for Sentry. Source map files will be deleted after upload.',
181 );
182 }
183 }
184
185 // Nitro v3 has a `sourcemapMinify` plugin that destructively deletes `sourcesContent`,
186 // `x_google_ignoreList`, and clears `mappings` for any chunk containing `node_modules`.
187 // This makes sourcemaps unusable for Sentry.
188 config.experimental = config.experimental || {};
189 config.experimental.sourcemapMinify = false;
190
191 return { sentryEnabledSourcemaps };
192}

Callers 2

sourceMaps.test.tsFile · 0.90
setupSentryNitroModuleFunction · 0.90

Calls 2

warnMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected