mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
packager: ResolutionRequest: unify asset resolution
Summary: The existing resolution logic of assets: * goes over all the files of the asset's directory for every resolution request; * duplicates the parsing logic of `AssetPaths` by building up a custom regex for each resolution request. This changeset proposes to tweak this by building an index for each particular directory in which we're looking for assets, so that we don't have to crawl a single directory twice, and so that it reuses the logic of `AssetPaths.tryParse()` for determining variants. Reviewed By: davidaurelio Differential Revision: D5062435 fbshipit-source-id: 708fc5612f57b14565499fad741701269438c806
This commit is contained in:
committed by
Facebook Github Bot
parent
280ec6e1eb
commit
98fc4373fc
@@ -21,6 +21,7 @@ import type {
|
||||
TransformedCodeFile,
|
||||
} from '../types.flow';
|
||||
|
||||
const AssetResolutionCache = require('../../node-haste/AssetResolutionCache');
|
||||
const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
|
||||
const FilesByDirNameIndex = require('../../node-haste/FilesByDirNameIndex');
|
||||
const HasteFS = require('./HasteFS');
|
||||
@@ -110,6 +111,11 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||
const hasteMapBuilt = hasteMap.build();
|
||||
const resolutionRequests = {};
|
||||
const filesByDirNameIndex = new FilesByDirNameIndex(hasteMap.getAllFiles());
|
||||
const assetResolutionCache = new AssetResolutionCache({
|
||||
assetExtensions: new Set(assetExts),
|
||||
getDirFiles: dirPath => filesByDirNameIndex.getAllFiles(dirPath),
|
||||
platforms,
|
||||
});
|
||||
return (id, source, platform, _, callback) => {
|
||||
let resolutionRequest = resolutionRequests[platform];
|
||||
if (!resolutionRequest) {
|
||||
@@ -119,11 +125,12 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||
extraNodeModules,
|
||||
hasteFS,
|
||||
helpers,
|
||||
matchFiles: filesByDirNameIndex.match.bind(filesByDirNameIndex),
|
||||
moduleCache,
|
||||
moduleMap: getFakeModuleMap(hasteMap),
|
||||
platform,
|
||||
preferNativePlatform: true,
|
||||
resolveAsset: (dirPath, assetName) =>
|
||||
assetResolutionCache.resolve(dirPath, assetName, platform),
|
||||
sourceExts,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user