Files
react-native/scripts/build-types/index.js
T
Alex Hunt 050fb25c14 Add debug flag to show versionExportedApis graph in output (#52298)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52298

Exposes the ability to output inline debug annotations for the `versionExportedApis` transform (D77303917) as a formalised `--debug-version-annotations` CLI flag.

This is helpful for debugging and future maintenance, and will be used to show the effect of the next diffs.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D77373723

fbshipit-source-id: 91c91abcb657ab88ee2f8209efccb4024602acc7
2025-06-26 10:46:23 -07:00

94 lines
2.3 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'},
'debug-version-annotations': {type: 'boolean'},
help: {type: 'boolean'},
withSnapshot: {type: 'boolean'},
validate: {type: 'boolean'},
},
};
async function main() {
const {
values: {
debug: debugEnabled,
'debug-version-annotations': debugVersionAnnotations,
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:
--debug Enable debug logging.
--debug-version-annotations
Outputs debug info alongside versioned type hashes as
part of the API snapshot contents.
--withSnapshot [Experimental] Include API snapshot generation.
--validate Validate if the current API snapshot on disk is up to
date. Exits with an error if differences are detected.
`);
process.exitCode = 0;
return;
}
if (validate && !withSnapshot) {
console.error(
"build-types: '--validate' can only be used with '--withSnapshot'.",
);
process.exitCode = 2;
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(
styleText(['bold', 'inverse'], ' [Experimental] Building API snapshot ') +
'\n',
);
await buildApiSnapshot({validate, debugVersionAnnotations});
}
}
if (require.main === module) {
void main();
}