Skip to content

Split module paths on both separators so Windows modules are not dropped - #745

Merged
valscion merged 1 commit into
webpack:mainfrom
PerryLink:fix/windows-module-paths
Nov 2, 2026
Merged

valscion merged 1 commit into
webpack:mainfrom
PerryLink:fix/windows-module-paths

Conversation

@PerryLink

@PerryLink PerryLink commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Modules whose names use Windows path separators are silently dropped from the report.

// src/tree/utils.js:23-31
const parts = module.name.split('/')     // a name like "C:\\repo\\src\\x.js" yields one part
return parts.slice(1)                    // ... and slice(1) is empty -> null

Folder.addModule() (src/tree/Folder.js:79-83) then returns without a warning, so the module is
missing from the treemap and the JSON report, and statSize (src/analyzer.js:546) is under-counted.
The same happens to inner modules of a concatenated module (src/tree/ConcatenatedModule.js:80-84).

Reachable in practice: webpack writes an absolute path into module.name when the module lives on a
different drive than the project (webpack/lib/util/identifier.js, absoluteToRequest() returns the
absolute path when path.win32.relative() still produces one). A real webpack 5 build with the project
on D: and a module on C: produced 140 bytes of modules but statSize = 102, with cross.js absent
from the report.

The change

-  const parts = module.name.split('/')
+  const parts = module.name.split(/[\\/]/u)

One expression, slice(1) semantics unchanged, and identical results for every name that only uses /
(the existing fixtures are compared before/after and are byte-identical).

A changeset (.changeset/windows-path-module-names.md) is included, as the repository requires.

Verification

  • unit test added to test/analyzerUtils.js: 1 failed, 12 passed before (./shared/lib/util.js missing
    from the parsed path array), 13 passed after;
  • the real webpack 5 build above: statSize 102 → 140 and cross.js reappears;
  • the 8 existing expected-chart-data fixtures produce identical getViewerData() output before and
    after (including with-module-concatenation-info and the gzip column);
  • 5 non-puppeteer suites / 113 tests pass; eslint, prettier --check, tsc --noEmit clean;
  • git apply (with core.autocrlf=false) on a pristine tarball reproduces files/ byte-for-byte.

The new test is a pure string assertion with no path.sep or platform constants, so it behaves the same
on the ubuntu × Node 20/22/24 CI matrix.

The puppeteer-backed suites cannot run on this machine (no Chrome); their fixtures were compared through
getViewerData() instead, as described above.

Summary by CodeRabbit

  • Bug Fixes
    • Module paths using Windows separators now appear correctly in bundle analyzer reports, including paths resolved across drives.
    • Drive-qualified paths are normalized in the report while preserving bundle size totals.

@changeset-bot

changeset-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e3015b

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 Oct 18, 2026 •

Copy link
Copy Markdown

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

  • ✅ login: PerryLink / name: PerryLink (4e3015b)

@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72d0e578-dcf6-42eb-851b-f0cd4da22edb
📥 Commits

Reviewing files that changed from the base of the PR and between 0ebe1e5 and 4e3015b.

📒 Files selected for processing: 3
  • .changeset/windows-path-module-names.md
  • src/tree/utils.js
  • test/analyzerUtils.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Module path parsing now recognizes both forward and backslash separators. A new test checks that a Windows drive-qualified module name is reported as ./shared/lib/util.js, alongside ./src/index.js, and that the bundle stat size remains 150. A patch changeset records this change.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 4e301

Windows-style module paths are now included in reports and contribute to bundle sizes. No established issue warrants delaying the change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: splitting module paths on both slash types to prevent Windows modules from being dropped.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/analyzerUtils.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.54%. Comparing base (0ebe1e5) to head (4e3015b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #745      +/-   ##
==========================================
+ Coverage   89.92%   90.54%   +0.61%     
==========================================
  Files          17       17              
  Lines        1132     1132              
  Branches      420      420              
==========================================
+ Hits         1018     1025       +7     
+ Misses        105       99       -6     
+ Partials        9        8       -1     

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

Thanks!

@valscion
valscion merged commit 7eca787 into webpack:main Nov 2, 2026
9 checks passed
PerryLink added a commit to PerryLink/webpack-bundle-analyzer that referenced this pull request Nov 5, 2026
webpack#745 stopped dropping modules whose names use Windows path separators, but it
kept `slice(1)`, so the drive letter of an absolute path was still cut off:
`C:\shared\lib\util.js`, `D:\shared\lib\util.js` and `./shared/lib/util.js`
all became the same node, and the treemap showed one module with the sum of
their sizes.

Keep a `[A-Za-z]:` first part and drop all leading empty parts of absolute and
UNC names. Update the webpack#745 expectation that pinned the old behavior and add
coverage for the cross-drive, absolute and UNC cases.
valscion pushed a commit that referenced this pull request Nov 6, 2026
* fix: keep the drive letter of absolute Windows module paths

#745 stopped dropping modules whose names use Windows path separators, but it
kept `slice(1)`, so the drive letter of an absolute path was still cut off:
`C:\shared\lib\util.js`, `D:\shared\lib\util.js` and `./shared/lib/util.js`
all became the same node, and the treemap showed one module with the sum of
their sizes.

Keep a `[A-Za-z]:` first part and drop all leading empty parts of absolute and
UNC names. Update the #745 expectation that pinned the old behavior and add
coverage for the cross-drive, absolute and UNC cases.

* fix: keep UNC module names distinct from relative paths

Dropping every leading empty part made `\\server\share\x.js` produce the same
path parts as `./server/share/x.js`, so the two modules were merged into one
node. Keep the UNC server as a `UNC:server` marker instead: it cannot be
produced by a relative path and the displayed path stays free of empty
segments.

Add a regression test that puts a UNC module and a relative module with the
same path into one chunk; it fails on the previous commit and passes now.
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