Remove build package.json dirty state check (#55420)

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

After https://github.com/facebook/react-native/pull/54857 (use of the "publishConfig" field), this check is no longer necessary, since `yarn build` will no longer make changes to any checked in files.

In the (expectedly) rare case that `yarn build --prepack` changes are committed (only intended for CI), Flow will also fail independently.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D92397786

fbshipit-source-id: 872cc91b62295cdb6d8c2799cffb8a4cadc4106e
This commit is contained in:
Alex Hunt
2026-02-05 09:14:33 -08:00
committed by meta-codesync[bot]
parent 11e257cec0
commit a25049b8dd
3 changed files with 7 additions and 58 deletions
-3
View File
@@ -29,9 +29,6 @@ runs:
- name: Lint file structure
shell: bash
run: ./.github/workflow-scripts/lint_files.sh
- name: Verify not committing repo after running build
shell: bash
run: yarn run build --validate
- name: Run flowcheck
shell: bash
run: yarn flow-check
+6 -53
View File
@@ -37,7 +37,6 @@ const config = {
allowPositionals: true,
options: {
prepack: {type: 'boolean'},
validate: {type: 'boolean'},
help: {type: 'boolean'},
},
};
@@ -45,7 +44,7 @@ const config = {
async function build() {
const {
positionals: packageNames,
values: {prepack, validate, help},
values: {prepack, help},
/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
* https://fburl.com/workplace/6291gfvu */
} = parseArgs(config);
@@ -62,19 +61,15 @@ async function build() {
Options:
--prepack Run the ./prepack.js script after building, applying
package.json "publishConfig" changes to the working copy.
This is usually run before npm publish.
--validate Validate that no build artifacts have been accidentally
committed.
(This is usually run later in CI before npm publish).
`);
process.exitCode = 0;
return;
}
if (!validate) {
console.log(
'\n' + styleText(['bold', 'inverse'], 'Building packages') + '\n',
);
}
console.log(
'\n' + styleText(['bold', 'inverse'], 'Building packages') + '\n',
);
const packagesToBuild = packageNames.length
? packageNames.filter(packageName => packageName in buildConfig.packages)
@@ -82,27 +77,12 @@ async function build() {
let ok = true;
for (const packageName of packagesToBuild) {
if (validate) {
ok &&= await checkPackage(packageName);
} else {
await buildPackage(packageName, prepack);
}
await buildPackage(packageName, prepack);
}
process.exitCode = ok ? 0 : 1;
}
async function checkPackage(packageName /*: string */) /*: Promise<boolean> */ {
const artifacts = await exportedBuildArtifacts(packageName);
if (artifacts.length > 0) {
console.log(
`${styleText('bgRed', packageName)}: has been built and the ${styleText('bold', 'build artifacts')} committed to the repository. This will break Flow checks.`,
);
return false;
}
return true;
}
async function buildPackage(packageName /*: string */, prepack /*: boolean */) {
try {
const {emitTypeScriptDefs} = getBuildOptions(packageName);
@@ -248,33 +228,6 @@ type PackageJson = {
};
*/
function isStringOnly(entries /*: mixed */) /*: entries is string */ {
return typeof entries === 'string';
}
async function exportedBuildArtifacts(
packageName /*: string */,
) /*: Promise<string[]> */ {
const packagePath = path.resolve(PACKAGES_DIR, packageName, 'package.json');
const pkg /*: PackageJson */ = JSON.parse(
await fs.readFile(packagePath, 'utf8'),
);
if (pkg.exports == null) {
throw new Error(
packageName +
' does not define an "exports" field in its package.json. As part ' +
'of the build setup, this field must be used in order to rewrite ' +
'paths to built files in production.',
);
}
return Object.values(pkg.exports)
.filter(isStringOnly)
.filter(filepath =>
path.dirname(filepath).split(path.sep).includes(BUILD_DIR),
);
}
/**
* Get the set of Flow entry points to build.
*
+1 -2
View File
@@ -53,10 +53,9 @@ try {
describe('Test: feature flags codegen');
execAndLog(`${YARN_BINARY} run featureflags --verify-unchanged`);
describe('Test: eslint');
execAndLog(`${YARN_BINARY} run lint`);
describe('Test: No JS build artifacts');
execAndLog(`${YARN_BINARY} run build --validate`);
describe('Test: Validate JS API snapshot');
execAndLog(`${YARN_BINARY} run build-types --validate`);