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
Add assetExts to ResolutionContext, remove isAssetFile
Summary:
This commit removes the `isAssetFile` API used both for the module resolver and by `transformHelpers` — both based on `resolver.assetExts`, but the former being user-overridable in the resolver via `ResolutionContext.isAssetFile`.
Motivation:
- Correctness: While `ResolutionContext.isAssetFile` is respected by the resolver, the current `node-haste` implementation in Metro discards this selection, coercing the resolution to a `sourceFile`. With this change, a common `isAssetFile` implementation is now shared by both layers, leading to consistent behaviour when customised.
- Simplicity: `assetExts` is sufficiently expressive for most use cases — and can be bailed out from using `ResolutionContext.resolveRequest`.
Changelog: **[Breaking]** Remove `isAssetFile` from custom resolver context, add `assetExts`
Reviewed By: motiz88
Differential Revision: D43735610
fbshipit-source-id: 77d4aa7e17b27b24d1fae87a162753beb1501d92
Copy file name to clipboardExpand all lines: docs/Resolution.md
+5-7
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ These are the rules that Metro's default resolver follows. Refer to [`metro-reso
62
62
63
63
2. Otherwise, try to resolve _moduleName_ as a relative or absolute path:
64
64
1. If the path is relative, convert it to an absolute path by prepending the current directory (i.e. parent of [`context.originModulePath`](#originmodulepath-string)).
65
-
2. If the path refers to an [asset](#isassetfile-string--boolean):
65
+
2. If the path refers to an [asset](#assetexts-readonlysetstring):
66
66
67
67
1. Use [`context.resolveAsset`](#resolveasset-dirpath-string-assetname-string-extension-string--readonlyarraystring) to collect all asset variants.
68
68
2. Return an [asset resolution](#asset-files) containing the collected asset paths.
@@ -120,18 +120,16 @@ These are the rules that Metro's default resolver follows. Refer to [`metro-reso
120
120
121
121
### Resolution context
122
122
123
+
#### `assetExts: $ReadOnlySet<string>`
124
+
125
+
The set of file extensions used to identify asset files. Defaults to [`resolver.assetExts`](./Configuration.md#assetexts).
126
+
123
127
#### `doesFileExist: string => boolean`
124
128
125
129
Returns `true` if the file with the given path exists, or `false` otherwise.
126
130
127
131
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.
128
132
129
-
#### `isAssetFile: string => boolean`
130
-
131
-
Returns `true` if the given path represents an asset file, or `false` otherwise.
132
-
133
-
By default, Metro implements this by checking the file's extension against [`resolver.assetExts`](./Configuration.md#assetexts).
134
-
135
133
#### `nodeModulesPaths: $ReadOnlyArray<string>`
136
134
137
135
A list of paths to check for modules after looking through all `node_modules` directories.
0 commit comments