Communitygithub.com

Bun 執行環境

Bun 作為執行環境、套件管理器、打包工具和測試執行器。說明何時選擇 Bun 而非 Node、遷移注意事項以及 Vercel 支援。

Bun 執行環境 是什麼?

這項技能提供了關於 Bun 的全面指南,Bun 是一個快速的全方位 JavaScript 執行環境與工具組,整合了執行環境、套件管理器、打包工具和測試執行器。它幫助開發者判斷何時應選擇 Bun 而非 Node.js,以及如何從 Node.js 無痛遷移。技能內容涵蓋 Bun 的核心功能,包括其基於 JavaScriptCore 和 Zig 的高效能執行環境、比 npm/yarn 快上許多的 `bun install` 指令、內建的打包與轉譯工具,以及具備 Jest 風格 API 的測試框架。此外,也詳細說明了在 Vercel 平台上如何設定與部署 Bun 專案。本技能支援 Claude Code 等 AI 代理,能協助開發者進行 Bun 相關的專案初始化、腳本除錯及組態設定。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/bun-runtime

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Bun 執行環境 是做什麼的?

Bun 是一個快速的全方位 JavaScript 執行環境與工具組:它同時是執行環境、套件管理器、打包工具和測試執行器。

使用時機

  • 優先選擇 Bun 的情況:新的 JS/TS 專案、重視安裝/執行速度的腳本、使用 Bun 執行環境的 Vercel 部署,以及希望使用單一工具鏈(執行 + 安裝 + 測試 + 建置)時。
  • 優先選擇 Node 的情況:需要最大生態系相容性、使用假設為 Node 環境的舊工具,或當某個相依套件已知在 Bun 上有問題時。

適用於:採用 Bun、從 Node 遷移、撰寫或除錯 Bun 腳本/測試,或在 Vercel 或其他平台上設定 Bun。

運作方式

  • 執行環境:可作為 Node 的替代品(基於 JavaScriptCore,以 Zig 實作)。
  • 套件管理器:bun install 顯著比 npm/yarn 快。鎖定檔案預設為 bun.lock(純文字);較舊版本使用 bun.lockb(二進位)。
  • 打包工具:內建的打包器和轉譯器,適用於應用程式和函式庫。
  • 測試執行器:內建 bun test,提供類似 Jest 的 API。

從 Node 遷移:將 node script.js 取代為 bun run script.js 或 bun script.js。以 bun install 取代 npm install;大多數套件都能運作。使用 bun run 執行 npm 腳本;使用 bun x 進行類似 npx 的一次性執行。支援 Node 內建模組;若 Bun 有提供對應 API,建議優先使用以獲得更好的效能。

Vercel:在專案設定中將執行環境設為 Bun。建置指令:bun run build 或 bun build ./src/index.ts --outdir=dist。安裝指令:使用 bun install --frozen-lockfile 以確保可重複部署。

範例

執行與安裝

# 安裝相依套件(建立/更新 bun.lock 或 bun.lockb)
bun install

# 執行腳本或檔案
bun run dev
bun run src/index.ts
bun src/index.ts

腳本與環境變數

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

測試

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

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

執行環境 API

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

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

最佳實務

  • 提交鎖定檔案(bun.lock 或 bun.lockb)以確保可重複安裝。
  • 優先使用 bun run 執行腳本。對於 TypeScript,Bun 原生執行 .ts 檔案。
  • 保持相依套件更新;Bun 及其生態系演進迅速。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能