- Fast .d.ts generation
- Highly configurable
- Lightweight library
- Cross-platform binary
bun install -d @stacksjs/dtsx
@npmjs.com, please allow us to use the dtsx
package name 🙏
There are two ways of using this ".d.ts generation" tool: as a library or as a CLI.
But before you get started, please ensure you enabled isolatedDeclarations
in your tsconfig.json
file.
{
"compilerOptions": {
"isolatedDeclarations": true
}
}
Given the npm package is installed, you can use the generate
function to generate TypeScript declaration files from your project.
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'
clean: true, // default: false
verbose: true, // default: false
// keepComments: true, // coming soon
}
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,
verbose: true,
}
You may also run:
./dtsx generate
# if the package is installed, you can also run:
# bunx dtsx generate
The dtsx
CLI provides a simple way to generate TypeScript declaration files from your project. Here's how to use it:
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')--verbose
: Enable verbose output (default: false)
To learn more, head over to the documentation.
bun test
Please see our releases page for more information on what has changed recently.
Please review the Contributing Guide for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
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
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.
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙