GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: add exact option to CachedInputFileSystem#purge by alexander-akait · Pull Request #591 · webpack/enhanced-resolve Conversation
Member
Pass { exact: true } as the second argument to purge to remove only
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsPass { exact: true } as the second argument to purge to remove only
cache entries whose key matches the input exactly, instead of the
default prefix-match behavior. Useful when callers know a specific
file changed and want to avoid evicting unrelated descendants under
the same path prefix.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
🦋 Changeset detectedLatest commit: c8ca735 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
When exact: true is set, the caller is naming the exact directory whose readdir cache should be evicted, so going through purgeParent (which strips to dirname before purging) targets the wrong key. Call the readdir backend's purge directly in exact mode instead.
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## main #591 +/- ## ========================================== + Coverage 96.49% 96.53% +0.03% ========================================== Files 50 50 Lines 2999 3032 +33 Branches 952 969 +17 ========================================== + Hits 2894 2927 +33 Misses 89 89 Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Adds an opt-in exact mode to CachedInputFileSystem#purge so callers can evict only the specific cache key(s) provided, rather than the legacy prefix-based eviction behavior (and for readdir, the legacy parent-based eviction behavior).
Changes:
CachedInputFileSystem#purge (and underlying cache backends) to accept an optional { exact?: boolean } argument.CacheBackend.purge when options.exact === true, including iterable inputs.stat/readdir and Buffer inputs; add a changeset entry documenting the new option.Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/CachedInputFileSystem.js |
Adds options parameter to purge and implements exact-match eviction logic; adjusts readdir purging behavior for exact mode. |
types.d.ts |
Updates TypeScript declaration for CachedInputFileSystem#purge to include the optional { exact?: boolean } options parameter. |
test/CachedInputFileSystem.test.js |
Adds tests validating exact-only eviction vs legacy prefix/parent eviction behavior. |
.changeset/feat-purge-exact-matching.md |
Documents the new purge option and bumps the package minor version via changesets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } else if ( | ||
| return; | ||
| } | ||
| const exact = options !== undefined && options.exact === true; |
| purge(what, options) { | ||
| this._statBackend.purge(what, options); | ||
| this._lstatBackend.purge(what, options); | ||
| if (options && options.exact) { |
There was an error while loading. Please reload this page.
Merging this PR will not alter performance
Comparing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- CacheBackend.purge: null options now treated as no-options instead of crashing on options.exact dereference. - CachedInputFileSystem.purge: switch the readdir branch to the same strict === true check used by CacheBackend so exact-mode is enabled consistently across all backends. - Add a regression test for purge(what, null).
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -377,7 +378,39 @@ class CacheBackend { | |||
| } | |||
| this._enterIdleMode(); | |||
| } | |||
| } else if ( | |||
| return; | |||
| } | |||
The legacy guard if (!what) confused valid cache keys — 0 (a file descriptor, included in the signature) and '' — with the no-argument 'purge all' form. Tighten to an explicit null/undefined check in both CacheBackend.purge and CacheBackend.purgeParent.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| purge(what, options) { | ||
| if (what === undefined || what === null) { | ||
| if (this._mode !== STORAGE_MODE_IDLE) { | ||
| this._data.clear(); | ||
| for (const level of this._levels) { | ||
| level.clear(); | ||
| } | ||
| this._enterIdleMode(); | ||
| } | ||
| } else if ( | ||
| return; | ||
| } | ||
| const exact = | ||
| options !== undefined && options !== null && options.exact === true; | ||
| if (exact) { |
Previously purge('') hit the !what fast-path and was an O(1) Map#clear.
After tightening the !what guard to undefined/null only, '' fell into
the prefix branch and became an O(n) scan even though it still matches
every key. Restore the fast path for the empty-string prefix.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.