diff --git a/@commitlint/cli/package.json b/@commitlint/cli/package.json index 8a62ba8503..d8a41f8744 100644 --- a/@commitlint/cli/package.json +++ b/@commitlint/cli/package.json @@ -38,7 +38,7 @@ "devDependencies": { "@commitlint/test": "^12.1.4", "@commitlint/utils": "^12.1.4", - "@types/yargs": "^16.0.0", + "@types/yargs": "^17.0.0", "execa": "^5.0.0", "fs-extra": "^10.0.0" }, diff --git a/@commitlint/cli/src/cli.ts b/@commitlint/cli/src/cli.ts index d113ff03da..bae03d6500 100644 --- a/@commitlint/cli/src/cli.ts +++ b/@commitlint/cli/src/cli.ts @@ -4,7 +4,7 @@ import read from '@commitlint/read'; import isFunction from 'lodash/isFunction'; import resolveFrom from 'resolve-from'; import resolveGlobal from 'resolve-global'; -import yargs from 'yargs'; +import yargs, {Arguments} from 'yargs'; import util from 'util'; import {CliFlags, Seed} from './types'; @@ -116,7 +116,7 @@ const cli = yargs ) .strict(); -main({edit: false, ...cli.argv}).catch((err) => { +main(cli.argv).catch((err) => { setTimeout(() => { if (err.type === pkg.name) { process.exit(1); @@ -141,7 +141,22 @@ async function stdin() { return result; } -async function main(options: CliFlags) { +type MainArgsObject = { + [key in keyof Arguments]: Arguments[key]; +}; +type MainArgsPromise = Promise; +type MainArgs = MainArgsObject | MainArgsPromise; + +async function resolveArgs(args: MainArgs): Promise { + return typeof args.then === 'function' ? await args : args; +} + +async function main(args: MainArgs) { + const options = await resolveArgs(args); + if (typeof options.edit === 'undefined') { + options.edit = false; + } + const raw = options._; const flags = normalizeFlags(options); diff --git a/@packages/utils/package.json b/@packages/utils/package.json index 8ced38d9e6..8cc72a1ca2 100644 --- a/@packages/utils/package.json +++ b/@packages/utils/package.json @@ -37,7 +37,7 @@ }, "license": "MIT", "devDependencies": { - "@types/yargs": "^16.0.0" + "@types/yargs": "^17.0.0" }, "dependencies": { "execa": "^5.0.0", diff --git a/yarn.lock b/yarn.lock index 934637ddb5..1b94da8706 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2400,10 +2400,10 @@ dependencies: "@types/yargs-parser" "*" -"@types/yargs@^16.0.0": - version "16.0.0" - resolved "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.0.tgz#0e033b23452da5d61b6c44747612cb80ac528751" - integrity sha512-2nN6AGeMwe8+O6nO9ytQfbMQOJy65oi1yK2y/9oReR08DaXSGtMsrLyCM1ooKqfICpCx4oITaR4LkOmdzz41Ww== +"@types/yargs@^17.0.0": + version "17.0.0" + resolved "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.0.tgz#32f740934eedf0a5cd19470249f317755c91f1ae" + integrity sha512-RS7u2X7vdXjVQs160PWY1pjLBw6GJj04utojn0KU8p2rRZR37FSzzK6XOT+KLzT/DVbDYRyezroc0LHIvM5Z2A== dependencies: "@types/yargs-parser" "*"