Skip to content

Commit b837faf

Browse files
renovate[bot]renovate-botAdeAttwood
authored
chore: update dependency @types/yargs to v17 (conventional-changelog#2613)
* 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]>
1 parent be701bd commit b837faf

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

@commitlint/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"devDependencies": {
3939
"@commitlint/test": "^12.1.4",
4040
"@commitlint/utils": "^12.1.4",
41-
"@types/yargs": "^16.0.0",
41+
"@types/yargs": "^17.0.0",
4242
"execa": "^5.0.0",
4343
"fs-extra": "^10.0.0"
4444
},

@commitlint/cli/src/cli.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import read from '@commitlint/read';
44
import isFunction from 'lodash/isFunction';
55
import resolveFrom from 'resolve-from';
66
import resolveGlobal from 'resolve-global';
7-
import yargs from 'yargs';
7+
import yargs, {Arguments} from 'yargs';
88
import util from 'util';
99

1010
import {CliFlags, Seed} from './types';
@@ -116,7 +116,7 @@ const cli = yargs
116116
)
117117
.strict();
118118

119-
main({edit: false, ...cli.argv}).catch((err) => {
119+
main(cli.argv).catch((err) => {
120120
setTimeout(() => {
121121
if (err.type === pkg.name) {
122122
process.exit(1);
@@ -141,7 +141,22 @@ async function stdin() {
141141
return result;
142142
}
143143

144-
async function main(options: CliFlags) {
144+
type MainArgsObject = {
145+
[key in keyof Arguments<CliFlags>]: Arguments<CliFlags>[key];
146+
};
147+
type MainArgsPromise = Promise<MainArgsObject>;
148+
type MainArgs = MainArgsObject | MainArgsPromise;
149+
150+
async function resolveArgs(args: MainArgs): Promise<MainArgsObject> {
151+
return typeof args.then === 'function' ? await args : args;
152+
}
153+
154+
async function main(args: MainArgs) {
155+
const options = await resolveArgs(args);
156+
if (typeof options.edit === 'undefined') {
157+
options.edit = false;
158+
}
159+
145160
const raw = options._;
146161
const flags = normalizeFlags(options);
147162

@packages/utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"license": "MIT",
3939
"devDependencies": {
40-
"@types/yargs": "^16.0.0"
40+
"@types/yargs": "^17.0.0"
4141
},
4242
"dependencies": {
4343
"execa": "^5.0.0",

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2400,10 +2400,10 @@
24002400
dependencies:
24012401
"@types/yargs-parser" "*"
24022402

2403-
"@types/yargs@^16.0.0":
2404-
version "16.0.0"
2405-
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.0.tgz#0e033b23452da5d61b6c44747612cb80ac528751"
2406-
integrity sha512-2nN6AGeMwe8+O6nO9ytQfbMQOJy65oi1yK2y/9oReR08DaXSGtMsrLyCM1ooKqfICpCx4oITaR4LkOmdzz41Ww==
2403+
"@types/yargs@^17.0.0":
2404+
version "17.0.0"
2405+
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.0.tgz#32f740934eedf0a5cd19470249f317755c91f1ae"
2406+
integrity sha512-RS7u2X7vdXjVQs160PWY1pjLBw6GJj04utojn0KU8p2rRZR37FSzzK6XOT+KLzT/DVbDYRyezroc0LHIvM5Z2A==
24072407
dependencies:
24082408
"@types/yargs-parser" "*"
24092409

0 commit comments

Comments
 (0)