@@ -61,7 +61,7 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
61
61
} ,
62
62
} ;
63
63
64
- const { promise : filesToDeleteAfterUpload , resolve : reportFilesToDeleteAfterUpload } =
64
+ const { promise : filesToDeleteAfterUpload , resolve : resolveFilesToDeleteAfterUpload } =
65
65
createFilesToDeleteAfterUploadPromise ( ) ;
66
66
67
67
const mergedOptions = {
@@ -99,6 +99,10 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
99
99
console . warn (
100
100
'sentry-vite-debug-id-upload-plugin not found in sentryPlugins! Cannot modify plugin - returning default Sentry Vite plugins' ,
101
101
) ;
102
+
103
+ // resolving filesToDeleteAfterUpload here, because we return the original deletion plugin which awaits the promise
104
+ resolveFilesToDeleteAfterUpload ( undefined ) ;
105
+
102
106
return sentryPlugins ;
103
107
}
104
108
@@ -108,6 +112,10 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
108
112
console . warn (
109
113
'sentry-file-deletion-plugin not found in sentryPlugins! Cannot modify plugin - returning default Sentry Vite plugins' ,
110
114
) ;
115
+
116
+ // resolving filesToDeleteAfterUpload here, because we return the original deletion plugin which awaits the promise
117
+ resolveFilesToDeleteAfterUpload ( undefined ) ;
118
+
111
119
return sentryPlugins ;
112
120
}
113
121
@@ -117,6 +125,10 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
117
125
console . warn (
118
126
'sentry-release-management-plugin not found in sentryPlugins! Cannot modify plugin - returning default Sentry Vite plugins' ,
119
127
) ;
128
+
129
+ // resolving filesToDeleteAfterUpload here, because we return the original deletion plugin which awaits the promise
130
+ resolveFilesToDeleteAfterUpload ( undefined ) ;
131
+
120
132
return sentryPlugins ;
121
133
}
122
134
@@ -141,11 +153,13 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
141
153
const sourceMapSettingsPlugin : Plugin = {
142
154
name : 'sentry-sveltekit-update-source-map-setting-plugin' ,
143
155
apply : 'build' , // only apply this plugin at build time
144
- config : ( config : UserConfig ) => {
156
+ config : async ( config : UserConfig ) => {
145
157
const settingKey = 'build.sourcemap' ;
146
158
147
159
const { updatedSourceMapSetting, previousSourceMapSetting } = getUpdatedSourceMapSetting ( config ) ;
148
160
161
+ const userProvidedFilesToDeleteAfterUpload = await options ?. sourcemaps ?. filesToDeleteAfterUpload ;
162
+
149
163
if ( previousSourceMapSetting === 'unset' ) {
150
164
consoleSandbox ( ( ) => {
151
165
// eslint-disable-next-line no-console
@@ -157,24 +171,30 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
157
171
// dir which could be a non-hidden directory, like `build` for the Node adapter.
158
172
const defaultFileDeletionGlob = [ './.*/**/*.map' , `./${ adapterOutputDir } /**/*.map` ] ;
159
173
160
- consoleSandbox ( ( ) => {
161
- // eslint-disable-next-line no-console
162
- console . warn (
163
- `[Sentry] Automatically setting \`sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload: [${ defaultFileDeletionGlob
164
- . map ( file => `"${ file } "` )
165
- . join ( ', ' ) } ]\` to delete generated source maps after they were uploaded to Sentry.`,
166
- ) ;
167
- } ) ;
174
+ if ( userProvidedFilesToDeleteAfterUpload ) {
175
+ resolveFilesToDeleteAfterUpload ( userProvidedFilesToDeleteAfterUpload ) ;
176
+ } else {
177
+ consoleSandbox ( ( ) => {
178
+ // eslint-disable-next-line no-console
179
+ console . warn (
180
+ `[Sentry] Automatically setting \`sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload: [${ defaultFileDeletionGlob
181
+ . map ( file => `"${ file } "` )
182
+ . join ( ', ' ) } ]\` to delete generated source maps after they were uploaded to Sentry.`,
183
+ ) ;
184
+ } ) ;
168
185
169
- // In case we enabled source map, we also want to delete them.
170
- // So either use the glob(s) that users specified, or the default one!
171
- reportFilesToDeleteAfterUpload ( options ?. sourcemaps ?. filesToDeleteAfterUpload ?? defaultFileDeletionGlob ) ;
186
+ // In case we enabled source map, we also want to delete them.
187
+ // So either use the glob(s) that users specified, or the default one!
188
+ resolveFilesToDeleteAfterUpload ( defaultFileDeletionGlob ) ;
189
+ }
172
190
173
191
return {
174
192
...config ,
175
193
build : { ...config . build , sourcemap : updatedSourceMapSetting } ,
176
194
} ;
177
- } else if ( previousSourceMapSetting === 'disabled' ) {
195
+ }
196
+
197
+ if ( previousSourceMapSetting === 'disabled' ) {
178
198
consoleSandbox ( ( ) => {
179
199
// eslint-disable-next-line no-console
180
200
console . warn (
@@ -186,13 +206,13 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
186
206
consoleSandbox ( ( ) => {
187
207
// eslint-disable-next-line no-console
188
208
console . log (
189
- `[Sentry] We discovered you enabled source map generation in your Vite configuration (\`${ settingKey } \`). Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.` ,
209
+ `[Sentry] We discovered you enabled source map generation in your Vite configuration (\`${ settingKey } \`). Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.` ,
190
210
) ;
191
211
} ) ;
192
212
}
193
213
}
194
214
195
- reportFilesToDeleteAfterUpload ( options ?. sourcemaps ?. filesToDeleteAfterUpload ) ;
215
+ resolveFilesToDeleteAfterUpload ( userProvidedFilesToDeleteAfterUpload ) ;
196
216
197
217
return config ;
198
218
} ,
@@ -345,7 +365,7 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
345
365
const outDir = path . resolve ( process . cwd ( ) , adapterOutputDir ) ;
346
366
try {
347
367
// @ts -expect-error - the writeBundle hook expects two args we can't pass in here (they're only available in `writeBundle`)
348
- await writeBundleFn ( { dir : outDir , _sentryFilesToDelete } ) ;
368
+ await writeBundleFn ( { dir : outDir } ) ;
349
369
} catch ( e ) {
350
370
// eslint-disable-next-line no-console
351
371
console . warn ( 'Failed to delete source maps:' , e ) ;
@@ -381,7 +401,7 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug
381
401
/**
382
402
* Whether the user enabled (true, 'hidden', 'inline') or disabled (false) source maps
383
403
*/
384
- export type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined ;
404
+ type UserSourceMapSetting = 'enabled' | 'disabled' | 'unset' | undefined ;
385
405
386
406
/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-javascript/issues/13993)
387
407
*
@@ -403,25 +423,25 @@ export function getUpdatedSourceMapSetting(viteConfig: {
403
423
sourcemap ?: boolean | 'inline' | 'hidden' ;
404
424
} ;
405
425
} ) : { updatedSourceMapSetting : boolean | 'inline' | 'hidden' ; previousSourceMapSetting : UserSourceMapSetting } {
406
- let previousSourceMapSetting : UserSourceMapSetting ;
407
- let updatedSourceMapSetting : boolean | 'inline' | 'hidden' | undefined ;
408
-
409
426
viteConfig . build = viteConfig . build || { } ;
410
427
411
- const viteSourceMap = viteConfig . build . sourcemap ;
412
-
413
- if ( viteSourceMap === false ) {
414
- previousSourceMapSetting = 'disabled' ;
415
- updatedSourceMapSetting = viteSourceMap ;
416
- } else if ( viteSourceMap && [ 'hidden' , 'inline' , true ] . includes ( viteSourceMap ) ) {
417
- previousSourceMapSetting = 'enabled' ;
418
- updatedSourceMapSetting = viteSourceMap ;
419
- } else {
420
- previousSourceMapSetting = 'unset' ;
421
- updatedSourceMapSetting = 'hidden' ;
428
+ const originalSourcemapSetting = viteConfig . build . sourcemap ;
429
+
430
+ if ( originalSourcemapSetting === false ) {
431
+ return {
432
+ previousSourceMapSetting : 'disabled' ,
433
+ updatedSourceMapSetting : originalSourcemapSetting ,
434
+ } ;
422
435
}
423
436
424
- return { previousSourceMapSetting, updatedSourceMapSetting } ;
437
+ if ( originalSourcemapSetting && [ 'hidden' , 'inline' , true ] . includes ( originalSourcemapSetting ) ) {
438
+ return { previousSourceMapSetting : 'enabled' , updatedSourceMapSetting : originalSourcemapSetting } ;
439
+ }
440
+
441
+ return {
442
+ previousSourceMapSetting : 'unset' ,
443
+ updatedSourceMapSetting : 'hidden' ,
444
+ } ;
425
445
}
426
446
427
447
function getFiles ( dir : string ) : string [ ] {
0 commit comments