mirror of https://github.com/status-im/metro.git
packager: never allow platform-specific asset resolution
Summary: I stumbled on this while refactoring that function, and i realised that, I believe it doesn't make sense to take into account the platform extension of the "potiential" file path. The reason is, if you try to require "foo.ios.png", the returned asset name would be "foo", and thus we'd try to find "foo.${ext}.png" where `ext` could actually be `android` or anything else! So it's confusing. There's no reason we should allow callsites to specify platform anyway I think. With this changeset we're not losing any functionality, but it might require people to fix some incorrect callsites. Reviewed By: cpojer Differential Revision: D5051791 fbshipit-source-id: 2a1ec7a8bfa6791b6016213305a72bc0b81f23b9
This commit is contained in:
parent
aadd914f0d
commit
633432ceca
|
@ -119,7 +119,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||||
moduleCache,
|
moduleCache,
|
||||||
moduleMap: getFakeModuleMap(hasteMap),
|
moduleMap: getFakeModuleMap(hasteMap),
|
||||||
platform,
|
platform,
|
||||||
platforms,
|
|
||||||
preferNativePlatform: true,
|
preferNativePlatform: true,
|
||||||
sourceExts,
|
sourceExts,
|
||||||
});
|
});
|
||||||
|
|
|
@ -233,7 +233,6 @@ class DependencyGraph extends EventEmitter {
|
||||||
moduleCache: this._moduleCache,
|
moduleCache: this._moduleCache,
|
||||||
moduleMap: this._moduleMap,
|
moduleMap: this._moduleMap,
|
||||||
platform,
|
platform,
|
||||||
platforms: this._opts.platforms,
|
|
||||||
preferNativePlatform: this._opts.preferNativePlatform,
|
preferNativePlatform: this._opts.preferNativePlatform,
|
||||||
sourceExts: this._opts.sourceExts,
|
sourceExts: this._opts.sourceExts,
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,7 +88,6 @@ type Options<TModule, TPackage> = {|
|
||||||
+moduleCache: ModuleishCache<TModule, TPackage>,
|
+moduleCache: ModuleishCache<TModule, TPackage>,
|
||||||
+moduleMap: ModuleMap,
|
+moduleMap: ModuleMap,
|
||||||
+platform: ?string,
|
+platform: ?string,
|
||||||
+platforms: Set<string>,
|
|
||||||
+preferNativePlatform: boolean,
|
+preferNativePlatform: boolean,
|
||||||
+sourceExts: Array<string>,
|
+sourceExts: Array<string>,
|
||||||
|};
|
|};
|
||||||
|
@ -109,6 +108,8 @@ function tryResolveSync<T>(action: () => T, secondaryAction: () => T): T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EMPTY_SET = new Set();
|
||||||
|
|
||||||
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
||||||
_doesFileExist = filePath => this._options.hasteFS.exists(filePath);
|
_doesFileExist = filePath => this._options.hasteFS.exists(filePath);
|
||||||
_immediateResolutionCache: {[key: string]: TModule};
|
_immediateResolutionCache: {[key: string]: TModule};
|
||||||
|
@ -613,10 +614,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
||||||
fromModule: TModule,
|
fromModule: TModule,
|
||||||
toModule: string,
|
toModule: string,
|
||||||
): TModule {
|
): TModule {
|
||||||
const {name, type} = getAssetDataFromName(
|
const {name, type} = getAssetDataFromName(potentialModulePath, EMPTY_SET);
|
||||||
potentialModulePath,
|
|
||||||
this._options.platforms,
|
|
||||||
);
|
|
||||||
|
|
||||||
let pattern = '^' + name + '(@[\\d\\.]+x)?';
|
let pattern = '^' + name + '(@[\\d\\.]+x)?';
|
||||||
if (this._options.platform != null) {
|
if (this._options.platform != null) {
|
||||||
|
|
Loading…
Reference in New Issue