Skip to content

Commit 80824e6

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Expose build entry point for AssetRegistry
Summary: **Problem** Following D108750303, we now expose an `AssetsRegistry` API from `'react-native'`. This is great, as we need to replace a deep `/Libraries/...` import in Metro configs (`transformer.assetRegistryPath`): https://www.internalfb.com/code/fbsource/[31661d52e803d77356725429f44331135601b634]/xplat/js/react-native-github/packages/metro-config/src/index.flow.js?lines=87 **Unfortunately**, we can't quite reuse the new `AssetRegistry` API from the index module, as we'd break Metro's API contract (generate an inline require) — we need a dedicated wrapper module that can be read without destructuring. **This diff** Adds a new `'react-native/asset-registry'` secondary entry point, intended/documented for this Metro config use case — and deprecates `react-native/assets-registry/registry`. - Solves the above problem (migrated in our own `react-native/metro-config` use). - Remains consistent with D108750302 (we intend to remove `react-native/assets-registry` at a later date). - As a bonus, fixes the longstanding naming inconsistency between `react-native/assets-registry` and `'react-native/Libraries/Image/AssetRegistry'` — `AssetRegistry` (singular) is now canonical. Changelog: - [General][Breaking] - `react-native/Libraries/Image/AssetRegistry` is removed. Please use the `AssetRegistry` API (apps/library code) and/or the `react-native/asset-registry` entrypoint (Metro/build configs). - [General][Deprecated] - **assets-registry**: `react-native/assets-registry/registry` is deprecated. Please use the `AssetRegistry` API (apps/library code) and/or the `react-native/asset-registry` entrypoint (Metro/build configs). Differential Revision: D108750303
1 parent 6635de8 commit 80824e6

5 files changed

Lines changed: 39 additions & 19 deletions

File tree

packages/assets-registry/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ Most apps never import this directly — assets are handled through `<Image>`.
88

99
## API
1010

11-
### `@react-native/assets-registry/registry`
12-
13-
> [!Note]
14-
> Aliases to [`AssetRegistry`](https://reactnative.dev/docs/assetregistry) (since 0.87). Prefer importing directly from the `'react-native'` package in libraries.
11+
### `@react-native/assets-registry/registry` (DEPRECATED)
12+
13+
> [!Warning]
14+
> **Deprecated**: Aliases to [`AssetRegistry`](https://reactnative.dev/docs/assetregistry) (since 0.87).
15+
>
16+
> Please use:
17+
> - `import { AssetRegistry } from 'react-native';` (apps/library code)
18+
> - `'react-native/asset-registry'` (entrypoint for Metro/build configs)
1519
1620
| Export | Signature | Notes |
1721
|---|---|---|

packages/metro-config/src/index.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
8484
},
8585
transformer: {
8686
allowOptionalDependencies: true,
87-
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
87+
assetRegistryPath: 'react-native/asset-registry',
8888
asyncRequireModulePath: require.resolve(
8989
'metro-runtime/src/modules/asyncRequire',
9090
),

packages/react-native/Libraries/Image/AssetRegistry.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/react-native/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
"react-native-strict-api": null,
5757
"default": "./types/*.d.ts"
5858
},
59+
"./asset-registry/*": {
60+
"types": null,
61+
"default": "./src/asset-registry.js"
62+
},
5963
"./gradle/*": null,
6064
"./React/*": null,
6165
"./ReactAndroid/*": null,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
// ----------------------------------------------------------------------------
12+
// Secondary react-native/assets-registry entry point.
13+
//
14+
// This is an untyped secondary entry point intended to be referenced from
15+
// Metro's `transformer.assetRegistryPath` config option.
16+
//
17+
// Apps/libraries should prefer `import {AssetRegistry} from 'react-native'`.
18+
// ----------------------------------------------------------------------------
19+
20+
import {AssetRegistry} from './private/assets/AssetRegistry';
21+
22+
/* eslint-disable @react-native/monorepo/no-commonjs-exports */
23+
module.exports = {
24+
registerAsset: AssetRegistry.registerAsset,
25+
getAssetByID: AssetRegistry.getAssetByID,
26+
};

0 commit comments

Comments
 (0)