Repository navigation
Commit 8e5c936
metro-file-map: Create
If `fileMapCacheDirectory` points at a directory that doesn't exist yet, the file map cache is never written, so every restart crawls the project from scratch. The only sign is a warning at startup:
```
[metro-file-map] Cache write error
: Error: ENOENT: no such file or directory, open '/path/to/project/node_modules/.cache/metro-file-map/metro-file-map-<hash>-<hash>'
```
The default, `os.tmpdir()`, always exists, so this only affects a custom directory - but a project-local one like `node_modules/.cache/metro-file-map` won't exist after any fresh install. The transform cache doesn't have this problem, because `FileStore` creates its directory when a write fails with `ENOENT`.
This change does the same in `DiskCacheManager`: on `ENOENT`, create the directory (recursively) and retry the write once. Writes into an existing directory are unchanged.
Changelog:
```
- **[Fix]**: Create `fileMapCacheDirectory` if it doesn't exist, rather than failing to persist the file map cache
```
Test plan:
New test in `DiskCacheManager-test.js` where the first write fails with `ENOENT`, asserting that the directory is created and the snapshot written without an error. It fails before this change and passes after.
Also checked end-to-end with `createFileMap` and `fileMapCacheDirectory` set to a missing `<project>/node_modules/.cache/metro-file-map`: before, the warning above and no directory; after, no warning and the cache file is written.
```
yarn jest packages/metro-file-map packages/metro/src/node-haste packages/metro/src/DeltaBundler
yarn flow check
yarn eslint packages/metro-file-map
yarn verify-api-snapshots
```
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>fileMapCacheDirectory if it doesn't exist1 parent 17fa699 commit 8e5c936
2 files changed
Lines changed: 44 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
119 | 131 | | |
120 | 132 | | |
121 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
192 | 223 | | |
193 | 224 | | |
194 | 225 | | |
| |||
0 commit comments