mirror of https://github.com/status-im/metro.git
packager: getAssetDataFromName: @flow
Reviewed By: davidaurelio Differential Revision: D4921247 fbshipit-source-id: 47c516257cde5de6b69604d714e45310d00afe19
This commit is contained in:
parent
b8e9ed1559
commit
30b1e17ba5
|
@ -46,12 +46,12 @@ const platforms = new Set(defaults.platforms);
|
|||
*/
|
||||
function getFakeModuleMap(hasteMap: HasteMap) {
|
||||
return {
|
||||
getModule(name: string, platform_: string): ?string {
|
||||
const module = hasteMap.getModule(name, platform_);
|
||||
getModule(name: string, platform: ?string): ?string {
|
||||
const module = hasteMap.getModule(name, platform);
|
||||
return module && module.type === 'Module' ? module.path : null;
|
||||
},
|
||||
getPackage(name: string, platform_: string): ?string {
|
||||
const module = hasteMap.getModule(name, platform_);
|
||||
getPackage(name: string, platform: ?string): ?string {
|
||||
const module = hasteMap.getModule(name, platform);
|
||||
return module && module.type === 'Package' ? module.path : null;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -33,8 +33,8 @@ type DirExistsFn = (filePath: string) => boolean;
|
|||
* `jest-haste-map`'s interface for ModuleMap.
|
||||
*/
|
||||
export type ModuleMap = {
|
||||
getModule(name: string, platform: string, supportsNativePlatform: boolean): ?string,
|
||||
getPackage(name: string, platform: string, supportsNativePlatform: boolean): ?string,
|
||||
getModule(name: string, platform: ?string, supportsNativePlatform: boolean): ?string,
|
||||
getPackage(name: string, platform: ?string, supportsNativePlatform: boolean): ?string,
|
||||
};
|
||||
|
||||
type Packageish = {
|
||||
|
@ -68,7 +68,7 @@ type Options<TModule, TPackage> = {|
|
|||
+matchFiles: MatchFilesByDirAndPattern,
|
||||
+moduleCache: ModuleishCache<TModule, TPackage>,
|
||||
+moduleMap: ModuleMap,
|
||||
+platform: string,
|
||||
+platform: ?string,
|
||||
+platforms: Set<string>,
|
||||
+preferNativePlatform: boolean,
|
||||
|};
|
||||
|
@ -99,7 +99,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
|||
_matchFiles: MatchFilesByDirAndPattern;
|
||||
_moduleCache: ModuleishCache<TModule, TPackage>;
|
||||
_moduleMap: ModuleMap;
|
||||
_platform: string;
|
||||
_platform: ?string;
|
||||
_platforms: Set<string>;
|
||||
_preferNativePlatform: boolean;
|
||||
static emptyModule: string;
|
||||
|
|
|
@ -209,7 +209,7 @@ class DependencyGraph extends EventEmitter {
|
|||
recursive = true,
|
||||
}: {
|
||||
entryPath: string,
|
||||
platform: string,
|
||||
platform: ?string,
|
||||
transformOptions: TransformOptions,
|
||||
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
|
||||
recursive: boolean,
|
||||
|
@ -254,7 +254,7 @@ class DependencyGraph extends EventEmitter {
|
|||
return Promise.resolve(this._hasteFS.matchFiles(pattern));
|
||||
}
|
||||
|
||||
_getRequestPlatform(entryPath: string, platform: string) {
|
||||
_getRequestPlatform(entryPath: string, platform: ?string): ?string {
|
||||
if (platform == null) {
|
||||
platform = getPlatformExtension(entryPath, this._opts.platforms);
|
||||
} else if (!this._opts.platforms.has(platform)) {
|
||||
|
|
|
@ -5,13 +5,22 @@
|
|||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const getPlatformExtension = require('./getPlatformExtension');
|
||||
const path = require('path');
|
||||
|
||||
function getAssetDataFromName(filename, platforms) {
|
||||
function getAssetDataFromName(filename: string, platforms: Set<string>): {|
|
||||
assetName: string,
|
||||
name: string,
|
||||
platform: ?string,
|
||||
resolution: number,
|
||||
type: string,
|
||||
|} {
|
||||
const ext = path.extname(filename);
|
||||
const platformExt = getPlatformExtension(filename, platforms);
|
||||
|
||||
|
@ -45,11 +54,11 @@ function getAssetDataFromName(filename, platforms) {
|
|||
assetName = decodeURIComponent(assetName);
|
||||
|
||||
return {
|
||||
resolution,
|
||||
assetName,
|
||||
type: ext.slice(1),
|
||||
name: path.basename(assetName, ext),
|
||||
platform: platformExt,
|
||||
resolution,
|
||||
type: ext.slice(1),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const SUPPORTED_PLATFORM_EXTS = new Set([
|
||||
|
@ -15,7 +18,10 @@ const SUPPORTED_PLATFORM_EXTS = new Set([
|
|||
]);
|
||||
|
||||
// Extract platform extension: index.ios.js -> ios
|
||||
function getPlatformExtension(file, platforms = SUPPORTED_PLATFORM_EXTS) {
|
||||
function getPlatformExtension(
|
||||
file: string,
|
||||
platforms: Set<string> = SUPPORTED_PLATFORM_EXTS,
|
||||
): ?string {
|
||||
const last = file.lastIndexOf('.');
|
||||
const secondToLast = file.lastIndexOf('.', last - 1);
|
||||
if (secondToLast === -1) {
|
||||
|
|
Loading…
Reference in New Issue