You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make ResolutionContext.fileSystemLookup stable and required
Summary:
Promote `ResolutionContext.fileSystemLookup` to stable and (for providers of `ResolutionContext`) make it mandatory.
`fileSystemLookup` has two main advantages over `doesFileExist`:
- It allows nonempty directory existence checks, which is important for resolver performance.
- It exposes `realPath`. Metro has no other API for using the in-memory file system to resolve a path to a real path.
The latter is critical for correct implementation of custom resolvers (non-real paths can mean duplication in the module graph, and broken Fast Refresh, whereas use of `fs` obscures traversed symlinks, which interferes with incremental resolution).
From now on, we will require custom resolvers to return absolute, *real*, paths, and suggest that they use this method to do it.
`ResolutionContext.doesFileExist` is consequently deprecated as redundant and potentially misleading for implementers..
Changelog:
```
- **[Breaking]**: [Custom resolvers](https://metrobundler.dev/docs/configuration#resolverequest) must now return absolute, real paths for any successful resolution.
- **[Feature]**: Expose [`ResolutionContext.fileSystemLookup`](https://metrobundler.dev/docs/resolution#resolution-context) for performing file and directory existence checks and resolving real paths.
```
Reviewed By: huntie
Differential Revision: D62374241
fbshipit-source-id: 7760bd4278736e6db27f994a7598784b6578ab9c
Returns `true` if the file with the given path exists, or `false` otherwise.
174
174
175
-
By default, Metro implements this by consulting an in-memory map of the filesystem that has been prepared in advance. This approach avoids disk I/O during module resolution.
175
+
The default implementation wraps [`fileSystemLookup`](#filesystemlookup-string--exists-true-type-fd-realpath-string--exists-false) - prefer using that directly.
Return information about the given absolute or project-relative path, following symlinks. A file "exists" if and only if it is watched, and a directory must be non-empty. The returned `realPath` is real and absolute.
182
+
183
+
By default, Metro implements this by consulting an in-memory map of the filesystem that has been prepared in advance. This approach avoids disk I/O during module resolution and performs realpath resolution at negligible additional cost.
Returned paths (`filePath` and `filePaths`) must be *absolute* and *real*, such as the `realPath` returned by [`fileSystemLookup`](#filesystemlookup-string--exists-true-type-fd-realpath-string--exists-false).
279
+
270
280
When calling the default resolver with a non-null `resolveRequest` function, it represents a custom resolver and will always be called, fully replacing the default resolution logic.
271
281
272
282
Inside a custom resolver, `resolveRequest` is set to the default resolver function, for easy chaining and customization.
0 commit comments