Skip to content

feat(nextjs): Add optional options argument to withSentryConfig as an alternative to the sentry property #6721

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

Merged
merged 6 commits into from
Jan 12, 2023
Merged
Changes from 5 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
14 changes: 8 additions & 6 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ 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 sentryWizardAddon Addons from automatic config.next.js merging from Sentry Wizard
* @returns The modified config to be exported
*/
export function withSentryConfig(
exportedUserNextConfig: ExportedNextConfig = {},
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
sentryWizardAddon?: 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;
// If there are addons from the Wizard, add them to existing config
userNextConfigObject.sentry = { ...userNextConfigObject.sentry, ...sentryWizardAddon };
return getFinalConfigObject(phase, userNextConfigObject, userSentryWebpackPluginOptions);
};
}

Expand Down