Skip to content

fix: preserve compiler paths for shared plugin instances - #725

Merged
valscion merged 2 commits into
webpack:mainfrom
utkarshalpha:fix/shared-plugin-compiler-path
Jul 28, 2026
Merged

fix: preserve compiler paths for shared plugin instances#725
valscion merged 2 commits into
webpack:mainfrom
utkarshalpha:fix/shared-plugin-compiler-path

Conversation

@utkarshalpha

Copy link
Copy Markdown
Contributor

Summary

Fixes #506.

A BundleAnalyzerPlugin instance can be applied to multiple compilers, but the plugin previously stored only the most recently applied compiler. As a result, every done-hook callback resolved bundle assets and report files against that compiler's output directory.

This change:

  • passes the compiler captured by each done-hook closure into report and stats generation;
  • resolves bundle directories and output filenames against that compiler;
  • uses the current compiler's bundle directory when refreshing server-mode chart data; and
  • adds a multi-compiler regression test with one shared plugin instance for both Webpack 4 and Webpack 5.

Testing

  • npm exec -- jest test/plugin.js --runInBand --testNamePattern=should.use.each.compiler.output.path (2 passed)
  • npm exec -- jest test/viewer.js --runInBand (5 passed)
  • npm exec -- eslint src/BundleAnalyzerPlugin.js src/viewer.js test/plugin.js
  • npm exec -- tsc --pretty --noEmit
  • npm exec -- prettier --check src/BundleAnalyzerPlugin.js src/viewer.js test/plugin.js .changeset/calm-compilers-report.md
  • npm run build

@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8fabe1a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-bundle-analyzer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: utkarshalpha / name: Utkarsh Tiwari (268ab53)

Comment thread src/BundleAnalyzerPlugin.js Outdated
async generateStatsFile(stats) {
async generateStatsFile(
stats,
compiler = /** @type {Compiler} */ (this.compiler),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to allow leaving out the compiler argument now? This looks like AI using protective coding pattern over understanding if this default is what we want or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — there was no real need for the default. The hook already threads the actual compiler through every internal call site, so I removed the this.compiler fallback and made the parameter required in 8fabe1a.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.29%. Comparing base (97d2ef8) to head (8fabe1a).

Files with missing lines Patch % Lines
src/BundleAnalyzerPlugin.js 61.53% 5 Missing ⚠️
src/viewer.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #725   +/-   ##
=======================================
  Coverage   76.29%   76.29%           
=======================================
  Files          17       17           
  Lines         983      983           
  Branches      357      358    +1     
=======================================
  Hits          750      750           
  Misses        206      206           
  Partials       27       27           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@valscion valscion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Also, noticed that analyzerMode === "server" is not really covered even in base branch so those changed lines also can't be verified by CI... would be lovely to see a change that would add missing coverage for that.

@valscion
valscion merged commit 83a8ee5 into webpack:main Jul 28, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect bundle paths when bundles are in multiple directories.

2 participants