Skip to content

Commit 7389411

Browse files
committed
add in fix for next js webpack plugin not using the correct webpack
1 parent fcfe02c commit 7389411

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.changeset/wise-toys-hug.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@codecov/nextjs-webpack-plugin": patch
3+
"@codecov/bundler-plugin-core": patch
4+
"@codecov/remix-vite-plugin": patch
5+
"@codecov/solidstart-plugin": patch
6+
"@codecov/sveltekit-plugin": patch
7+
"@codecov/webpack-plugin": patch
8+
"@codecov/rollup-plugin": patch
9+
"@codecov/astro-plugin": patch
10+
"@codecov/nuxt-plugin": patch
11+
"@codecov/vite-plugin": patch
12+
---
13+
14+
Fix issue not using the correct webpack in the nextjs plugin

packages/nextjs-webpack-plugin/src/nextjs-webpack-bundle-analysis/nextJSWebpackBundleAnalysisPlugin.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { red, type ExtendedBAUploadPlugin } from "@codecov/bundler-plugin-core";
2-
import type * as webpack from "webpack";
2+
import type * as TWebpack from "webpack";
33

44
import {
55
_internal_processAssets as processAssets,
@@ -8,8 +8,8 @@ import {
88
} from "@codecov/webpack-plugin";
99

1010
export 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

Comments
 (0)