Skip to content

Commit 7028dd3

Browse files
committed
add helper to find specific plugin in webpackConfig.plugins array
1 parent 3ea40d4 commit 7028dd3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dropUndefinedKeys, logger } from '@sentry/utils';
33
import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
44
import * as fs from 'fs';
55
import * as path from 'path';
6-
import { DefinePlugin } from 'webpack';
6+
import { DefinePlugin, WebpackPluginInstance } from 'webpack';
77

88
import {
99
BuildContext,
@@ -310,3 +310,19 @@ export function getWebpackPluginOptions(
310310

311311
return { ...defaultPluginOptions, ...userPluginOptions };
312312
}
313+
314+
/**
315+
* Helper function to search through the webpack config object's `plugins` array for a particular plugin.
316+
*
317+
* Note: Though it's used only once here, this is abstracted into a separate function because it's helpful for tests.
318+
*
319+
* @param webpackConfig The webpack config in object form
320+
* @param pluginName The name of the desired plugin
321+
* @returns The instance of the plugin, if it's included in `plugins`, or undefined if it's not
322+
*/
323+
export function findWebpackPlugin(
324+
webpackConfig: WebpackConfigObject,
325+
pluginName: string,
326+
): WebpackPluginInstance | SentryWebpackPlugin | undefined {
327+
return webpackConfig.plugins?.find(plugin => plugin.constructor.name === pluginName);
328+
}

0 commit comments

Comments
 (0)