mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51893 This diff adds `--validate` flag that runs snapshot validation to determine if the `ReactNativeApi.d.ts` rollup has been changed (if JS public API has been touched). There was also an issue with `sortProperties` that reordered some properties (ex. in ImagePropsBase) after removing one of them (ex. accessible) which had negative impact on the displayed result. ### Motivation Compare previous snapshot with the one built on the current revision to determine the impact of made changes on the public API surface. Display differences in human readable format using `diff` method from the `jest-diff` library. For now `--validate` flag is not useful on its own. It should be used with `--withSnapshot` flag (which will be removed shortly and generating snapshot will be a default mechanism). Changelog: [General][Added] - Add `--validate` flag to `build-types` script for JS API snapshot validation. Reviewed By: huntie Differential Revision: D76135158 fbshipit-source-id: 53f5b142c66e3e3931961f741c3f2fab8ccdc228
79 lines
1.6 KiB
JavaScript
79 lines
1.6 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
|
|
*/
|
|
|
|
require('../babel-register').registerForScript();
|
|
|
|
const buildApiSnapshot = require('./BuildApiSnapshot');
|
|
const buildGeneratedTypes = require('./buildGeneratedTypes');
|
|
const debug = require('debug');
|
|
const {parseArgs, styleText} = require('util');
|
|
|
|
const config = {
|
|
options: {
|
|
debug: {type: 'boolean'},
|
|
help: {type: 'boolean'},
|
|
withSnapshot: {type: 'boolean'},
|
|
validate: {type: 'boolean'},
|
|
},
|
|
};
|
|
|
|
async function main() {
|
|
const {
|
|
values: {debug: debugEnabled, help, withSnapshot, validate},
|
|
/* $FlowFixMe[incompatible-call] Natural Inference rollout. See
|
|
* https://fburl.com/workplace/6291gfvu */
|
|
} = parseArgs(config);
|
|
|
|
if (help) {
|
|
console.log(`
|
|
Usage: node ./scripts/build-types
|
|
|
|
Build generated TypeScript types for react-native.
|
|
|
|
Options:
|
|
--withSnapshot [Experimental] Include API snapshot generation.
|
|
`);
|
|
process.exitCode = 0;
|
|
return;
|
|
}
|
|
|
|
if (debugEnabled) {
|
|
debug.enable('build-types:*');
|
|
}
|
|
|
|
console.log(
|
|
'\n' +
|
|
styleText(
|
|
['bold', 'inverse'],
|
|
'Building generated react-native package types',
|
|
) +
|
|
'\n',
|
|
);
|
|
|
|
await buildGeneratedTypes();
|
|
|
|
if (withSnapshot) {
|
|
console.log(
|
|
'\n' +
|
|
styleText(
|
|
['bold', 'inverse', 'yellow'],
|
|
'EXPERIMENTAL - Building API snapshot',
|
|
) +
|
|
'\n',
|
|
);
|
|
|
|
await buildApiSnapshot(validate);
|
|
}
|
|
}
|
|
|
|
if (require.main === module) {
|
|
void main();
|
|
}
|