Communitygithub.com

Bun 執行環境

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

Bun 執行環境 是什麼?

這項技能專注於 Bun——一個高效的全能型 JavaScript 執行環境與工具鏈,涵蓋執行環境、套件管理器、打包工具與測試執行器。它協助開發者判斷何時使用 Bun 而非 Node.js(例如新專案、對速度有要求的腳本或 Vercel 部署),並提供從 Node.js 遷移的實用建議,包括取代 `node`、`npm` 與 `npx` 指令。技能文件詳細說明 Bun 的核心運作方式:基於 JavaScriptCore 且以 Zig 實作的相容執行環境、快速的 `bun install`(使用 `bun.lock` 或 `bun.lockb` 鎖定檔案)、內建打包工具與相容 Jest 的測試執行器。此外,也涵蓋 Vercel 部署設定(將執行環境設為 Bun、使用 `bun install --frozen-lockfile` 確保可重複部署),以及最佳實務如提交鎖定檔案與優先使用 `bun run`。技能適合任何採用 Bun、從 Node 遷移、或想最佳化 Bun 開發與部署流程的開發者。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/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 預設使用 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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能