@@ -6,26 +6,29 @@ import type {
6
6
NextConfigObject ,
7
7
NextConfigObjectWithSentry ,
8
8
SentryWebpackPluginOptions ,
9
+ UserSentryOptions ,
9
10
} from './types' ;
10
11
11
12
/**
12
13
* Add Sentry options to the config to be exported from the user's `next.config.js` file.
13
14
*
14
15
* @param exportedUserNextConfig The existing config to be exported prior to adding Sentry
15
16
* @param userSentryWebpackPluginOptions Configuration for SentryWebpackPlugin
17
+ * @param sentryOptions Optional additional options to add as alternative to `sentry` property of config
16
18
* @returns The modified config to be exported
17
19
*/
18
20
export function withSentryConfig (
19
21
exportedUserNextConfig : ExportedNextConfig = { } ,
20
22
userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > = { } ,
23
+ sentryOptions ?: UserSentryOptions ,
21
24
) : NextConfigFunction | NextConfigObject {
22
25
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 ) ;
29
32
} ;
30
33
}
31
34
0 commit comments