Skip to content

Commit 697e946

Browse files
huntiefacebook-github-bot
authored andcommitted
Convert assets-registry to Flow comment syntax (#48458)
Summary: Pull Request resolved: #48458 NOTE: This change is made once and is not guaranteed. **Motivation**: Requiring Flow parsing for `react-native` and its dependencies in user space can involve friction. For the case of `react-native/assets-registry` → `react-native-web`, I believe we should do the pragmatic thing to relax this requirement. - This is a convenience stopgap until #39542 can be stabilised. - This package is tiny and infrequently modified — I believe it's pragmatic/safe to do a one-time conversion, with the above notice and no changelog (i.e. "experimental" for now). Resolves #48349. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D67764460 fbshipit-source-id: 7687fd79c6dea73c234a46e475c1cc745225830b
1 parent 5ef9e1f commit 697e946

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

packages/assets/path-support.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @format
87
* @flow strict
8+
* @format
99
*/
1010

1111
'use strict';
1212

13-
import type {PackagerAsset} from './registry.js';
13+
/*:: import type {PackagerAsset} from './registry.js'; */
1414

1515
const androidScaleSuffix = {
1616
'0.75': 'ldpi',
@@ -27,7 +27,7 @@ const ANDROID_BASE_DENSITY = 160;
2727
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
2828
* floating point numbers imprecision.
2929
*/
30-
function getAndroidAssetSuffix(scale: number): string {
30+
function getAndroidAssetSuffix(scale /*: number */) /*: string */ {
3131
if (scale.toString() in androidScaleSuffix) {
3232
// $FlowFixMe[invalid-computed-prop]
3333
return androidScaleSuffix[scale.toString()];
@@ -53,9 +53,9 @@ const drawableFileTypes = new Set([
5353
]);
5454

5555
function getAndroidResourceFolderName(
56-
asset: PackagerAsset,
57-
scale: number,
58-
): string {
56+
asset /*: PackagerAsset */,
57+
scale /*: number */,
58+
) /*: string */ {
5959
if (!drawableFileTypes.has(asset.type)) {
6060
return 'raw';
6161
}
@@ -73,15 +73,17 @@ function getAndroidResourceFolderName(
7373
return 'drawable-' + suffix;
7474
}
7575

76-
function getAndroidResourceIdentifier(asset: PackagerAsset): string {
76+
function getAndroidResourceIdentifier(
77+
asset /*: PackagerAsset */,
78+
) /*: string */ {
7779
return (getBasePath(asset) + '/' + asset.name)
7880
.toLowerCase()
7981
.replace(/\//g, '_') // Encode folder structure in file name
8082
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
8183
.replace(/^(?:assets|assetsunstable_path)_/, ''); // Remove "assets_" or "assetsunstable_path_" prefix
8284
}
8385

84-
function getBasePath(asset: PackagerAsset): string {
86+
function getBasePath(asset /*: PackagerAsset */) /*: string */ {
8587
const basePath = asset.httpServerLocation;
8688
return basePath.startsWith('/') ? basePath.slice(1) : basePath;
8789
}

packages/assets/registry.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
'use strict';
1212

13+
/*::
1314
export type AssetDestPathResolver = 'android' | 'generic';
1415
1516
export type PackagerAsset = {
@@ -25,16 +26,17 @@ export type PackagerAsset = {
2526
+resolver?: AssetDestPathResolver,
2627
...
2728
};
29+
*/
2830

29-
const assets: Array<PackagerAsset> = [];
31+
const assets /*: Array<PackagerAsset> */ = [];
3032

31-
function registerAsset(asset: PackagerAsset): number {
33+
function registerAsset(asset /*: PackagerAsset */) /*: number */ {
3234
// `push` returns new array length, so the first asset will
3335
// get id 1 (not 0) to make the value truthy
3436
return assets.push(asset);
3537
}
3638

37-
function getAssetByID(assetId: number): PackagerAsset {
39+
function getAssetByID(assetId /*: number */) /*: PackagerAsset */ {
3840
return assets[assetId - 1];
3941
}
4042

0 commit comments

Comments
 (0)