This Bun plugin generates dts files for your TypeScript projects.
- Auto-imports support for Bun
bun install -d bun-plugin-auto-imports
You may now use the plugin:
// index.ts
import type { AutoImportsOptions } from 'bun-plugin-auto-imports'
import { plugin } from 'bun'
import { autoImports } from 'bun-plugin-auto-imports'
const options: AutoImportsOptions = {
presets: ['solid-js'], // any unimport presets are valid
imports: [{ name: 'z', from: 'zod' }],
dts: `./src/auto-import.d.ts`, // default is `./auto-import.d.ts`
}
plugin(autoImports(options))
Bun.serve({
fetch: handler,
port: 3000,
})
In your "server file," you may now use the auto-imported modules:
// server.ts
// `z` is auto imported from zod
const Body = z.object({
msg: z.string(),
})
export async function handler(req: Request) {
try {
const body = await req.json()
const data = Body.parse(body)
return new Response(`Received: ${data.msg}`)
}
catch (e) {
return new Response('Invalid body', { status: 400 })
}
}
As a minor side note, if you are familiar with unimport
, AutoImportsOptions
proxies UnimportOptions
.
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
You will always be free to use any of the Stacks OSS software. We would also love to see which parts of the world Stacks ends up in. Receiving postcards makes us happy—and we will publish them on our website.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
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.
Many thanks to the following core technologies & people who have contributed to this package:
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙