1
- import type { ExportedNextConfig , NextConfigFunction , NextConfigObject , SentryWebpackPluginOptions } from './types' ;
1
+ import type {
2
+ ExportedNextConfig ,
3
+ NextConfigFunction ,
4
+ NextConfigObject ,
5
+ NextConfigObjectWithSentry ,
6
+ SentryWebpackPluginOptions ,
7
+ } from './types' ;
2
8
import { constructWebpackConfigFunction } from './webpack' ;
3
9
4
10
/**
@@ -16,35 +22,29 @@ export function withSentryConfig(
16
22
// `defaults` in order to pass them along to the user's function
17
23
if ( typeof exportedUserNextConfig === 'function' ) {
18
24
return function ( phase : string , defaults : { defaultConfig : NextConfigObject } ) : NextConfigObject {
19
- let userNextConfigObject = exportedUserNextConfig ( phase , defaults ) ;
25
+ const userNextConfigObject = exportedUserNextConfig ( phase , defaults ) ;
20
26
21
- // Next 12.2.3+ warns about non-canonical properties on `userNextConfig`, so grab and then remove the `sentry`
22
- // property there. Where we actually need it is in the webpack config function we're going to create, so pass it
23
- // to `constructWebpackConfigFunction` so that it will be in the created function's closure.
24
- const { sentry : userSentryOptions } = userNextConfigObject ;
25
- delete userNextConfigObject . sentry ;
26
- // Remind TS that there's now no `sentry` property
27
- userNextConfigObject = userNextConfigObject as NextConfigObject ;
28
-
29
- return {
30
- ...userNextConfigObject ,
31
- webpack : constructWebpackConfigFunction (
32
- userNextConfigObject ,
33
- userSentryWebpackPluginOptions ,
34
- userSentryOptions ,
35
- ) ,
36
- } ;
27
+ return getFinalConfigObject ( userNextConfigObject , userSentryWebpackPluginOptions ) ;
37
28
} ;
38
29
}
39
30
40
31
// Otherwise, we can just merge their config with ours and return an object.
32
+ return getFinalConfigObject ( exportedUserNextConfig , userSentryWebpackPluginOptions ) ;
33
+ }
41
34
42
- // Prevent nextjs from getting mad about having a non-standard config property in `userNextConfig`. (See note above
43
- // for a more thorough explanation of what we're doing here.)
44
- const { sentry : userSentryOptions } = exportedUserNextConfig ;
45
- delete exportedUserNextConfig . sentry ;
35
+ // Modify the materialized object form of the user's next config by deleting the `sentry` property and wrapping the
36
+ // `webpack` property
37
+ function getFinalConfigObject (
38
+ incomingUserNextConfigObject : NextConfigObjectWithSentry ,
39
+ userSentryWebpackPluginOptions : Partial < SentryWebpackPluginOptions > ,
40
+ ) : NextConfigObject {
41
+ // Next 12.2.3+ warns about non-canonical properties on `userNextConfig`, so grab and then remove the `sentry`
42
+ // property there. Where we actually need it is in the webpack config function we're going to create, so pass it
43
+ // to `constructWebpackConfigFunction` so that it can live in the returned function's closure.
44
+ const { sentry : userSentryOptions } = incomingUserNextConfigObject ;
45
+ delete incomingUserNextConfigObject . sentry ;
46
46
// Remind TS that there's now no `sentry` property
47
- const userNextConfigObject = exportedUserNextConfig as NextConfigObject ;
47
+ const userNextConfigObject = incomingUserNextConfigObject as NextConfigObject ;
48
48
49
49
return {
50
50
...userNextConfigObject ,
0 commit comments