From 6d7ba472eec2d7bed92be3aef379fd66c2c72bb9 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Fri, 8 Dec 2017 04:39:48 -0800 Subject: [PATCH] Consolidate AssetData flow types Reviewed By: jeanlauliac Differential Revision: D6497429 fbshipit-source-id: cd9abe2d8c5b2b7eb48d8a0335ea5bfa8ac13269 --- packages/metro/src/Assets/index.js | 43 +++++++++++++++-------------- packages/metro/src/Bundler/index.js | 15 ---------- packages/metro/src/Bundler/util.js | 7 ++--- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/packages/metro/src/Assets/index.js b/packages/metro/src/Assets/index.js index a92f9b8b..7a537adc 100644 --- a/packages/metro/src/Assets/index.js +++ b/packages/metro/src/Assets/index.js @@ -26,29 +26,30 @@ const stat = denodeify(fs.stat); const readDir = denodeify(fs.readdir); const readFile = denodeify(fs.readFile); -import type {AssetPath} from '../node-haste/lib/AssetPaths'; - -export type AssetData = {| - __packager_asset: boolean, - fileSystemLocation: string, - httpServerLocation: string, - width: ?number, - height: ?number, - scales: Array, - files: Array, - hash: string, - name: string, - type: string, -|}; - export type AssetInfo = {| - files: Array, - hash: string, - name: string, - scales: Array, - type: string, + +files: Array, + +hash: string, + +name: string, + +scales: Array, + +type: string, |}; +export type AssetDataWithoutFiles = { + +__packager_asset: boolean, + +fileSystemLocation: string, + +hash: string, + +height: ?number, + +httpServerLocation: string, + +name: string, + +scales: Array, + +type: string, + +width: ?number, +}; + +export type AssetData = AssetDataWithoutFiles & { + +files: Array, +}; + const hashFiles = denodeify(function hashFilesCb(files, hash, callback) { if (!files.length) { callback(null); @@ -268,7 +269,7 @@ async function getAssetFiles( assetPath: string, platform: ?string = null, ): Promise> { - const assetData = await getAbsoluteAssetInfo(assetPath, platform); + const assetData = await getAbsoluteAssetRecord(assetPath, platform); return assetData.files; } diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index ef5f6abb..9d88f30a 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -62,21 +62,6 @@ export type GetTransformOptions = ( getDependenciesOf: (string) => Promise>, ) => Promise; -export type AssetDescriptor = { - +__packager_asset: boolean, - +httpServerLocation: string, - +width: ?number, - +height: ?number, - +scales: Array, - +hash: string, - +name: string, - +type: string, -}; - -export type ExtendedAssetDescriptor = AssetDescriptor & { - +fileSystemLocation: string, -}; - export type PostMinifyProcess = ({ code: string, map: ?MappingsMap, diff --git a/packages/metro/src/Bundler/util.js b/packages/metro/src/Bundler/util.js index 8aaacf14..954c8d2a 100644 --- a/packages/metro/src/Bundler/util.js +++ b/packages/metro/src/Bundler/util.js @@ -13,10 +13,9 @@ 'use strict'; const babel = require('babel-core'); -const babelGenerate = require('babel-generator').default; const babylon = require('babylon'); -import type {ExtendedAssetDescriptor} from '.'; +import type {AssetDataWithoutFiles} from '../Assets'; import type {ModuleTransportLike} from '../shared/types.flow'; // Structure of the object: dir.name.scale = asset @@ -42,7 +41,7 @@ const assetPropertyBlacklist = new Set(['files', 'fileSystemLocation', 'path']); function generateAssetCodeFileAst( assetRegistryPath: string, - assetDescriptor: ExtendedAssetDescriptor, + assetDescriptor: AssetDataWithoutFiles, ): Ast { const properDescriptor = filterObject( assetDescriptor, @@ -93,7 +92,7 @@ function generateAssetCodeFileAst( */ function generateRemoteAssetCodeFileAst( assetSourceResolverPath: string, - assetDescriptor: ExtendedAssetDescriptor, + assetDescriptor: AssetDataWithoutFiles, remoteServer: string, remoteFileMap: RemoteFileMap, ): ?Ast {