Allow to resolve assets with explicit platform extension

Summary: Given a file `test.android.png`, this allows it to be found as `test.android` for arbitrary platforms.

Reviewed By: bestander

Differential Revision: D5305807

fbshipit-source-id: d869a1da0cc502f853314790385734897f269d6a
This commit is contained in:
David Aurelio 2017-06-23 16:35:40 -07:00 committed by Facebook Github Bot
parent b62669e2da
commit 5f0c5b231e
3 changed files with 28 additions and 21 deletions

View File

@ -102,9 +102,16 @@ class AssetResolutionCache {
continue;
}
getWithDefaultArray(results, assetData.assetName).push({
platform: assetData.platform,
fileName,
platform: assetData.platform,
});
if (assetData.platform) {
const assetNameWithPlatform = `${assetData.name}.${assetData.platform}.${assetData.type}`;
getWithDefaultArray(results, assetNameWithPlatform).push({
fileName,
platform: null,
});
}
}
return results;
};

View File

@ -38,7 +38,11 @@ describe('AssetResolutionCache', () => {
it('finds the correct assets', () => {
const results = cache.resolve('/assets', 'test.png', 'ios');
expect(results).toMatchSnapshot();
expect(results).toEqual([
'test@2x.ios.png',
'test@1x.ios.png',
'test@1.5x.ios.png',
]);
});
it('correctly clears out', () => {
@ -46,6 +50,20 @@ describe('AssetResolutionCache', () => {
fileNames.push('test@3x.ios.png');
cache.clear();
const results = cache.resolve('/assets', 'test.png', 'ios');
expect(results).toMatchSnapshot();
expect(results).toEqual([
'test@2x.ios.png',
'test@1x.ios.png',
'test@1.5x.ios.png',
'test@3x.ios.png',
]);
});
it('allows resolving assets with platform extension', () => {
const results = cache.resolve('/assets', 'test.ios.png', 'android');
expect(results).toEqual([
'test@2x.ios.png',
'test@1x.ios.png',
'test@1.5x.ios.png',
]);
});
});

View File

@ -1,18 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AssetResolutionCache correctly clears out 1`] = `
Array [
"test@2x.ios.png",
"test@1x.ios.png",
"test@1.5x.ios.png",
"test@3x.ios.png",
]
`;
exports[`AssetResolutionCache finds the correct assets 1`] = `
Array [
"test@2x.ios.png",
"test@1x.ios.png",
"test@1.5x.ios.png",
]
`;