make the RN packager output more deterministic

Reviewed By: davidaurelio

Differential Revision: D4357109

fbshipit-source-id: bc9ef04d81223299fe7708aeb0fe654647330ab7
This commit is contained in:
Chris Hopman 2016-12-22 15:57:53 -08:00 committed by Facebook Github Bot
parent b5dae70e61
commit 8e9549fb2b
2 changed files with 18 additions and 20 deletions

View File

@ -134,7 +134,7 @@ describe('Bundler', function() {
it('create a bundle', function() {
assetServer.getAssetData.mockImplementation(() => {
return {
return Promise.resolve({
scales: [1,2,3],
files: [
'/root/img/img.png',
@ -144,7 +144,7 @@ describe('Bundler', function() {
hash: 'i am a hash',
name: 'img',
type: 'png',
};
});
});
return bundler.bundle({
@ -170,8 +170,8 @@ describe('Bundler', function() {
__packager_asset: true,
fileSystemLocation: '/root/img',
httpServerLocation: '/assets/img',
width: 25,
height: 50,
width: 50,
height: 100,
scales: [1, 2, 3],
files: [
'/root/img/img.png',
@ -217,7 +217,7 @@ describe('Bundler', function() {
name: 'img',
type: 'png',
};
assetServer.getAssetData.mockImplementation(() => mockAsset);
assetServer.getAssetData.mockImplementation(() => Promise.resolve(mockAsset));
return bundler.bundle({
entryFile: '/root/foo.js',
@ -230,8 +230,8 @@ describe('Bundler', function() {
__packager_asset: true,
fileSystemLocation: '/root/img',
httpServerLocation: '/assets/img',
width: 25,
height: 50,
width: 50,
height: 100,
scales: [1, 2, 3],
files: [
'/root/img/img.png',
@ -242,7 +242,7 @@ describe('Bundler', function() {
name: 'img',
type: 'png',
extraReverseHash: 'hsah a ma i',
extraPixelCount: 1250,
extraPixelCount: 5000,
}]);
});
});
@ -281,7 +281,7 @@ describe('Bundler', function() {
beforeEach(() => {
assetServer.getAssetData.mockImplementation(function(relPath) {
if (relPath === 'img/new_image.png') {
return {
return Promise.resolve({
scales: [1,2,3],
files: [
'/root/img/new_image.png',
@ -291,9 +291,9 @@ describe('Bundler', function() {
hash: 'i am a hash',
name: 'img',
type: 'png',
};
});
} else if (relPath === 'img/new_image2.png') {
return {
return Promise.resolve({
scales: [1,2,3],
files: [
'/root/img/new_image2.png',
@ -303,7 +303,7 @@ describe('Bundler', function() {
hash: 'i am a hash',
name: 'img',
type: 'png',
};
});
}
throw new Error('unknown image ' + relPath);

View File

@ -673,20 +673,18 @@ class Bundler {
'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
].indexOf(extname(module.path).slice(1)) !== -1;
return Promise.all([
isImage ? sizeOf(module.path) : null,
this._assetServer.getAssetData(relPath, platform),
]).then((res) => {
return this._assetServer.getAssetData(relPath, platform).then((assetData) => {
return Promise.all([isImage ? sizeOf(assetData.files[0]) : null, assetData]);
}).then((res) => {
const dimensions = res[0];
const assetData = res[1];
const scale = assetData.scales[0];
const asset = {
__packager_asset: true,
fileSystemLocation: pathDirname(module.path),
httpServerLocation: assetUrlPath,
/* $FlowFixMe: `resolution` is assets-only */
width: dimensions ? dimensions.width / module.resolution : undefined,
/* $FlowFixMe: `resolution` is assets-only */
height: dimensions ? dimensions.height / module.resolution : undefined,
width: dimensions ? dimensions.width / scale : undefined,
height: dimensions ? dimensions.height / scale : undefined,
scales: assetData.scales,
files: assetData.files,
hash: assetData.hash,