Skip to content

metro-file-map: Fix regressions with symlinks and unnormalised roots - #2093

Open
robhogan wants to merge 1 commit into
mainfrom
pr2093
Open

robhogan wants to merge 1 commit into
mainfrom
pr2093

Conversation

@robhogan

@robhogan robhogan commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes three edge case regressions since 0.87.1:

  • metro-file-map: Add FileMap.addRoot聽#2064 drops cached files outside the roots on a warm start. This only affects configs that set watchFolders to non-real paths. Watchman lists a symlinked root's files under its real path, so they're all dropped, and imports into it fail until --reset-cache:
    watchFolders: [path.resolve(__dirname, 'node_modules/my-linked-lib')]
    Real paths of roots now count too (built-in crawlers only - so we don鈥檛 assume file map contents are backed by the real FS).
  • metro-file-map: Check hierarchicalLookup candidates from their own nodes聽#1946 broke hierarchicalLookup through a symlink in a root to its parent:
    app/monorepo -> ..      (watchFolders: ['/repo'])
    import './monorepo/shared'
    -> ENOENT: /repo/app/mo/package.json
    
  • performance: Improve metro-file-map's Node crawler hot-path聽#1677 stopped the Node crawler normalising roots:
    roots: ['/proj/sub/']             -> 'sub//a.js'
    roots: ['/proj/other/../shared']  -> blockList for '/shared/dist' ignored
    

Changelog: Internal

Test plan:

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 23, 2026
@robhogan robhogan changed the title metro-file-map: Keep a symlinked root's files on a warm start metro-file-map: Fix regressions with symlinks and unnormalised roots Oct 23, 2026
Fixes three regressions since 0.87.1:

- #2064 drops cached files outside the roots on a warm start. Watchman lists a symlinked root's files under its real path, so they're all dropped, and imports into it fail until `--reset-cache`:
  ```js
  watchFolders: [path.resolve(__dirname, 'node_modules/my-linked-lib')]
  ```
  Real paths of roots now count too (built-in crawlers only).
- #1946 broke `hierarchicalLookup` through a symlink in a root to its parent:
  ```
  app/monorepo -> ..      (watchFolders: ['/repo'])
  import './monorepo/shared'
  -> ENOENT: /repo/app/mo/package.json
  ```
- #1677 stopped the Node crawler normalising roots:
  ```
  roots: ['/proj/sub/']             -> 'sub//a.js'
  roots: ['/proj/other/../shared']  -> blockList for '/shared/dist' ignored
  ```

Changelog: Internal

Test plan:
- New unit tests for each, failing without this change.
- Real Watchman, watch folder linked from `node_modules`: 3/3 files on a warm start (`main`: 1/3).
- `hierarchicalLookup` fuzz, 50k lookups in random symlinked trees: every difference from before #1946 matches a real-path model.
@robhogan
robhogan marked this pull request as ready for review October 23, 2026 20:09
@robhogan robhogan mentioned this pull request Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant