metro-buck: getLibrary: precompute asset hashes

Reviewed By: davidaurelio

Differential Revision: D6937279

fbshipit-source-id: 328f06b2b66eeed6fd2f767dab1a03854c4dd28c
This commit is contained in:
Jean Lauliac 2018-02-08 09:58:15 -08:00 committed by Facebook Github Bot
parent 01a92f3c2f
commit 1498c4ba6b
3 changed files with 11 additions and 0 deletions

View File

@ -196,6 +196,10 @@ export type AssetFile = {|
* Guessed from the file extension, for example `png` or `html`.
*/
+contentType: string,
/**
* Hash of the asset file content.
*/
+hash: string,
/**
* The path of the original file for this asset. For example
* `foo/bar@3x.ios.png`. This is most useful for reporting purposes, such as

View File

@ -7,6 +7,7 @@ Object {
"contentBase64": "eyJfX3NpemUiOnsid2lkdGgiOjMwLCJoZWlnaHQiOjIwfX0=",
"contentType": "png",
"filePath": "foo.png",
"hash": "AGicIEH/IsIy5t7si/9ocI6Ur8s=",
"physicalSize": Object {
"height": 20,
"width": 30,
@ -25,6 +26,7 @@ Object {
"contentBase64": "eyJfX3NpemUiOnsid2lkdGgiOjMwLCJoZWlnaHQiOjIwfX0=",
"contentType": "png",
"filePath": "foo@2x.ios.png",
"hash": "AGicIEH/IsIy5t7si/9ocI6Ur8s=",
"physicalSize": Object {
"height": 20,
"width": 30,

View File

@ -17,6 +17,7 @@ const JsFileWrapping = require('./JsFileWrapping');
const Platforms = require('./Platforms');
const collectDependencies = require('./collectDependencies');
const crypto = require('crypto');
const defaults = require('../../defaults');
const docblock = require('jest-docblock');
const generate = require('./generate');
@ -173,6 +174,10 @@ function transformAsset(
assetPath: assetData.assetName,
contentBase64: content.toString('base64'),
contentType,
hash: crypto
.createHash('sha1')
.update(content)
.digest('base64'),
filePath,
physicalSize: getAssetSize(contentType, content, filePath),
platform: assetData.platform,