Socket
Book a DemoInstallSign in
Socket

bun-plugin-auto-imports

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bun-plugin-auto-imports

A Bun Bundler plugin that allows for auto-imports.

latest
Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
695
-64.79%
Maintainers
0
Weekly downloads
 
Created
Source

Social Card of Bun Plugin Auto Imports

npm version GitHub Actions Commitizen friendly npm downloads

This Bun plugin allows for support of auto-imports in your server-side code.

Features

  • Auto-imports support for Bun

Usage

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' }],
  dirs: ['./src'],
  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 })
  }
}

[!NOTE] If you are familiar with unimport, AutoImportsOptions proxies UnimportOptions.

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

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.

Credits

Many thanks to the following core technologies & people who have contributed to this package:

License

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

Made with 💙

Keywords

auto-imports

FAQs

Package last updated on 21 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts