Repository navigation
Conversation
Since #1944, `lookup` and `hierarchicalLookup` take an optional `Observations` record, but `matchFiles` doesn't. That leaves listing a directory as the one file system query whose dependencies can't be recorded, so anything built on an enumeration (`require.context` today, resolver-provided virtual modules later) can't be invalidated precisely. This adds the same optional trailing parameter to `matchFiles`. Each directory listed is recorded in `content`, since adding or removing an entry is a modification of the directory. Each symlink encountered is recorded along with what it resolved to. A `rootDir` that is a file, or the first missing segment of one that doesn't exist, is recorded in `existence`. Recording happens as the result is iterated. Metro doesn't pass a record yet - `require.context` lists files when the context module is transformed, outside any resolution. Changelog: Internal Test plan: New unit tests, on posix and win32. Listing from an ancestor of the project root doesn't resolve symlinks inside the project (existing behaviour, with or without a record), so that case only asserts the directories listed.
There was a problem hiding this comment.
🟡 Changes recommended
The tests do not verify that following a symlink to a distinct directory records its canonical path in content, leaving target-directory observation unprotected against regressions.
1 open issue
What changed in this PR
Adds optional observation recording to metro-file-map’s matchFiles, extending the dependency-tracking approach used by lookup and hierarchicalLookup. This lays groundwork for precise invalidation of directory-based queries such as require.context.
Changes:
- Records directory contents, symlink resolutions, and missing or non-directory roots as results are iterated.
- Updates the public interface and API snapshot.
- Adds observation tests for POSIX and Windows paths, including lazy recording.
| File | Description |
|---|---|
packages/metro-file-map/src/lib/TreeFS.js |
Collects optional observations during file enumeration. |
packages/metro-file-map/src/lib/__tests__/TreeFS-test.js |
Tests observation contents and iteration timing across platforms. |
packages/metro-file-map/src/flow-types.js |
Declares and documents the optional observations parameter. |
packages/metro-file-map/API.md |
Updates the public API snapshot. |
Review effort: Balanced
| content: new Set(content.map(canonical)), | ||
| existence: new Set(existence.map(canonical)), | ||
| }); | ||
| }); |
Metro review: Looks goodRisk: low · Commit: This update builds the symlink lookup options once per No findings. Verified
Not run: I didn't benchmark. The change only hoists one object spread out of the per-symlink loop, and only when an observations record is passed, which Metro doesn't do yet. Windows path behavior was covered only by the win32-mode unit tests, not run on a real Windows machine. Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |

Since #1944,
lookupandhierarchicalLookuptake an optionalObservationsrecord, butmatchFilesdoesn't. That leaves it as the one file system query whose dependencies can't be recorded, so anything built on it (require.contexttoday) can't be invalidated precisely.This adds the same optional trailing parameter to
matchFiles. Each directory listed is recorded incontent, since adding or removing an entry is a modification of the directory. Each symlink encountered is recorded along with what it resolved to. ArootDirthat is a file, or the first missing segment of one that doesn't exist, is recorded inexistence. Recording happens as the result is iterated.Metro doesn't pass a record yet -
require.contextlists files when the context module is transformed, outside any resolution.Changelog: Internal
Test plan:
New unit tests, on posix and win32. Listing from an ancestor of the project root doesn't resolve symlinks inside the project (existing behaviour, with or without a record), so that case only asserts the directories listed.