mirror of https://github.com/status-im/metro.git
make the RN packager output more deterministic
Reviewed By: davidaurelio Differential Revision: D4357109 fbshipit-source-id: bc9ef04d81223299fe7708aeb0fe654647330ab7
This commit is contained in:
parent
b5dae70e61
commit
8e9549fb2b
|
@ -134,7 +134,7 @@ describe('Bundler', function() {
|
||||||
|
|
||||||
it('create a bundle', function() {
|
it('create a bundle', function() {
|
||||||
assetServer.getAssetData.mockImplementation(() => {
|
assetServer.getAssetData.mockImplementation(() => {
|
||||||
return {
|
return Promise.resolve({
|
||||||
scales: [1,2,3],
|
scales: [1,2,3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/img.png',
|
'/root/img/img.png',
|
||||||
|
@ -144,7 +144,7 @@ describe('Bundler', function() {
|
||||||
hash: 'i am a hash',
|
hash: 'i am a hash',
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return bundler.bundle({
|
return bundler.bundle({
|
||||||
|
@ -170,8 +170,8 @@ describe('Bundler', function() {
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: '/root/img',
|
fileSystemLocation: '/root/img',
|
||||||
httpServerLocation: '/assets/img',
|
httpServerLocation: '/assets/img',
|
||||||
width: 25,
|
width: 50,
|
||||||
height: 50,
|
height: 100,
|
||||||
scales: [1, 2, 3],
|
scales: [1, 2, 3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/img.png',
|
'/root/img/img.png',
|
||||||
|
@ -217,7 +217,7 @@ describe('Bundler', function() {
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
};
|
};
|
||||||
assetServer.getAssetData.mockImplementation(() => mockAsset);
|
assetServer.getAssetData.mockImplementation(() => Promise.resolve(mockAsset));
|
||||||
|
|
||||||
return bundler.bundle({
|
return bundler.bundle({
|
||||||
entryFile: '/root/foo.js',
|
entryFile: '/root/foo.js',
|
||||||
|
@ -230,8 +230,8 @@ describe('Bundler', function() {
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: '/root/img',
|
fileSystemLocation: '/root/img',
|
||||||
httpServerLocation: '/assets/img',
|
httpServerLocation: '/assets/img',
|
||||||
width: 25,
|
width: 50,
|
||||||
height: 50,
|
height: 100,
|
||||||
scales: [1, 2, 3],
|
scales: [1, 2, 3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/img.png',
|
'/root/img/img.png',
|
||||||
|
@ -242,7 +242,7 @@ describe('Bundler', function() {
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
extraReverseHash: 'hsah a ma i',
|
extraReverseHash: 'hsah a ma i',
|
||||||
extraPixelCount: 1250,
|
extraPixelCount: 5000,
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -281,7 +281,7 @@ describe('Bundler', function() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
assetServer.getAssetData.mockImplementation(function(relPath) {
|
assetServer.getAssetData.mockImplementation(function(relPath) {
|
||||||
if (relPath === 'img/new_image.png') {
|
if (relPath === 'img/new_image.png') {
|
||||||
return {
|
return Promise.resolve({
|
||||||
scales: [1,2,3],
|
scales: [1,2,3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/new_image.png',
|
'/root/img/new_image.png',
|
||||||
|
@ -291,9 +291,9 @@ describe('Bundler', function() {
|
||||||
hash: 'i am a hash',
|
hash: 'i am a hash',
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
};
|
});
|
||||||
} else if (relPath === 'img/new_image2.png') {
|
} else if (relPath === 'img/new_image2.png') {
|
||||||
return {
|
return Promise.resolve({
|
||||||
scales: [1,2,3],
|
scales: [1,2,3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/new_image2.png',
|
'/root/img/new_image2.png',
|
||||||
|
@ -303,7 +303,7 @@ describe('Bundler', function() {
|
||||||
hash: 'i am a hash',
|
hash: 'i am a hash',
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('unknown image ' + relPath);
|
throw new Error('unknown image ' + relPath);
|
||||||
|
|
|
@ -673,20 +673,18 @@ class Bundler {
|
||||||
'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
|
'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
|
||||||
].indexOf(extname(module.path).slice(1)) !== -1;
|
].indexOf(extname(module.path).slice(1)) !== -1;
|
||||||
|
|
||||||
return Promise.all([
|
return this._assetServer.getAssetData(relPath, platform).then((assetData) => {
|
||||||
isImage ? sizeOf(module.path) : null,
|
return Promise.all([isImage ? sizeOf(assetData.files[0]) : null, assetData]);
|
||||||
this._assetServer.getAssetData(relPath, platform),
|
}).then((res) => {
|
||||||
]).then((res) => {
|
|
||||||
const dimensions = res[0];
|
const dimensions = res[0];
|
||||||
const assetData = res[1];
|
const assetData = res[1];
|
||||||
|
const scale = assetData.scales[0];
|
||||||
const asset = {
|
const asset = {
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: pathDirname(module.path),
|
fileSystemLocation: pathDirname(module.path),
|
||||||
httpServerLocation: assetUrlPath,
|
httpServerLocation: assetUrlPath,
|
||||||
/* $FlowFixMe: `resolution` is assets-only */
|
width: dimensions ? dimensions.width / scale : undefined,
|
||||||
width: dimensions ? dimensions.width / module.resolution : undefined,
|
height: dimensions ? dimensions.height / scale : undefined,
|
||||||
/* $FlowFixMe: `resolution` is assets-only */
|
|
||||||
height: dimensions ? dimensions.height / module.resolution : undefined,
|
|
||||||
scales: assetData.scales,
|
scales: assetData.scales,
|
||||||
files: assetData.files,
|
files: assetData.files,
|
||||||
hash: assetData.hash,
|
hash: assetData.hash,
|
||||||
|
|
Loading…
Reference in New Issue