1
1
import { red , type ExtendedBAUploadPlugin } from "@codecov/bundler-plugin-core" ;
2
- import type * as webpack from "webpack" ;
2
+ import type * as TWebpack from "webpack" ;
3
3
4
4
import {
5
5
_internal_processAssets as processAssets ,
8
8
} from "@codecov/webpack-plugin" ;
9
9
10
10
export const nextJSWebpackBundleAnalysisPlugin : ExtendedBAUploadPlugin < {
11
- webpack : typeof webpack | null ;
12
- } > = ( { output, pluginName, pluginVersion } ) => ( {
11
+ webpack : typeof TWebpack | null ;
12
+ } > = ( { output, pluginName, pluginVersion, options } ) => ( {
13
13
version : output . version ,
14
14
name : pluginName ,
15
15
pluginVersion,
@@ -25,7 +25,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
25
25
} ,
26
26
webpack ( compiler ) {
27
27
compiler . hooks . thisCompilation . tap ( pluginName , ( compilation ) => {
28
- if ( ! webpack ) {
28
+ if ( ! options . webpack ) {
29
29
red (
30
30
"Unable to run bundle analysis, Webpack wasn't passed successfully." ,
31
31
) ;
@@ -35,9 +35,16 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
35
35
compilation . hooks . processAssets . tapPromise (
36
36
{
37
37
name : pluginName ,
38
- stage : webpack . Compilation . PROCESS_ASSETS_STAGE_REPORT ,
38
+ stage : options . webpack . Compilation . PROCESS_ASSETS_STAGE_REPORT ,
39
39
} ,
40
40
async ( ) => {
41
+ if ( ! options . webpack ) {
42
+ red (
43
+ "Unable to run bundle analysis, Webpack wasn't passed successfully." ,
44
+ ) ;
45
+ return ;
46
+ }
47
+
41
48
output . setBundleName ( output . originalBundleName ) ;
42
49
// Webpack base chunk format options: https://webpack.js.org/configuration/output/#outputchunkformat
43
50
if ( typeof compilation . outputOptions . chunkFormat === "string" ) {
@@ -65,7 +72,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
65
72
66
73
output . bundler = {
67
74
name : "webpack" ,
68
- version : webpack . version ,
75
+ version : options . webpack . version ,
69
76
} ;
70
77
71
78
const outputOptions = compilation . outputOptions ;
@@ -96,7 +103,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
96
103
97
104
// only output file if running dry run
98
105
if ( output . dryRun ) {
99
- const { RawSource } = webpack . sources ;
106
+ const { RawSource } = options . webpack . sources ;
100
107
compilation . emitAsset (
101
108
`${ output . bundleName } -stats.json` ,
102
109
new RawSource ( output . bundleStatsToJson ( ) ) ,
0 commit comments