Skip to content

Installation

Terminal window
# npm
npm install clibuilder
# yarn
yarn add clibuilder
# pnpm
pnpm add clibuilder
# rush
rush add -p clibuilder
  • Node.js 20.19 or newer.
  • TypeScript is optional but recommended. The type inference in run(args) is the main reason to use clibuilder over a hand-rolled parser; in plain JavaScript everything still works, you just don’t see the inferred types.

clibuilder 11 publishes both ESM and CJS. clibuilder 12 publishes ESM only, and require('clibuilder') still works through Node’s require(esm), which Node.js 20.19 and newer have unflagged. Either of these works:

// ESM
import { cli, command, t } from 'clibuilder'
// CJS
const { cli, command, t } = require('clibuilder')

Arguments and options declare their type with t, which clibuilder exports. You install nothing for it.

import { t } from 'clibuilder'

A command’s config takes any Standard Schema. Install the library you pick as your own dependency, for example npm install zod.

js-yaml is an optional peer dependency. If your users write a .yaml or .yml config file, install it too:

Terminal window
npm install js-yaml

Without it, reading a YAML config fails with a CliError whose code is missing-peer-dependency. JSON, JSONC, cjs and mjs config files need nothing extra.

Build something with it: Your First CLI.