Delete @react-native/assets-registry (#58780)

Summary:
`react-native/assets-registry` has been deprecated since 0.87 (https://github.com/react/react-native/issues/57370), with two release cycles (0.87 and 0.88) ahead of its removal. Delete the package from the monorepo for 0.89.

Callers migrate as documented in the deprecation:

- `react-native/assets-registry/registry` → `AssetRegistry` from `react-native`, or the `react-native/asset-registry` entry point.
- `react-native/assets-registry/path-support` → `react-native/asset-utils`.

Changelog: [General][Breaking] - **Assets**: Remove `react-native/assets-registry`. Use `AssetRegistry` from `react-native` and `react-native/asset-utils` instead.

Pull Request resolved: https://github.com/react/react-native/pull/58780

Test Plan:
No remaining references to the package in the repo (excluding `CHANGELOG*.md`):

```
grep -rn --exclude-dir=node_modules --exclude-dir=.git 'assets-registry' . | grep -v CHANGELOG
```

✅ Jest for the packages that took over the package's functionality:

```
yarn test packages/asset-utils packages/react-native/Libraries/Image packages/community-cli-plugin/src/commands/bundle
# Test Suites: 6 passed, 6 total / Tests: 41 passed, 41 total
```

Reviewed By: javache

Differential Revision: D122667835

Pulled By: Abbondanzo

fbshipit-source-id: 57c6964f3926b8cfb7d9ed7c030d0dee3860dd98
This commit is contained in:
Alex Hunt authored and meta-codesync[bot] committed 2026-10-01 07:13:46 -07:00
1 parent d7878263ca
commit 56c48ac0eb
8 files changed
-343

No files matched your search

-1
View File
@@ -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: {
-39
View File
@@ -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>`, `Image.resolveAssetSource()`, and any code that resolves `require('./img.png')` on native.
Most apps never import this directly — assets are handled through `<Image>`.
## 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 |
@@ -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');
});
});
-33
View File
@@ -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": "*"
}
}
-28
View File
@@ -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;
-96
View File
@@ -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,
};
-39
View File
@@ -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<number>;
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;
-23
View File
@@ -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,
};