[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M715JTD2BCAAA2BZ7EC3CS62":3,"skill-same:01M715JTD2BCAAA2BZ7EC3CS62":64},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":49,"install":50,"resources":63},"01M715JTD2BCAAA2BZ7EC3CS62","bun-development",null,"Fast, modern JavaScript\u002FTypeScript development with the Bun runtime, inspired by [oven-sh\u002Fbun](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun).","sapsapshen\u002Fai-memory-router","sapsapshen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F20347959?v=4","01M6XDQEF1DP50DKF37H81J3J5","shenmian","01M6XDQEJPE41Y3DT2763X8ZJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fbun-development\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37],"bun development","development","bun","community","unknown","2026","typescript","runtime","javascript","with","bun runtime","github","https","fast","2026-11-10 10:12:30",false,"---\nname: bun-development\ndescription: \"Fast, modern JavaScript\u002FTypeScript development with the Bun runtime, inspired by [oven-sh\u002Fbun](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun).\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n\u003C!-- security-allowlist: curl-pipe-bash, irm-pipe-iex -->\n\n# ⚡ Bun Development\n\n> Fast, modern JavaScript\u002FTypeScript development with the Bun runtime, inspired by [oven-sh\u002Fbun](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun).\n\n## When to Use This Skill\n\nUse this skill when:\n\n- Starting new JS\u002FTS projects with Bun\n- Migrating from Node.js to Bun\n- Optimizing development speed\n- Using Bun's built-in tools (bundler, test runner)\n- Troubleshooting Bun-specific issues\n\n---\n\n## 1. Getting Started\n\n### 1.1 Installation\n\n```bash\n# macOS \u002F Linux\ncurl -fsSL https:\u002F\u002Fbun.sh\u002Finstall | bash\n\n# Windows\npowershell -c \"irm bun.sh\u002Finstall.ps1 | iex\"\n\n# Homebrew\nbrew tap oven-sh\u002Fbun\nbrew install bun\n\n# npm (if needed)\nnpm install -g bun\n\n# Upgrade\nbun upgrade\n```\n\n### 1.2 Why Bun?\n\n| Feature         | Bun            | Node.js                     |\n| :-------------- | :------------- | :-------------------------- |\n| Startup time    | ~25ms          | ~100ms+                     |\n| Package install | 10-100x faster | Baseline                    |\n| TypeScript      | Native         | Requires transpiler         |\n| JSX             | Native         | Requires transpiler         |\n| Test runner     | Built-in       | External (Jest, Vitest)     |\n| Bundler         | Built-in       | External (Webpack, esbuild) |\n\n---\n\n## 2. Project Setup\n\n### 2.1 Create New Project\n\n```bash\n# Initialize project\nbun init\n\n# Creates:\n# ├── package.json\n# ├── tsconfig.json\n# ├── index.ts\n# └── README.md\n\n# With specific template\nbun create \u003Ctemplate> \u003Cproject-name>\n\n# Examples\nbun create react my-app        # React app\nbun create next my-app         # Next.js app\nbun create vite my-app         # Vite app\nbun create elysia my-api       # Elysia API\n```\n\n### 2.2 package.json\n\n```json\n{\n  \"name\": \"my-bun-project\",\n  \"version\": \"1.0.0\",\n  \"module\": \"index.ts\",\n  \"type\": \"module\",\n  \"scripts\": {\n    \"dev\": \"bun run --watch index.ts\",\n    \"start\": \"bun run index.ts\",\n    \"test\": \"bun test\",\n    \"build\": \"bun build .\u002Findex.ts --outdir .\u002Fdist\",\n    \"lint\": \"bunx eslint .\"\n  },\n  \"devDependencies\": {\n    \"@types\u002Fbun\": \"latest\"\n  },\n  \"peerDependencies\": {\n    \"typescript\": \"^5.0.0\"\n  }\n}\n```\n\n### 2.3 tsconfig.json (Bun-optimized)\n\n```json\n{\n  \"compilerOptions\": {\n    \"lib\": [\"ESNext\"],\n    \"module\": \"esnext\",\n    \"target\": \"esnext\",\n    \"moduleResolution\": \"bundler\",\n    \"moduleDetection\": \"force\",\n    \"allowImportingTsExtensions\": true,\n    \"noEmit\": true,\n    \"composite\": true,\n    \"strict\": true,\n    \"downlevelIteration\": true,\n    \"skipLibCheck\": true,\n    \"jsx\": \"react-jsx\",\n    \"allowSyntheticDefaultImports\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"types\": [\"bun-types\"]\n  }\n}\n```\n\n---\n\n## 3. Package Management\n\n### 3.1 Installing Packages\n\n```bash\n# Install from package.json\nbun install              # or 'bun i'\n\n# Add dependencies\nbun add express          # Regular dependency\nbun add -d typescript    # Dev dependency\nbun add -D @types\u002Fnode   # Dev dependency (alias)\nbun add --optional pkg   # Optional dependency\n\n# From specific registry\nbun add lodash --registry https:\u002F\u002Fregistry.npmmirror.com\n\n# Install specific version\nbun add react@18.2.0\nbun add react@latest\nbun add react@next\n\n# From git\nbun add github:user\u002Frepo\nbun add git+https:\u002F\u002Fgithub.com\u002Fuser\u002Frepo.git\n```\n\n### 3.2 Removing & Updating\n\n```bash\n# Remove package\nbun remove lodash\n\n# Update packages\nbun update              # Update all\nbun update lodash       # Update specific\nbun update --latest     # Update to latest (ignore ranges)\n\n# Check outdated\nbun outdated\n```\n\n### 3.3 bunx (npx equivalent)\n\n```bash\n# Execute package binaries\nbunx prettier --write .\nbunx tsc --init\nbunx create-react-app my-app\n\n# With specific version\nbunx -p typescript@4.9 tsc --version\n\n# Run without installing\nbunx cowsay \"Hello from Bun!\"\n```\n\n### 3.4 Lockfile\n\n```bash\n# bun.lockb is a binary lockfile (faster parsing)\n# To generate text lockfile for debugging:\nbun install --yarn    # Creates yarn.lock\n\n# Trust existing lockfile\nbun install --frozen-lockfile\n```\n\n---\n\n## 4. Running Code\n\n### 4.1 Basic Execution\n\n```bash\n# Run TypeScript directly (no build step!)\nbun run index.ts\n\n# Run JavaScript\nbun run index.js\n\n# Run with arguments\nbun run server.ts --port 3000\n\n# Run package.json script\nbun run dev\nbun run build\n\n# Short form (for scripts)\nbun dev\nbun build\n```\n\n### 4.2 Watch Mode\n\n```bash\n# Auto-restart on file changes\nbun --watch run index.ts\n\n# With hot reloading\nbun --hot run server.ts\n```\n\n### 4.3 Environment Variables\n\n```typescript\n\u002F\u002F .env file is loaded automatically!\n\n\u002F\u002F Access environment variables\nconst apiKey = Bun.env.API_KEY;\nconst port = Bun.env.PORT ?? \"3000\";\n\n\u002F\u002F Or use process.env (Node.js compatible)\nconst dbUrl = process.env.DATABASE_URL;\n```\n\n```bash\n# Run with specific env file\nbun --env-file=.env.production run index.ts\n```\n\n---\n\n## 5. Built-in APIs\n\n### 5.1 File System (Bun.file)\n\n```typescript\n\u002F\u002F Read file\nconst file = Bun.file(\".\u002Fdata.json\");\nconst text = await file.text();\nconst json = await file.json();\nconst buffer = await file.arrayBuffer();\n\n\u002F\u002F File info\nconsole.log(file.size); \u002F\u002F bytes\nconsole.log(file.type); \u002F\u002F MIME type\n\n\u002F\u002F Write file\nawait Bun.write(\".\u002Foutput.txt\", \"Hello, Bun!\");\nawait Bun.write(\".\u002Fdata.json\", JSON.stringify({ foo: \"bar\" }));\n\n\u002F\u002F Stream large files\nconst reader = file.stream();\nfor await (const chunk of reader) {\n  console.log(chunk);\n}\n```\n\n### 5.2 HTTP Server (Bun.serve)\n\n```typescript\nconst server = Bun.serve({\n  port: 3000,\n\n  fetch(request) {\n    const url = new URL(request.url);\n\n    if (url.pathname === \"\u002F\") {\n      return new Response(\"Hello World!\");\n    }\n\n    if (url.pathname === \"\u002Fapi\u002Fusers\") {\n      return Response.json([\n        { id: 1, name: \"Alice\" },\n        { id: 2, name: \"Bob\" },\n      ]);\n    }\n\n    return new Response(\"Not Found\", { status: 404 });\n  },\n\n  error(error) {\n    return new Response(`Error: ${error.message}`, { status: 500 });\n  },\n});\n\nconsole.log(`Server running at http:\u002F\u002Flocalhost:${server.port}`);\n```\n\n### 5.3 WebSocket Server\n\n```typescript\nconst server = Bun.serve({\n  port: 3000,\n\n  fetch(req, server) {\n    \u002F\u002F Upgrade to WebSocket\n    if (server.upgrade(req)) {\n      return; \u002F\u002F Upgraded\n    }\n    return new Response(\"Upgrade failed\", { status: 500 });\n  },\n\n  websocket: {\n    open(ws) {\n      console.log(\"Client connected\");\n      ws.send(\"Welcome!\");\n    },\n\n    message(ws, message) {\n      console.log(`Received: ${message}`);\n      ws.send(`Echo: ${message}`);\n    },\n\n    close(ws) {\n      console.log(\"Client disconnected\");\n    },\n  },\n});\n```\n\n### 5.4 SQLite (Bun.sql)\n\n```typescript\nimport { Database } from \"bun:sqlite\";\n\nconst db = new Database(\"mydb.sqlite\");\n\n\u002F\u002F Create table\ndb.run(`\n  CREATE TABLE IF NOT EXISTS users (\n    id INTEGER PRIMARY KEY AUTOINCREMENT,\n    name TEXT NOT NULL,\n    email TEXT UNIQUE\n  )\n`);\n\n\u002F\u002F Insert\nconst insert = db.prepare(\"INSERT INTO users (name, email) VALUES (?, ?)\");\ninsert.run(\"Alice\", \"alice@example.com\");\n\n\u002F\u002F Query\nconst query = db.prepare(\"SELECT * FROM users WHERE name = ?\");\nconst user = query.get(\"Alice\");\nconsole.log(user); \u002F\u002F { id: 1, name: \"Alice\", email: \"alice@example.com\" }\n\n\u002F\u002F Query all\nconst allUsers = db.query(\"SELECT * FROM users\").all();\n```\n\n### 5.5 Password Hashing\n\n```typescript\n\u002F\u002F Hash password\nconst password = \"super-secret\";\nconst hash = await Bun.password.hash(password);\n\n\u002F\u002F Verify password\nconst isValid = await Bun.password.verify(password, hash);\nconsole.log(isValid); \u002F\u002F true\n\n\u002F\u002F With algorithm options\nconst bcryptHash = await Bun.password.hash(password, {\n  algorithm: \"bcrypt\",\n  cost: 12,\n});\n```\n\n---\n\n## 6. Testing\n\n### 6.1 Basic Tests\n\n```typescript\n\u002F\u002F math.test.ts\nimport { describe, it, expect, beforeAll, afterAll } from \"bun:test\";\n\ndescribe(\"Math operations\", () => {\n  it(\"adds two numbers\", () => {\n    expect(1 + 1).toBe(2);\n  });\n\n  it(\"subtracts two numbers\", () => {\n    expect(5 - 3).toBe(2);\n  });\n});\n```\n\n### 6.2 Running Tests\n\n```bash\n# Run all tests\nbun test\n\n# Run specific file\nbun test math.test.ts\n\n# Run matching pattern\nbun test --grep \"adds\"\n\n# Watch mode\nbun test --watch\n\n# With coverage\nbun test --coverage\n\n# Timeout\nbun test --timeout 5000\n```\n\n### 6.3 Matchers\n\n```typescript\nimport { expect, test } from \"bun:test\";\n\ntest(\"matchers\", () => {\n  \u002F\u002F Equality\n  expect(1).toBe(1);\n  expect({ a: 1 }).toEqual({ a: 1 });\n  expect([1, 2]).toContain(1);\n\n  \u002F\u002F Comparisons\n  expect(10).toBeGreaterThan(5);\n  expect(5).toBeLessThanOrEqual(5);\n\n  \u002F\u002F Truthiness\n  expect(true).toBeTruthy();\n  expect(null).toBeNull();\n  expect(undefined).toBeUndefined();\n\n  \u002F\u002F Strings\n  expect(\"hello\").toMatch(\u002Fell\u002F);\n  expect(\"hello\").toContain(\"ell\");\n\n  \u002F\u002F Arrays\n  expect([1, 2, 3]).toHaveLength(3);\n\n  \u002F\u002F Exceptions\n  expect(() => {\n    throw new Error(\"fail\");\n  }).toThrow(\"fail\");\n\n  \u002F\u002F Async\n  await expect(Promise.resolve(1)).resolves.toBe(1);\n  await expect(Promise.reject(\"err\")).rejects.toBe(\"err\");\n});\n```\n\n### 6.4 Mocking\n\n```typescript\nimport { mock, spyOn } from \"bun:test\";\n\n\u002F\u002F Mock function\nconst mockFn = mock((x: number) => x * 2);\nmockFn(5);\nexpect(mockFn).toHaveBeenCalled();\nexpect(mockFn).toHaveBeenCalledWith(5);\nexpect(mockFn.mock.results[0].value).toBe(10);\n\n\u002F\u002F Spy on method\nconst obj = {\n  method: () => \"original\",\n};\nconst spy = spyOn(obj, \"method\").mockReturnValue(\"mocked\");\nexpect(obj.method()).toBe(\"mocked\");\nexpect(spy).toHaveBeenCalled();\n```\n\n---\n\n## 7. Bundling\n\n### 7.1 Basic Build\n\n```bash\n# Bundle for production\nbun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist\n\n# With options\nbun build .\u002Fsrc\u002Findex.ts \\\n  --outdir .\u002Fdist \\\n  --target browser \\\n  --minify \\\n  --sourcemap\n```\n\n### 7.2 Build API\n\n```typescript\nconst result = await Bun.build({\n  entrypoints: [\".\u002Fsrc\u002Findex.ts\"],\n  outdir: \".\u002Fdist\",\n  target: \"browser\", \u002F\u002F or \"bun\", \"node\"\n  minify: true,\n  sourcemap: \"external\",\n  splitting: true,\n  format: \"esm\",\n\n  \u002F\u002F External packages (not bundled)\n  external: [\"react\", \"react-dom\"],\n\n  \u002F\u002F Define globals\n  define: {\n    \"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n  },\n\n  \u002F\u002F Naming\n  naming: {\n    entry: \"[name].[hash].js\",\n    chunk: \"chunks\u002F[name].[hash].js\",\n    asset: \"assets\u002F[name].[hash][ext]\",\n  },\n});\n\nif (!result.success) {\n  console.error(result.logs);\n}\n```\n\n### 7.3 Compile to Executable\n\n```bash\n# Create standalone executable\nbun build .\u002Fsrc\u002Fcli.ts --compile --outfile myapp\n\n# Cross-compile\nbun build .\u002Fsrc\u002Fcli.ts --compile --target=bun-linux-x64 --outfile myapp-linux\nbun build .\u002Fsrc\u002Fcli.ts --compile --target=bun-darwin-arm64 --outfile myapp-mac\n\n# With embedded assets\nbun build .\u002Fsrc\u002Fcli.ts --compile --outfile myapp --embed .\u002Fassets\n```\n\n---\n\n## 8. Migration from Node.js\n\n### 8.1 Compatibility\n\n```typescript\n\u002F\u002F Most Node.js APIs work out of the box\nimport fs from \"fs\";\nimport path from \"path\";\nimport crypto from \"crypto\";\n\n\u002F\u002F process is global\nconsole.log(process.cwd());\nconsole.log(process.env.HOME);\n\n\u002F\u002F Buffer is global\nconst buf = Buffer.from(\"hello\");\n\n\u002F\u002F __dirname and __filename work\nconsole.log(__dirname);\nconsole.log(__filename);\n```\n\n### 8.2 Common Migration Steps\n\n```bash\n# 1. Install Bun\ncurl -fsSL https:\u002F\u002Fbun.sh\u002Finstall | bash\n\n# 2. Replace package manager\nrm -rf node_modules package-lock.json\nbun install\n\n# 3. Update scripts in package.json\n# \"start\": \"node index.js\" → \"start\": \"bun run index.ts\"\n# \"test\": \"jest\" → \"test\": \"bun test\"\n\n# 4. Add Bun types\nbun add -d @types\u002Fbun\n```\n\n### 8.3 Differences from Node.js\n\n```typescript\n\u002F\u002F ❌ Node.js specific (may not work)\nrequire(\"module\")             \u002F\u002F Use import instead\nrequire.resolve(\"pkg\")        \u002F\u002F Use import.meta.resolve\n__non_webpack_require__       \u002F\u002F Not supported\n\n\u002F\u002F ✅ Bun equivalents\nimport pkg from \"pkg\";\nconst resolved = import.meta.resolve(\"pkg\");\nBun.resolveSync(\"pkg\", process.cwd());\n\n\u002F\u002F ❌ These globals differ\nprocess.hrtime()              \u002F\u002F Use Bun.nanoseconds()\nsetImmediate()                \u002F\u002F Use queueMicrotask()\n\n\u002F\u002F ✅ Bun-specific features\nconst file = Bun.file(\".\u002Fdata.txt\");  \u002F\u002F Fast file API\nBun.serve({ port: 3000, fetch: ... }); \u002F\u002F Fast HTTP server\nBun.password.hash(password);           \u002F\u002F Built-in hashing\n```\n\n---\n\n## 9. Performance Tips\n\n### 9.1 Use Bun-native APIs\n\n```typescript\n\u002F\u002F Slow (Node.js compat)\nimport fs from \"fs\u002Fpromises\";\nconst content = await fs.readFile(\".\u002Fdata.txt\", \"utf-8\");\n\n\u002F\u002F Fast (Bun-native)\nconst file = Bun.file(\".\u002Fdata.txt\");\nconst content = await file.text();\n```\n\n### 9.2 Use Bun.serve for HTTP\n\n```typescript\n\u002F\u002F Don't: Express\u002FFastify (overhead)\nimport express from \"express\";\nconst app = express();\n\n\u002F\u002F Do: Bun.serve (native, 4-10x faster)\nBun.serve({\n  fetch(req) {\n    return new Response(\"Hello!\");\n  },\n});\n\n\u002F\u002F Or use Elysia (Bun-optimized framework)\nimport { Elysia } from \"elysia\";\nnew Elysia().get(\"\u002F\", () => \"Hello!\").listen(3000);\n```\n\n### 9.3 Bundle for Production\n\n```bash\n# Always bundle and minify for production\nbun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist --minify --target node\n\n# Then run the bundle\nbun run .\u002Fdist\u002Findex.js\n```\n\n---\n\n## Quick Reference\n\n| Task         | Command                                    |\n| :----------- | :----------------------------------------- |\n| Init project | `bun init`                                 |\n| Install deps | `bun install`                              |\n| Add package  | `bun add \u003Cpkg>`                            |\n| Run script   | `bun run \u003Cscript>`                         |\n| Run file     | `bun run file.ts`                          |\n| Watch mode   | `bun --watch run file.ts`                  |\n| Run tests    | `bun test`                                 |\n| Build        | `bun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist` |\n| Execute pkg  | `bunx \u003Cpkg>`                               |\n\n---\n\n## Resources\n\n- [Bun Documentation](https:\u002F\u002Fbun.sh\u002Fdocs)\n- [Bun GitHub](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun)\n- [Elysia Framework](https:\u002F\u002Felysiajs.com\u002F)\n- [Bun Discord](https:\u002F\u002Fbun.sh\u002Fdiscord)\n","\u003C!-- security-allowlist: curl-pipe-bash, irm-pipe-iex -->\n\n# ⚡ Bun Development\n\n> Fast, modern JavaScript\u002FTypeScript development with the Bun runtime, inspired by [oven-sh\u002Fbun](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun).\n\n## When to Use This Skill\n\nUse this skill when:\n\n- Starting new JS\u002FTS projects with Bun\n- Migrating from Node.js to Bun\n- Optimizing development speed\n- Using Bun's built-in tools (bundler, test runner)\n- Troubleshooting Bun-specific issues\n\n---\n\n## 1. Getting Started\n\n### 1.1 Installation\n\n```bash\n# macOS \u002F Linux\ncurl -fsSL https:\u002F\u002Fbun.sh\u002Finstall | bash\n\n# Windows\npowershell -c \"irm bun.sh\u002Finstall.ps1 | iex\"\n\n# Homebrew\nbrew tap oven-sh\u002Fbun\nbrew install bun\n\n# npm (if needed)\nnpm install -g bun\n\n# Upgrade\nbun upgrade\n```\n\n### 1.2 Why Bun?\n\n| Feature         | Bun            | Node.js                     |\n| :-------------- | :------------- | :-------------------------- |\n| Startup time    | ~25ms          | ~100ms+                     |\n| Package install | 10-100x faster | Baseline                    |\n| TypeScript      | Native         | Requires transpiler         |\n| JSX             | Native         | Requires transpiler         |\n| Test runner     | Built-in       | External (Jest, Vitest)     |\n| Bundler         | Built-in       | External (Webpack, esbuild) |\n\n---\n\n## 2. Project Setup\n\n### 2.1 Create New Project\n\n```bash\n# Initialize project\nbun init\n\n# Creates:\n# ├── package.json\n# ├── tsconfig.json\n# ├── index.ts\n# └── README.md\n\n# With specific template\nbun create \u003Ctemplate> \u003Cproject-name>\n\n# Examples\nbun create react my-app        # React app\nbun create next my-app         # Next.js app\nbun create vite my-app         # Vite app\nbun create elysia my-api       # Elysia API\n```\n\n### 2.2 package.json\n\n```json\n{\n  \"name\": \"my-bun-project\",\n  \"version\": \"1.0.0\",\n  \"module\": \"index.ts\",\n  \"type\": \"module\",\n  \"scripts\": {\n    \"dev\": \"bun run --watch index.ts\",\n    \"start\": \"bun run index.ts\",\n    \"test\": \"bun test\",\n    \"build\": \"bun build .\u002Findex.ts --outdir .\u002Fdist\",\n    \"lint\": \"bunx eslint .\"\n  },\n  \"devDependencies\": {\n    \"@types\u002Fbun\": \"latest\"\n  },\n  \"peerDependencies\": {\n    \"typescript\": \"^5.0.0\"\n  }\n}\n```\n\n### 2.3 tsconfig.json (Bun-optimized)\n\n```json\n{\n  \"compilerOptions\": {\n    \"lib\": [\"ESNext\"],\n    \"module\": \"esnext\",\n    \"target\": \"esnext\",\n    \"moduleResolution\": \"bundler\",\n    \"moduleDetection\": \"force\",\n    \"allowImportingTsExtensions\": true,\n    \"noEmit\": true,\n    \"composite\": true,\n    \"strict\": true,\n    \"downlevelIteration\": true,\n    \"skipLibCheck\": true,\n    \"jsx\": \"react-jsx\",\n    \"allowSyntheticDefaultImports\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"allowJs\": true,\n    \"types\": [\"bun-types\"]\n  }\n}\n```\n\n---\n\n## 3. Package Management\n\n### 3.1 Installing Packages\n\n```bash\n# Install from package.json\nbun install              # or 'bun i'\n\n# Add dependencies\nbun add express          # Regular dependency\nbun add -d typescript    # Dev dependency\nbun add -D @types\u002Fnode   # Dev dependency (alias)\nbun add --optional pkg   # Optional dependency\n\n# From specific registry\nbun add lodash --registry https:\u002F\u002Fregistry.npmmirror.com\n\n# Install specific version\nbun add react@18.2.0\nbun add react@latest\nbun add react@next\n\n# From git\nbun add github:user\u002Frepo\nbun add git+https:\u002F\u002Fgithub.com\u002Fuser\u002Frepo.git\n```\n\n### 3.2 Removing & Updating\n\n```bash\n# Remove package\nbun remove lodash\n\n# Update packages\nbun update              # Update all\nbun update lodash       # Update specific\nbun update --latest     # Update to latest (ignore ranges)\n\n# Check outdated\nbun outdated\n```\n\n### 3.3 bunx (npx equivalent)\n\n```bash\n# Execute package binaries\nbunx prettier --write .\nbunx tsc --init\nbunx create-react-app my-app\n\n# With specific version\nbunx -p typescript@4.9 tsc --version\n\n# Run without installing\nbunx cowsay \"Hello from Bun!\"\n```\n\n### 3.4 Lockfile\n\n```bash\n# bun.lockb is a binary lockfile (faster parsing)\n# To generate text lockfile for debugging:\nbun install --yarn    # Creates yarn.lock\n\n# Trust existing lockfile\nbun install --frozen-lockfile\n```\n\n---\n\n## 4. Running Code\n\n### 4.1 Basic Execution\n\n```bash\n# Run TypeScript directly (no build step!)\nbun run index.ts\n\n# Run JavaScript\nbun run index.js\n\n# Run with arguments\nbun run server.ts --port 3000\n\n# Run package.json script\nbun run dev\nbun run build\n\n# Short form (for scripts)\nbun dev\nbun build\n```\n\n### 4.2 Watch Mode\n\n```bash\n# Auto-restart on file changes\nbun --watch run index.ts\n\n# With hot reloading\nbun --hot run server.ts\n```\n\n### 4.3 Environment Variables\n\n```typescript\n\u002F\u002F .env file is loaded automatically!\n\n\u002F\u002F Access environment variables\nconst apiKey = Bun.env.API_KEY;\nconst port = Bun.env.PORT ?? \"3000\";\n\n\u002F\u002F Or use process.env (Node.js compatible)\nconst dbUrl = process.env.DATABASE_URL;\n```\n\n```bash\n# Run with specific env file\nbun --env-file=.env.production run index.ts\n```\n\n---\n\n## 5. Built-in APIs\n\n### 5.1 File System (Bun.file)\n\n```typescript\n\u002F\u002F Read file\nconst file = Bun.file(\".\u002Fdata.json\");\nconst text = await file.text();\nconst json = await file.json();\nconst buffer = await file.arrayBuffer();\n\n\u002F\u002F File info\nconsole.log(file.size); \u002F\u002F bytes\nconsole.log(file.type); \u002F\u002F MIME type\n\n\u002F\u002F Write file\nawait Bun.write(\".\u002Foutput.txt\", \"Hello, Bun!\");\nawait Bun.write(\".\u002Fdata.json\", JSON.stringify({ foo: \"bar\" }));\n\n\u002F\u002F Stream large files\nconst reader = file.stream();\nfor await (const chunk of reader) {\n  console.log(chunk);\n}\n```\n\n### 5.2 HTTP Server (Bun.serve)\n\n```typescript\nconst server = Bun.serve({\n  port: 3000,\n\n  fetch(request) {\n    const url = new URL(request.url);\n\n    if (url.pathname === \"\u002F\") {\n      return new Response(\"Hello World!\");\n    }\n\n    if (url.pathname === \"\u002Fapi\u002Fusers\") {\n      return Response.json([\n        { id: 1, name: \"Alice\" },\n        { id: 2, name: \"Bob\" },\n      ]);\n    }\n\n    return new Response(\"Not Found\", { status: 404 });\n  },\n\n  error(error) {\n    return new Response(`Error: ${error.message}`, { status: 500 });\n  },\n});\n\nconsole.log(`Server running at http:\u002F\u002Flocalhost:${server.port}`);\n```\n\n### 5.3 WebSocket Server\n\n```typescript\nconst server = Bun.serve({\n  port: 3000,\n\n  fetch(req, server) {\n    \u002F\u002F Upgrade to WebSocket\n    if (server.upgrade(req)) {\n      return; \u002F\u002F Upgraded\n    }\n    return new Response(\"Upgrade failed\", { status: 500 });\n  },\n\n  websocket: {\n    open(ws) {\n      console.log(\"Client connected\");\n      ws.send(\"Welcome!\");\n    },\n\n    message(ws, message) {\n      console.log(`Received: ${message}`);\n      ws.send(`Echo: ${message}`);\n    },\n\n    close(ws) {\n      console.log(\"Client disconnected\");\n    },\n  },\n});\n```\n\n### 5.4 SQLite (Bun.sql)\n\n```typescript\nimport { Database } from \"bun:sqlite\";\n\nconst db = new Database(\"mydb.sqlite\");\n\n\u002F\u002F Create table\ndb.run(`\n  CREATE TABLE IF NOT EXISTS users (\n    id INTEGER PRIMARY KEY AUTOINCREMENT,\n    name TEXT NOT NULL,\n    email TEXT UNIQUE\n  )\n`);\n\n\u002F\u002F Insert\nconst insert = db.prepare(\"INSERT INTO users (name, email) VALUES (?, ?)\");\ninsert.run(\"Alice\", \"alice@example.com\");\n\n\u002F\u002F Query\nconst query = db.prepare(\"SELECT * FROM users WHERE name = ?\");\nconst user = query.get(\"Alice\");\nconsole.log(user); \u002F\u002F { id: 1, name: \"Alice\", email: \"alice@example.com\" }\n\n\u002F\u002F Query all\nconst allUsers = db.query(\"SELECT * FROM users\").all();\n```\n\n### 5.5 Password Hashing\n\n```typescript\n\u002F\u002F Hash password\nconst password = \"super-secret\";\nconst hash = await Bun.password.hash(password);\n\n\u002F\u002F Verify password\nconst isValid = await Bun.password.verify(password, hash);\nconsole.log(isValid); \u002F\u002F true\n\n\u002F\u002F With algorithm options\nconst bcryptHash = await Bun.password.hash(password, {\n  algorithm: \"bcrypt\",\n  cost: 12,\n});\n```\n\n---\n\n## 6. Testing\n\n### 6.1 Basic Tests\n\n```typescript\n\u002F\u002F math.test.ts\nimport { describe, it, expect, beforeAll, afterAll } from \"bun:test\";\n\ndescribe(\"Math operations\", () => {\n  it(\"adds two numbers\", () => {\n    expect(1 + 1).toBe(2);\n  });\n\n  it(\"subtracts two numbers\", () => {\n    expect(5 - 3).toBe(2);\n  });\n});\n```\n\n### 6.2 Running Tests\n\n```bash\n# Run all tests\nbun test\n\n# Run specific file\nbun test math.test.ts\n\n# Run matching pattern\nbun test --grep \"adds\"\n\n# Watch mode\nbun test --watch\n\n# With coverage\nbun test --coverage\n\n# Timeout\nbun test --timeout 5000\n```\n\n### 6.3 Matchers\n\n```typescript\nimport { expect, test } from \"bun:test\";\n\ntest(\"matchers\", () => {\n  \u002F\u002F Equality\n  expect(1).toBe(1);\n  expect({ a: 1 }).toEqual({ a: 1 });\n  expect([1, 2]).toContain(1);\n\n  \u002F\u002F Comparisons\n  expect(10).toBeGreaterThan(5);\n  expect(5).toBeLessThanOrEqual(5);\n\n  \u002F\u002F Truthiness\n  expect(true).toBeTruthy();\n  expect(null).toBeNull();\n  expect(undefined).toBeUndefined();\n\n  \u002F\u002F Strings\n  expect(\"hello\").toMatch(\u002Fell\u002F);\n  expect(\"hello\").toContain(\"ell\");\n\n  \u002F\u002F Arrays\n  expect([1, 2, 3]).toHaveLength(3);\n\n  \u002F\u002F Exceptions\n  expect(() => {\n    throw new Error(\"fail\");\n  }).toThrow(\"fail\");\n\n  \u002F\u002F Async\n  await expect(Promise.resolve(1)).resolves.toBe(1);\n  await expect(Promise.reject(\"err\")).rejects.toBe(\"err\");\n});\n```\n\n### 6.4 Mocking\n\n```typescript\nimport { mock, spyOn } from \"bun:test\";\n\n\u002F\u002F Mock function\nconst mockFn = mock((x: number) => x * 2);\nmockFn(5);\nexpect(mockFn).toHaveBeenCalled();\nexpect(mockFn).toHaveBeenCalledWith(5);\nexpect(mockFn.mock.results[0].value).toBe(10);\n\n\u002F\u002F Spy on method\nconst obj = {\n  method: () => \"original\",\n};\nconst spy = spyOn(obj, \"method\").mockReturnValue(\"mocked\");\nexpect(obj.method()).toBe(\"mocked\");\nexpect(spy).toHaveBeenCalled();\n```\n\n---\n\n## 7. Bundling\n\n### 7.1 Basic Build\n\n```bash\n# Bundle for production\nbun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist\n\n# With options\nbun build .\u002Fsrc\u002Findex.ts \\\n  --outdir .\u002Fdist \\\n  --target browser \\\n  --minify \\\n  --sourcemap\n```\n\n### 7.2 Build API\n\n```typescript\nconst result = await Bun.build({\n  entrypoints: [\".\u002Fsrc\u002Findex.ts\"],\n  outdir: \".\u002Fdist\",\n  target: \"browser\", \u002F\u002F or \"bun\", \"node\"\n  minify: true,\n  sourcemap: \"external\",\n  splitting: true,\n  format: \"esm\",\n\n  \u002F\u002F External packages (not bundled)\n  external: [\"react\", \"react-dom\"],\n\n  \u002F\u002F Define globals\n  define: {\n    \"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n  },\n\n  \u002F\u002F Naming\n  naming: {\n    entry: \"[name].[hash].js\",\n    chunk: \"chunks\u002F[name].[hash].js\",\n    asset: \"assets\u002F[name].[hash][ext]\",\n  },\n});\n\nif (!result.success) {\n  console.error(result.logs);\n}\n```\n\n### 7.3 Compile to Executable\n\n```bash\n# Create standalone executable\nbun build .\u002Fsrc\u002Fcli.ts --compile --outfile myapp\n\n# Cross-compile\nbun build .\u002Fsrc\u002Fcli.ts --compile --target=bun-linux-x64 --outfile myapp-linux\nbun build .\u002Fsrc\u002Fcli.ts --compile --target=bun-darwin-arm64 --outfile myapp-mac\n\n# With embedded assets\nbun build .\u002Fsrc\u002Fcli.ts --compile --outfile myapp --embed .\u002Fassets\n```\n\n---\n\n## 8. Migration from Node.js\n\n### 8.1 Compatibility\n\n```typescript\n\u002F\u002F Most Node.js APIs work out of the box\nimport fs from \"fs\";\nimport path from \"path\";\nimport crypto from \"crypto\";\n\n\u002F\u002F process is global\nconsole.log(process.cwd());\nconsole.log(process.env.HOME);\n\n\u002F\u002F Buffer is global\nconst buf = Buffer.from(\"hello\");\n\n\u002F\u002F __dirname and __filename work\nconsole.log(__dirname);\nconsole.log(__filename);\n```\n\n### 8.2 Common Migration Steps\n\n```bash\n# 1. Install Bun\ncurl -fsSL https:\u002F\u002Fbun.sh\u002Finstall | bash\n\n# 2. Replace package manager\nrm -rf node_modules package-lock.json\nbun install\n\n# 3. Update scripts in package.json\n# \"start\": \"node index.js\" → \"start\": \"bun run index.ts\"\n# \"test\": \"jest\" → \"test\": \"bun test\"\n\n# 4. Add Bun types\nbun add -d @types\u002Fbun\n```\n\n### 8.3 Differences from Node.js\n\n```typescript\n\u002F\u002F ❌ Node.js specific (may not work)\nrequire(\"module\")             \u002F\u002F Use import instead\nrequire.resolve(\"pkg\")        \u002F\u002F Use import.meta.resolve\n__non_webpack_require__       \u002F\u002F Not supported\n\n\u002F\u002F ✅ Bun equivalents\nimport pkg from \"pkg\";\nconst resolved = import.meta.resolve(\"pkg\");\nBun.resolveSync(\"pkg\", process.cwd());\n\n\u002F\u002F ❌ These globals differ\nprocess.hrtime()              \u002F\u002F Use Bun.nanoseconds()\nsetImmediate()                \u002F\u002F Use queueMicrotask()\n\n\u002F\u002F ✅ Bun-specific features\nconst file = Bun.file(\".\u002Fdata.txt\");  \u002F\u002F Fast file API\nBun.serve({ port: 3000, fetch: ... }); \u002F\u002F Fast HTTP server\nBun.password.hash(password);           \u002F\u002F Built-in hashing\n```\n\n---\n\n## 9. Performance Tips\n\n### 9.1 Use Bun-native APIs\n\n```typescript\n\u002F\u002F Slow (Node.js compat)\nimport fs from \"fs\u002Fpromises\";\nconst content = await fs.readFile(\".\u002Fdata.txt\", \"utf-8\");\n\n\u002F\u002F Fast (Bun-native)\nconst file = Bun.file(\".\u002Fdata.txt\");\nconst content = await file.text();\n```\n\n### 9.2 Use Bun.serve for HTTP\n\n```typescript\n\u002F\u002F Don't: Express\u002FFastify (overhead)\nimport express from \"express\";\nconst app = express();\n\n\u002F\u002F Do: Bun.serve (native, 4-10x faster)\nBun.serve({\n  fetch(req) {\n    return new Response(\"Hello!\");\n  },\n});\n\n\u002F\u002F Or use Elysia (Bun-optimized framework)\nimport { Elysia } from \"elysia\";\nnew Elysia().get(\"\u002F\", () => \"Hello!\").listen(3000);\n```\n\n### 9.3 Bundle for Production\n\n```bash\n# Always bundle and minify for production\nbun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist --minify --target node\n\n# Then run the bundle\nbun run .\u002Fdist\u002Findex.js\n```\n\n---\n\n## Quick Reference\n\n| Task         | Command                                    |\n| :----------- | :----------------------------------------- |\n| Init project | `bun init`                                 |\n| Install deps | `bun install`                              |\n| Add package  | `bun add \u003Cpkg>`                            |\n| Run script   | `bun run \u003Cscript>`                         |\n| Run file     | `bun run file.ts`                          |\n| Watch mode   | `bun --watch run file.ts`                  |\n| Run tests    | `bun test`                                 |\n| Build        | `bun build .\u002Fsrc\u002Findex.ts --outdir .\u002Fdist` |\n| Execute pkg  | `bunx \u003Cpkg>`                               |\n\n---\n\n## Resources\n\n- [Bun Documentation](https:\u002F\u002Fbun.sh\u002Fdocs)\n- [Bun GitHub](https:\u002F\u002Fgithub.com\u002Foven-sh\u002Fbun)\n- [Elysia Framework](https:\u002F\u002Felysiajs.com\u002F)\n- [Bun Discord](https:\u002F\u002Fbun.sh\u002Fdiscord)\n",{"name":5,"risk":28,"source":27,"date_added":43,"description":7},"2026-02-27","main","7a38d8e7073e61c16eda85681cb32fb68a8657a5","skills-store\u002Fcursor\u002Fbun-development","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router","https:\u002F\u002Fgithub.com\u002Fsapsapshen","2026-04-14 21:12:12",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add sapsapshen\u002Fai-memory-router --skill bun-development",{"tool":56,"command":57},"bunx","bunx skills add sapsapshen\u002Fai-memory-router --skill bun-development",{"tool":59,"command":60},"pnpm","pnpm dlx skills add sapsapshen\u002Fai-memory-router --skill bun-development","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fbun-development\u002FSKILL.md",true,[],[65,88,114,124,137,153],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":76,"publishedAt":38},"01M71ATQRKG48SH06FQ697T5G9","wechat-search","Search WeChat Official Account articles using OpenClaw's web search and fetch capabilities with compliance-focused design.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fwechat-search-release\u002FSKILL.md",[71],{"categoryNo":72,"categoryName":73,"taxonomyType":74,"taxonomyTypeDesc":75},"01JBSEEDCAT000000000000037","律师与法务","PROFESSION","适用职业",[77,78,79,80,81,82,83,84,85,86,87,33],"wechat search","wechat","search","capabilities","openclaw","design","web search","compliance","web","official","fetch",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":38},"01M71ATNAVGZB35PFYM2GC5N00","trend-tap","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend tap', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-tap\u002FSKILL.md",[],[95,96,97,98,99,100,79,101,102,103,104,105,106,107,108,109,110,111,112,113],"trend","trend tap","tap","api keys","Bash","time","trending","hacker","aggregator","do","when","brew","live","data","google","install","read","across","api",{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":38},"01M71ATJ9AM5KM15AA8PS302EB","trend-radar","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend pulse', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-radar\u002FSKILL.md",[],[121,122,95,106,107,108,109,99,79,111,123,112,113,105,103,102,101,110,100,98],"trend radar","radar","pulse",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":38},"01M71ATGF095N3EJM9G8SD0BB5","tech-news-daily","每日科技新闻汇——从全球多个 RSS 源抓取最新科技新闻，翻译（英→中）、去重、排版成每日简报。当用户询问科技新闻、科技新鲜事、每日科技、技术动态、Daily Tech News 或类似表达时触发此技能。","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftech-news-daily\u002FSKILL.md",[],[131,132,133,134,135,136],"news","tech","tech news daily","daily","rss","翻译",{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":146,"publishedAt":38},"01M71ATFAEAMQ17M70NQNY7SR8","summarize","Summarize URLs or files with the summarize CLI (web, PDFs, images, audio, YouTube).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsummarize\u002FSKILL.md",[143],{"categoryNo":144,"categoryName":145,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000021","资料检索与研究",[139,85,147,148,149,33,106,150,36,151,97,152,110],"Audio","cli","youtube","images","files","pdfs",{"skillNo":154,"name":155,"nameZh":6,"description":156,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":157,"categories":158,"keywords":159,"publishedAt":38},"01M71ATDNS3R0M4H936PACQAWZ","sonoscli","Control Sonos speakers (discover\u002Fstatus\u002Fplay\u002Fvolume\u002Fgroup).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsonoscli\u002FSKILL.md",[],[155,160,161,162,110,163,36,35,164,165,166,167],"status","play","go","latest","discover","control","cmd","volume"]