11import { red , type ExtendedBAUploadPlugin } from "@codecov/bundler-plugin-core" ;
2- import type * as webpack from "webpack" ;
2+ import type * as TWebpack from "webpack" ;
33
44import {
55 _internal_processAssets as processAssets ,
88} from "@codecov/webpack-plugin" ;
99
1010export const nextJSWebpackBundleAnalysisPlugin : ExtendedBAUploadPlugin < {
11- webpack : typeof webpack | null ;
12- } > = ( { output, pluginName, pluginVersion } ) => ( {
11+ webpack : typeof TWebpack | null ;
12+ } > = ( { output, pluginName, pluginVersion, options } ) => ( {
1313 version : output . version ,
1414 name : pluginName ,
1515 pluginVersion,
@@ -25,7 +25,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
2525 } ,
2626 webpack ( compiler ) {
2727 compiler . hooks . thisCompilation . tap ( pluginName , ( compilation ) => {
28- if ( ! webpack ) {
28+ if ( ! options . webpack ) {
2929 red (
3030 "Unable to run bundle analysis, Webpack wasn't passed successfully." ,
3131 ) ;
@@ -35,9 +35,16 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
3535 compilation . hooks . processAssets . tapPromise (
3636 {
3737 name : pluginName ,
38- stage : webpack . Compilation . PROCESS_ASSETS_STAGE_REPORT ,
38+ stage : options . webpack . Compilation . PROCESS_ASSETS_STAGE_REPORT ,
3939 } ,
4040 async ( ) => {
41+ if ( ! options . webpack ) {
42+ red (
43+ "Unable to run bundle analysis, Webpack wasn't passed successfully." ,
44+ ) ;
45+ return ;
46+ }
47+
4148 output . setBundleName ( output . originalBundleName ) ;
4249 // Webpack base chunk format options: https://webpack.js.org/configuration/output/#outputchunkformat
4350 if ( typeof compilation . outputOptions . chunkFormat === "string" ) {
@@ -65,7 +72,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
6572
6673 output . bundler = {
6774 name : "webpack" ,
68- version : webpack . version ,
75+ version : options . webpack . version ,
6976 } ;
7077
7178 const outputOptions = compilation . outputOptions ;
@@ -96,7 +103,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
96103
97104 // only output file if running dry run
98105 if ( output . dryRun ) {
99- const { RawSource } = webpack . sources ;
106+ const { RawSource } = options . webpack . sources ;
100107 compilation . emitAsset (
101108 `${ output . bundleName } -stats.json` ,
102109 new RawSource ( output . bundleStatsToJson ( ) ) ,
0 commit comments