Files
react-native/packages/react-native/scripts/bundle.js
T
Tim YungandFacebook GitHub Bot e7a9322bdf RN: Flowify packages/react-native-scripts (#51671)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51671

Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic).

This will help improve type safety when making changes both in these files as well as files that these depend on.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75581879

fbshipit-source-id: 6dcd8cc55d0021973eeae2670c1ebceb6d69fa8f
2025-05-29 07:52:38 -07:00

83 lines
2.0 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 strict-local
* @format
*/
'use strict';
const {bundleCommand: bc} = require('@react-native/community-cli-plugin');
const {execSync} = require('child_process');
const commander = require('commander');
const {readFileSync} = require('fs');
const path = require('path');
// Commander 12.0.0 changes from the global to named export
// $FlowFixMe[signature-verification-failure]
const program = commander.program ?? commander;
program.version(
JSON.parse(
readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'),
).version,
);
program
.name(bc.name)
.description(bc.description ?? '')
.option(
'--config-cmd <string>',
'Command to generate a JSON project config',
'npx react-native config',
)
.option('--load-config <string>', 'JSON project config')
.option('--verbose', 'Additional logs', () => true, false)
.allowUnknownOption()
.action(async function handleAction() {
let config = null;
let options = program
.opts /*::<{
configCmd?: string,
loadConfig?: string,
verbose: boolean,
...
}>*/
();
if (options.loadConfig != null) {
config = JSON.parse(
options.loadConfig.replace(/^\W*'/, '').replace(/'\W*$/, ''),
);
} else if (options.configCmd != null) {
config = JSON.parse(
execSync(options.configCmd.trim(), {encoding: 'utf8'}),
);
}
if (config == null) {
throw new Error('No config provided');
}
await bc.func(program.args, config, options);
});
if (bc.options != null) {
for (const o of bc.options) {
program.option(
o.name,
o.description ?? '',
o.parse ?? (value => value),
o.default,
);
}
}
if (require.main === module) {
program.parse(process.argv);
}
module.exports = program;