Skip to content

Commit

Permalink
chore: update dependency @types/yargs to v17 (#2613)
Browse files Browse the repository at this point in the history
* chore: update dependency @types/yargs to v17

* fix(cli): refactor types to fix when yargs arguments is a Promise

I a update to the "yargs" types they added a `Promise` to the `Args`
interface. The main cli did not handle this type and failed type
checking. Now the main will handle a `Promise` by resolving it into
the `CliFlags` interface that is expected.

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Ade Attwood <[email protected]>
  • Loading branch information
3 people authored May 24, 2021
1 parent be701bd commit b837faf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion @commitlint/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
21 changes: 18 additions & 3 deletions @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -141,7 +141,22 @@ async function stdin() {
return result;
}

async function main(options: CliFlags) {
type MainArgsObject = {
[key in keyof Arguments<CliFlags>]: Arguments<CliFlags>[key];
};
type MainArgsPromise = Promise<MainArgsObject>;
type MainArgs = MainArgsObject | MainArgsPromise;

async function resolveArgs(args: MainArgs): Promise<MainArgsObject> {
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);

Expand Down
2 changes: 1 addition & 1 deletion @packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"license": "MIT",
"devDependencies": {
"@types/yargs": "^16.0.0"
"@types/yargs": "^17.0.0"
},
"dependencies": {
"execa": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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" "*"

Expand Down

0 comments on commit b837faf

Please sign in to comment.