Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FileStore: lazily create empty cache directories
Summary: Metro's transform cache `FileStore` currently creates its file structure on construction, which typically happens within `metro-config`'s `getDefaultValues`: https://github.com/facebook/metro/blob/46aad4669098c694134bbc4b4f98cb9db9fdd7a2/packages/metro-config/src/defaults/index.js#L156 This means that's there's no way to use Metro's `loadConfig` or `getDefaultConfig` without creating an empty cache directory structure within `os.tmpdir()`, even if you subsequently override `cacheStores: []` and don't want a cache. `getDefaultConfig()` shouldn't be writing to the file system - this is a bug. There's also no good reason for `FileStore` to initialise this structure eagerly, since with a lazy structure: - Cache misses will fail in the same way (faster, if anything). - Cache writes already create directories if they don't exist (as they must, to avoid crashing if the user deletes the cache while Metro is running), and since cache writes are relatively slow (typically following a transform), the extra mkdirp isn't likely to be significant. Here we make directory creation lazy. Changelog: ``` - **[Fix]**: Don't eagerly create empty cache directories during `getDefaultConfig` ``` Reviewed By: vzaidman Differential Revision: D63030122 fbshipit-source-id: fd28f88113d09831affebec0deca4d33de877628
- Loading branch information