opção

bun-runtime

affaan-m/ECC affaan-m/ECC

Oferece orientações sobre como usar o Bun como ambiente de execução de JavaScript, gerenciador de pacotes, empacotador e executor de testes, incluindo a migração do Node.js e a implantação no Vercel.

...Expandir tudo
0
Tempo atualizado 1 de Outubro de 2026

Bun Runtime

O Bun é um ambiente de execução e kit de ferramentas JavaScript rápido e completo: ambiente de execução, gerenciador de pacotes, empacotador e executor de testes.

Quando usar

  • Prefira o Bun para: novos projetos em JS/TS, scripts em que a velocidade de instalação/execução é importante, implantações no Vercel com o ambiente de execução do Bun e quando você deseja uma única cadeia de ferramentas (execução + instalação + teste + compilação).
  • Prefira o Node para: compatibilidade máxima com o ecossistema, ferramentas legadas que dependem do Node ou quando uma dependência apresentar problemas conhecidos com o Bun.

Use quando: estiver adotando o Bun, migrando do Node, escrevendo ou depurando scripts/testes do Bun, ou configurando o Bun no Vercel ou em outras plataformas.

Como funciona

  • Runtime: Runtime compatível com o Node, pronto para uso (desenvolvido com base no JavaScriptCore, implementado em Zig).
  • Gerenciador de pacotes: bun install é significativamente mais rápido que o npm/yarn. O arquivo de bloqueio é bun.lock (texto) por padrão na versão atual do Bun; versões mais antigas usavam bun.lockb (binário).
  • Empacotador: Empacotador e transpilador integrados para aplicativos e bibliotecas.
  • Executor de testes: Integrado bun test com API semelhante à do Jest.

Migração do Node: Substitua node script.js por bun run script.js ou bun script.js. Execute bun install em vez de npm install; a maioria dos pacotes funciona. Use bun run para scripts do npm; bun x para execuções únicas no estilo npx. Os comandos embutidos do Node são suportados; dê preferência às APIs do Bun, quando disponíveis, para obter melhor desempenho.

Vercel: Defina o ambiente de execução como Bun nas configurações do projeto. Compilação: bun run build ou bun build ./src/index.ts --outdir=dist. Instalação: bun install --frozen-lockfile para implantações reproduzíveis.

Exemplos

Execute e instale

# Install dependencies (creates/updates bun.lock or bun.lockb)
bun install

# Run a script or file
bun run dev
bun run src/index.ts
bun src/index.ts

Scripts e ambiente

bun run --env-file=.env dev
FOO=bar bun run script.ts

Testes

bun test
bun test --watch
// test/example.test.ts
import { expect, test } from "bun:test";

test("add", () => {
  expect(1 + 2).toBe(3);
});

API de tempo de execução

const file = Bun.file("package.json");
const json = await file.json();

Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello");
  },
});

Melhores práticas

  • Confirme o arquivo de bloqueio (bun.lock ou bun.lockb) para instalações reproduzíveis.
  • Dê preferência a bun run o uso de scripts. Para TypeScript, o Bun é executado .ts nativamente.
  • Mantenha as dependências atualizadas; o Bun e o ecossistema evoluem rapidamente.
Ver no GitHub
---
name: bun-runtime
description: Provides guidance on using Bun as a JavaScript runtime, package manager, bundler, and test runner, including migration from Node.js and Vercel deployment.
---

# Bun Runtime

Bun is a fast all-in-one JavaScript runtime and toolkit: runtime, package manager, bundler, and test runner.

## When to Use

- **Prefer Bun** for: new JS/TS projects, scripts where install/run speed matters, Vercel deployments with Bun runtime, and when you want a single toolchain (run + install + test + build).
- **Prefer Node** for: maximum ecosystem compatibility, legacy tooling that assumes Node, or when a dependency has known Bun issues.

Use when: adopting Bun, migrating from Node, writing or debugging Bun scripts/tests, or configuring Bun on Vercel or other platforms.

## How It Works

- **Runtime**: Drop-in Node-compatible runtime (built on JavaScriptCore, implemented in Zig).
- **Package manager**: `bun install` is significantly faster than npm/yarn. Lockfile is `bun.lock` (text) by default in current Bun; older versions used `bun.lockb` (binary).
- **Bundler**: Built-in bundler and transpiler for apps and libraries.
- **Test runner**: Built-in `bun test` with Jest-like API.

**Migration from Node**: Replace `node script.js` with `bun run script.js` or `bun script.js`. Run `bun install` in place of `npm install`; most packages work. Use `bun run` for npm scripts; `bun x` for npx-style one-off runs. Node built-ins are supported; prefer Bun APIs where they exist for better performance.

**Vercel**: Set runtime to Bun in project settings. Build: `bun run build` or `bun build ./src/index.ts --outdir=dist`. Install: `bun install --frozen-lockfile` for reproducible deploys.

## Examples

### Run and install

```bash
# Install dependencies (creates/updates bun.lock or bun.lockb)
bun install

# Run a script or file
bun run dev
bun run src/index.ts
bun src/index.ts
```

### Scripts and env

```bash
bun run --env-file=.env dev
FOO=bar bun run script.ts
```

### Testing

```bash
bun test
bun test --watch
```

```typescript
// test/example.test.ts
import { expect, test } from "bun:test";

test("add", () => {
  expect(1 + 2).toBe(3);
});
```

### Runtime API

```typescript
const file = Bun.file("package.json");
const json = await file.json();

Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello");
  },
});
```

## Best Practices

- Commit the lockfile (`bun.lock` or `bun.lockb`) for reproducible installs.
- Prefer `bun run` for scripts. For TypeScript, Bun runs `.ts` natively.
- Keep dependencies up to date; Bun and the ecosystem evolve quickly.

Todos os arquivos

1 arquivos

Instalar bun-runtime

Baixe e descompacte os arquivos de habilidades no diretório .claude/skills/.

Baixar ZIP

Clone o repositório e copie os arquivos da habilidade para o seu projeto.

git clone https://github.com/affaan-m/ECC/tree/main/skills/bun-runtime # Copy SKILL.md to your .claude/skills/ directory

Copiar Copiar
Configuração rápida: Copie a pasta da habilidade para .claude/skills/ O Claude detectará e utilizará automaticamente a habilidade
Repositório affaan-m/ECC

Habilidades relacionadas

algorithmic-art
Tempo atualizado 27 de Agosto de 2026
systematic-debugging
Tempo atualizado 3 de Setembro de 2026
tech-debt-tracker
Tempo atualizado 29 de Agosto de 2026
continual-learning
Tempo atualizado 10 de Setembro de 2026
OR