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

@bunli/generator

v0.6.4

Published

The Bunli command type generator that creates TypeScript definitions from your CLI commands using Bun's native APIs.

Downloads

3,502

Readme

@bunli/generator

The Bunli command type generator that creates TypeScript definitions from your CLI commands using Bun's native APIs.

Features

  • Bun-Native: Uses Bun.Glob for fast file scanning
  • Type-Safe: Generates full TypeScript definitions with module augmentation
  • Schema-Aware: Extracts metadata from Zod, Valibot, and other schema libraries
  • Watch Mode: Integrated with Bun's native watch capabilities
  • Minimal Dependencies: Uses Babel for AST parsing, Bun APIs for everything else

Usage

Basic Generation

import { Generator } from '@bunli/generator'
import { Result } from 'better-result'

const generator = new Generator({
  entry: './src/cli.ts',
  directory: './src/commands',
  outputFile: './.bunli/commands.gen.ts'
})

const runResult = await generator.run()
if (Result.isError(runResult)) {
  console.error(runResult.error.message)
}

With Watch Mode

import { Generator } from '@bunli/generator'
import { Result } from 'better-result'

const generator = new Generator({
  entry: './src/cli.ts',
  directory: './src/commands',
  outputFile: './.bunli/commands.gen.ts'
})

// Initial generation
const runResult = await generator.run()
if (Result.isError(runResult)) {
  console.error(runResult.error.message)
}

// Watch for changes (integrated with Bun's watch mode)
// This is handled automatically by bunli dev

Generated Output

The generator creates a commands.gen.ts file with:

// Generated command registry
export interface CommandRegistry {
  'deploy': {
    name: 'deploy'
    description: 'Deploy your application'
    options: {
      env: { type: 'string', required: true, description: 'Environment' }
      force: { type: 'boolean', required: false, default: false }
    }
    filePath: './commands/deploy.ts'
    exportPath: './commands/deploy'
  }
}

// Module augmentation for @bunli/core
declare module '@bunli/core' {
  interface GeneratedCommands extends CommandRegistry {}
}

// Helper functions
export function getCommandApi<T extends keyof CommandRegistry>(name: T): CommandRegistry[T]
export function getCommandNames(): (keyof CommandRegistry)[]
export function hasCommand(name: string): name is keyof CommandRegistry
export function getCommandByAlias(alias: string): keyof CommandRegistry | undefined
export function listCommands(): Array<{...}>

Command File Structure

The generator discovers command modules from your CLI entry (commands.entry / build.entry) and parses default-exported defineCommand / defineGroup calls:

import { defineCommand, option } from '@bunli/core'
import { z } from 'zod'

export default defineCommand({
  name: 'deploy',
  description: 'Deploy your application',
  alias: 'd',
  options: {
    env: option(z.string(), { 
      description: 'Environment to deploy to',
      short: 'e'
    }),
    force: option(z.boolean().default(false), {
      description: 'Force deployment'
    })
  },
  handler: async ({ flags }) => {
    // Implementation
  }
})

Integration with Bunli CLI

The generator is automatically integrated with:

  • bunli dev - Generates types and watches for changes
  • bunli build - Pre-build codegen step
  • bunli generate - Standalone generation command

Configuration

Configure the generator in your bunli.config.ts:

import { defineConfig } from '@bunli/core'

export default defineConfig({
  name: 'my-cli',
  version: '1.0.0',
})

API Reference

Generator

class Generator {
  constructor(config: GeneratorConfig)
  async run(event?: GeneratorEvent): Promise<Result<void, GeneratorRunError>>
  getConfig(): GeneratorConfig
  updateConfig(updates: Partial<GeneratorConfig>): void
}

Types

interface GeneratorConfig {
  entry: string
  directory?: string
  outputFile: string
  config?: any
}

interface GeneratorEvent {
  type: 'create' | 'update' | 'delete'
  path: string
}

interface CommandMetadata {
  name: string
  description: string
  alias?: string | string[]
  options?: Record<string, OptionMetadata>
  filePath: string
  exportPath: string
}

Performance

  • Fast Scanning: Uses Bun's native Bun.Glob for file discovery
  • Incremental: Only regenerates when command files change
  • Memory Efficient: Processes files one at a time
  • TypeScript Optimized: Generates minimal, efficient type definitions

License

MIT