Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stacksjs/bun-plugin-auto-imports
Auto Imports support for Bun.
https://github.com/stacksjs/bun-plugin-auto-imports
auto-imports bun bun-plugin
Last synced: 2 months ago
JSON representation
Auto Imports support for Bun.
- Host: GitHub
- URL: https://github.com/stacksjs/bun-plugin-auto-imports
- Owner: stacksjs
- License: mit
- Created: 2024-10-24T13:39:48.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T14:28:04.000Z (2 months ago)
- Last Synced: 2024-10-25T17:55:09.985Z (2 months ago)
- Topics: auto-imports, bun, bun-plugin
- Language: TypeScript
- Homepage:
- Size: 85 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
![Social Card of Bun Plugin Auto Imports](https://github.com/stacksjs/bun-plugin-auto-imports/blob/main/.github/art/cover.png)
[![npm version][npm-version-src]][npm-version-href]
[![GitHub Actions][github-actions-src]][github-actions-href]
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![npm downloads][npm-downloads-src]][npm-downloads-href]This Bun plugin generates dts files for your TypeScript projects.
## Features
- Auto-imports support for Bun
## Usage
```bash
bun install -d bun-plugin-auto-imports
```You may now use the plugin:
```ts
// 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:
```ts
// 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`._
## Testing
```bash
bun test
```## Changelog
Please see our [releases](https://github.com/stacksjs/bun-plugin-auto-imports/releases) page for more information on what has changed recently.
## Contributing
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
## Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
For casual chit-chat with others using this package:
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
## Postcardware
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 π
## 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.
- [JetBrains](https://www.jetbrains.com/)
- [The Solana Foundation](https://solana.com/)## Credits
Many thanks to the following core technologies & people who have contributed to this package:
- [unimport](https://github.com/unjs/unimport)
- [Chris Breuer](https://github.com/chrisbbreuer)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/bun-plugin-auto-imports/tree/main/LICENSE.md) for more information.
Made with π
[npm-version-src]:
[npm-version-href]:
[npm-downloads-src]:
[npm-downloads-href]:
[github-actions-src]:
[github-actions-href]: