Files
react-native/scripts/js-api/diff-api-snapshot/index.js
T
Alex Hunt a22ab422e8 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
2025-12-16 08:14:38 -08:00

61 lines
1.5 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
require('../../shared/babelRegister').registerForScript();
const {diffApiSnapshot} = require('./diffApiSnapshot');
const fs = require('fs');
const {parseArgs} = require('util');
const config = {
allowPositionals: true,
options: {
help: {type: 'boolean'},
},
};
async function main() {
const {
positionals: [prevSnapshot, newSnapshot],
values: {help},
/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
* https://fburl.com/workplace/6291gfvu */
} = parseArgs(config);
if (help) {
console.log(`
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_BREAKING', 'POTENTIALLY_NON_BREAKING' or 'NON_BREAKING'.
- changedApis: List of changed APIs.
`);
process.exitCode = 0;
return;
}
try {
const result = diffApiSnapshot(
fs.readFileSync(prevSnapshot, 'utf8'),
fs.readFileSync(newSnapshot, 'utf8'),
);
console.log(JSON.stringify(result, null, 2));
} catch (e) {
console.error('Error parsing API snapshot:', e);
process.exitCode = 1;
}
}
if (require.main === module) {
void main();
}