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): Add optional options argument to withSentryConfig as an alternative to the sentry property #6721

Merged
merged 6 commits into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import type {
NextConfigObject,
NextConfigObjectWithSentry,
SentryWebpackPluginOptions,
UserSentryOptions,
} from './types';

/**
* Add Sentry options to the config to be exported from the user's `next.config.js` file.
*
* @param exportedUserNextConfig The existing config to be exported prior to adding Sentry
* @param userSentryWebpackPluginOptions Configuration for SentryWebpackPlugin
* @param sentryOptions Optional additional options to add as alternative to `sentry` property of config
* @returns The modified config to be exported
*/
export function withSentryConfig(
exportedUserNextConfig: ExportedNextConfig = {},
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
sentryOptions?: UserSentryOptions,
): NextConfigFunction | NextConfigObject {
return function (phase: string, defaults: { defaultConfig: NextConfigObject }): NextConfigObject {
if (typeof exportedUserNextConfig === 'function') {
const userNextConfigObject = exportedUserNextConfig(phase, defaults);
return getFinalConfigObject(phase, userNextConfigObject, userSentryWebpackPluginOptions);
} else {
return getFinalConfigObject(phase, exportedUserNextConfig, userSentryWebpackPluginOptions);
}
const userNextConfigObject =
typeof exportedUserNextConfig === 'function' ? exportedUserNextConfig(phase, defaults) : exportedUserNextConfig;
// Inserts additional `sentry` options into the existing config, allows for backwards compatability
// in case nothing is passed into the optional `sentryOptions` argument
userNextConfigObject.sentry = { ...userNextConfigObject.sentry, ...sentryOptions };
return getFinalConfigObject(phase, userNextConfigObject, userSentryWebpackPluginOptions);
};
}

Expand Down