Loosen JS API breaking change detection, improve Danger message (#54901)

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

At present, we're only using a rough heuristic for whether a code change to `ReactNativeApi.d.ts` is a breaking change. Introduce `POTENTIALLY_BREAKING` result level and update Danger warnings box.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D89287801

fbshipit-source-id: aced7911ecde37a1ad2c355d56ef0f0edde88fd4
This commit is contained in:
Alex Hunt authored and meta-codesync[bot] committed 2025-12-16 08:14:38 -08:00
1 parent 498514d12e
commit a22ab422e8
3 files changed
+18 -14

No files matched your search

+13 -9
View File
@@ -30,20 +30,24 @@ const isFromPhabricator = body_contains('differential revision:');
// Provides advice if a summary section is missing, or body is too short
const includesSummary = body_contains('## summary', 'summary:');
const snapshot_output = JSON.parse(
const diffJsApiChangesOutput = JSON.parse(
fs.readFileSync(
path.join(process.env.RUNNER_TEMP, 'diff-js-api-changes/output.json'),
'utf8',
),
);
if (snapshot_output && snapshot_output.result !== 'NON_BREAKING') {
const title = ':exclamation: JavaScript API change detected';
const idea =
'This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. ' +
'Please include a clear changelog message. ' +
'This change will be subject to extra review.\n\n' +
`This change was flagged as: <code>${snapshot_output.result}</code>`;
warn(`${title} - <i>${idea}</i>`);
if (diffJsApiChangesOutput != null) {
const detail = `
<strong>JavaScript API change detected</strong>
This PR commits an update to <code>ReactNativeApi.d.ts</code>, indicating a change to React Native's public JavaScript API.
- Please include a <strong>clear changelog message</strong>.
- This change will be subject to additional review.
This change was flagged as: <strong><code>${diffJsApiChangesOutput.result}</code></strong>
`;
warn(detail.trim());
}
const hasNoUsefulBody =
@@ -14,6 +14,7 @@ const t = require('@babel/types');
const Result = {
BREAKING: 'BREAKING',
POTENTIALLY_BREAKING: 'POTENTIALLY_BREAKING',
POTENTIALLY_NON_BREAKING: 'POTENTIALLY_NON_BREAKING',
NON_BREAKING: 'NON_BREAKING',
} as const;
@@ -62,7 +63,7 @@ function analyzeSpecHashPairs(
const newHash = newSpecHashMapping[name];
if (hash !== newHash) {
// The hash has changed which means that the statement has changed
output.result = Result.BREAKING;
output.result = Result.POTENTIALLY_BREAKING;
output.changedApis.push(name);
}
delete newSpecHashMapping[name];
+3 -4
View File
@@ -35,10 +35,9 @@ async function main() {
Usage: node ./scripts/js-api/diff-api-snapshot <prev-snapshot> <new-snapshot>
Analyze changes between two versions of React Native's JavaScript API
snapshot (yarn build-types). Returns a JSON object with the following
fields:
- result: 'BREAKING', 'POTENTIALLY_NON_BREAKING' or 'NON_BREAKING'.
- changedApis: List of changed APIs.
snapshot (yarn build-types). Returns a JSON object with the following fields:
- result: 'BREAKING', 'POTENTIALLY_BREAKING', 'POTENTIALLY_NON_BREAKING' or 'NON_BREAKING'.
- changedApis: List of changed APIs.
`);
process.exitCode = 0;
return;