Upgrading commander 8 to 9
Breaking8.3.0 → 9.5.0Breaking2Platform1Deprecated1New12Changed10Fixed7Other5
BreakingUpgrade verdict
2 breaking changes and a platform requirement change.
In plain terms
- A boolean option's declared default is now always applied; use .preset() to reproduce some previous behaviours.
- Commander no longer guesses the script name from require.main.filename; supply details yourself.
- You must run Node.js version 12.20.0 or newer to use this version.
- Short flags made of more than one character, like -ws, are now deprecated.
Must act 4 items need code or config changes
Node.js requirement changed in 9.0.0-0: >= 12 → ^12.20.0 || >=14.
What you must change
Breaking2
Default value specified for a boolean option is now always used as the default value.
.preset()Removes internal fallback to require.main.filename when the script is not known from arguments passed to .parse().
require.main.filename.parse().name().executableDir()executableFilePlatform1
Commander 9 requires Node.js v12.20.0 or higher.
Deprecations to plan for
Deprecated1
Deprecates multi-character short option flags such as -ws.
-wsAPI changes
Generated by DepDelta from published .d.ts files. Not mixed with prose notes.
- changed:
method Argument.choices(values: string[]): this → method Argument.choices(values: readonly string[]): this - changed:
method Command.aliases(aliases: string[]): this → method Command.aliases(aliases: readonly string[]): this - changed:
method Command.exitOverride(callback?: (err: CommanderError) => never|void): this → method Command.exitOverride(callback?: (err: CommanderError) => never | void): this - changed:
method Command.getOptionValueSource(key: string): OptionValueSource → method Command.getOptionValueSource(key: string): OptionValueSource | undefined - changed:
method Command.option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this → method Command.option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this - changed:
method Command.option(flags: string, description?: string, defaultValue?: string | boolean): this → method Command.option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this - changed:
method Command.parse(argv?: string[], options?: ParseOptions): this → method Command.parse(argv?: readonly string[], options?: ParseOptions): this - changed:
method Command.parseAsync(argv?: string[], options?: ParseOptions): Promise<this> → method Command.parseAsync(argv?: readonly string[], options?: ParseOptions): Promise<this> - changed:
method Command.requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this → method Command.requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this - changed:
method Command.requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this → method Command.requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this - changed:
method Option.choices(values: string[]): this → method Option.choices(values: readonly string[]): this - changed:
type HookEvent = 'preAction' | 'postAction' → type HookEvent = 'preSubcommand' | 'preAction' | 'postAction' - changed:
type OptionValueSource = 'default' | 'env' | 'config' | 'cli' → type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied' - added:
interface ErrorOptions - added:
method Command.error(message: string, errorOptions?: ErrorOptions): never - added:
method Command.executableDir(): string - added:
method Command.executableDir(path: string): this - added:
method Command.getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined - added:
method Command.nameFromFilename(filename: string): this - added:
method Command.optsWithGlobals<T extends OptionValues>(): T - added:
method Command.summary(): string - added:
method Command.summary(str: string): this - added:
method Help.longestGlobalOptionTermLength(cmd: Command, helper: Help): number - added:
method Help.visibleGlobalOptions(cmd: Command): Option[] - added:
method Option.conflicts(names: string | string[]): this - added:
method Option.implies(optionValues: OptionValues): this - added:
method Option.isBoolean(): boolean - added:
method Option.preset(arg: unknown): this - added:
property ErrorOptions.code?: string - added:
property ErrorOptions.exitCode?: number - added:
property Help.showGlobalOptions: boolean