From 5d1724eaf34348332f2fac6993403e31a5928c7c Mon Sep 17 00:00:00 2001 From: junbao Date: Thu, 5 Aug 2021 19:10:10 +0800 Subject: [PATCH] fix(yargs): use positionals to fix #14, #15 --- package.json | 8 ++++---- src/bin/dpdm.ts | 19 +++++++++++++++---- yarn.lock | 24 ++++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index c42b615..71d4707 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dpdm", - "version": "3.7.0", + "version": "3.7.1", "description": "Analyze circular dependencies in your JavaScript/TypeScript projects.", "keywords": [ "circular", @@ -56,7 +56,7 @@ "lint-staged": "^11.1.1", "npm-run-all": "^4.1.5", "prettier": "^2.3.2", - "rollup": "^2.53.3", + "rollup": "^2.56.0", "ts-jest": "^27.0.4", "ts-node": "^10.1.0" }, @@ -64,13 +64,13 @@ "@types/fs-extra": "^9.0.12", "@types/glob": "^7.1.4", "@types/yargs": "^17.0.2", - "chalk": "^4.1.1", + "chalk": "^4.1.2", "fs-extra": "^10.0.0", "glob": "^7.1.7", "ora": "^5.4.1", "tslib": "^2.3.0", "typescript": "^4.3.5", - "yargs": "^17.0.1" + "yargs": "^17.1.0" }, "cliVersion": "8.8.4", "lint-staged": { diff --git a/src/bin/dpdm.ts b/src/bin/dpdm.ts index 2fa7a5b..a89cdf4 100644 --- a/src/bin/dpdm.ts +++ b/src/bin/dpdm.ts @@ -25,7 +25,18 @@ import { async function main() { const argv = await yargs .strict() - .usage('$0 [options] files...') + .usage( + '$0 [options] ', + "Analyze the files' dependencies.", + (yargs) => { + return yargs.positional('files', { + description: 'The file paths or globs', + demandOption: true, + type: 'string', + array: true, + }); + }, + ) .option('context', { type: 'string', desc: 'the context directory to shorten path, default is current directory', @@ -96,7 +107,9 @@ async function main() { .alias('h', 'help') .wrap(Math.min(yargs.terminalWidth(), 100)).argv; - if (argv._.length === 0) { + const files = argv.files as string[]; + + if (files.length === 0) { yargs.showHelp(); console.log('\nMissing entry file'); process.exit(1); @@ -152,8 +165,6 @@ async function main() { onProgress, }; - const files = argv._.filter((t) => typeof t === 'string') as string[]; - parseDependencyTree(files, options) .then(async (tree) => { o.succeed(`[${ended}/${total}] Analyze done!`); diff --git a/yarn.lock b/yarn.lock index b13eae3..dfaf131 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1169,6 +1169,14 @@ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.2: + version "4.1.2" + resolved "https://registry.nlark.com/chalk/download/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha1-qsTit3NKdAhnrrFr8CqtVWoeegE= + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + char-regex@^1.0.2: version "1.0.2" resolved "https://registry.nlark.com/char-regex/download/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf" @@ -3040,10 +3048,10 @@ rimraf@^3.0.0: dependencies: glob "^7.1.3" -rollup@^2.53.3: - version "2.53.3" - resolved "https://registry.nlark.com/rollup/download/rollup-2.53.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Frollup%2Fdownload%2Frollup-2.53.3.tgz#14b0e57f0874d4ad23bdbb13050cf70bcd1eabf7" - integrity sha1-FLDlfwh01K0jvbsTBQz3C80eq/c= +rollup@^2.56.0: + version "2.56.0" + resolved "https://registry.nlark.com/rollup/download/rollup-2.56.0.tgz#daa832955d2b58f1ed52a3c4c85b7d1adaf076d0" + integrity sha1-2qgylV0rWPHtUqPEyFt9GtrwdtA= optionalDependencies: fsevents "~2.3.2" @@ -3683,10 +3691,10 @@ yargs@^16.0.3: y18n "^5.0.5" yargs-parser "^20.2.2" -yargs@^17.0.1: - version "17.0.1" - resolved "https://registry.nlark.com/yargs/download/yargs-17.0.1.tgz?cache=0&sync_timestamp=1620086465147&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fyargs%2Fdownload%2Fyargs-17.0.1.tgz#6a1ced4ed5ee0b388010ba9fd67af83b9362e0bb" - integrity sha1-ahztTtXuCziAELqf1nr4O5Ni4Ls= +yargs@^17.1.0: + version "17.1.0" + resolved "https://registry.nlark.com/yargs/download/yargs-17.1.0.tgz#0cd9827a0572c9a1795361c4d1530e53ada168cf" + integrity sha1-DNmCegVyyaF5U2HE0VMOU62haM8= dependencies: cliui "^7.0.2" escalade "^3.1.1"