From 19e37dd51e754820ecb1e671701fc23e30e95cd6 Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:38:05 +0000 Subject: [PATCH] metro-file-map: Use the default health check prefix when given an empty 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 https://github.com/expo/expo/pull/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). --- docs/Configuration.md | 2 +- packages/metro-file-map/src/__tests__/index-test.js | 12 ++++++++++++ packages/metro-file-map/src/index.js | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 86955cf94c..33ea3a9184 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1013,7 +1013,7 @@ Whether to periodically check the [filesystem watcher](./Concepts.md#file-watchi Type: `string` -The name of the temporary file that health checks write into the project. Defaults to `'.metro-health-check'`. +The name of the temporary file that health checks write into the project. Metro ignores files whose names start with this prefix. Defaults to `'.metro-health-check'`, which is also used if this is an empty string. :::note diff --git a/packages/metro-file-map/src/__tests__/index-test.js b/packages/metro-file-map/src/__tests__/index-test.js index 86ef936a27..41c6a18bb5 100644 --- a/packages/metro-file-map/src/__tests__/index-test.js +++ b/packages/metro-file-map/src/__tests__/index-test.js @@ -540,6 +540,18 @@ describe('FileMap', () => { expect([...fileSystem.matchFiles({filter: /Kiwi/})]).toEqual([]); }); + test('an empty health check file prefix does not exclude any files', async () => { + mockFs[p('/project/fruits/Kiwi.js')] = ` + // Kiwi! + `; + const {fileSystem} = await buildNewFileMap({ + healthCheck: {...defaultConfig.healthCheck, filePrefix: ''}, + }); + expect([...fileSystem.matchFiles({filter: /Kiwi/})]).toEqual([ + p('/project/fruits/Kiwi.js'), + ]); + }); + test('ignores vcs directories without ignore pattern', async () => { mockFs[p('/project/fruits/.git/fruit-history.js')] = ` // test diff --git a/packages/metro-file-map/src/index.js b/packages/metro-file-map/src/index.js index e66df92653..e0680ebd99 100644 --- a/packages/metro-file-map/src/index.js +++ b/packages/metro-file-map/src/index.js @@ -752,7 +752,11 @@ export default class FileMap extends EventEmitter { crawl: this.#crawler, enableSymlinks, extensions, - healthCheckFilePrefix: this.#options.healthCheck.filePrefix, + // Files whose names start with this prefix are health check files, which + // are left out of the crawl and the watcher's changes. Every name starts + // with an empty prefix, so the default is used instead. + healthCheckFilePrefix: + this.#options.healthCheck.filePrefix || '.metro-health-check', // TODO: Refactor out the two different ignore strategies here. ignoreForCrawl: filePath => { const ignoreMatched = ignorePattern.test(filePath);