@@ -10,6 +10,7 @@ import {
1010 EntryPropertyObject ,
1111 NextConfigObject ,
1212 SentryWebpackPluginOptions ,
13+ UserSentryOptions ,
1314 WebpackConfigFunction ,
1415 WebpackConfigObject ,
1516 WebpackEntryProperty ,
@@ -36,6 +37,7 @@ export { SentryWebpackPlugin };
3637export function constructWebpackConfigFunction (
3738 userNextConfig : Partial < NextConfigObject > = { } ,
3839 userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > = { } ,
40+ userSentryOptions : UserSentryOptions = { } ,
3941) : WebpackConfigFunction {
4042 // Will be called by nextjs and passed its default webpack configuration and context data about the build (whether
4143 // we're building server or client, whether we're in dev, what version of webpack we're using, etc). Note that
@@ -93,9 +95,7 @@ export function constructWebpackConfigFunction(
9395 // with the `--ignore-scripts` option, this will be blocked and the missing binary will cause an error when users
9496 // try to build their apps.)
9597 ensureCLIBinaryExists ( ) &&
96- ( isServer
97- ? ! userNextConfig . sentry ?. disableServerWebpackPlugin
98- : ! userNextConfig . sentry ?. disableClientWebpackPlugin ) ;
98+ ( isServer ? ! userSentryOptions . disableServerWebpackPlugin : ! userSentryOptions . disableClientWebpackPlugin ) ;
9999
100100 if ( enableWebpackPlugin ) {
101101 // TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
@@ -109,12 +109,14 @@ export function constructWebpackConfigFunction(
109109 // the browser won't look for them and throw errors into the console when it can't find them. Because this is a
110110 // front-end-only problem, and because `sentry-cli` handles sourcemaps more reliably with the comment than
111111 // without, the option to use `hidden-source-map` only applies to the client-side build.
112- newConfig . devtool = userNextConfig . sentry ? .hideSourceMaps && ! isServer ? 'hidden-source-map' : 'source-map' ;
112+ newConfig . devtool = userSentryOptions . hideSourceMaps && ! isServer ? 'hidden-source-map' : 'source-map' ;
113113 }
114114
115115 newConfig . plugins = newConfig . plugins || [ ] ;
116116 newConfig . plugins . push (
117- new SentryWebpackPlugin ( getWebpackPluginOptions ( buildContext , userSentryWebpackPluginOptions ) ) ,
117+ new SentryWebpackPlugin (
118+ getWebpackPluginOptions ( buildContext , userSentryWebpackPluginOptions , userSentryOptions ) ,
119+ ) ,
118120 ) ;
119121 }
120122
@@ -286,6 +288,7 @@ function shouldAddSentryToEntryPoint(entryPointName: string, isServer: boolean):
286288export function getWebpackPluginOptions (
287289 buildContext : BuildContext ,
288290 userPluginOptions : Partial < SentryWebpackPluginOptions > ,
291+ userSentryOptions : UserSentryOptions ,
289292) : SentryWebpackPluginOptions {
290293 const { buildId, isServer, webpack, config : userNextConfig , dev : isDev , dir : projectDir } = buildContext ;
291294 const distDir = userNextConfig . distDir ?? '.next' ; // `.next` is the default directory
@@ -301,14 +304,14 @@ export function getWebpackPluginOptions(
301304 isWebpack5 ? [ { paths : [ `${ distDir } /server/chunks/` ] , urlPrefix : `${ urlPrefix } /server/chunks` } ] : [ ] ,
302305 ) ;
303306
304- const clientInclude = userNextConfig . sentry ? .widenClientFileUpload
307+ const clientInclude = userSentryOptions . widenClientFileUpload
305308 ? [ { paths : [ `${ distDir } /static/chunks` ] , urlPrefix : `${ urlPrefix } /static/chunks` } ]
306309 : [ { paths : [ `${ distDir } /static/chunks/pages` ] , urlPrefix : `${ urlPrefix } /static/chunks/pages` } ] ;
307310
308311 const defaultPluginOptions = dropUndefinedKeys ( {
309312 include : isServer ? serverInclude : clientInclude ,
310313 ignore :
311- isServer || ! userNextConfig . sentry ? .widenClientFileUpload
314+ isServer || ! userSentryOptions . widenClientFileUpload
312315 ? [ ]
313316 : // Widening the upload scope is necessarily going to lead to us uploading files we don't need to (ones which
314317 // don't include any user code). In order to lessen that where we can, exclude the internal nextjs files we know
0 commit comments