@@ -7,32 +7,31 @@ import type { OutputOptions } from 'rollup';
77import type { SentryNuxtModuleOptions } from '../common/types' ;
88
99/**
10- * Whether the user enabled (true, 'hidden', 'inline') or disabled (false) sourcemaps
10+ * Whether the user enabled (true, 'hidden', 'inline') or disabled (false) source maps
1111 */
12- export type UserSourcemapSetting = 'enabled' | 'disabled' | 'unset' | undefined ;
12+ export type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined ;
1313
1414/**
15- * Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for N itr/**
16- *
15+ * Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for Nitro).
1716 */
1817export function setupSourceMaps ( moduleOptions : SentryNuxtModuleOptions , nuxt : Nuxt ) : void {
1918 const sourceMapsUploadOptions = moduleOptions . sourceMapsUploadOptions || { } ;
2019 const sourceMapsEnabled = sourceMapsUploadOptions . enabled ?? true ;
2120
2221 nuxt . hook ( 'modules:done' , ( ) => {
2322 if ( sourceMapsEnabled && ! nuxt . options . dev ) {
24- changeNuxtSourcemapSettings ( nuxt , moduleOptions ) ;
23+ changeNuxtSourceMapSettings ( nuxt , moduleOptions ) ;
2524 }
2625 } ) ;
2726
2827 nuxt . hook ( 'vite:extendConfig' , async ( viteConfig , _env ) => {
2928 if ( sourceMapsEnabled && viteConfig . mode !== 'development' ) {
30- const previousUserSourcemapSetting = changeViteSourcemapSettings ( viteConfig , moduleOptions ) ;
29+ const previousUserSourceMapSetting = changeViteSourceMapSettings ( viteConfig , moduleOptions ) ;
3130
3231 // Add Sentry plugin
3332 viteConfig . plugins = viteConfig . plugins || [ ] ;
3433 viteConfig . plugins . push (
35- sentryVitePlugin ( getPluginOptions ( moduleOptions , previousUserSourcemapSetting === 'unset' ) ) ,
34+ sentryVitePlugin ( getPluginOptions ( moduleOptions , previousUserSourceMapSetting === 'unset' ) ) ,
3635 ) ;
3736 }
3837 } ) ;
@@ -50,11 +49,11 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
5049 nitroConfig . rollupConfig . plugins = [ nitroConfig . rollupConfig . plugins ] ;
5150 }
5251
53- const previousUserSourcemapSetting = changeRollupSourcemapSettings ( nitroConfig , moduleOptions ) ;
52+ const previousUserSourceMapSetting = changeRollupSourceMapSettings ( nitroConfig , moduleOptions ) ;
5453
5554 // Add Sentry plugin
5655 nitroConfig . rollupConfig . plugins . push (
57- sentryRollupPlugin ( getPluginOptions ( moduleOptions , previousUserSourcemapSetting === 'unset' ) ) ,
56+ sentryRollupPlugin ( getPluginOptions ( moduleOptions , previousUserSourceMapSetting === 'unset' ) ) ,
5857 ) ;
5958 }
6059 } ) ;
@@ -102,7 +101,7 @@ export function getPluginOptions(
102101
103102 sourcemaps : {
104103 // The server/client files are in different places depending on the nitro preset (e.g. '.output/server' or '.netlify/functions-internal/server')
105- // We cannot determine automatically how the build folder looks like (depends on the preset), so we have to accept that sourcemaps are uploaded multiple times (with the vitePlugin for Nuxt and the rollupPlugin for Nitro).
104+ // We cannot determine automatically how the build folder looks like (depends on the preset), so we have to accept that source maps are uploaded multiple times (with the vitePlugin for Nuxt and the rollupPlugin for Nitro).
106105 // If we could know where the server/client assets are located, we could do something like this (based on the Nitro preset): isNitro ? ['./.output/server/**/*'] : ['./.output/public/**/*'],
107106 assets : sourceMapsUploadOptions . sourcemaps ?. assets ?? undefined ,
108107 ignore : sourceMapsUploadOptions . sourcemaps ?. ignore ?? undefined ,
@@ -117,77 +116,76 @@ export function getPluginOptions(
117116 } ;
118117}
119118
120- /* There are 3 ways to set up sourcemaps (https://github.com/getsentry/sentry-javascript/issues/13993)
121- 1. User explicitly disabled sourcemaps
119+ /* There are 3 ways to set up source maps (https://github.com/getsentry/sentry-javascript/issues/13993)
120+ 1. User explicitly disabled source maps
122121 - keep this setting (emit a warning that errors won't be unminified in Sentry)
123122 - We will not upload anything
124123 2. users enabled source map generation (true, hidden, inline).
125- - keep this setting this and
126- - don't do anything (i.e. deletion) besides uploading.
124+ - keep this setting (don't do anything - like deletion - besides uploading)
127125 3. users did not set source maps generation
128126 - we enable 'hidden' source maps generation
129127 - configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this)
130128
131- Nuxt has 3 places to set sourcemaps : vite options, rollup options, nuxt itself
132- Ideally, all 3 are enabled to get all sourcemaps .
129+ Nuxt has 3 places to set source maps : vite options, rollup options, nuxt itself
130+ Ideally, all 3 are enabled to get all source maps .
133131 */
134132
135133/** only exported for testing */
136- export function changeNuxtSourcemapSettings (
134+ export function changeNuxtSourceMapSettings (
137135 nuxt : Nuxt ,
138136 sentryModuleOptions : SentryNuxtModuleOptions ,
139- ) : { client : UserSourcemapSetting ; server : UserSourcemapSetting } {
137+ ) : { client : UserSourceMapSetting ; server : UserSourceMapSetting } {
140138 nuxt . options = nuxt . options || { } ;
141139 nuxt . options . sourcemap = nuxt . options . sourcemap ?? { server : undefined , client : undefined } ;
142140
143- let previousUserSourceMapSetting : { client : UserSourcemapSetting ; server : UserSourcemapSetting } = {
141+ let previousUserSourceMapSetting : { client : UserSourceMapSetting ; server : UserSourceMapSetting } = {
144142 client : undefined ,
145143 server : undefined ,
146144 } ;
147145
148- const nuxtSourcemap = nuxt . options . sourcemap ;
146+ const nuxtSourceMap = nuxt . options . sourcemap ;
149147
150- if ( typeof nuxtSourcemap === 'string' || typeof nuxtSourcemap === 'boolean' || typeof nuxtSourcemap === 'undefined' ) {
151- switch ( nuxtSourcemap ) {
148+ if ( typeof nuxtSourceMap === 'string' || typeof nuxtSourceMap === 'boolean' || typeof nuxtSourceMap === 'undefined' ) {
149+ switch ( nuxtSourceMap ) {
152150 case false :
153- warnExplicitlyDisabledSourcemap ( 'sourcemap' ) ;
151+ warnExplicitlyDisabledSourceMap ( 'sourcemap' ) ;
154152 previousUserSourceMapSetting = { client : 'disabled' , server : 'disabled' } ;
155153 break ;
156154
157155 case 'hidden' :
158156 case true :
159- logKeepSourcemapSetting ( sentryModuleOptions , 'sourcemap' , ( nuxtSourcemap as true ) . toString ( ) ) ;
157+ logKeepSourceMapSetting ( sentryModuleOptions , 'sourcemap' , ( nuxtSourceMap as true ) . toString ( ) ) ;
160158 previousUserSourceMapSetting = { client : 'enabled' , server : 'enabled' } ;
161159 break ;
162160 case undefined :
163161 nuxt . options . sourcemap = { server : 'hidden' , client : 'hidden' } ;
164- logSentryEnablesSourcemap ( 'sourcemap.client' , 'hidden' ) ;
165- logSentryEnablesSourcemap ( 'sourcemap.server' , 'hidden' ) ;
162+ logSentryEnablesSourceMap ( 'sourcemap.client' , 'hidden' ) ;
163+ logSentryEnablesSourceMap ( 'sourcemap.server' , 'hidden' ) ;
166164 previousUserSourceMapSetting = { client : 'unset' , server : 'unset' } ;
167165 break ;
168166 }
169167 } else {
170- if ( nuxtSourcemap . client === false ) {
171- warnExplicitlyDisabledSourcemap ( 'sourcemap.client' ) ;
168+ if ( nuxtSourceMap . client === false ) {
169+ warnExplicitlyDisabledSourceMap ( 'sourcemap.client' ) ;
172170 previousUserSourceMapSetting . client = 'disabled' ;
173- } else if ( [ 'hidden' , true ] . includes ( nuxtSourcemap . client ) ) {
174- logKeepSourcemapSetting ( sentryModuleOptions , 'sourcemap.client' , nuxtSourcemap . client . toString ( ) ) ;
171+ } else if ( [ 'hidden' , true ] . includes ( nuxtSourceMap . client ) ) {
172+ logKeepSourceMapSetting ( sentryModuleOptions , 'sourcemap.client' , nuxtSourceMap . client . toString ( ) ) ;
175173 previousUserSourceMapSetting . client = 'enabled' ;
176174 } else {
177175 nuxt . options . sourcemap . client = 'hidden' ;
178- logSentryEnablesSourcemap ( 'sourcemap.client' , 'hidden' ) ;
176+ logSentryEnablesSourceMap ( 'sourcemap.client' , 'hidden' ) ;
179177 previousUserSourceMapSetting . client = 'unset' ;
180178 }
181179
182- if ( nuxtSourcemap . server === false ) {
183- warnExplicitlyDisabledSourcemap ( 'sourcemap.server' ) ;
180+ if ( nuxtSourceMap . server === false ) {
181+ warnExplicitlyDisabledSourceMap ( 'sourcemap.server' ) ;
184182 previousUserSourceMapSetting . server = 'disabled' ;
185- } else if ( [ 'hidden' , true ] . includes ( nuxtSourcemap . server ) ) {
186- logKeepSourcemapSetting ( sentryModuleOptions , 'sourcemap.server' , nuxtSourcemap . server . toString ( ) ) ;
183+ } else if ( [ 'hidden' , true ] . includes ( nuxtSourceMap . server ) ) {
184+ logKeepSourceMapSetting ( sentryModuleOptions , 'sourcemap.server' , nuxtSourceMap . server . toString ( ) ) ;
187185 previousUserSourceMapSetting . server = 'enabled' ;
188186 } else {
189187 nuxt . options . sourcemap . server = 'hidden' ;
190- logSentryEnablesSourcemap ( 'sourcemap.server' , 'hidden' ) ;
188+ logSentryEnablesSourceMap ( 'sourcemap.server' , 'hidden' ) ;
191189 previousUserSourceMapSetting . server = 'unset' ;
192190 }
193191 }
@@ -196,32 +194,32 @@ export function changeNuxtSourcemapSettings(
196194}
197195
198196/** only exported for testing */
199- export function changeViteSourcemapSettings (
197+ export function changeViteSourceMapSettings (
200198 viteConfig : { build ?: { sourcemap ?: boolean | 'inline' | 'hidden' } } ,
201199 sentryModuleOptions : SentryNuxtModuleOptions ,
202- ) : UserSourcemapSetting {
200+ ) : UserSourceMapSetting {
203201 viteConfig . build = viteConfig . build || { } ;
204- const viteSourcemap = viteConfig . build . sourcemap ;
202+ const viteSourceMap = viteConfig . build . sourcemap ;
205203
206- let previousUserSourceMapSetting : UserSourcemapSetting ;
204+ let previousUserSourceMapSetting : UserSourceMapSetting ;
207205
208- if ( viteSourcemap === false ) {
209- warnExplicitlyDisabledSourcemap ( 'vite.build.sourcemap' ) ;
206+ if ( viteSourceMap === false ) {
207+ warnExplicitlyDisabledSourceMap ( 'vite.build.sourcemap' ) ;
210208 previousUserSourceMapSetting = 'disabled' ;
211- } else if ( viteSourcemap && [ 'hidden' , 'inline' , true ] . includes ( viteSourcemap ) ) {
212- logKeepSourcemapSetting ( sentryModuleOptions , 'vite.build.sourcemap' , viteSourcemap . toString ( ) ) ;
209+ } else if ( viteSourceMap && [ 'hidden' , 'inline' , true ] . includes ( viteSourceMap ) ) {
210+ logKeepSourceMapSetting ( sentryModuleOptions , 'vite.build.sourcemap' , viteSourceMap . toString ( ) ) ;
213211 previousUserSourceMapSetting = 'enabled' ;
214212 } else {
215213 viteConfig . build . sourcemap = 'hidden' ;
216- logSentryEnablesSourcemap ( 'vite.build.sourcemap' , 'hidden' ) ;
214+ logSentryEnablesSourceMap ( 'vite.build.sourcemap' , 'hidden' ) ;
217215 previousUserSourceMapSetting = 'unset' ;
218216 }
219217
220218 return previousUserSourceMapSetting ;
221219}
222220
223221/** only exported for testing */
224- export function changeRollupSourcemapSettings (
222+ export function changeRollupSourceMapSettings (
225223 nitroConfig : {
226224 rollupConfig ?: {
227225 output ?: {
@@ -231,38 +229,38 @@ export function changeRollupSourcemapSettings(
231229 } ;
232230 } ,
233231 sentryModuleOptions : SentryNuxtModuleOptions ,
234- ) : UserSourcemapSetting {
232+ ) : UserSourceMapSetting {
235233 nitroConfig . rollupConfig = nitroConfig . rollupConfig || { } ;
236234 nitroConfig . rollupConfig . output = nitroConfig . rollupConfig . output || { sourcemap : undefined } ;
237235
238- let previousUserSourceMapSetting : UserSourcemapSetting ;
236+ let previousUserSourceMapSetting : UserSourceMapSetting ;
239237
240- const nitroSourcemap = nitroConfig . rollupConfig . output . sourcemap ;
238+ const nitroSourceMap = nitroConfig . rollupConfig . output . sourcemap ;
241239
242- if ( nitroSourcemap === false ) {
243- warnExplicitlyDisabledSourcemap ( 'nitro.rollupConfig.output.sourcemap' ) ;
240+ if ( nitroSourceMap === false ) {
241+ warnExplicitlyDisabledSourceMap ( 'nitro.rollupConfig.output.sourcemap' ) ;
244242 previousUserSourceMapSetting = 'disabled' ;
245- } else if ( nitroSourcemap && [ 'hidden' , 'inline' , true ] . includes ( nitroSourcemap ) ) {
246- logKeepSourcemapSetting ( sentryModuleOptions , 'nitro.rollupConfig.output.sourcemap' , nitroSourcemap . toString ( ) ) ;
243+ } else if ( nitroSourceMap && [ 'hidden' , 'inline' , true ] . includes ( nitroSourceMap ) ) {
244+ logKeepSourceMapSetting ( sentryModuleOptions , 'nitro.rollupConfig.output.sourcemap' , nitroSourceMap . toString ( ) ) ;
247245 previousUserSourceMapSetting = 'enabled' ;
248246 } else {
249247 nitroConfig . rollupConfig . output . sourcemap = 'hidden' ;
250- logSentryEnablesSourcemap ( 'nitro.rollupConfig.output.sourcemap' , 'hidden' ) ;
248+ logSentryEnablesSourceMap ( 'nitro.rollupConfig.output.sourcemap' , 'hidden' ) ;
251249 previousUserSourceMapSetting = 'unset' ;
252250 }
253251
254252 nitroConfig . rollupConfig . output . sourcemapExcludeSources = false ;
255253 consoleSandbox ( ( ) => {
256254 // eslint-disable-next-line no-console
257255 console . log (
258- '[Sentry] Disabled sourcemap setting in the Nuxt config: `nitro.rollupConfig.output.sourcemapExcludeSources`. Source maps will include the actual code to be able to un-minify code snippets in Sentry.' ,
256+ '[Sentry] Disabled source map setting in the Nuxt config: `nitro.rollupConfig.output.sourcemapExcludeSources`. Source maps will include the actual code to be able to un-minify code snippets in Sentry.' ,
259257 ) ;
260258 } ) ;
261259
262260 return previousUserSourceMapSetting ;
263261}
264262
265- function logKeepSourcemapSetting (
263+ function logKeepSourceMapSetting (
266264 sentryNuxtModuleOptions : SentryNuxtModuleOptions ,
267265 settingKey : string ,
268266 settingValue : string ,
@@ -271,24 +269,24 @@ function logKeepSourcemapSetting(
271269 consoleSandbox ( ( ) => {
272270 // eslint-disable-next-line no-console
273271 console . log (
274- `[Sentry] We discovered \`${ settingKey } \` is set to \`${ settingValue } \`. Sentry will keep this sourcemap setting. This will un-minify the code snippet on the Sentry Issue page.` ,
272+ `[Sentry] We discovered \`${ settingKey } \` is set to \`${ settingValue } \`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.` ,
275273 ) ;
276274 } ) ;
277275 }
278276}
279277
280- function warnExplicitlyDisabledSourcemap ( settingKey : string ) : void {
278+ function warnExplicitlyDisabledSourceMap ( settingKey : string ) : void {
281279 consoleSandbox ( ( ) => {
282280 // eslint-disable-next-line no-console
283281 console . warn (
284- `[Sentry] Parts of sourcemap generation are currently disabled in your Nuxt configuration (\`${ settingKey } : false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without sourcemaps , code snippets on the Sentry Issues page will remain minified. To show unminified code, enable sourcemaps in \`${ settingKey } \`.` ,
282+ `[Sentry] Parts of source map generation are currently disabled in your Nuxt configuration (\`${ settingKey } : false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps , code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${ settingKey } \`.` ,
285283 ) ;
286284 } ) ;
287285}
288286
289- function logSentryEnablesSourcemap ( settingKey : string , settingValue : string ) : void {
287+ function logSentryEnablesSourceMap ( settingKey : string , settingValue : string ) : void {
290288 consoleSandbox ( ( ) => {
291289 // eslint-disable-next-line no-console
292- console . log ( `[Sentry] Enabled sourcemap generation in the build options with \`${ settingKey } : ${ settingValue } \`.` ) ;
290+ console . log ( `[Sentry] Enabled source map generation in the build options with \`${ settingKey } : ${ settingValue } \`.` ) ;
293291 } ) ;
294292}
0 commit comments