From 5d2a400e9953a4f8dd1ff8e034680ac041b77dc7 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 23 Sep 2022 18:00:18 -0700 Subject: [PATCH] JS: Update Flow Definitions for `yargs` to v17 Summary: Changelog: [Internal] Reviewed By: GijsWeterings Differential Revision: D39677869 fbshipit-source-id: 4495b0c6c5e245d20034906fff4547265c7cc157 --- .../inspector/tools/msggen/src/index.js | 4 +- flow-typed/npm/yargs_v17.x.x.js | 341 ++++++++++++++++++ 2 files changed, 343 insertions(+), 2 deletions(-) create mode 100644 flow-typed/npm/yargs_v17.x.x.js diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/index.js b/ReactCommon/hermes/inspector/tools/msggen/src/index.js index 1a137ac7170759..7952d539f30eab 100644 --- a/ReactCommon/hermes/inspector/tools/msggen/src/index.js +++ b/ReactCommon/hermes/inspector/tools/msggen/src/index.js @@ -197,8 +197,8 @@ function filterReachableFromRoots( return {types, commands, events}; } -function main() { - const args = yargs +async function main(): Promise { + const args = await yargs .usage('Usage: msggen ') .alias('h', 'help') .help('h') diff --git a/flow-typed/npm/yargs_v17.x.x.js b/flow-typed/npm/yargs_v17.x.x.js new file mode 100644 index 00000000000000..2750236797a305 --- /dev/null +++ b/flow-typed/npm/yargs_v17.x.x.js @@ -0,0 +1,341 @@ +// flow-typed signature: cab38813101e0a162deaae556391abc8 +// flow-typed version: f7c859e705/yargs_v17.x.x/flow_>=v0.104.x + +declare module "yargs" { + declare type Argv = { + [key: string]: any, + _: Array, + $0: string, + ... + }; + + declare type Options = $Shape<{ + alias: string | Array, + array: boolean, + boolean: boolean, + choices: Array, + coerce: (arg: {[key: string]: any, ...} | any) => mixed, + config: boolean, + configParser: (configPath: string) => { [key: string]: mixed, ... }, + conflicts: string | Array | { [key: string]: string, ... }, + count: boolean, + default: mixed, + defaultDescription: string, + demandOption: boolean | string, + desc: string, + describe: string, + description: string, + global: boolean, + group: string, + hidden: boolean, + implies: string | { [key: string]: string, ... }, + nargs: number, + normalize: boolean, + number: boolean, + required: boolean, + requiresArg: boolean, + skipValidation: boolean, + string: boolean, + type: "array" | "boolean" | "count" | "number" | "string", + ... + }>; + + declare type CommonModuleObject = {| + command?: string | Array, + aliases?: Array | string, + builder?: { [key: string]: Options, ... } | ((yargsInstance: Yargs) => mixed), + handler?: ((argv: Argv) => void) | ((argv: Argv) => Promise) + |}; + + declare type ModuleObjectDesc = {| + ...CommonModuleObject, + desc?: string | false + |}; + + declare type ModuleObjectDescribe = {| + ...CommonModuleObject, + describe?: string | false + |}; + + declare type ModuleObjectDescription = {| + ...CommonModuleObject, + description?: string | false + |}; + + declare type ModuleObject = + | ModuleObjectDesc + | ModuleObjectDescribe + | ModuleObjectDescription; + + declare type MiddleWareCallback = + | (argv: Argv, yargsInstance?: Yargs) => void + | (argv: Argv, yargsInstance?: Yargs) => Promise; + + declare type Middleware = MiddleWareCallback | Array; + + declare class Yargs { + (args: Array): Yargs; + + alias(key: string, alias: string): this; + alias(alias: { [key: string]: string | Array, ... }): this; + argv: Argv | Promise; + array(key: string | Array): this; + boolean(parameter: string | Array): this; + check(fn: (argv: Argv, options: Array) => mixed): this; + choices(key: string, allowed: Array): this; + choices(allowed: { [key: string]: Array, ... }): this; + coerce(key: string, fn: (value: any) => mixed): this; + coerce(object: { [key: string]: (value: any) => mixed, ... }): this; + coerce(keys: Array, fn: (value: any) => mixed): this; + + command( + cmd: string | Array, + desc: string | false, + builder?: + | { [key: string]: Options, ... } + | ((yargsInstance: Yargs) => mixed), + handler?: Function + ): this; + command( + cmd: string | Array, + desc: string | false, + module: ModuleObject + ): this; + command(module: ModuleObject): this; + + commands( + cmd: string | Array, + desc: string | false, + builder?: + | { [key: string]: Options, ... } + | ((yargsInstance: Yargs) => mixed), + handler?: Function + ): this; + commands( + cmd: string | Array, + desc: string | false, + module: ModuleObject + ): this; + commands(module: ModuleObject): this; + + commandDir( + directory: string, + options?: { + exclude?: string | Function, + extensions?: Array, + include?: string | Function, + recurse?: boolean, + visit?: Function, + ... + }, + ): this; + + completion( + cmd?: string, + description?: string | false | ( + current: string, + argv: Argv, + done: (compeltion: Array) => void + ) => ?(Array | Promise>), + fn?: ( + current: string, + argv: Argv, + done: (completion: Array) => void + ) => ?(Array | Promise>) + ): this; + + config( + key?: string, + description?: string, + parseFn?: (configPath: string) => { [key: string]: mixed, ... } + ): this; + config( + key: string, + parseFn?: (configPath: string) => { [key: string]: mixed, ... } + ): this; + config(config: { [key: string]: mixed, ... }): this; + + conflicts(key: string, value: string | Array): this; + conflicts(keys: { [key: string]: string | Array, ... }): this; + + count(name: string): this; + + default(key: string, value: mixed, description?: string): this; + default(defaults: { [key: string]: mixed, ... }): this; + + // Deprecated: use demandOption() and demandCommand() instead. + demand(key: string, msg?: string | boolean): this; + demand(count: number, max?: number, msg?: string | boolean): this; + + demandOption(key: string | Array, msg?: string | boolean): this; + + demandCommand(): this; + demandCommand(min: number, minMsg?: string): this; + demandCommand( + min: number, + max: number, + minMsg?: string, + maxMsg?: string + ): this; + + describe(key: string, description: string): this; + describe(describeObject: { [key: string]: string, ... }): this; + + detectLocale(shouldDetect: boolean): this; + + env(prefix?: string): this; + + epilog(text: string): this; + epilogue(text: string): this; + + example(cmd: string, desc?: string): this; + + exitProcess(enable: boolean): this; + + fail(fn: (failureMessage: string, err: Error, yargs: Yargs) => mixed): this; + + getCompletion( + args: Array, + fn: (err: Error | null, completions: Array | void) => void + ): Promise | void>; + + global(globals: string | Array, isGlobal?: boolean): this; + + group(key: string | Array, groupName: string): this; + + help(option: boolean): this; + + help(option?: string, desc?: string): this; + + hide(key: string): this; + + implies(key: string, value: string | Array): this; + implies(keys: { [key: string]: string | Array, ... }): this; + + locale( + locale: | "de" + | "en" + | "es" + | "fr" + | "hi" + | "hu" + | "id" + | "it" + | "ja" + | "ko" + | "nb" + | "pirate" + | "pl" + | "pt" + | "pt_BR" + | "ru" + | "th" + | "tr" + | "zh_CN" + ): this; + locale(): string; + + middleware( + middlewareCallbacks: Middleware, + applyBeforeValidation?: boolean, + ): this; + + nargs(key: string, count: number): this; + + normalize(key: string): this; + + number(key: string | Array): this; + + option(key: string, options?: Options): this; + option(optionMap: { [key: string]: Options, ... }): this; + + options(key: string, options?: Options): this; + options(optionMap: { [key: string]: Options, ... }): this; + + parse( + args?: string | Array, + context?: { [key: string]: any, ... }, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Argv | Promise; + parse( + args?: string | Array, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Argv | Promise; + + parseAsync( + args?: string | Array, + context?: { [key: string]: any, ... }, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Promise; + parseAsync( + args?: string | Array, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Promise; + + parseSync( + args?: string | Array, + context?: { [key: string]: any, ... }, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Argv; + parseSync( + args?: string | Array, + parseCallback?: (err: Error, argv: Argv, output?: string) => void + ): Argv; + + parserConfiguration(configuration: {[key: string]: any, ...}): this; + + pkgConf(key: string, cwd?: string): this; + + positional(key: string, opt?: Options): this; + + recommendCommands(): this; + + // Alias of demand() + require(key: string, msg: string | boolean): this; + require(count: number, max?: number, msg?: string | boolean): this; + + requiresArg(key: string | Array): this; + + scriptName(name: string): this; + + showCompletionScript(): this; + + showHelp(consoleLevel?: "error" | "warn" | "log"): this; + showHelp(printCallback: (usageData: string) => void): this; + + showHelpOnFail(enable: boolean, message?: string): this; + + skipValidation(key: string): this; + + showVersion(consoleLevel?: "error" | "warn" | "log"): this; + showVersion(printCallback: (usageData: string) => void): this; + + strict(enabled?: boolean): this; + + strictCommands(enabled?: boolean): this; + + strictOptions(enabled?: boolean): this; + + string(key: string | Array): this; + + terminalWidth(): number; + + updateLocale(obj: { [key: string]: string, ... }): this; + updateStrings(obj: { [key: string]: string, ... }): this; + + usage(message: string, opts?: { [key: string]: Options, ... }): this; + + version(): this; + version(version: string | false): this; + version(option: string | (() => string), version: string): this; + version( + option: string | (() => string), + description: string | (() => string), + version: string + ): this; + + wrap(columns: number | null): this; + } + + declare module.exports: Yargs; +}