-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
6442685
commit c6548f7
Showing
11 changed files
with
44 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -771,7 +771,6 @@ describe('with package exports resolution enabled', () => { | |
|
||
describe('asset resolutions', () => { | ||
const assetResolutions = ['1', '1.5', '2', '3', '4']; | ||
const isAssetFile = (filePath: string) => filePath.endsWith('.png'); | ||
|
||
const baseContext = { | ||
...createResolutionContext({ | ||
|
@@ -786,7 +785,7 @@ describe('with package exports resolution enabled', () => { | |
'/root/node_modules/test-pkg/assets/icons/[email protected]': '', | ||
'/root/node_modules/test-pkg/assets/icons/[email protected]': '', | ||
}), | ||
isAssetFile, | ||
assetExts: new Set(['png']), | ||
originModulePath: '/root/src/main.js', | ||
unstable_enablePackageExports: true, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import path from 'path'; | ||
|
||
/** | ||
* Determine if a file path should be considered an asset file based on the | ||
* given `assetExts`. | ||
*/ | ||
export default function isAssetFile( | ||
filePath: string, | ||
assetExts: $ReadOnlySet<string>, | ||
): boolean { | ||
return assetExts.has(path.extname(filePath).slice(1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters