Guía de migración completa: runtime, paquetes, tests y build en un solo comando
| Node / npm / npx | Bun equivalente | Descripción | |
|---|---|---|---|
npm install |
→ | bun install |
Instala dependencias; genera bun.lock |
npm install express |
→ | bun add express |
Añade dependencia de producción |
npm install -D vitest |
→ | bun add -d vitest |
Añade devDependency |
node src/index.ts |
→ | bun src/index.ts |
Ejecuta TS directamente, sin compilar |
npm run dev |
→ | bun run dev |
Ejecuta script de package.json |
npx prisma generate |
→ | bun x prisma generate |
Ejecuta binario sin instalar globalmente |
jest |
→ | bun test |
Test runner integrado, API compatible con Jest |
webpack --mode=production |
→ | bun build ./src --outdir=dist |
Bundler nativo de Bun |
import { expect, test, describe, beforeEach } from "bun:test"; import { scoreLead } from "../scorer"; describe("LeadFlow Scorer", () => { test("puntúa lead caliente correctamente", () => { const lead = { company_size: 50, visited_pricing: true, email_opens: 5, industry: "marketing" }; expect(scoreLead(lead)).toBeGreaterThan(80); }); test("lead frío score bajo", () => { const lead = { company_size: 2, visited_pricing: false, email_opens: 0 }; expect(scoreLead(lead)).toBeLessThan(30); }); });
# Ejecutar tests bun test # Watch mode durante desarrollo bun test --watch # Solo un archivo concreto bun test src/leads/__tests__/scorer.test.ts
// Bun.file — leer config JSON sin fs nativa const configFile = Bun.file("config/leadflow.json"); const config = await configFile.json<LeadFlowConfig>(); // Bun.serve — HTTP server nativo de alta performance Bun.serve({ port: config.webhook_port ?? 3001, async fetch(req: Request) { const url = new URL(req.url); if (url.pathname === "/webhook/lead" && req.method === "POST") { const body = await req.json(); // Procesa el lead entrante await processInboundLead(body); return new Response(JSON.stringify({ ok: true }), { headers: { "Content-Type": "application/json" } }); } return new Response("Not found", { status: 404 }); } }); console.log(`LeadFlow webhook server en :${config.webhook_port}`);
{ "installCommand": "bun install --frozen-lockfile", "buildCommand": "bun run build", "framework": "nextjs" }
- uses: oven-sh/setup-bun@v1 with: bun-version: latest - run: bun install --frozen-lockfile - run: bun test - run: bun run build
Usa --frozen-lockfile en CI para installs reproducibles.
Bun ≥ 1.1 genera bun.lock (texto, versionable en git).
Versiones anteriores generaban bun.lockb (binario).
Hacer commit del lockfile es obligatorio para deploys deterministas.
curl -fsSL https://bun.sh/install | bash · Verificar: bun --version
Borrar node_modules/ y package-lock.json. Ejecutar bun install para generar bun.lock.
Sustituir npm run X por bun run X en docs y CI. Comprobar que bun run dev arranca sin errores.
Cambiar imports de "jest" a "bun:test". La API es compatible (describe/test/expect). Ejecutar bun test.
Añadir vercel.json con installCommand: bun install --frozen-lockfile. Usar oven-sh/setup-bun@v1 en CI.
bun.lock garantiza installs idénticos en CI y producción. Nunca ignorarlo en .gitignore..ts directamente. No necesitas ts-node ni compilar previamente para scripts y workers.import from "bun:test" en proyectos nuevos. Más rápido, sin config extra, API idéntica a Jest.Bun.serve() sin Express ni Fastify.