1
1
import { isThenable } from '@sentry/utils' ;
2
2
3
3
import type {
4
- ExportedNextConfig ,
4
+ ExportedNextConfig as NextConfig ,
5
5
NextConfigFunction ,
6
6
NextConfigObject ,
7
- NextConfigObjectWithSentry ,
8
7
SentryWebpackPluginOptions ,
9
8
UserSentryOptions ,
10
9
} from './types' ;
@@ -13,52 +12,51 @@ import { constructWebpackConfigFunction } from './webpack';
13
12
let showedExportModeTunnelWarning = false ;
14
13
15
14
/**
16
- * Add Sentry options to the config to be exported from the user's `next.config.js` file.
15
+ * Modifies the passed in Next.js configuration
17
16
*
18
- * @param exportedUserNextConfig The existing config to be exported prior to adding Sentry
19
- * @param userSentryWebpackPluginOptions Configuration for SentryWebpackPlugin
20
- * @param sentryOptions Optional additional options to add as alternative to `sentry` property of config
17
+ * @param nextConfig The existing config to be exported prior to adding Sentry
18
+ * @param sentryWebpackPluginOptions Configuration for SentryWebpackPlugin
19
+ * @param sentrySDKOptions Optional additional options to add as alternative to `sentry` property of config
21
20
* @returns The modified config to be exported
22
21
*/
23
22
export function withSentryConfig (
24
- exportedUserNextConfig : ExportedNextConfig = { } ,
25
- userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > = { } ,
26
- sentryOptions ? : UserSentryOptions ,
23
+ nextConfig : NextConfig = { } ,
24
+ sentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > = { } ,
25
+ sentrySDKOptions : UserSentryOptions = { } ,
27
26
) : NextConfigFunction | NextConfigObject {
28
- if ( typeof exportedUserNextConfig === 'function' ) {
27
+ if ( typeof nextConfig === 'function' ) {
29
28
return function ( this : unknown , ...webpackConfigFunctionArgs : unknown [ ] ) : ReturnType < NextConfigFunction > {
30
- const maybeUserNextConfigObject : NextConfigObjectWithSentry = exportedUserNextConfig . apply (
31
- this ,
32
- webpackConfigFunctionArgs ,
33
- ) ;
29
+ const maybePromiseNextConfig : ReturnType < typeof nextConfig > = nextConfig . apply ( this , webpackConfigFunctionArgs ) ;
34
30
35
- if ( isThenable ( maybeUserNextConfigObject ) ) {
36
- return maybeUserNextConfigObject . then ( function ( userNextConfigObject : NextConfigObjectWithSentry ) {
37
- const userSentryOptions = { ...userNextConfigObject . sentry , ...sentryOptions } ;
38
- return getFinalConfigObject ( userNextConfigObject , userSentryOptions , userSentryWebpackPluginOptions ) ;
31
+ if ( isThenable ( maybePromiseNextConfig ) ) {
32
+ return maybePromiseNextConfig . then ( promiseResultNextConfig => {
33
+ return getFinalConfigObject ( promiseResultNextConfig , sentrySDKOptions , sentryWebpackPluginOptions ) ;
39
34
} ) ;
40
35
}
41
36
42
- // Reassign for naming-consistency sake.
43
- const userNextConfigObject = maybeUserNextConfigObject ;
44
- const userSentryOptions = { ...userNextConfigObject . sentry , ...sentryOptions } ;
45
- return getFinalConfigObject ( userNextConfigObject , userSentryOptions , userSentryWebpackPluginOptions ) ;
37
+ return getFinalConfigObject ( maybePromiseNextConfig , sentrySDKOptions , sentryWebpackPluginOptions ) ;
46
38
} ;
47
39
} else {
48
- const userSentryOptions = { ...exportedUserNextConfig . sentry , ...sentryOptions } ;
49
- return getFinalConfigObject ( exportedUserNextConfig , userSentryOptions , userSentryWebpackPluginOptions ) ;
40
+ return getFinalConfigObject ( nextConfig , sentrySDKOptions , sentryWebpackPluginOptions ) ;
50
41
}
51
42
}
52
43
53
44
// Modify the materialized object form of the user's next config by deleting the `sentry` property and wrapping the
54
45
// `webpack` property
55
46
function getFinalConfigObject (
56
- incomingUserNextConfigObject : NextConfigObjectWithSentry ,
47
+ incomingUserNextConfigObject : NextConfigObject ,
57
48
userSentryOptions : UserSentryOptions ,
58
49
userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > ,
59
50
) : NextConfigObject {
60
- // Next 12.2.3+ warns about non-canonical properties on `userNextConfig`.
61
- delete incomingUserNextConfigObject . sentry ;
51
+ if ( 'sentry' in incomingUserNextConfigObject ) {
52
+ // eslint-disable-next-line no-console
53
+ console . warn (
54
+ '[@sentry/nextjs] Setting a `sentry` property on the Next.js config is no longer supported. Please use the `sentrySDKOptions` argument of `withSentryConfig` instead.' ,
55
+ ) ;
56
+
57
+ // Next 12.2.3+ warns about non-canonical properties on `userNextConfig`.
58
+ delete incomingUserNextConfigObject . sentry ;
59
+ }
62
60
63
61
if ( userSentryOptions ?. tunnelRoute ) {
64
62
if ( incomingUserNextConfigObject . output === 'export' ) {
0 commit comments