Skip to content

Commit

Permalink
Convert cli-commands to Flow strict
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Differential Revision: https://internalfb.com/D48066180

fbshipit-source-id: 150f23c239c9f7474798eab4004c9c9f7abd25fb
  • Loading branch information
Alex Hunt authored and facebook-github-bot committed Aug 11, 2023
1 parent 6f402b3 commit c65f1a0
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 33 deletions.
30 changes: 30 additions & 0 deletions flow-typed/npm/@react-native-community/cli-types_v12.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@
*/

declare module '@react-native-community/cli-types' {
declare export type CommandFunction<Args = Object> = (
argv: Array<string>,
ctx: Config,
args: Args,
) => Promise<void> | void;

declare export type OptionValue = string | boolean | number;

declare export type CommandOption<T = (ctx: Config) => OptionValue> = {
name: string,
description?: string,
parse?: (val: string) => any,
default?: OptionValue | T,
};

declare export type Command = {
name: string,
description?: string,
examples?: Array<{
desc: string,
cmd: string,
}>,
pkg?: {
name: string,
version: string,
},
func: CommandFunction<Object>,
options?: Array<CommandOption<(ctx: Config) => OptionValue>>,
};

declare type PlatformConfig = {
npmPackageName: string,
...
Expand Down
104 changes: 104 additions & 0 deletions flow-typed/npm/chalk_v4.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* 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
*/

declare module 'chalk' {
declare type TemplateStringsArray = $ReadOnlyArray<string>;

declare type Level = $Values<{
None: 0,
Basic: 1,
Ansi256: 2,
TrueColor: 3,
...
}>;

declare type ChalkOptions = {
enabled?: boolean,
level?: Level,
};

declare type ColorSupport = {
level: Level,
hasBasic: boolean,
has256: boolean,
has16m: boolean,
};

declare type Chalk = {
(...text: string[]): string,
(text: TemplateStringsArray, ...placeholders: string[]): string,
Instance(options?: ChalkOptions): Chalk,
level: Level,
rgb(r: number, g: number, b: number): Chalk,
hsl(h: number, s: number, l: number): Chalk,
hsv(h: number, s: number, v: number): Chalk,
hwb(h: number, w: number, b: number): Chalk,
bgHex(color: string): Chalk,
bgKeyword(color: string): Chalk,
bgRgb(r: number, g: number, b: number): Chalk,
bgHsl(h: number, s: number, l: number): Chalk,
bgHsv(h: number, s: number, v: number): Chalk,
bgHwb(h: number, w: number, b: number): Chalk,
hex(color: string): Chalk,
keyword(color: string): Chalk,

+reset: Chalk,
+bold: Chalk,
+dim: Chalk,
+italic: Chalk,
+underline: Chalk,
+inverse: Chalk,
+hidden: Chalk,
+strikethrough: Chalk,

+visible: Chalk,

+black: Chalk,
+red: Chalk,
+green: Chalk,
+yellow: Chalk,
+blue: Chalk,
+magenta: Chalk,
+cyan: Chalk,
+white: Chalk,
+gray: Chalk,
+grey: Chalk,
+blackBright: Chalk,
+redBright: Chalk,
+greenBright: Chalk,
+yellowBright: Chalk,
+blueBright: Chalk,
+magentaBright: Chalk,
+cyanBright: Chalk,
+whiteBright: Chalk,

+bgBlack: Chalk,
+bgRed: Chalk,
+bgGreen: Chalk,
+bgYellow: Chalk,
+bgBlue: Chalk,
+bgMagenta: Chalk,
+bgCyan: Chalk,
+bgWhite: Chalk,
+bgBlackBright: Chalk,
+bgRedBright: Chalk,
+bgGreenBright: Chalk,
+bgYellowBright: Chalk,
+bgBlueBright: Chalk,
+bgMagentaBright: Chalk,
+bgCyanBright: Chalk,
+bgWhiteBrigh: Chalk,

supportsColor: ColorSupport,
};

declare module.exports: Chalk;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down Expand Up @@ -64,7 +64,7 @@ async function buildBundleWithConfig(
process.env.NODE_ENV = args.dev ? 'development' : 'production';

let sourceMapUrl = args.sourcemapOutput;
if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
if (sourceMapUrl != null && !args.sourcemapUseAbsolutePath) {
sourceMapUrl = path.basename(sourceMapUrl);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/community-cli-plugin/src/commands/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand All @@ -22,7 +22,8 @@ export function bundleWithOutput(
_: Array<string>,
config: Config,
args: CommandLineArgs,
output: any, // untyped metro/src/shared/output/bundle or metro/src/shared/output/RamBundle
// $FlowFixMe[unclear-type] untyped metro/src/shared/output/bundle or metro/src/shared/output/RamBundle
output: any,
): Promise<void> {
return buildBundle(args, config, output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
23 changes: 13 additions & 10 deletions packages/community-cli-plugin/src/commands/bundle/ramBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/

import type {Config} from '@react-native-community/cli-types';
import type {Command, Config} from '@react-native-community/cli-types';
import type {CommandLineArgs} from './bundleCommandLineArgs';

import outputUnbundle from 'metro/src/shared/output/RamBundle';
Expand All @@ -27,17 +27,20 @@ function ramBundle(
return bundleWithOutput(argv, config, args, outputUnbundle);
}

export default {
export default ({
name: 'ram-bundle',
description:
'Build the RAM bundle for the provided JavaScript entry file. See https://reactnative.dev/docs/ram-bundles-inline-requires.',
func: ramBundle,
options: (bundleCommandLineArgs.concat({
name: '--indexed-ram-bundle',
description:
'Force the "Indexed RAM" bundle file format, even when building for android',
default: false,
}): Array<Object>),
};
options: [
...bundleCommandLineArgs,
{
name: '--indexed-ram-bundle',
description:
'Force the "Indexed RAM" bundle file format, even when building for android',
default: false,
},
],
}: Command);

export {ramBundle};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down Expand Up @@ -34,7 +34,7 @@ async function saveAssets(
assetsDest?: string,
assetCatalogDest?: string,
): Promise<void> {
if (!assetsDest) {
if (assetsDest == null) {
logger.warn('Assets destination folder is not set, skipping...');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/community-cli-plugin/src/commands/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/community-cli-plugin/src/commands/start/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ async function runServer(_argv: Array<string>, ctx: Config, args: Args) {
server: Server,
) => {
if (customEnhanceMiddleware) {
metroMiddleware = customEnhanceMiddleware(metroMiddleware, server);
return middleware.use(customEnhanceMiddleware(metroMiddleware, server));
}
return middleware.use(metroMiddleware);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down Expand Up @@ -45,6 +45,7 @@ function enableWatchMode(
// As a result we have to implement our own method for exiting
// and other commands (e.g. ctrl+c & ctrl+z)
// $FlowIgnore[method-unbinding]
// $FlowFixMe[sketchy-null-mixed]
if (!process.stdin.setRawMode) {
logger.debug('Watch mode is not supported in this environment');
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/community-cli-plugin/src/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/community-cli-plugin/src/utils/KeyPressHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/community-cli-plugin/src/utils/loadMetroConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
* @oncall react_native
*/
Expand Down
Loading

0 comments on commit c65f1a0

Please sign in to comment.