Skip to content
Merged
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
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