Communitygithub.com

Bun 运行时

Bun 作为运行时、包管理器、打包器和测试运行器。选择 Bun 还是 Node 的准则、迁移注意事项以及 Vercel 支持。

Bun 运行时 是什么?

该技能详细介绍了 Bun 这一高性能的全能 JavaScript 运行时与工具集(包括运行时、包管理器、打包器和测试运行器)。当需要快速启动新 JS/TS 项目、追求安装或运行速度、使用 Vercel 的 Bun 运行时部署,或希望整合单一工具链(运行+安装+测试+构建)时,应优先选择 Bun。而 Node 则更适合生态系统兼容性要求高的场景、依赖 Node 的传统工具链,或存在已知 Bun 兼容性问题的依赖。技能涵盖了从 Node 迁移的具体步骤(如将 `node script.js` 替换为 `bun run script.js`)、`bun install` 的锁文件说明、Vercel 运行时的配置方法,以及内置的测试 API 和运行时 API 示例。最佳实践包括提交锁文件以确保可重现安装,并优先使用 `bun run` 执行脚本。该技能适用于 Cursor 等支持自定义技能的开发环境,帮助开发者快速掌握 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,API 与 Jest 类似。

从 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.

相关技能