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
scripts/build-types
TypeScript build pipeline for React Native's JavaScript API.
Overview
yarn build-types is a custom build pipeline for translating React Native's Flow source code to TypeScript.
Specifically, it reduces the runtime JavaScript API of react-native into two outputs:
- Generated TypeScript types
Public user types for react-native, shipped to npm
packages/react-native/types_generated/ - Public API snapshot (experimental)
Snapshot file of the public API shape, used by maintainers
packages/react-native/ReactNativeApi.d.ts
Dependencies
yarn build-types makes use of the following dependencies, composed with other pre/post transformation steps and dependency resolution.
- Flow → TypeScript conversion: flow-api-extractor
- TypeScript → (initial) API rollup: @microsoft/api-extractor
Usage
yarn build-types is designed to be run by maintainers with minimal arguments.
API snapshot generation is currently experimental, and will be folded into the default behaviour when ready.
# Build types
yarn build-types
# Build types + API snapshot (experimental)
yarn build-types --withSnapshot [--validate]
Configuration
Sparse configuration options are defined and documented in scripts/build-types/config.js.
About the two formats
Generated TypeScript types
types_generated/
Directory providing TypeScript user types for the react-native package, distributed via npm.
- Gitignored.
- Scoped to the
index.d.tsentry point viapackage.json#exports. - Preserves
unstable_andexperimental_APIs. - Preserves doc comments.
- Preserves source file names (for go to definition).
Public API snapshot (experimental)
ReactNative.d.ts
Provides a human-readable, maintainable reference of the React Native's public JavaScript API, optimized for developers and diff tooling.
- Committed to the repo.
- Strips
unstable_andexperimental_APIs. - Strips doc comments.
- Strips source file names and some un-exported type names (WIP).