A framework for building native applications using React
Move JavaScript exports rewrites to publishConfig/prepack (#54857)
Summary:
### Motivation
Updates the shared JavaScript build setup to use the modern `publishConfig` convention.
This:
- Simplifies the build script.
- Makes the production values for `"exports"` more understandable in place (especially by separating from exports conditions).
- Prevents us from creating a dirty file state when running `yarn build`.
### Changes
- Add `publishConfig` to each `package.json` listing production `"exports"` targets.
- Add `scripts/build/prepack.js` script to action `publishConfig` (now on `npm pack`, `npm publish` exclusively).
- Remove `"exports"` rewriting (and un-rewriting safeguards) from build script.
**Note on `"prepack"`**
Slightly unfortunately, `publishConfig` doesn't work consistently between package managers currently, including npm — so this does not work implicitly (but may in future).
We're instead following `publishConfig` as a convention, and explicitly implementing a full copy (theoretically forking us towards pnpm and Yarn v4's approach).
However, I believe this is:
- Worthwhile, for the motivations above — and in particular being able to understand the final shape of `"exports"` (independent from the dimension of conditional exports, which may come into play later).
- Completely inspectable/maintainable as an explicit implementation (`scripts/build/prepack.js`).
Changelog: [Internal]
Pull Request resolved: https://github.com/facebook/react-native/pull/54857
Test Plan:
### CI
✅ GitHub Actions
### End-to-end release test script
(Note: Rebased on `0.83-stable` when tested)
```
yarn test-release-local -t "RNTestProject" -p "iOS" -c $GITHUB_TOKEN
```
{F1984106139}
✅ Test script runs `npm publish` on packages to a local proxy.
{F1984106146}
✅ Installed packages have `publishConfig` `"exports"` values applied
NOTE: ⬆️ This is **exactly** the same output as before.
{F1984106148}
✅ `/tmp/RNTestProject` runs using built + proxy-published + proxy-installed packages
Reviewed By: cipolleschi
Differential Revision: D88963450
Pulled By: huntie
fbshipit-source-id: f328252cf93a1f1039b79d7f369d1e6e7e5b4b52 A
Alex Hunt committed
cc9164c337b3b97c8c1137a18a81f4443e228b7f
Parent: 7d2a7c9
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com>
on 12/12/2025, 12:08:59 PM