Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs)!: Always return async function from withSentryConfig() #14610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export type SentryBuildOptions = {
export type NextConfigFunction = (
phase: string,
defaults: { defaultConfig: NextConfigObject },
) => NextConfigObject | PromiseLike<NextConfigObject>;
) => Promise<NextConfigObject>;

/**
* Webpack config
Expand Down
19 changes: 11 additions & 8 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ let showedExportModeTunnelWarning = false;
* @param sentryBuildOptions Additional options to configure instrumentation and
* @returns The modified config to be exported
*/
// TODO(v9): Always return an async function here to allow us to do async things like grabbing a deterministic build ID.
export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBuildOptions = {}): C {
export function withSentryConfig(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nextConfig?: any,
sentryBuildOptions: SentryBuildOptions = {},
): NextConfigFunction {
const castNextConfig = (nextConfig as NextConfig) || {};
if (typeof castNextConfig === 'function') {
return function (this: unknown, ...webpackConfigFunctionArgs: unknown[]): ReturnType<NextConfigFunction> {
return async function (this: unknown, ...webpackConfigFunctionArgs: unknown[]): ReturnType<NextConfigFunction> {
if (typeof castNextConfig === 'function') {
const maybePromiseNextConfig: ReturnType<typeof castNextConfig> = castNextConfig.apply(
this,
webpackConfigFunctionArgs,
Expand All @@ -37,10 +40,10 @@ export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBu
}

return getFinalConfigObject(maybePromiseNextConfig, sentryBuildOptions);
} as C;
} else {
return getFinalConfigObject(castNextConfig, sentryBuildOptions) as C;
}
} else {
return getFinalConfigObject(castNextConfig, sentryBuildOptions);
}
};
}

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