Add error when running build script after prepack (#55914)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55914

Introduce a clear error message if running `yarn build` again after `yarn prepack` (which will have applied the `"publishConfig"` field to each `package.json`, just ahead of publishing to npm). This state should never happen in CI or local dev, but can occur if repeat-running `yarn test-release-local` without `yarn test-release-local-clean`.

Introducing a validation error is preferable over making this idempotent (logic would be complex + fragile) for this rare + out-of-design edge case.

Changelog: [Internal]

Reviewed By: alanleedev

Differential Revision: D95215735

fbshipit-source-id: 5a9be44f0d0ae1f2721eed2b11088466a4ff7f72
This commit is contained in:
Alex Hunt authored and meta-codesync[bot] committed 2026-03-04 09:23:50 -08:00
1 parent 7f7dbe7580
commit 238bd2452e
1 file changed
+13 -4
+13 -4
View File
@@ -85,6 +85,10 @@ async function build() {
async function buildPackage(packageName /*: string */, prepack /*: boolean */) {
try {
process.stdout.write(
`${packageName} ${styleText('dim', '.').repeat(72 - packageName.length)} `,
);
const {emitTypeScriptDefs} = getBuildOptions(packageName);
const entryPoints = await getEntryPoints(packageName);
@@ -98,10 +102,6 @@ async function buildPackage(packageName /*: string */, prepack /*: boolean */) {
!entryPoints.has(file.replace(/\.js$/, '.flow.js')),
);
process.stdout.write(
`${packageName} ${styleText('dim', '.').repeat(72 - packageName.length)} `,
);
// Build regular files
for (const file of files) {
await buildFile(path.normalize(file), {
@@ -299,6 +299,15 @@ async function getEntryPoints(
continue;
}
if (target.startsWith('./' + BUILD_DIR + '/')) {
throw new Error(
`Found ./${BUILD_DIR}/* entry in package.json exports for ` +
`${packageName}. This is either a misconfiguration, or the ` +
`prepack script was previously run and the package.json state ` +
`is dirty. Please re-run against a clean working copy.`,
);
}
if (target.includes('*')) {
console.warn(
`${styleText('yellow', 'Warning')}: Encountered subpath pattern ${subpath}` +