From a81f1d4bf2b65bf7f8197086c292d2c13d38ff6b Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 8 Apr 2026 00:03:33 +0100 Subject: [PATCH] feat: add argument parsers and CLI builders to preferred manifest --- docs/modules/README.md | 2 ++ docs/modules/commander.md | 33 +++++++++++++++++++++ docs/modules/parseargs.md | 24 ++++++++++++++++ manifests/preferred.json | 60 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 docs/modules/commander.md create mode 100644 docs/modules/parseargs.md diff --git a/docs/modules/README.md b/docs/modules/README.md index 5c8dda3..d7615b2 100644 --- a/docs/modules/README.md +++ b/docs/modules/README.md @@ -24,6 +24,7 @@ ESLint plugin. - [`chalk`](./chalk.md) - [`clean-webpack-plugin`](./clean-webpack-plugin.md) - [`clipboardy`](./clipboardy.md) +- [`commander`](./commander.md) - [`collection-map`](./collection-map.md) - [`core-util-is`](./core-util-is.md) - [`cosmiconfig`](./cosmiconfig.md) @@ -77,6 +78,7 @@ ESLint plugin. - [`md5`](./md5.md) - [`mkdirp`](./mkdirp.md) - [`moment.js`](./moment.md) +- [`mri`](./parseargs.md) - [`npm-run-all`](./npm-run-all.md) - [`node-fetch`](./fetch.md) - [`node-telegram-bot-api`](./node-telegram-bot-api.md) diff --git a/docs/modules/commander.md b/docs/modules/commander.md new file mode 100644 index 0000000..9fe8080 --- /dev/null +++ b/docs/modules/commander.md @@ -0,0 +1,33 @@ +--- +description: Modern alternatives to packages for building CLI applications +--- + +# Replacements for CLI builders + +## `sade` + +[`sade`](https://github.com/lukeed/sade) is a small but powerful tool for building CLI applications for Node.js + +```ts +import sade from 'sade' + +const prog = sade('my-cli') + +prog + .version('1.0.5') + .option('--global, -g', 'An example global flag') + .option('-c, --config', 'Provide path to custom config', 'foo.config.js') + +prog + .command('build ') + .describe('Build the source directory. Expects an `index.js` entry file.') + .option('-o, --output', 'Change the name of the output file', 'bundle.js') + .example('build src build --global --config my-conf.js') + .example('build app public -o main.js') + .action((src, dest, opts) => { + console.log(`> building from ${src} to ${dest}`) + console.log('> these are extra opts', opts) + }) + +prog.parse(process.argv) +``` diff --git a/docs/modules/parseargs.md b/docs/modules/parseargs.md new file mode 100644 index 0000000..51b3479 --- /dev/null +++ b/docs/modules/parseargs.md @@ -0,0 +1,24 @@ +--- +description: Modern alternatives to packages for CLI argument parsing +--- + +# Replacements for argument parsers + +## `util.parseArgs` (native, since Node.js 16.17.0) + +[`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig) can replace many common CLI parsing libraries such as `arg`, `minimist`, `mri`, `yargs-parser`. + +Example: + +```ts +import { parseArgs } from 'node:util' + +const { values, positionals } = parseArgs({ + args: process.argv.slice(2), + options: { + force: { type: 'boolean', short: 'f' }, + output: { type: 'string', short: 'o' } + }, + allowPositionals: true +}) +``` diff --git a/manifests/preferred.json b/manifests/preferred.json index c06ac71..64e235d 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -24,6 +24,12 @@ "replacements": ["fetch", "ofetch", "ky"], "url": {"type": "e18e", "id": "fetch"} }, + "arg": { + "type": "module", + "moduleName": "arg", + "replacements": ["util.parseArgs"], + "url": {"type": "e18e", "id": "parseargs"} + }, "axios": { "type": "module", "moduleName": "axios", @@ -108,6 +114,12 @@ "replacements": ["util.styleText", "picocolors", "ansis"], "url": {"type": "e18e", "id": "chalk"} }, + "commander": { + "type": "module", + "moduleName": "commander", + "replacements": ["sade"], + "url": {"type": "e18e", "id": "commander"} + }, "copy-text-to-clipboard": { "type": "module", "moduleName": "copy-text-to-clipboard", @@ -348,6 +360,12 @@ "replacements": ["dlv", "object-path"], "url": {"type": "e18e", "id": "dot-prop"} }, + "getopts": { + "type": "module", + "moduleName": "getopts", + "replacements": ["util.parseArgs"], + "url": {"type": "e18e", "id": "parseargs"} + }, "glob": { "type": "module", "moduleName": "glob", @@ -2388,6 +2406,18 @@ "replacements": ["node:crypto"], "url": {"type": "e18e", "id": "md5"} }, + "meow": { + "type": "module", + "moduleName": "meow", + "replacements": ["sade"], + "url": {"type": "e18e", "id": "commander"} + }, + "minimist": { + "type": "module", + "moduleName": "minimist", + "replacements": ["util.parseArgs"], + "url": {"type": "e18e", "id": "parseargs"} + }, "mkdirp": { "type": "module", "moduleName": "mkdirp", @@ -2400,6 +2430,12 @@ "replacements": ["day.js", "date-fns", "luxon", "Date"], "url": {"type": "e18e", "id": "moment"} }, + "mri": { + "type": "module", + "moduleName": "mri", + "replacements": ["util.parseArgs"], + "url": {"type": "e18e", "id": "parseargs"} + }, "node-fetch": { "type": "module", "moduleName": "node-fetch", @@ -2713,6 +2749,18 @@ "moduleName": "xmldom", "replacements": ["@xmldom/xmldom"], "url": {"type": "e18e", "id": "xmldom"} + }, + "yargs": { + "type": "module", + "moduleName": "yargs", + "replacements": ["sade"], + "url": {"type": "e18e", "id": "commander"} + }, + "yargs-parser": { + "type": "module", + "moduleName": "yargs-parser", + "replacements": ["util.parseArgs"], + "url": {"type": "e18e", "id": "parseargs"} } }, "replacements": { @@ -3390,6 +3438,12 @@ "url": {"type": "e18e", "id": "source-map-explorer"}, "replacementModule": "rollup-plugin-visualizer" }, + "sade": { + "id": "sade", + "type": "documented", + "url": {"type": "e18e", "id": "commander"}, + "replacementModule": "sade" + }, "smol-toml": { "id": "smol-toml", "type": "documented", @@ -3515,6 +3569,12 @@ "id": "api/util.html#utilisdeepstrictequalval1-val2-options" } }, + "util.parseArgs": { + "id": "util.parseArgs", + "type": "native", + "nodeFeatureId": {"moduleName": "node:util", "exportName": "parseArgs"}, + "url": {"type": "node", "id": "api/util.html#utilparseargsconfig"} + }, "util.stripVTControlCharacters": { "id": "util.stripVTControlCharacters", "type": "native",