Skip to content

Commit 254b5bb

Browse files
committed
simplify NextConfigObject type
1 parent 0ef7e94 commit 254b5bb

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

packages/nextjs/src/config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExportedNextConfig, NextConfigFunction, NextConfigObject, SentryWebpackPluginOptions } from './types';
1+
import type { ExportedNextConfig, NextConfigFunction, NextConfigObject, SentryWebpackPluginOptions } from './types';
22
import { constructWebpackConfigFunction } from './webpack';
33

44
/**
@@ -11,11 +11,11 @@ import { constructWebpackConfigFunction } from './webpack';
1111
export function withSentryConfig(
1212
userNextConfig: ExportedNextConfig = {},
1313
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
14-
): NextConfigFunction | Partial<NextConfigObject> {
14+
): NextConfigFunction | NextConfigObject {
1515
// If the user has passed us a function, we need to return a function, so that we have access to `phase` and
1616
// `defaults` in order to pass them along to the user's function
1717
if (typeof userNextConfig === 'function') {
18-
return function (phase: string, defaults: { defaultConfig: NextConfigObject }): Partial<NextConfigObject> {
18+
return function (phase: string, defaults: { defaultConfig: NextConfigObject }): NextConfigObject {
1919
const materializedUserNextConfig = userNextConfig(phase, defaults);
2020

2121
// Next 12.2.3+ warns about non-canonical properties on `userNextConfig`, so grab and then remove the `sentry`

packages/nextjs/src/config/types.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ export type SentryWebpackPlugin = WebpackPluginInstance & { options: SentryWebpa
88
* Overall Nextjs config
99
*/
1010

11-
export type ExportedNextConfig = Partial<NextConfigObject> | NextConfigFunction;
11+
export type ExportedNextConfig = NextConfigObject | NextConfigFunction;
1212

1313
export type NextConfigObject = {
1414
// custom webpack options
15-
webpack: WebpackConfigFunction;
15+
webpack?: WebpackConfigFunction;
1616
// whether to build serverless functions for all pages, not just API routes
17-
target: 'server' | 'experimental-serverless-trace';
17+
target?: 'server' | 'experimental-serverless-trace';
1818
// the output directory for the built app (defaults to ".next")
19-
distDir: string;
19+
distDir?: string;
2020
// the root at which the nextjs app will be served (defaults to "/")
21-
basePath: string;
21+
basePath?: string;
2222
sentry?: UserSentryOptions;
23-
} & {
24-
// other `next.config.js` options
25-
[key: string]: unknown;
2623
};
2724

2825
export type UserSentryOptions = {
@@ -42,10 +39,7 @@ export type UserSentryOptions = {
4239
widenClientFileUpload?: boolean;
4340
};
4441

45-
export type NextConfigFunction = (
46-
phase: string,
47-
defaults: { defaultConfig: NextConfigObject },
48-
) => Partial<NextConfigObject>;
42+
export type NextConfigFunction = (phase: string, defaults: { defaultConfig: NextConfigObject }) => NextConfigObject;
4943

5044
/**
5145
* Webpack config

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export { SentryWebpackPlugin };
3636
* @returns The function to set as the nextjs config's `webpack` value
3737
*/
3838
export function constructWebpackConfigFunction(
39-
userNextConfig: Partial<NextConfigObject> = {},
39+
userNextConfig: NextConfigObject = {},
4040
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
4141
userSentryOptions: UserSentryOptions = {},
4242
): WebpackConfigFunction {

packages/nextjs/test/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ afterEach(() => {
6464
});
6565

6666
/** Mocks of the arguments passed to `withSentryConfig` */
67-
const userNextConfig: Partial<NextConfigObject> = {
67+
const userNextConfig: NextConfigObject = {
6868
publicRuntimeConfig: { location: 'dogpark', activities: ['fetch', 'chasing', 'digging'] },
6969
webpack: (config: WebpackConfigObject, _options: BuildContext) => ({
7070
...config,
@@ -124,7 +124,7 @@ const clientWebpackConfig = {
124124
// dynamically.
125125
function getBuildContext(
126126
buildTarget: 'server' | 'client',
127-
userNextConfig: Partial<NextConfigObject>,
127+
userNextConfig: NextConfigObject,
128128
webpackVersion: string = '5.4.15',
129129
): BuildContext {
130130
return {

0 commit comments

Comments
 (0)