Skip to content

Commit 53effc8

Browse files
committed
correctly type sentry webpack plugin
1 parent d6a0695 commit 53effc8

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SentryCliPluginOptions } from '@sentry/webpack-plugin';
2+
import { WebpackPluginInstance } from 'webpack';
23

34
export type SentryWebpackPluginOptions = SentryCliPluginOptions;
4-
export type SentryWebpackPlugin = { options: SentryWebpackPluginOptions };
5+
export type SentryWebpackPlugin = WebpackPluginInstance & { options: SentryWebpackPluginOptions };
56

67
/**
78
* Overall Nextjs config
@@ -37,7 +38,7 @@ export type WebpackConfigFunction = (config: WebpackConfigObject, options: Build
3738

3839
export type WebpackConfigObject = {
3940
devtool?: string;
40-
plugins?: Array<{ [key: string]: unknown }>;
41+
plugins?: Array<WebpackPluginInstance | SentryWebpackPlugin>;
4142
entry: WebpackEntryProperty;
4243
output: { filename: string; path: string };
4344
target: string;

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getSentryRelease } from '@sentry/node';
22
import { dropUndefinedKeys, logger } from '@sentry/utils';
3-
import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
3+
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
44
import * as fs from 'fs';
55
import * as path from 'path';
66

@@ -96,8 +96,6 @@ export function constructWebpackConfigFunction(
9696

9797
newConfig.plugins = newConfig.plugins || [];
9898
newConfig.plugins.push(
99-
// @ts-ignore Our types for the plugin are messed up somehow - TS wants this to be `SentryWebpackPlugin.default`,
100-
// but that's not actually a thing
10199
new SentryWebpackPlugin(getWebpackPluginOptions(buildContext, userSentryWebpackPluginOptions)),
102100
);
103101
}

packages/nextjs/test/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('Sentry webpack plugin config', () => {
336336
incomingWebpackBuildContext: serverBuildContext,
337337
});
338338

339-
expect(finalWebpackConfig.plugins?.[0].options).toEqual(
339+
expect((finalWebpackConfig.plugins?.[0] as SentryWebpackPlugin).options).toEqual(
340340
expect.objectContaining({
341341
include: expect.any(Array), // default, tested separately elsewhere
342342
ignore: [], // default
@@ -360,7 +360,7 @@ describe('Sentry webpack plugin config', () => {
360360
incomingWebpackBuildContext: serverBuildContext,
361361
});
362362

363-
expect((finalWebpackConfig.plugins?.[0].options as SentryWebpackPluginOptions).debug).toEqual(true);
363+
expect((finalWebpackConfig.plugins?.[0] as SentryWebpackPlugin).options.debug).toEqual(true);
364364
});
365365

366366
it('warns when overriding certain default values', () => {

0 commit comments

Comments
 (0)