diff --git a/packager/src/ModuleGraph/node-haste/node-haste.js b/packager/src/ModuleGraph/node-haste/node-haste.js index c3a136727..966e248d2 100644 --- a/packager/src/ModuleGraph/node-haste/node-haste.js +++ b/packager/src/ModuleGraph/node-haste/node-haste.js @@ -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; }, }; diff --git a/packager/src/node-haste/DependencyGraph/ResolutionRequest.js b/packager/src/node-haste/DependencyGraph/ResolutionRequest.js index eca28e640..a937ed74c 100644 --- a/packager/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packager/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -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 = {| +matchFiles: MatchFilesByDirAndPattern, +moduleCache: ModuleishCache, +moduleMap: ModuleMap, - +platform: string, + +platform: ?string, +platforms: Set, +preferNativePlatform: boolean, |}; @@ -99,7 +99,7 @@ class ResolutionRequest { _matchFiles: MatchFilesByDirAndPattern; _moduleCache: ModuleishCache; _moduleMap: ModuleMap; - _platform: string; + _platform: ?string; _platforms: Set; _preferNativePlatform: boolean; static emptyModule: string; diff --git a/packager/src/node-haste/index.js b/packager/src/node-haste/index.js index 4f6311141..ad4a843ba 100644 --- a/packager/src/node-haste/index.js +++ b/packager/src/node-haste/index.js @@ -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)) { diff --git a/packager/src/node-haste/lib/getAssetDataFromName.js b/packager/src/node-haste/lib/getAssetDataFromName.js index 86be496c9..e41279188 100644 --- a/packager/src/node-haste/lib/getAssetDataFromName.js +++ b/packager/src/node-haste/lib/getAssetDataFromName.js @@ -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): {| + 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), }; } diff --git a/packager/src/node-haste/lib/getPlatformExtension.js b/packager/src/node-haste/lib/getPlatformExtension.js index 6f5058333..bc3bf7f81 100644 --- a/packager/src/node-haste/lib/getPlatformExtension.js +++ b/packager/src/node-haste/lib/getPlatformExtension.js @@ -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 = SUPPORTED_PLATFORM_EXTS, +): ?string { const last = file.lastIndexOf('.'); const secondToLast = file.lastIndexOf('.', last - 1); if (secondToLast === -1) {