Skip to content
/ dtsx Public

Extremely fast & configurable .d.ts emitter.

License

Notifications You must be signed in to change notification settings

stacksjs/dtsx

Repository files navigation

Social Card of this repo

npm version GitHub Actions Commitizen friendly

Features

  • Fast .d.ts generation (via isolatedDeclaration)
  • Highly configurable
  • Lightweight library
  • Cross-platform binary

Install

bun install -d @stacksjs/dtsx

@npmjs.com, please allow us to use the dtsx package name 🙏

Get Started

There are two ways of using this ".d.ts generation" tool: as a library or as a CLI.

Library

Given the npm package is installed, you can use the generate function to generate TypeScript declaration files from your project.

Usage

import type { DtsGenerationOptions } from '@stacksjs/dtsx'
import { generate } from '@stacksjs/dtsx'

const options: DtsGenerationOptions = {
  cwd: './', // default: process.cwd()
  root: './src', // default: './src'
  entrypoints: ['**/*.ts'], // default: ['**/*.ts']
  outdir: './dist', // default: './dist'
  keepComments: true, // default: true
  clean: true, // default: false
}

await generate(options)

Available options:

Library usage can also be configured using a dts.config.ts (or dts.config.js) file which is automatically loaded when running the ./dtsx (or bunx dtsx) command. It is also loaded when the generate function is called, unless custom options are provided.

// dts.config.ts (or dts.config.js)

export default {
  cwd: './',
  root: './src',
  entrypoints: ['**/*.ts'],
  outdir: './dist',
  keepComments: true,
  clean: true,
}

You may also run:

./dtsx generate

# if the package is installed, you can also run:
# bunx dtsx generate

CLI

The dtsx CLI provides a simple way to generate TypeScript declaration files from your project. Here's how to use it:

Usage

Generate declaration files using the default options:

dtsx generate

Or use custom options:

# Generate declarations for specific entry points:
dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types

# Generate declarations with custom configuration:
dtsx generate --root ./lib --outdir ./types --clean

dtsx --help
dtsx --version

Available options:

  • --cwd <path>: Set the current working directory (default: current directory)
  • --root <path>: Specify the root directory of the project (default: './src')
  • --entrypoints <files>: Define entry point files (comma-separated, default: '**/*.ts')
  • --outdir <path>: Set the output directory for generated .d.ts files (default: './dist')
  • --keep-comments: Keep comments in generated .d.ts files (default: true)
  • --clean: Clean output directory before generation (default: false)
  • --tsconfig <path>: Specify the path to tsconfig.json (default: 'tsconfig.json')

To learn more, head over to the documentation.

Testing

bun test

Changelog

Please see our releases page for more information on what has changed recently.

Contributing

Please review the Contributing Guide for details.

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discussions on GitHub

For casual chit-chat with others using this package:

Join the Stacks Discord Server

Postcardware

Two things are true: Stacks OSS will always stay open-source, and we do love to receive postcards from wherever Stacks is used! 🌍 We also publish them on our website. And thank you, Spatie

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094

Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Made with 💙