npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ib-commander

v1.6.0

Published

A TypeScript framework for building structured CLI applications

Readme

ib-commander

A TypeScript framework for building structured CLI applications with a clean dispatch model.

ib <controller> <action> [--option value ...]

Requirements

  • Node.js >= 20
  • TypeScript with experimentalDecorators and emitDecoratorMetadata

Installation

npm install ib-commander reflect-metadata ts-ioc-container commander type-fest zod

TypeScript configuration

Enable decorator support in tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Quick Start

import 'reflect-metadata';
import { Application, SetupModule } from 'ib-commander';
import { bindTo, Container, inject, register, Registration } from 'ts-ioc-container';
import { z } from 'zod';
import { execute, onBefore, onDefault, onAfter, onError, readInput } from 'ib-commander';

const GreetOptionsSchema = z.object({
  name: z.string().default('World'),
});

@register(bindTo('greet'))
class GreetController {
  @onBefore(execute())
  setup() {
    // runs before every action
  }

  @onDefault(execute())
  hello(@inject(readInput(GreetOptionsSchema, (cmd) => cmd.option('--name <name>'))) opts: z.infer<typeof GreetOptionsSchema>) {
    console.log(`Hello, ${opts.name}!`);
  }

  @onAfter(execute())
  teardown() {
    // runs after every action
  }

  @onError(execute())
  onError() {
    // runs when an action throws
  }
}

const container = new Container().useModule(new SetupModule()).addRegistration(Registration.fromClass(GreetController));
Application.bootstrap(container).run();

Run it:

node dist/main.js greet --name Alice
# Hello, Alice!

node dist/main.js greet
# Hello, World!

Dispatch Model

Each CLI invocation is routed as:

  1. Parse process.argv to extract controller, action (defaults to "default"), and named options.
  2. Resolve the controller class from the IoC container by token.
  3. Run hooks in order: onBefore → action → onAfter. On error: onErrorIErrorHandler.

Decorators

| Decorator | Description | | -------------------- | ------------------------------------------------ | | @onBefore(...fns) | Runs before every action on the controller | | @onDefault(...fns) | Marks the method as the default action handler | | @onAfter(...fns) | Runs after every action on the controller | | @onError(...fns) | Runs when an action throws an error |

Pass execute() as the hook function to invoke the decorated method:

@onDefault(execute())
myAction() { ... }

Input Parsing

Use readInput(schema, mapCommand?) with @inject to receive validated, typed options:

const MySchema = z.object({
  output: z.string(),
  verbose: z.boolean().optional(),
});

@onDefault(execute())
generate(
  @inject(readInput(MySchema, (cmd) => cmd.option('--output <path>').option('--verbose')))
  opts: z.infer<typeof MySchema>
) {
  console.log(opts.output);
}

Options are parsed from process.argv and validated against the Zod schema. A ValidationError is thrown if validation fails.

You can also extend the base schema that includes controller and action:

import { BASIC_OPTION_SCHEMA } from 'ib-commander';

const MySchema = BASIC_OPTION_SCHEMA.extend({ output: z.string() });

Container Setup

SetupModule registers the default implementations of IInputService, IErrorHandler, and ILogger:

const container = new Container().useModule(new SetupModule());

Register controllers using ts-ioc-container's @register + bindTo, then apply the registration to the container:

@register(bindTo('changelog'))
class ChangelogController { ... }

const container = new Container()
  .useModule(new SetupModule())
  .addRegistration(Registration.fromClass(ChangelogController));

The token ('changelog') is the first positional argument in the CLI invocation.

Customizing Services

Replace any built-in service by registering your own implementation:

import { IErrorHandlerKey, ILoggerKey, IInputServiceKey, Provider } from 'ib-commander';

container.register(IErrorHandlerKey.token, Provider.fromValue(myErrorHandler));
container.register(ILoggerKey.token, Provider.fromValue(myLogger));

IErrorHandler

interface IErrorHandler {
  handleError(error: unknown): void;
}

Default: logs to console.error and exits with code 1.

ILogger

interface ILogger {
  info(...args: unknown[]): void;
  error(...args: unknown[]): void;
}

Default: delegates to console.log / console.error.

Error Handling

Errors thrown inside action methods are:

  1. Passed to any @onError hooks on the same controller.
  2. Forwarded to IErrorHandler.handleError().
  3. Process exits with code 1 (default handler).

Unknown controller tokens produce a typed ControllerNotFoundError; unknown actions produce ActionNotFoundError. Both are forwarded to IErrorHandler.

Validation Utility

validateBySchema can be used standalone outside of hook injection:

import { validateBySchema } from 'ib-commander';
import { z } from 'zod';

const parse = validateBySchema(z.object({ name: z.string() }));
const result = parse({ name: 'Alice' }); // typed result or throws ValidationError

License

MIT © Igor Babkin