@@ -6,26 +6,29 @@ import type {
66 NextConfigObject ,
77 NextConfigObjectWithSentry ,
88 SentryWebpackPluginOptions ,
9+ UserSentryOptions ,
910} from './types' ;
1011
1112/**
1213 * Add Sentry options to the config to be exported from the user's `next.config.js` file.
1314 *
1415 * @param exportedUserNextConfig The existing config to be exported prior to adding Sentry
1516 * @param userSentryWebpackPluginOptions Configuration for SentryWebpackPlugin
17+ * @param sentryOptions Optional additional options to add as alternative to `sentry` property of config
1618 * @returns The modified config to be exported
1719 */
1820export function withSentryConfig (
1921 exportedUserNextConfig : ExportedNextConfig = { } ,
2022 userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > = { } ,
23+ sentryOptions ?: UserSentryOptions ,
2124) : NextConfigFunction | NextConfigObject {
2225 return function ( phase : string , defaults : { defaultConfig : NextConfigObject } ) : NextConfigObject {
23- if ( typeof exportedUserNextConfig === 'function' ) {
24- const userNextConfigObject = exportedUserNextConfig ( phase , defaults ) ;
25- return getFinalConfigObject ( phase , userNextConfigObject , userSentryWebpackPluginOptions ) ;
26- } else {
27- return getFinalConfigObject ( phase , exportedUserNextConfig , userSentryWebpackPluginOptions ) ;
28- }
26+ const userNextConfigObject =
27+ typeof exportedUserNextConfig === 'function' ? exportedUserNextConfig ( phase , defaults ) : exportedUserNextConfig ;
28+ // Inserts additional `sentry` options into the existing config, allows for backwards compatability
29+ // in case nothing is passed into the optional `sentryOptions` argument
30+ userNextConfigObject . sentry = { ... userNextConfigObject . sentry , ... sentryOptions } ;
31+ return getFinalConfigObject ( phase , userNextConfigObject , userSentryWebpackPluginOptions ) ;
2932 } ;
3033}
3134
0 commit comments