Skip to content

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

Merged
valscion merged 4 commits into
webpack:mainfrom
Menny1337:fix/parse-nested-webpack5-umd
Aug 23, 2026
Merged

fix: parse Webpack 5 module maps nested in UMD wrappers#733
valscion merged 4 commits into
webpack:mainfrom
Menny1337:fix/parse-nested-webpack5-umd

Conversation

@Menny1337

Copy link
Copy Markdown
Contributor

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: eba7f74

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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.58%. Comparing base (24e3f77) to head (eba7f74).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #733      +/-   ##
==========================================
+ Coverage   76.39%   78.58%   +2.19%     
==========================================
  Files          17       17              
  Lines        1004     1060      +56     
  Branches      360      383      +23     
==========================================
+ Hits          767      833      +66     
+ Misses        207      199       -8     
+ Partials       30       28       -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.

Menny1337 and others added 3 commits August 23, 2026 12:57
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
Add a generated UMD fixture parsed through the standard no-options harness and cover candidate fallback behavior while simplifying selection.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Menny1337
Menny1337 force-pushed the fix/parse-nested-webpack5-umd branch from fee1368 to c24d570 Compare August 23, 2026 10:06
@Menny1337

Menny1337 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the coverage feedback in c24d570 and eba7f74.

  • added a generated Webpack 5 UMD fixture exercised by the standard no-options parser test harness
  • verified upstream main returns no modules for that fixture while this branch returns module IDs 447 and 956
  • covered empty/decoy candidates, nested member access, legacy top-level fallback, matching non-runtime candidates, child assets, and modules without IDs
  • retained Improve analyzer performance for bundles with many assets #723's chunk-index optimization and single-pass root asset module selection
  • measured every production line and branch added by this PR at 100% coverage (analyzer.js: 11/11 lines, 8/8 branches; parseUtils.js: 58/58 lines, 60/60 branches)

The targeted parser/analyzer tests, lint/type/format checks, and production build pass locally.

Exercise every production line and branch added by the nested Webpack 5 UMD fix while preserving single-pass root asset module selection.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Menny1337

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @valscion. I’ve rebased onto the latest main, resolved the #723 conflict, and expanded the regression coverage.

The tests now include a generated Webpack 5 UMD bundle parsed through the normal no-options path, plus candidate-selection edge cases. All production lines and branches added by this PR have 100% coverage.

The PR is conflict-free and ready for another look when you have time.

@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, thanks for the contribution!

@valscion
valscion merged commit a5b70c3 into webpack:main Aug 23, 2026
9 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.

2 participants