Skip to content

feat: add readdirPrefix option to CachedInputFileSystem#purge - #712

Merged
alexander-akait merged 1 commit into
mainfrom
feat/purge-readdir-prefix
Nov 12, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
feat/purge-readdir-prefix

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Needed for webpack/webpack#23281.

webpack's watcher purges a changed context directory with { exact: true }, so the file stats below it stay cached (webpack/webpack#21020). But the cached readdir of its subdirectories stays too, so a file added in pages/sub/ is never listed. A plain prefix purge fixes that but drops every stat below the directory again.

readdirPrefix: true keeps exact for every cache but readdir, which is purged by prefix. The readdir cache holds one entry per directory, so the extra scan is small.

fs.purge("/app/pages", { exact: true, readdirPrefix: true });
// readdir("/app/pages/sub")          -> read again
// stat("/app/pages/sub/existing.js") -> still cached

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes: test/CachedInputFileSystem.test.js ("should prefix-purge readdir but keep stats with readdirPrefix: true"), failing without the change.

Does this PR introduce a breaking change?

No. The option is new and off by default.

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

JSDoc and types/CachedInputFileSystem.d.ts updated; changeset added.

Use of AI

Claude Code designed the option, wrote the change, test and changeset, and checked it against webpack's watch test with this patch linked in.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added an option to purge cached directory listings beneath a specified path while retaining exact-match purging for other cached data.
  • Documentation
    • Documented the new cache-purge option and its behavior.

With exact: true, readdirPrefix: true still drops the cached readdir
results below the purged path, while file stats stay cached.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1d27bca

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

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Minor

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

@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The purge options now include readdirPrefix. When exact and readdirPrefix are both true, purge removes matching-prefix readdir entries and retains exact-match behavior for other backends. The added test checks that a descendant directory listing is refreshed while a cached file stat remains. A changeset records the minor release.

Merge Risk: Minimal · up to 1d27b

This adds an optional cache-purge setting that leaves current behavior unchanged when it is not used. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a new readdirPrefix option for CachedInputFileSystem#purge. The raw summary confirms the changeset, JSDoc, type declarations, and a test for this option. The title is …
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: Title check

Explanation

The title names the main change: a new readdirPrefix option for CachedInputFileSystem#purge. The raw summary confirms the changeset, JSDoc, type declarations, and a test for this option. The title is specific, concise, and uses a conventional feat: prefix. It does not cover every detail, which is expected.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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.

ESLint install timed out. The project may have too many dependencies for 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b28fc89a-830e-4eda-8a58-e1ade1f39e74
Commits

Reviewing files that changed from the base of the PR and between 9704b87 and 1d27bca.

Files selected for processing: 4

  • .changeset/purge-readdir-prefix.md
  • lib/CachedInputFileSystem.js
  • test/CachedInputFileSystem.test.js
  • types/CachedInputFileSystem.d.ts

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

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.99%. Comparing base (9704b87) to head (1d27bca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #712   +/-   ##
=======================================
  Coverage   98.99%   98.99%           
=======================================
  Files          52       52           
  Lines       10940    10944    +4     
=======================================
+ Hits        10830    10834    +4     
  Misses        110      110           
Flag Coverage Δ
integration 98.99% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@codspeed

codspeed Bot commented Nov 12, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 20.86%

2 warnings, 1 note

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 10 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 2 improved benchmarks
❌ 8 regressed benchmarks
✅ 132 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory cached-fs-burst: 64 sequential cached stat calls 2 KB 3.5 KB -40.72%
❌ Memory deep-hierarchy: bare specifier from 10-deep dir (warm) 2.2 KB 3.4 KB -37.25%
❌ Memory deep-hierarchy: relative from 10-deep dir (warm) 2.2 KB 3.4 KB -37.17%
❌ Memory array-alias: @ -> [preferred, fallback] (warm) 2.2 KB 3.5 KB -37.1%
❌ Memory deep-package-subpath: pkg/a/b/c requests (warm) 2.2 KB 3.5 KB -36.95%
❌ Memory cache-predicate: mixed cached/uncached requests (warm) 2.3 KB 3.6 KB -35.97%
❌ Memory concurrent-batch: Promise.all of 15 resolves (warm) 2.9 KB 4.2 KB -30.37%
❌ Memory cached-fs-burst: 64 concurrent cached stat calls 3.6 KB 4.2 KB -15.24%
⚡ Memory alias-first-char-miss: 300 aliases, scoped tail matches 2.8 KB 1.5 KB +83.67%
⚡ Memory node-compare: node require.resolve x 1000 75.7 KB 50.5 KB +49.91%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/purge-readdir-prefix (1d27bca) with main (9704b87)

Open in CodSpeed

@alexander-akait
alexander-akait merged commit fc4d3fa into main Nov 12, 2026
38 of 40 checks passed
@alexander-akait
alexander-akait deleted the feat/purge-readdir-prefix branch November 12, 2026 15:13
alexander-akait pushed a commit that referenced this pull request Nov 12, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## enhanced-resolve@5.27.0

### Minor Changes

- Add a `readdirPrefix` option to `CachedInputFileSystem#purge` that,
with `exact: true`, still removes the cached directory listings below
`what`. (by [@alexander-akait](https://github.com/alexander-akait) in
[#712](#712))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant