Repository navigation
Conversation
…ty one `FileMap` treats every file whose name starts with `watcher.healthCheck.filePrefix` as a health check file. It's left out of the crawl, and a watcher event for one is taken as a health check rather than a change: https://github.com/react/metro/blob/e4b598a0103cb8a9600d7a0008db451d4b673338/packages/metro-file-map/src/Watcher.js#L217-L219 Every name starts with `''`, so `filePrefix: ''` drops every file from the crawl and every change in watch mode, and Metro can't resolve anything. That's been the case since at least 0.80, whether or not health checks are enabled. An empty prefix can't work as a prefix, and `FileMap` needs one anyway, because it writes health check files at startup to confirm that a watcher backend such as `NativeWatcher` is live, even with health checks disabled. This uses the default, `.metro-health-check`, in its place. Rejecting `''` would also be safe, since no working config can use it, but I think a config that sets it to "turn off" health checks should just work. Expo's fork of `metro-file-map` takes the same fix in expo/expo#54143. Changelog: ``` - **[Fix]**: Treat an empty `watcher.healthCheck.filePrefix` as the default, instead of ignoring every file ``` Test plan: New unit test, failing without this change (the crawl finds no files).
…atch before crawl) (#54143) # Why Currently, a file change made while the project is being crawled may be missed permanently, because watching only starts after crawling has finished and cache has been written. On macOS there's a second, smaller window: `fs.watch` returns before its FSEvents stream is live, so a change made just after startup can be missed too. This new structure also the base for porting `addRoot` cleanly, which Metro 0.88 needs. | Upstream | What | Expo | |---|---|---| | react/metro#2054 | Do not miss files changed while the file map builds | - | | react/metro#2003 | Fix `NativeWatcher` missing changes made straight after startup | - | | react/metro#2294 (open) | Use the default health check prefix in place of an empty one | - | # How This ports both. With the node crawler, which is Expo's default, the watcher backends (`NativeWatcher` on macOS, `FallbackWatcher` elsewhere) now start before the crawl, and their events are buffered and replayed once the file map starts watching. With Watchman, the subscription is made `since` the crawl's clock, which covers the same window, and a failed Watchman crawl starts the node backends before falling back. A backend that isn't live on start (`isLiveOnStart()`, false only for `NativeWatcher`) has **each root's watch confirmed with a health check file before it's relied on**, warning if it can't be. This uses the configured health check prefix even when periodic health checks are off, which they are by default, so the crawl now always ignores files with that prefix, as upstream does. # Test Plan - Unit tests (791 passed, 1 skipped). - Upstream's `Watcher` tests are ported, and its `WatchmanWatcher` tests for subscribing `since` a crawl clock. Upstream's `index-test` cases aren't, as the fork has no `FileMap` unit test, so passing the crawl's clocks from `FileMap` to the watcher is covered only by reading. - Upstream's `watch-integration-test.js` (from react/metro#2107) is ported as the fork's first end-to-end watch test. It drives `FileMap` in watch mode over a real directory, with a new case that adds a file while the cache is written. That case fails without this change on macOS and passes with it. - On macOS, `FileMap` over real directories: changes made while the cache is written (a file deleted, modified, created, created and deleted, and a directory renamed) all converge, with the node crawler and with Watchman, including two roots under one Watchman watch root and a failed Watchman crawl falling back. `end()` at any point during startup leaves no watch handles or health check files behind. Benchmark (AI-driven), against #54047, with the same app, harness and machines as #54047's: Metro's `DependencyGraph` with `@expo/metro-file-map` swapped in as Expo CLI does (on-demand filesystem off, no Watchman), 34,488 files, interleaved rounds, Node 24.21.0. 8 rounds on Linux and Windows. The macOS figures are 15 rounds with upstream's `path.basename` check, as a rerun with this one was too noisy to use. | Platform | Metric | #54047 | This PR [95% CI] | |---|---|---|---| | macOS | Cold start | 83ms | -4.5% [-8.4, -1.0] | | macOS | Warm start | 97ms | -7.3% [-9.0, -5.8] | | macOS | Watch-mode start, warm cache | 98ms | +6.4% [+3.8, +8.8] | | macOS | Watch-mode start, cold cache | 83ms | +12.5% [+6.7, +17.3] | | Linux | Cold start | 301ms | +3.1% [+0.5, +5.0] | | Linux | Warm start | 343ms | +2.7% [+2.2, +3.7] | | Linux | Watch-mode start, warm cache | 678ms | +1.6% [-1.0, +1.7] | | Linux | Watch-mode start, cold cache | 636ms | -1.3% [-3.0, +0.4] | | Windows | Cold start | 169ms | +2.7% [+1.5, +3.8] | | Windows | Warm start | 198ms | +2.9% [+1.5, +4.4] | | Windows | Watch-mode start, warm cache | 731ms | -0.2% [-2.1, +0.4] | | Windows | Watch-mode start, cold cache | 694ms | +0.1% [-1.8, +0.8] | On macOS, watch-mode starts pay for confirming the `NativeWatcher` watch (6-10ms, in line with upstream's measurement) - note that's a flat cost, not a function of project size. On Linux and Windows, starts without watching pay for the health check ignore in the crawl (5-9ms).
Metro review: Looks goodRisk: low · Commit: When No findings. Verified
Not run: No benchmark: the change is one Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
…atch before crawl) (#54143) # Why Currently, a file change made while the project is being crawled may be missed permanently, because watching only starts after crawling has finished and cache has been written. On macOS there's a second, smaller window: `fs.watch` returns before its FSEvents stream is live, so a change made just after startup can be missed too. This new structure also the base for porting `addRoot` cleanly, which Metro 0.88 needs. | Upstream | What | Expo | |---|---|---| | react/metro#2054 | Do not miss files changed while the file map builds | - | | react/metro#2003 | Fix `NativeWatcher` missing changes made straight after startup | - | | react/metro#2294 (open) | Use the default health check prefix in place of an empty one | - | # How This ports both. With the node crawler, which is Expo's default, the watcher backends (`NativeWatcher` on macOS, `FallbackWatcher` elsewhere) now start before the crawl, and their events are buffered and replayed once the file map starts watching. With Watchman, the subscription is made `since` the crawl's clock, which covers the same window, and a failed Watchman crawl starts the node backends before falling back. A backend that isn't live on start (`isLiveOnStart()`, false only for `NativeWatcher`) has **each root's watch confirmed with a health check file before it's relied on**, warning if it can't be. This uses the configured health check prefix even when periodic health checks are off, which they are by default, so the crawl now always ignores files with that prefix, as upstream does. # Test Plan - Unit tests (791 passed, 1 skipped). - Upstream's `Watcher` tests are ported, and its `WatchmanWatcher` tests for subscribing `since` a crawl clock. Upstream's `index-test` cases aren't, as the fork has no `FileMap` unit test, so passing the crawl's clocks from `FileMap` to the watcher is covered only by reading. - Upstream's `watch-integration-test.js` (from react/metro#2107) is ported as the fork's first end-to-end watch test. It drives `FileMap` in watch mode over a real directory, with a new case that adds a file while the cache is written. That case fails without this change on macOS and passes with it. - On macOS, `FileMap` over real directories: changes made while the cache is written (a file deleted, modified, created, created and deleted, and a directory renamed) all converge, with the node crawler and with Watchman, including two roots under one Watchman watch root and a failed Watchman crawl falling back. `end()` at any point during startup leaves no watch handles or health check files behind. Benchmark (AI-driven), against #54047, with the same app, harness and machines as #54047's: Metro's `DependencyGraph` with `@expo/metro-file-map` swapped in as Expo CLI does (on-demand filesystem off, no Watchman), 34,488 files, interleaved rounds, Node 24.21.0. 8 rounds on Linux and Windows. The macOS figures are 15 rounds with upstream's `path.basename` check, as a rerun with this one was too noisy to use. | Platform | Metric | #54047 | This PR [95% CI] | |---|---|---|---| | macOS | Cold start | 83ms | -4.5% [-8.4, -1.0] | | macOS | Warm start | 97ms | -7.3% [-9.0, -5.8] | | macOS | Watch-mode start, warm cache | 98ms | +6.4% [+3.8, +8.8] | | macOS | Watch-mode start, cold cache | 83ms | +12.5% [+6.7, +17.3] | | Linux | Cold start | 301ms | +3.1% [+0.5, +5.0] | | Linux | Warm start | 343ms | +2.7% [+2.2, +3.7] | | Linux | Watch-mode start, warm cache | 678ms | +1.6% [-1.0, +1.7] | | Linux | Watch-mode start, cold cache | 636ms | -1.3% [-3.0, +0.4] | | Windows | Cold start | 169ms | +2.7% [+1.5, +3.8] | | Windows | Warm start | 198ms | +2.9% [+1.5, +4.4] | | Windows | Watch-mode start, warm cache | 731ms | -0.2% [-2.1, +0.4] | | Windows | Watch-mode start, cold cache | 694ms | +0.1% [-1.8, +0.8] | On macOS, watch-mode starts pay for confirming the `NativeWatcher` watch (6-10ms, in line with upstream's measurement) - note that's a flat cost, not a function of project size. On Linux and Windows, starts without watching pay for the health check ignore in the crawl (5-9ms). (cherry picked from commit 5054f20)
FileMaptreats every file whose name starts withwatcher.healthCheck.filePrefixas a health check file. It's left out of the crawl, and a watcher event for one is taken as a health check rather than a change:metro/packages/metro-file-map/src/Watcher.js
Lines 217 to 219 in e4b598a
Every name starts with
'', sofilePrefix: ''drops every file from the crawl and every change in watch mode, and Metro can't resolve anything. That's been the case since at least 0.80, whether or not health checks are enabled.An empty prefix can't work as a prefix, and
FileMapneeds one anyway, because it writes health check files at startup to confirm that a watcher backend such asNativeWatcheris live, even with health checks disabled. This uses the default,.metro-health-check, in its place. Rejecting''would also be safe, since no working config can use it, but I think a config that sets it to "turn off" health checks should just work.Expo's fork of
metro-file-maptakes the same fix in expo/expo#54143.Changelog:
Test plan:
New unit test, failing without this change (the crawl finds no files).