Move asset related modules into metro-buck

Summary:
These files are some of the few standalone files from the `local-cli` that are used internally. This diff copies them into the one place where they are used. Note that I am leaving the old files in `local-cli`. Even if they are unused, moving them would break flow (require module verification).

This diff also moves the `assetPathUtils` file into `Libraries/Image`, which is where it is used. This was previously part of D13337412 but I had to squash them to make buck happy.

Reviewed By: TheSavior

Differential Revision: D13337304

fbshipit-source-id: 2d501109ba7d4ba94ca7e8f2953258221947b90e
This commit is contained in:
Christoph Nakazawa
2018-12-06 20:06:47 -08:00
committed by Facebook Github Bot
parent ee7c702308
commit 2e5e9fa88a
6 changed files with 3 additions and 165 deletions

View File

@@ -22,7 +22,7 @@ import type {PackagerAsset} from 'AssetRegistry';
const PixelRatio = require('PixelRatio');
const Platform = require('Platform');
const assetPathUtils = require('../../local-cli/bundle/assetPathUtils');
const assetPathUtils = require('./assetPathUtils');
const invariant = require('invariant');
/**

View File

@@ -10,7 +10,7 @@
'use strict';
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
import type {PackagerAsset} from './AssetRegistry';
/**
* FIXME: using number to represent discrete scale numbers is fragile in essence because of

View File

@@ -1,42 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/
'use strict';
jest.dontMock('../filterPlatformAssetScales').dontMock('../assetPathUtils');
const filterPlatformAssetScales = require('../filterPlatformAssetScales');
describe('filterPlatformAssetScales', () => {
it('removes everything but 2x and 3x for iOS', () => {
expect(filterPlatformAssetScales('ios', [1, 1.5, 2, 3, 4])).toEqual([
1,
2,
3,
]);
expect(filterPlatformAssetScales('ios', [3, 4])).toEqual([3]);
});
it('keeps closest largest one if nothing matches', () => {
expect(filterPlatformAssetScales('ios', [0.5, 4, 100])).toEqual([4]);
expect(filterPlatformAssetScales('ios', [0.5, 100])).toEqual([100]);
expect(filterPlatformAssetScales('ios', [0.5])).toEqual([0.5]);
expect(filterPlatformAssetScales('ios', [])).toEqual([]);
});
it('keeps all scales for unknown platform', () => {
expect(filterPlatformAssetScales('freebsd', [1, 1.5, 2, 3.7])).toEqual([
1,
1.5,
2,
3.7,
]);
});
});

View File

@@ -1,75 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/
'use strict';
jest.dontMock('../getAssetDestPathAndroid').dontMock('../assetPathUtils');
const getAssetDestPathAndroid = require('../getAssetDestPathAndroid');
const path = require('path');
describe('getAssetDestPathAndroid', () => {
it('should use the right destination folder', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/test',
};
const expectDestPathForScaleToStartWith = (scale, path) => {
if (!getAssetDestPathAndroid(asset, scale).startsWith(path)) {
throw new Error(
`asset for scale ${scale} should start with path '${path}'`,
);
}
};
expectDestPathForScaleToStartWith(1, 'drawable-mdpi');
expectDestPathForScaleToStartWith(1.5, 'drawable-hdpi');
expectDestPathForScaleToStartWith(2, 'drawable-xhdpi');
expectDestPathForScaleToStartWith(3, 'drawable-xxhdpi');
expectDestPathForScaleToStartWith(4, 'drawable-xxxhdpi');
});
it('should lowercase path', () => {
const asset = {
name: 'Icon',
type: 'png',
httpServerLocation: '/assets/App/Test',
};
expect(getAssetDestPathAndroid(asset, 1)).toBe(
path.normalize('drawable-mdpi/app_test_icon.png'),
);
});
it('should remove `assets/` prefix', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/RKJSModules/Apps/AndroidSample/Assets',
};
expect(getAssetDestPathAndroid(asset, 1).startsWith('assets_')).toBeFalsy();
});
it('should put non-drawable resources to `raw/`', () => {
const asset = {
name: 'video',
type: 'mp4',
httpServerLocation: '/assets/app/test',
};
expect(getAssetDestPathAndroid(asset, 1)).toBe(
path.normalize('raw/app_test_video.mp4'),
);
});
});

View File

@@ -1,45 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/
'use strict';
jest.dontMock('../getAssetDestPathIOS');
const getAssetDestPathIOS = require('../getAssetDestPathIOS');
const path = require('path');
describe('getAssetDestPathIOS', () => {
it('should build correct path', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/test',
};
expect(getAssetDestPathIOS(asset, 1)).toBe(
path.normalize('assets/test/icon.png'),
);
});
it('should consider scale', () => {
const asset = {
name: 'icon',
type: 'png',
httpServerLocation: '/assets/test',
};
expect(getAssetDestPathIOS(asset, 2)).toBe(
path.normalize('assets/test/icon@2x.png'),
);
expect(getAssetDestPathIOS(asset, 3)).toBe(
path.normalize('assets/test/icon@3x.png'),
);
});
});

View File

@@ -10,7 +10,7 @@
'use strict';
const assetPathUtils = require('./assetPathUtils');
const assetPathUtils = require('../../Libraries/Image/assetPathUtils');
const path = require('path');
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';