From 20a96aa421312521ff19c7797408992070c326ff Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 30 Sep 2026 23:23:54 +0100 Subject: [PATCH] Delete @react-native/assets-registry --- .eslintrc.js | 1 - packages/assets-registry/README.md | 39 -------- .../__tests__/path-support-test.js | 84 ---------------- packages/assets-registry/package.json | 33 ------- packages/assets-registry/path-support.d.ts | 28 ------ packages/assets-registry/path-support.js | 96 ------------------- packages/assets-registry/registry.d.ts | 39 -------- packages/assets-registry/registry.js | 23 ----- 8 files changed, 343 deletions(-) delete mode 100644 packages/assets-registry/README.md delete mode 100644 packages/assets-registry/__tests__/path-support-test.js delete mode 100644 packages/assets-registry/package.json delete mode 100644 packages/assets-registry/path-support.d.ts delete mode 100644 packages/assets-registry/path-support.js delete mode 100644 packages/assets-registry/registry.d.ts delete mode 100644 packages/assets-registry/registry.js diff --git a/.eslintrc.js b/.eslintrc.js index 9db5a0e48996..5c5f2e298ae5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,7 +51,6 @@ module.exports = { files: [ './packages/react-native/Libraries/**/*.{js,flow}', './packages/react-native/src/**/*.{js,flow}', - './packages/assets-registry/registry.js', ], parser: 'flow-eslint', rules: { diff --git a/packages/assets-registry/README.md b/packages/assets-registry/README.md deleted file mode 100644 index 1dd81110155e..000000000000 --- a/packages/assets-registry/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# @react-native/assets-registry - -![npm package](https://img.shields.io/npm/v/@react-native/assets-registry?color=brightgreen&label=npm%20package) - -> [!Warning] -> **This package is deprecated (since 0.87)** and will be removed in a future release. Use [`AssetRegistry`](https://reactnative.dev/docs/assetregistry) from `react-native` (or the `react-native/asset-registry` build entry point) instead of `@react-native/assets-registry/registry`, and [`@react-native/asset-utils`](https://www.npmjs.com/package/@react-native/asset-utils) instead of `@react-native/assets-registry/path-support`. - -Runtime registry that maps asset IDs generated in a Metro bundle to asset metadata. It backs ``, `Image.resolveAssetSource()`, and any code that resolves `require('./img.png')` on native. - -Most apps never import this directly — assets are handled through ``. - -## API - -### `@react-native/assets-registry/registry` (DEPRECATED) - -> [!Warning] -> **Deprecated**: Aliases to [`AssetRegistry`](https://reactnative.dev/docs/assetregistry) (since 0.87). -> -> Please use: -> - `import { AssetRegistry } from 'react-native';` (apps/library code) -> - `'react-native/asset-registry'` (entrypoint for Metro/build configs) - -| Export | Signature | Notes | -|---|---|---| -| `registerAsset` | `(asset: PackagerAsset) => number` | Stores the asset; returns a numeric ID | -| `getAssetByID` | `(assetId: number) => PackagerAsset` | Looks an asset back up by ID | - -### `@react-native/assets-registry/path-support` (DEPRECATED) - -> [!Warning] -> **Deprecated**: Use [`@react-native/asset-utils`](https://www.npmjs.com/package/@react-native/asset-utils) (since 0.87). - -Android resource-path helpers, used when copying assets into `drawable-*` folders. - -| Export | Signature | Notes | -|---|---|---| -| `getAndroidResourceFolderName` | `(asset: PackagerAsset, scale: number) => string` | e.g. `drawable-xhdpi`; non-drawable types resolve to `raw` | -| `getAndroidResourceIdentifier` | `(asset: PackagerAsset) => string` | Sanitised resource name | -| `getBasePath` | `(asset: PackagerAsset) => string` | `httpServerLocation` without the leading slash | diff --git a/packages/assets-registry/__tests__/path-support-test.js b/packages/assets-registry/__tests__/path-support-test.js deleted file mode 100644 index 9f81726a0014..000000000000 --- a/packages/assets-registry/__tests__/path-support-test.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -import {getAndroidResourceFolderName} from '../path-support'; - -const DRAWABLE_ASSET = { - __packager_asset: true, - fileSystemLocation: 'foo.png', - httpServerLocation: '/assets/', - width: 150, - height: 150, - scales: [1], - hash: '__HASH__', - name: 'foo', - type: 'png', -}; - -const NON_DRAWABLE_ASSET = { - __packager_asset: true, - fileSystemLocation: 'foo.txt', - httpServerLocation: '/assets/', - width: 150, - height: 150, - scales: [1], - hash: '__HASH__', - name: 'foo', - type: 'txt', -}; - -describe('getAndroidResourceFolderName', () => { - test('supports the six primary density buckets', () => { - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 0.75)).toBe( - 'drawable-ldpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 1)).toBe( - 'drawable-mdpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 1.5)).toBe( - 'drawable-hdpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 2)).toBe( - 'drawable-xhdpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 3)).toBe( - 'drawable-xxhdpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 4)).toBe( - 'drawable-xxxhdpi', - ); - }); - - test('supports nonstandard densities', () => { - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 1.25)).toBe( - 'drawable-200dpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 1.66)).toBe( - 'drawable-266dpi', - ); - expect(getAndroidResourceFolderName(DRAWABLE_ASSET, 1.33)).toBe( - 'drawable-213dpi', - ); // ~tvdpi - }); - - test('throws if the density cannot be processed', () => { - expect(() => getAndroidResourceFolderName(DRAWABLE_ASSET, -1)).toThrow(); - expect(() => getAndroidResourceFolderName(DRAWABLE_ASSET, 0)).toThrow(); - expect(() => - getAndroidResourceFolderName(DRAWABLE_ASSET, Infinity), - ).toThrow(); - }); - - test('returns "raw" for non-drawables', () => { - expect(getAndroidResourceFolderName(NON_DRAWABLE_ASSET, 0.75)).toBe('raw'); - expect(getAndroidResourceFolderName(NON_DRAWABLE_ASSET, 1)).toBe('raw'); - expect(getAndroidResourceFolderName(NON_DRAWABLE_ASSET, 1.25)).toBe('raw'); - }); -}); diff --git a/packages/assets-registry/package.json b/packages/assets-registry/package.json deleted file mode 100644 index 645604cc9846..000000000000 --- a/packages/assets-registry/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@react-native/assets-registry", - "version": "0.87.0-main", - "description": "Asset support code for React Native.", - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/react/react-native.git", - "directory": "packages/assets-registry" - }, - "homepage": "https://github.com/react/react-native/tree/HEAD/packages/assets-registry#readme", - "keywords": [ - "react-native" - ], - "bugs": "https://github.com/react/react-native/issues", - "engines": { - "node": "^22.13.0 || ^24.3.0 || >= 26.0.0" - }, - "files": [ - "path-support.js", - "path-support.d.ts", - "registry.js", - "registry.d.ts", - "README.md", - "!**/__docs__/**", - "!**/__fixtures__/**", - "!**/__mocks__/**", - "!**/__tests__/**" - ], - "peerDependencies": { - "react-native": "*" - } -} diff --git a/packages/assets-registry/path-support.d.ts b/packages/assets-registry/path-support.d.ts deleted file mode 100644 index cddc55f69bac..000000000000 --- a/packages/assets-registry/path-support.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -import type {PackagerAsset} from './registry'; - -/** - * @deprecated Use `getAndroidResourceFolderName` from `@react-native/asset-utils` instead. - */ -export function getAndroidResourceFolderName( - asset: PackagerAsset, - scale: number, -): string; - -/** - * @deprecated Use `getAndroidResourceIdentifier` from `@react-native/asset-utils` instead. - */ -export function getAndroidResourceIdentifier(asset: PackagerAsset): string; - -/** - * @deprecated Use `@react-native/asset-utils` instead. - */ -export function getBasePath(asset: PackagerAsset): string; diff --git a/packages/assets-registry/path-support.js b/packages/assets-registry/path-support.js deleted file mode 100644 index f7e51a9e6ecd..000000000000 --- a/packages/assets-registry/path-support.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -/*:: import type {PackagerAsset} from './registry.js'; */ - -const androidScaleSuffix = { - '0.75': 'ldpi', - '1': 'mdpi', - '1.5': 'hdpi', - '2': 'xhdpi', - '3': 'xxhdpi', - '4': 'xxxhdpi', -}; - -const ANDROID_BASE_DENSITY = 160; - -/** - * FIXME: using number to represent discrete scale numbers is fragile in essence because of - * floating point numbers imprecision. - */ -function getAndroidAssetSuffix(scale /*: number */) /*: string */ { - if (scale.toString() in androidScaleSuffix) { - // $FlowFixMe[invalid-computed-prop] - return androidScaleSuffix[scale.toString()]; - } - // NOTE: Android Gradle Plugin does not fully support the nnndpi format. - // See https://issuetracker.google.com/issues/72884435 - if (Number.isFinite(scale) && scale > 0) { - return Math.round(scale * ANDROID_BASE_DENSITY) + 'dpi'; - } - throw new Error('no such scale ' + scale.toString()); -} - -// See https://developer.android.com/guide/topics/resources/drawable-resource.html -const drawableFileTypes = new Set([ - 'gif', - 'heic', - 'heif', - 'jpeg', - 'jpg', - 'ktx', - 'png', - 'webp', - 'xml', -]); - -function getAndroidResourceFolderName( - asset /*: PackagerAsset */, - scale /*: number */, -) /*: string */ { - if (!drawableFileTypes.has(asset.type)) { - return 'raw'; - } - const suffix = getAndroidAssetSuffix(scale); - if (!suffix) { - throw new Error( - "Don't know which android drawable suffix to use for scale: " + - scale + - '\nAsset: ' + - JSON.stringify(asset, null, '\t') + - '\nPossible scales are:' + - JSON.stringify(androidScaleSuffix, null, '\t'), - ); - } - return 'drawable-' + suffix; -} - -function getAndroidResourceIdentifier( - asset /*: PackagerAsset */, -) /*: string */ { - return (getBasePath(asset) + '/' + asset.name) - .toLowerCase() - .replace(/\//g, '_') // Encode folder structure in file name - .replace(/([^a-z0-9_])/g, '') // Remove illegal chars - .replace(/^(?:assets|assetsunstable_path)_/, ''); // Remove "assets_" or "assetsunstable_path_" prefix -} - -function getBasePath(asset /*: PackagerAsset */) /*: string */ { - const basePath = asset.httpServerLocation; - return basePath.startsWith('/') ? basePath.slice(1) : basePath; -} - -module.exports = { - getAndroidResourceFolderName, - getAndroidResourceIdentifier, - getBasePath, -}; diff --git a/packages/assets-registry/registry.d.ts b/packages/assets-registry/registry.d.ts deleted file mode 100644 index fb8bfcc2a156..000000000000 --- a/packages/assets-registry/registry.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -/** - * @deprecated Use `import type {AssetDestPathResolver} from 'react-native'` instead. - */ -export type AssetDestPathResolver = 'android' | 'generic'; - -/** - * @deprecated Use `import type {PackagerAsset} from 'react-native'` instead. - */ -export type PackagerAsset = { - readonly __packager_asset: boolean; - readonly fileSystemLocation: string; - readonly httpServerLocation: string; - readonly width: number | null | undefined; - readonly height: number | null | undefined; - readonly scales: Array; - readonly hash: string; - readonly name: string; - readonly type: string; - readonly resolver?: AssetDestPathResolver | undefined; -}; - -/** - * @deprecated Use `import {AssetRegistry} from 'react-native'` instead. - */ -export function registerAsset(asset: PackagerAsset): number; - -/** - * @deprecated Use `import {AssetRegistry} from 'react-native'` instead. - */ -export function getAssetByID(assetId: number): PackagerAsset; diff --git a/packages/assets-registry/registry.js b/packages/assets-registry/registry.js deleted file mode 100644 index 08a0ef59fb35..000000000000 --- a/packages/assets-registry/registry.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -import {AssetRegistry} from 'react-native'; - -/*:: -export type {AssetDestPathResolver, PackagerAsset} from 'react-native'; -*/ - -// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports -module.exports = { - registerAsset: AssetRegistry.registerAsset, - getAssetByID: AssetRegistry.getAssetByID, -};