@@ -2,6 +2,7 @@ import { getSentryRelease } from '@sentry/node';
2
2
import { dropUndefinedKeys , logger } from '@sentry/utils' ;
3
3
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin' ;
4
4
import * as fs from 'fs' ;
5
+ import * as os from 'os' ;
5
6
import * as path from 'path' ;
6
7
7
8
import {
@@ -127,14 +128,31 @@ async function addSentryToEntryProperty(
127
128
const newEntryProperty =
128
129
typeof currentEntryProperty === 'function' ? await currentEntryProperty ( ) : { ...currentEntryProperty } ;
129
130
131
+ // `sentry.server.config.js` or `sentry.client.config.js` (or their TS equivalents)
130
132
const userConfigFile = buildContext . isServer
131
133
? getUserConfigFile ( buildContext . dir , 'server' )
132
134
: getUserConfigFile ( buildContext . dir , 'client' ) ;
133
135
136
+ // we need to turn the filename into a path so webpack can find it
137
+ const filesToInject = [ `./${ userConfigFile } ` ] ;
138
+
139
+ // Support non-default output directories by making the output path (easy to get here at build-time) available to the
140
+ // server SDK's default `RewriteFrames` instance (which needs it at runtime).
141
+ if ( buildContext . isServer ) {
142
+ const rewriteFramesHelper = path . resolve (
143
+ fs . mkdtempSync ( path . resolve ( os . tmpdir ( ) , 'sentry-' ) ) ,
144
+ 'rewriteFramesHelper.js' ,
145
+ ) ;
146
+ fs . writeFileSync ( rewriteFramesHelper , `global.__rewriteFramesDistDir__ = '${ buildContext . config . distDir } ';\n` ) ;
147
+ // stick our helper file ahead of the user's config file so the value is in the global namespace *before*
148
+ // `Sentry.init()` is called
149
+ filesToInject . unshift ( rewriteFramesHelper ) ;
150
+ }
151
+
152
+ // inject into all entry points which might contain user's code
134
153
for ( const entryPointName in newEntryProperty ) {
135
154
if ( shouldAddSentryToEntryPoint ( entryPointName ) ) {
136
- // we need to turn the filename into a path so webpack can find it
137
- addFileToExistingEntryPoint ( newEntryProperty , entryPointName , `./${ userConfigFile } ` ) ;
155
+ addFilesToExistingEntryPoint ( newEntryProperty , entryPointName , filesToInject ) ;
138
156
}
139
157
}
140
158
0 commit comments