Skip to content

fix: parse Webpack 5 module maps nested in UMD wrappers - #733

Open
Menny1337 wants to merge 2 commits into
webpack:mainfrom
Menny1337:fix/parse-nested-webpack5-umd
Open

fix: parse Webpack 5 module maps nested in UMD wrappers#733
Menny1337 wants to merge 2 commits into
webpack:mainfrom
Menny1337:fix/parse-nested-webpack5-umd

Conversation

@Menny1337

Copy link
Copy Markdown

Summary

Related to #372.

Webpack 5 UMD output nests its bootstrap IIFE inside the UMD factory. The analyzer previously missed that module map, while empty or unrelated competing IIFEs could also be selected incorrectly.

This change:

  • discovers nested zero-argument Webpack bootstrap IIFEs
  • ranks candidates using expected module-ID overlap and Webpack runtime structure
  • excludes empty module maps
  • preserves top-level and legacy parser fallbacks
  • computes each asset's module metadata once
  • adds Webpack 5 regression fixtures covering empty and decoy IIFEs

A patch Changeset is included.

What kind of change does this PR introduce?

Fix.

Did you add tests for your changes?

Yes. The tests cover unhinted, partially hinted, tied, and non-matching candidate selection, analyzer module-ID plumbing, and single-pass asset-module collection.

Validation:

  • npm test -- test/parseUtils.js test/analyzerUtils.js — 27 passed
  • npm run build — passed
  • npm run test:coverage — 136 passed, 4 skipped
  • npm run lint — ESLint, TypeScript, and Prettier passed
  • git diff --check — passed

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

No documentation changes are required. This corrects existing bundle parsing behavior.

Use of AI

GitHub Copilot assisted with reproducing the failure, drafting the implementation and regression tests, and iterating on review feedback.

Human verification: I reviewed every generated change and the complete final diff, verified the behavior against Webpack 5.105.2 output, and ran all validation commands listed above. The patch also received independent review before publication. I understand the implementation and remain responsible for the contribution.

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fee1368

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 Aug 20, 2026

Copy link
Copy Markdown

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

Menny1337 and others added 2 commits August 20, 2026 12:08
Discover nested Webpack bootstrap IIFEs and select the correct non-empty module map using stats IDs and runtime structure, preserving accurate parsed module attribution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2cd1d86-732d-44fb-b556-cf0b08f9906c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2cd1d86-732d-44fb-b556-cf0b08f9906c
@Menny1337
Menny1337 force-pushed the fix/parse-nested-webpack5-umd branch from 791cc23 to fee1368 Compare August 20, 2026 09:08
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.48649% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.67%. Comparing base (23adc7a) to head (fee1368).

Files with missing lines Patch % Lines
src/parseUtils.js 85.55% 11 Missing and 2 partials ⚠️
src/analyzer.js 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #733      +/-   ##
==========================================
+ Coverage   76.29%   76.67%   +0.37%     
==========================================
  Files          17       17              
  Lines         983     1046      +63     
  Branches      358      382      +24     
==========================================
+ Hits          750      802      +52     
- Misses        206      215       +9     
- Partials       27       29       +2     

☔ 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! Can you take a look at the coverage report? To my eyes it looks like some branches you added are lacking code coverage. Ideally we'd have more tests that verify a real webpack bundle parses correctly without having to pass any custom optiona ourselves in test.

I'm ready to merge this once the coverage question has been dealt with

@valscion

Copy link
Copy Markdown
Collaborator

Looks like that #723 getting merged also caused a merge conflict here which needs to be resolved.

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.

2 participants