Skip to content

Commit 6286c97

Browse files
author
Luca Forstner
committed
feat(nextjs)!: Make withSentryConfig() always return an async function
1 parent 3778482 commit 6286c97

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export type SentryBuildOptions = {
448448
export type NextConfigFunction = (
449449
phase: string,
450450
defaults: { defaultConfig: NextConfigObject },
451-
) => NextConfigObject | PromiseLike<NextConfigObject>;
451+
) => Promise<NextConfigObject>;
452452

453453
/**
454454
* Webpack config

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ let showedExportModeTunnelWarning = false;
2020
* @param sentryBuildOptions Additional options to configure instrumentation and
2121
* @returns The modified config to be exported
2222
*/
23-
// TODO(v9): Always return an async function here to allow us to do async things like grabbing a deterministic build ID.
24-
export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBuildOptions = {}): C {
23+
export function withSentryConfig(
24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25+
nextConfig?: any,
26+
sentryBuildOptions: SentryBuildOptions = {},
27+
): NextConfigFunction {
2528
const castNextConfig = (nextConfig as NextConfig) || {};
26-
if (typeof castNextConfig === 'function') {
27-
return function (this: unknown, ...webpackConfigFunctionArgs: unknown[]): ReturnType<NextConfigFunction> {
29+
return async function (this: unknown, ...webpackConfigFunctionArgs: unknown[]): ReturnType<NextConfigFunction> {
30+
if (typeof castNextConfig === 'function') {
2831
const maybePromiseNextConfig: ReturnType<typeof castNextConfig> = castNextConfig.apply(
2932
this,
3033
webpackConfigFunctionArgs,
@@ -37,10 +40,10 @@ export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBu
3740
}
3841

3942
return getFinalConfigObject(maybePromiseNextConfig, sentryBuildOptions);
40-
} as C;
41-
} else {
42-
return getFinalConfigObject(castNextConfig, sentryBuildOptions) as C;
43-
}
43+
} else {
44+
return getFinalConfigObject(castNextConfig, sentryBuildOptions);
45+
}
46+
};
4447
}
4548

4649
// Modify the materialized object form of the user's next config by deleting the `sentry` property and wrapping the

0 commit comments

Comments
 (0)