dts
A Bun build plugin that emits TypeScript declaration files via oxc-transform's isolatedDeclaration API. The plugin walks every .ts source file once during onLoad, produces a sibling .d.ts next to the compiled module, and is significantly faster than running tsc for type emit.
Importing
ts
import { dts } from '@basmilius/tools';Usage
ts
import { build, dts } from '@basmilius/tools';
await build({
entrypoints: ['src/index.ts'],
root: 'src',
outdir: 'dist',
plugins: [
dts()
]
});A file at src/util/format.ts will produce dist/util/format.d.ts.
Requirements
- The build must define both
rootandoutdir. Without those, the plugin logs a warning and skips emit. - Source files must be compatible with
isolatedDeclarations. All exports must have explicit return types and inferred types must be resolvable per-file.
Behaviour
- Tracks visited paths in a
Setso each file is processed once per build. - Reads each
.tsfile viaBun.file().text(). - Calls
isolatedDeclaration(path, source)fromoxc-transform. - Writes the result to the same path, with
src/swapped fordist/and.tsswapped for.d.ts.
Returns
BunPlugin — pass into Bun.build's plugins array.
Type signature
ts
declare function dts(): BunPlugin;