@@ -157,8 +157,17 @@ async function materializeFinalWebpackConfig(options: {
157157 userSentryWebpackPluginConfig ,
158158 ) ;
159159
160+ // update incomingWebpackBuildContext's config
161+ const updatedIncomingWebpackBuildContext = {
162+ ...incomingWebpackBuildContext ,
163+ config : {
164+ ...incomingWebpackBuildContext . config ,
165+ ...userNextConfig ,
166+ } ,
167+ } ;
168+
160169 // call it to get concrete values for comparison
161- const finalWebpackConfigValue = webpackConfigFunction ( incomingWebpackConfig , incomingWebpackBuildContext ) ;
170+ const finalWebpackConfigValue = webpackConfigFunction ( incomingWebpackConfig , updatedIncomingWebpackBuildContext ) ;
162171 const webpackEntryProperty = finalWebpackConfigValue . entry as EntryPropertyFunction ;
163172 finalWebpackConfigValue . entry = await webpackEntryProperty ( ) ;
164173
@@ -420,6 +429,70 @@ describe('Sentry webpack plugin config', () => {
420429 } ) ;
421430 } ) ;
422431
432+ describe ( "Sentry webpack plugin `include` option with basePath filled on next's config" , ( ) => {
433+ const withBaseUrlNextConfig = {
434+ ...userNextConfig ,
435+ basePath : '/city-park' ,
436+ } ;
437+
438+ it ( 'has the correct value when building client bundles' , async ( ) => {
439+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
440+ userNextConfig : withBaseUrlNextConfig ,
441+ incomingWebpackConfig : clientWebpackConfig ,
442+ incomingWebpackBuildContext : clientBuildContext ,
443+ } ) ;
444+
445+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
446+
447+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
448+ { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/city-park/_next/static/chunks/pages' } ,
449+ ] ) ;
450+ } ) ;
451+
452+ it ( 'has the correct value when building serverless server bundles' , async ( ) => {
453+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
454+ userNextConfig : withBaseUrlNextConfig ,
455+ incomingWebpackConfig : serverWebpackConfig ,
456+ incomingWebpackBuildContext : { ...serverBuildContext , config : { target : 'experimental-serverless-trace' } } ,
457+ } ) ;
458+
459+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
460+
461+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
462+ { paths : [ '.next/serverless/' ] , urlPrefix : '~/city-park/_next/serverless' } ,
463+ ] ) ;
464+ } ) ;
465+
466+ it ( 'has the correct value when building serverful server bundles using webpack 4' , async ( ) => {
467+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
468+ userNextConfig : withBaseUrlNextConfig ,
469+ incomingWebpackConfig : serverWebpackConfig ,
470+ incomingWebpackBuildContext : { ...serverBuildContext , webpack : { version : '4.15.13' } } ,
471+ } ) ;
472+
473+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
474+
475+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
476+ { paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
477+ ] ) ;
478+ } ) ;
479+
480+ it ( 'has the correct value when building serverful server bundles using webpack 5' , async ( ) => {
481+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
482+ userNextConfig : withBaseUrlNextConfig ,
483+ incomingWebpackConfig : serverWebpackConfig ,
484+ incomingWebpackBuildContext : serverBuildContext ,
485+ } ) ;
486+
487+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
488+
489+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
490+ { paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
491+ { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/city-park/_next/server/chunks' } ,
492+ ] ) ;
493+ } ) ;
494+ } ) ;
495+
423496 it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
424497 const clientFinalNextConfig = materializeFinalNextConfig ( {
425498 ...userNextConfig ,
0 commit comments