From 1f8d1002ef991b66f4cac8d8b8689f27a244ac4d Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 25 Apr 2017 11:49:41 -0700 Subject: [PATCH] packager: buck library: expose asset content Reviewed By: davidaurelio Differential Revision: D4945778 fbshipit-source-id: ea132a3d284ed09c59c69afbdd7b707af9e521b9 --- Libraries/Image/AssetRegistry.js | 18 +++++++++--------- Libraries/Image/AssetSourceResolver.js | 4 ++-- local-cli/bundle/getAssetDestPathAndroid.js | 7 ++++++- local-cli/bundle/getAssetDestPathIOS.js | 7 ++++++- packager/src/Bundler/index.js | 4 ++-- packager/src/ModuleGraph/types.flow.js | 8 ++++++++ 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Libraries/Image/AssetRegistry.js b/Libraries/Image/AssetRegistry.js index fd03c69b5..116500eda 100644 --- a/Libraries/Image/AssetRegistry.js +++ b/Libraries/Image/AssetRegistry.js @@ -13,15 +13,15 @@ export type PackagerAsset = { - __packager_asset: boolean, - fileSystemLocation: string, - httpServerLocation: string, - width: number, - height: number, - scales: Array, - hash: string, - name: string, - type: string, + +__packager_asset: boolean, + +fileSystemLocation: string, + +httpServerLocation: string, + +width: ?number, + +height: ?number, + +scales: Array, + +hash: string, + +name: string, + +type: string, }; diff --git a/Libraries/Image/AssetSourceResolver.js b/Libraries/Image/AssetSourceResolver.js index 96ccfe90f..e8a747148 100644 --- a/Libraries/Image/AssetSourceResolver.js +++ b/Libraries/Image/AssetSourceResolver.js @@ -13,8 +13,8 @@ export type ResolvedAssetSource = { __packager_asset: boolean, - width: number, - height: number, + width: ?number, + height: ?number, uri: string, scale: number, }; diff --git a/local-cli/bundle/getAssetDestPathAndroid.js b/local-cli/bundle/getAssetDestPathAndroid.js index b4e49f8b5..c9f7e0192 100644 --- a/local-cli/bundle/getAssetDestPathAndroid.js +++ b/local-cli/bundle/getAssetDestPathAndroid.js @@ -5,13 +5,18 @@ * 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 assetPathUtils = require('./assetPathUtils'); const path = require('path'); -function getAssetDestPathAndroid(asset, scale) { +import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry'; + +function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string { const androidFolder = assetPathUtils.getAndroidDrawableFolderName(asset, scale); const fileName = assetPathUtils.getAndroidResourceIdentifier(asset); return path.join(androidFolder, fileName + '.' + asset.type); diff --git a/local-cli/bundle/getAssetDestPathIOS.js b/local-cli/bundle/getAssetDestPathIOS.js index d7db51858..4e6290748 100644 --- a/local-cli/bundle/getAssetDestPathIOS.js +++ b/local-cli/bundle/getAssetDestPathIOS.js @@ -5,12 +5,17 @@ * 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 path = require('path'); -function getAssetDestPathIOS(asset, scale) { +import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry'; + +function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string { const suffix = scale === 1 ? '' : '@' + scale + 'x'; const fileName = asset.name + suffix + '.' + asset.type; return path.join(asset.httpServerLocation.substr(1), fileName); diff --git a/packager/src/Bundler/index.js b/packager/src/Bundler/index.js index e38e70cdd..873bf0834 100644 --- a/packager/src/Bundler/index.js +++ b/packager/src/Bundler/index.js @@ -68,7 +68,7 @@ export type GetTransformOptions = ( getDependenciesOf: string => Promise>, ) => Promise; -type AssetDescriptor = { +export type AssetDescriptor = { +__packager_asset: boolean, +httpServerLocation: string, +width: ?number, @@ -79,7 +79,7 @@ type AssetDescriptor = { +type: string, }; -type ExtendedAssetDescriptor = AssetDescriptor & { +export type ExtendedAssetDescriptor = AssetDescriptor & { +fileSystemLocation: string, +files: Array, }; diff --git a/packager/src/ModuleGraph/types.flow.js b/packager/src/ModuleGraph/types.flow.js index de86d6784..fd27309e3 100644 --- a/packager/src/ModuleGraph/types.flow.js +++ b/packager/src/ModuleGraph/types.flow.js @@ -140,3 +140,11 @@ export type LibraryOptions = {| platform?: string, root: string, |}; + +export type Base64Content = string; + +export type Library = {| + files: Array, + /* cannot be a Map because it's JSONified later on */ + assets: {[destFilePath: string]: Base64Content}, +|};