@@ -10,6 +10,7 @@ import * as path from 'path';
10
10
import * as sorcery from 'sorcery' ;
11
11
import type { Plugin } from 'vite' ;
12
12
13
+ import type { GlobalSentryValues } from '../server/utils' ;
13
14
import { WRAPPED_MODULE_SUFFIX } from './autoInstrument' ;
14
15
import type { SupportedSvelteKitAdapters } from './detectAdapter' ;
15
16
import { getAdapterOutputDir , getHooksFileName , loadSvelteConfig } from './svelteConfig' ;
@@ -78,6 +79,10 @@ export async function makeCustomSentryVitePlugin(options?: CustomSentryVitePlugi
78
79
79
80
const serverHooksFile = getHooksFileName ( svelteConfig , 'server' ) ;
80
81
82
+ const globalSentryValues : GlobalSentryValues = {
83
+ __sentry_sveltekit_output_dir : outputDir ,
84
+ } ;
85
+
81
86
const customPlugin : Plugin = {
82
87
name : 'sentry-upload-source-maps' ,
83
88
apply : 'build' , // only apply this plugin at build time
@@ -117,8 +122,10 @@ export async function makeCustomSentryVitePlugin(options?: CustomSentryVitePlugi
117
122
const isServerHooksFile = new RegExp ( `/${ escapeStringForRegex ( serverHooksFile ) } (.(js|ts|mjs|mts))?` ) . test ( id ) ;
118
123
119
124
if ( isServerHooksFile ) {
120
- const injectedCode = `global.__sentry_sveltekit_output_dir = "${ outputDir || 'undefined' } ";\n` ;
121
- modifiedCode = `${ code } \n${ injectedCode } ` ;
125
+ const injectedCode = Object . entries ( globalSentryValues )
126
+ . map ( ( [ key , value ] ) => `globalThis["${ key } "] = ${ JSON . stringify ( value ) } ;` )
127
+ . join ( '\n' ) ;
128
+ modifiedCode = `${ code } \n${ injectedCode } \n` ;
122
129
}
123
130
// @ts -ignore - this hook exists on the plugin!
124
131
return sentryPlugin . transform ( modifiedCode , id ) ;
0 commit comments