File tree 4 files changed +22
-8
lines changed
4 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export type NextConfigObjectWithSentry = NextConfigObject & {
26
26
export type NextConfigFunctionWithSentry = (
27
27
phase : string ,
28
28
defaults : { defaultConfig : NextConfigObject } ,
29
- ) => NextConfigObjectWithSentry ;
29
+ ) => NextConfigObjectWithSentry | PromiseLike < NextConfigObjectWithSentry > ;
30
30
31
31
// Vendored from Next.js (this type is not complete - extend if necessary)
32
32
type NextRewrite = {
@@ -144,7 +144,10 @@ export type UserSentryOptions = {
144
144
automaticVercelMonitors ?: boolean ;
145
145
} ;
146
146
147
- export type NextConfigFunction = ( phase : string , defaults : { defaultConfig : NextConfigObject } ) => NextConfigObject ;
147
+ export type NextConfigFunction = (
148
+ phase : string ,
149
+ defaults : { defaultConfig : NextConfigObject } ,
150
+ ) => NextConfigObject | PromiseLike < NextConfigObject > ;
148
151
149
152
/**
150
153
* Webpack config
Original file line number Diff line number Diff line change
1
+ import { isThenable } from '@sentry/utils' ;
2
+
1
3
import type {
2
4
ExportedNextConfig ,
3
5
NextConfigFunction ,
@@ -24,12 +26,21 @@ export function withSentryConfig(
24
26
sentryOptions ?: UserSentryOptions ,
25
27
) : NextConfigFunction | NextConfigObject {
26
28
if ( typeof exportedUserNextConfig === 'function' ) {
27
- return function ( this : unknown , ...webpackConfigFunctionArgs : unknown [ ] ) : NextConfigObject {
28
- const userNextConfigObject : NextConfigObjectWithSentry = exportedUserNextConfig . apply (
29
+ return function ( this : unknown , ...webpackConfigFunctionArgs : unknown [ ] ) : ReturnType < NextConfigFunction > {
30
+ const maybeUserNextConfigObject : NextConfigObjectWithSentry = exportedUserNextConfig . apply (
29
31
this ,
30
32
webpackConfigFunctionArgs ,
31
33
) ;
32
34
35
+ if ( isThenable ( maybeUserNextConfigObject ) ) {
36
+ return maybeUserNextConfigObject . then ( function ( userNextConfigObject : NextConfigObjectWithSentry ) {
37
+ const userSentryOptions = { ...userNextConfigObject . sentry , ...sentryOptions } ;
38
+ return getFinalConfigObject ( userNextConfigObject , userSentryOptions , userSentryWebpackPluginOptions ) ;
39
+ } ) ;
40
+ }
41
+
42
+ // Reassign for naming-consistency sake.
43
+ const userNextConfigObject = maybeUserNextConfigObject ;
33
44
const userSentryOptions = { ...userNextConfigObject . sentry , ...sentryOptions } ;
34
45
return getFinalConfigObject ( userNextConfigObject , userSentryOptions , userSentryWebpackPluginOptions ) ;
35
46
} ;
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export function materializeFinalNextConfig(
35
35
if ( typeof sentrifiedConfig === 'function' ) {
36
36
// for some reason TS won't recognize that `finalConfigValues` is now a NextConfigObject, which is why the cast
37
37
// below is necessary
38
- finalConfigValues = sentrifiedConfig ( runtimePhase ?? defaultRuntimePhase , defaultsObject ) ;
38
+ finalConfigValues = sentrifiedConfig ( runtimePhase ?? defaultRuntimePhase , defaultsObject ) as NextConfigObject ;
39
39
}
40
40
41
41
return finalConfigValues as NextConfigObject ;
@@ -66,7 +66,7 @@ export async function materializeFinalWebpackConfig(options: {
66
66
// if the user's next config is a function, run it so we have access to the values
67
67
const materializedUserNextConfig =
68
68
typeof exportedNextConfig === 'function'
69
- ? exportedNextConfig ( 'phase-production-build' , defaultsObject )
69
+ ? await exportedNextConfig ( 'phase-production-build' , defaultsObject )
70
70
: exportedNextConfig ;
71
71
72
72
// extract the `sentry` property as we do in `withSentryConfig`
Original file line number Diff line number Diff line change 1
1
const { withSentryConfig } = require('@sentry/nextjs');
2
2
3
- const moduleExports = {
3
+ const moduleExports = async () => ( {
4
4
eslint: {
5
5
ignoreDuringBuilds: true,
6
6
},
@@ -11,7 +11,7 @@ const moduleExports = {
11
11
hideSourceMaps: false,
12
12
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
13
13
},
14
- };
14
+ }) ;
15
15
16
16
const SentryWebpackPluginOptions = {
17
17
dryRun: true,
You can’t perform that action at this time.
0 commit comments