Skip to content

Commit 72f16e2

Browse files
committed
differentiate between partial and full next config objects
1 parent e1f4f89 commit 72f16e2

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

packages/nextjs/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { constructWebpackConfigFunction } from './webpack';
1111
export function withSentryConfig(
1212
userNextConfig: ExportedNextConfig = {},
1313
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
14-
): NextConfigFunction | NextConfigObject {
14+
): NextConfigFunction | Partial<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 }): NextConfigObject {
18+
return function(phase: string, defaults: { defaultConfig: NextConfigObject }): Partial<NextConfigObject> {
1919
const materializedUserNextConfig = userNextConfig(phase, defaults);
2020
return {
2121
...materializedUserNextConfig,

packages/nextjs/src/config/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export type SentryWebpackPlugin = { options: SentryWebpackPluginOptions };
77
* Overall Nextjs config
88
*/
99

10-
export type ExportedNextConfig = NextConfigObject | NextConfigFunction;
10+
export type ExportedNextConfig = Partial<NextConfigObject> | NextConfigFunction;
1111

1212
export type NextConfigObject = {
1313
// custom webpack options
14-
webpack?: WebpackConfigFunction;
14+
webpack: WebpackConfigFunction;
1515
// whether to build serverless functions for all pages, not just API routes
16-
target?: 'server' | 'experimental-serverless-trace';
16+
target: 'server' | 'experimental-serverless-trace';
1717
sentry?: {
1818
disableServerWebpackPlugin?: boolean;
1919
disableClientWebpackPlugin?: boolean;
@@ -25,8 +25,8 @@ export type NextConfigObject = {
2525

2626
export type NextConfigFunction = (
2727
phase: string,
28-
defaults: { defaultConfig: { [key: string]: unknown } },
29-
) => NextConfigObject;
28+
defaults: { defaultConfig: NextConfigObject },
29+
) => Partial<NextConfigObject>;
3030

3131
/**
3232
* Webpack config
@@ -56,7 +56,7 @@ export type BuildContext = {
5656
isServer: boolean;
5757
buildId: string;
5858
dir: string;
59-
config: Partial<NextConfigObject>;
59+
config: NextConfigObject;
6060
webpack: { version: string };
6161
};
6262

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export { SentryWebpackPlugin };
3434
* @returns The function to set as the nextjs config's `webpack` value
3535
*/
3636
export function constructWebpackConfigFunction(
37-
userNextConfig: NextConfigObject = {},
37+
userNextConfig: Partial<NextConfigObject> = {},
3838
userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
3939
): WebpackConfigFunction {
4040
// Will be called by nextjs and passed its default webpack configuration and context data about the build (whether

packages/nextjs/test/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ process.env.SENTRY_RELEASE = 'doGsaREgReaT';
5858
const runtimePhase = 'ball-fetching';
5959
// `defaultConfig` is the defaults for all nextjs options (we don't use these at all in the tests, so for our purposes
6060
// here the values don't matter)
61-
const defaultsObject = { defaultConfig: {} };
61+
const defaultsObject = { defaultConfig: {} as NextConfigObject };
6262

6363
/** mocks of the arguments passed to `nextConfig.webpack` */
6464
const serverWebpackConfig = {
@@ -103,7 +103,7 @@ function getBuildContext(
103103
dev: false,
104104
buildId: 'sItStAyLiEdOwN',
105105
dir: '/Users/Maisey/projects/squirrelChasingSimulator',
106-
config: { target: 'server', ...userNextConfig },
106+
config: { target: 'server', ...userNextConfig } as NextConfigObject,
107107
webpack: { version: webpackVersion },
108108
isServer: buildTarget === 'server',
109109
};

0 commit comments

Comments
 (0)