Skip to content

Commit bc564a1

Browse files
committed
Fix typing issue with withSentryConfig and NextConfig
1 parent 9c66c39 commit bc564a1

File tree

7 files changed

+42
-4
lines changed

7 files changed

+42
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dependencies
22
node_modules/
33
packages/*/package-lock.json
4+
packages/**/test/**/yarn.lock
45
package-lock.json
56

67
# build and test

packages/nextjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
"test": "run-s test:unit",
6767
"test:all": "run-s test:unit test:integration",
6868
"test:unit": "jest",
69-
"test:integration": "test/run-integration-tests.sh",
69+
"test:integration": "test/run-integration-tests.sh && yarn test:types",
70+
"test:types": "cd test/types/ && yarn && tsc",
7071
"test:watch": "jest --watch",
7172
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
7273
"vercel:project": "source vercel/make-project-use-current-branch.sh"

packages/nextjs/src/config/types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type NextConfigFunctionWithSentry = (
2323

2424
export type NextConfigObject = {
2525
// Custom webpack options
26-
webpack?: WebpackConfigFunction;
26+
webpack?: WebpackConfigFunction | null;
2727
// Whether to build serverless functions for all pages, not just API routes. Removed in nextjs 12+.
2828
target?: 'server' | 'experimental-serverless-trace';
2929
// The output directory for the built app (defaults to ".next")
@@ -93,8 +93,13 @@ export type BuildContext = {
9393
isServer: boolean;
9494
buildId: string;
9595
dir: string;
96-
config: NextConfigObject;
96+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
97+
config: any;
9798
webpack: { version: string };
99+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
100+
defaultLoaders: { babel: any };
101+
totalPages: number;
102+
nextRuntime?: 'nodejs' | 'edge';
98103
};
99104

100105
/**

packages/nextjs/src/config/webpack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ export function getWebpackPluginOptions(
401401
userPluginOptions: Partial<SentryWebpackPluginOptions>,
402402
userSentryOptions: UserSentryOptions,
403403
): SentryWebpackPluginOptions {
404-
const { buildId, isServer, webpack, config: userNextConfig, dev: isDev, dir: projectDir } = buildContext;
404+
const { buildId, isServer, webpack, config, dev: isDev, dir: projectDir } = buildContext;
405+
const userNextConfig = config as NextConfigObject;
406+
405407
const distDir = userNextConfig.distDir ?? '.next'; // `.next` is the default directory
406408

407409
const isWebpack5 = webpack.version.startsWith('5');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { withSentryConfig } from '../../src/config';
2+
import { NextConfig } from 'next';
3+
4+
const config: NextConfig = {
5+
hideSourceMaps: true,
6+
webpack: config => ({
7+
...config,
8+
module: {
9+
...config.module,
10+
rules: [...config.module.rules],
11+
},
12+
}),
13+
};
14+
15+
module.exports = withSentryConfig(config, {
16+
validate: true,
17+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"description": "This is only used to install the nextjs v12 package so we can test against those types",
3+
"dependencies": {
4+
"next": "12.3.1"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": [
4+
"./**/*"
5+
]
6+
}

0 commit comments

Comments
 (0)