bun-knowledge-patch
Bun changes since training cutoff (latest: 1.3.10) — S3 client, built-in SQL/Redis, route-based HTTP server, CSS bundler, V8 compatibility. Load before working with Bun.
What this skill does
# Bun 1.2+ Knowledge Patch
Claude's baseline knowledge covers Bun through 1.1.x. This skill provides features from 1.2 (January 2025) onwards.
## Quick Reference
### HTTP Server (`Bun.serve`)
| Feature | Example |
|---------|---------|
| Routes with params | `"/api/users/:id"` → `req.params.id` |
| Method handlers | `{ GET: fn, POST: fn }` |
| Static routes | `"/health": new Response("OK")` |
| HTML imports | `import page from "./index.html"` |
| Cookies | `req.cookies.set("name", "value")` |
| CSRF | `await Bun.CSRF.generate(sessionId)` |
See `references/http-server.md` for routes, cookies, dev server, WebSocket proxy.
### SQL & Database
| Client | Connection |
|--------|------------|
| PostgreSQL | `import { sql } from "bun"` |
| MySQL/MariaDB | `new SQL("mysql://...")` |
| SQLite | `new SQL(":memory:")` |
| Redis | `import { redis } from "bun"` |
```ts
const users = await sql`SELECT * FROM users WHERE age >= ${minAge}`;
await sql`INSERT INTO users ${sql(user, "name", "email")}`;
```
See `references/sql-database.md` for tagged templates, dynamic columns, Redis pub/sub.
### S3 Storage (`Bun.s3`)
```ts
const file = s3.file("path/file.txt");
await file.text(); // Same API as Bun.file()
await file.write("data");
const url = s3.presign("file", { expiresIn: 3600 });
```
See `references/s3-storage.md` for bucket listing, upload options.
### Test Runner (`bun:test`)
| Feature | API |
|---------|-----|
| Fake timers | `jest.useFakeTimers()` |
| Concurrent tests | `test.concurrent()` |
| Retry flaky | `test("name", fn, { retry: 3 })` |
| Type testing | `expectTypeOf(x).toBeString()` |
| vi global | `vi.fn()`, `vi.mock()`, `vi.spyOn()` |
See `references/test-runner.md` for matchers, mocking, configuration.
### Package Manager
| Command | Purpose |
|---------|---------|
| `bun outdated` | View outdated deps |
| `bun audit` | Security scan |
| `bun why <pkg>` | Dependency path |
| `bun pm pkg get/set` | Manage package.json |
| `bun pm version patch` | Bump version |
See `references/package-manager.md` for workspaces, catalogs, linker modes.
### Bundler (`bun build`)
| Flag | Purpose |
|------|---------|
| `--compile` | Standalone executable |
| `--target=bun-*` | Cross-compile |
| `--production` | Production HTML build |
| `--metafile` / `--metafile-md` | Bundle analysis |
| `--feature=X` | Compile-time flags |
| `--target=browser` | Self-contained HTML |
See `references/bundler.md` for plugins, JSX config, virtual files.
### New APIs
| API | Purpose |
|-----|---------|
| `Bun.markdown` | MD → HTML/React |
| `Bun.YAML` | YAML parse/stringify |
| `Bun.JSON5` | JSON5 with comments |
| `Bun.Archive` | Tar creation/extraction |
| `Bun.Terminal` | PTY support |
| `Bun.secrets` | OS credential storage |
See `references/new-apis.md` for JSONC, JSONL, compression, text utilities.
### Runtime & CLI
| Feature | Example |
|---------|---------|
| Spawn timeout | `Bun.spawn({ cmd, timeout: 1000 })` |
| CPU profiling | `bun --cpu-prof script.js` |
| Heap profiling | `bun --heap-prof script.js` |
| Fetch proxy | `fetch(url, { proxy: "http://..." })` |
See `references/runtime-cli.md` for spawn options, profiling, CLI flags.
### Node.js Compatibility
| API | Status |
|-----|--------|
| `fs.glob` | Supported |
| `node:http2` | Supported |
| `node:vm` | SourceTextModule, SyntheticModule |
| `node:inspector` | Profiler API |
| `ReadableStream.json()` | Direct consumption |
See `references/node-compat.md` for full compatibility details.
## Reference Files
| File | Contents |
|------|----------|
| `http-server.md` | Routes, static, cookies, HTML imports, dev server |
| `sql-database.md` | Postgres, MySQL, SQLite, Redis clients |
| `s3-storage.md` | S3 client, presigned URLs, bucket listing |
| `test-runner.md` | Matchers, mocking, fake timers, concurrent |
| `package-manager.md` | Install, audit, workspaces, catalogs |
| `bundler.md` | Compile, plugins, metafile, feature flags |
| `new-apis.md` | Markdown, YAML, JSON5, Archive, Terminal |
| `node-compat.md` | fs.glob, vm, inspector, streams |
| `runtime-cli.md` | Spawn, profiling, CLI flags |
## Critical Examples
### Full-Stack Server with Routes
```ts
import homepage from "./index.html"; // Auto-bundles JS/CSS
import { sql } from "bun";
Bun.serve({
routes: {
"/": homepage,
"/api/users/:id": (req) => {
const { id } = req.params;
return Response.json({ id });
},
"/api/users": {
GET: async () => Response.json(await sql`SELECT * FROM users`),
POST: async (req) => {
const { name } = await req.json();
const [user] = await sql`INSERT INTO users (name) VALUES (${name}) RETURNING *`;
return Response.json(user);
},
},
},
});
```
### Cookies
```ts
// In route handler
req.cookies.set("session", token, { httpOnly: true, sameSite: "strict" });
req.cookies.get("session");
req.cookies.delete("session");
```
### SQL Dynamic Columns
```ts
// Insert/update specific columns from object
await sql`INSERT INTO users ${sql(user, "name", "email")}`;
await sql`UPDATE users SET ${sql(user, "name")} WHERE id = ${user.id}`;
// WHERE IN with array
await sql`SELECT * FROM users WHERE id IN ${sql([1, 2, 3])}`;
```
### Test Runner Essentials
```ts
import { test, expect, jest, mock } from "bun:test";
test("with fake timers", () => {
jest.useFakeTimers();
setTimeout(() => {}, 1000);
jest.advanceTimersByTime(1000);
jest.useRealTimers();
});
test.concurrent("runs in parallel", async () => {});
test("retry flaky", () => {}, { retry: 3 });
```
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.