git:20260614.78a2809 to git:20260614.d9b08e1

78 added, 78 removed. Audit B to B.

---
name: bun-runtime-expert
- description: "Panduan ahli untuk runtime JavaScript/TypeScript Bun. Digunakan saat membuat, menguji, atau meluncurkan aplikasi dengan Bun / Expert guide for Bun JavaScript/TypeScript runtime. Use when building, testing, or deploying applications with Bun."
+ description: "Expert guide for Bun JavaScript/TypeScript runtime. Use when building, testing, or deploying applications with Bun / Panduan ahli untuk runtime JavaScript/TypeScript Bun. Digunakan saat membuat, menguji, atau meluncurkan aplikasi dengan Bun."
author: "Roedy Rustam"
---
# Bun Runtime Expert
- [Bahasa Indonesia](#bahasa-indonesia) | [English](#english)
+ [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
---
- <a name="bahasa-indonesia"></a>
- ## Bahasa Indonesia
+ <a name="english"></a>
+ ## English
- Panduan tingkat ahli untuk membangun aplikasi berkinerja tinggi menggunakan runtime JavaScript/TypeScript Bun (v1.1+). Mencakup server HTTP bawaan, klien database, bundler, test runner, package manager, dan strategi migrasi dari Node.js.
+ Expert-level guidance for building high-performance applications with the Bun JavaScript/TypeScript runtime (v1.1+). Covers Bun's built-in HTTP server, database clients, bundler, test runner, package manager, and Node.js migration strategies.
- ### Kondisi Pemicu
- - Gunakan saat merancang proyek baru menggunakan Bun sebagai runtime.
- - Gunakan saat membangun server HTTP atau API dengan `Bun.serve()`.
- - Gunakan saat melakukan query database dengan `Bun.sql` (PostgreSQL, MySQL, SQLite).
- - Gunakan saat berinteraksi dengan object storage yang kompatibel dengan S3 via `Bun.s3`.
- - Gunakan saat membundel kode frontend atau backend dengan `bun build`.
- - Gunakan saat menulis pengujian (testing) menggunakan `bun:test`.
- - Gunakan saat memigrasikan proyek Node.js ke Bun.
- - Gunakan saat mengoptimalkan kecepatan instalasi paket atau manajemen lockfile.
+ ### Trigger Conditions
+ - Use when scaffolding a new project with Bun as the runtime.
+ - Use when building HTTP servers or APIs with `Bun.serve()`.
+ - Use when querying databases with `Bun.sql` (PostgreSQL, MySQL, SQLite).
+ - Use when interacting with S3-compatible object storage via `Bun.s3`.
+ - Use when bundling frontend or backend code with `bun build`.
+ - Use when writing tests with `bun:test`.
+ - Use when migrating an existing Node.js project to Bun.
+ - Use when optimizing package installation speed or lockfile management.
- ### Arsitektur Inti
+ ### Core Architecture
- #### Mengapa Bun?
- Bun adalah runtime JavaScript/TypeScript serba ada yang menggantikan Node.js, npm, Webpack/Vite, dan Jest dalam satu berkas biner tunggal:
+ #### Why Bun?
+ Bun is a batteries-included JavaScript/TypeScript runtime that replaces Node.js, npm, Webpack/Vite, and Jest in a single binary:
- | Kemampuan | Bawaan Bun | Setara di Node.js |
+ | Capability | Bun Built-in | Node.js Equivalent |
|---|---|---|
| Runtime | `bun run` | `node` |
| Package Manager | `bun install` | `npm` / `pnpm` / `yarn` |
| Bundler | `bun build` | Webpack / Vite / esbuild |
| Test Runner | `bun test` | Jest / Vitest |
| HTTP Server | `Bun.serve()` | Express / Fastify |
| SQL Client | `Bun.sql` | `pg` / `mysql2` / `better-sqlite3` |
| S3 Client | `Bun.s3` | `@aws-sdk/client-s3` |
| Redis Client | Built-in | `ioredis` |
- | TypeScript | Native (tanpa config) | `ts-node` / `tsx` |
+ | TypeScript | Native (zero config) | `ts-node` / `tsx` |
| `.env` loading | Native | `dotenv` |
- ### Memulai Cepat
+ ### Quick Start
- #### 1. Instal Bun
+ #### 1. Install Bun
```bash
- # Windows (PowerShell)
- powershell -c "irm bun.sh/install.ps1 | iex"
-
# macOS / Linux
curl -fsSL https://bun.sh/install | bash
- # Verifikasi instalasi
+ # Windows (PowerShell)
+ powershell -c "irm bun.sh/install.ps1 | iex"
+
+ # Verify installation
bun --version
```
- #### 2. Inisialisasi Proyek Baru
+ #### 2. Initialize a New Project
```bash
bun init
```
- Ini menghasilkan `package.json`, `tsconfig.json`, dan file entry point `index.ts`. TypeScript langsung berfungsi tanpa konfigurasi tambahan.
+ This generates `package.json`, `tsconfig.json`, and an `index.ts` entry point. TypeScript works out of the box with zero configuration.
- #### 3. Instal Dependensi
+ #### 3. Install Dependencies
```bash
- # Menginstal semua dependensi (10-100x lebih cepat dari npm)
+ # Install all dependencies (10-100x faster than npm)
bun install
- # Menambahkan paket
+ # Add a package
bun add hono zod drizzle-orm
- # Menambahkan dev dependency
+ # Add dev dependency
bun add -d @types/bun vitest
```
- ### Bun.serve() — HTTP Server Berkinerja Tinggi
- `Bun.serve()` adalah server HTTP tanpa dependensi eksternal dengan dukungan TLS bawaan, WebSocket, dan hot module reloading.
+ ### Bun.serve() — High-Performance HTTP Server
+ `Bun.serve()` is a zero-dependency HTTP server with built-in TLS, WebSocket support, and hot module reloading.
- #### Server HTTP Dasar
+ #### Basic HTTP Server
```typescript
Bun.serve({
port: 3000,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/api/health') {
return Response.json({ status: 'ok', runtime: 'bun' });
}
return new Response('Not Found', { status: 404 });
},
});
```
- ### Bun.sql — Klien Database Terpadu
- Klien SQL tanpa dependensi eksternal yang mendukung PostgreSQL, MySQL/MariaDB, dan SQLite melalui tagged template literals.
+ ### Bun.sql — Unified Database Client
+ Zero-dependency SQL client supporting PostgreSQL, MySQL/MariaDB, and SQLite via tagged template literals.
#### PostgreSQL
```typescript
import { sql } from 'bun';
const users = await sql`SELECT * FROM users WHERE active = ${true}`;
```
- ### Praktik Terbaik
- - **Performa:** Gunakan `Bun.serve()` secara langsung atau bersama Hono — hindari Express (karena lapisan kompatibilitasnya lebih lambat). Gunakan `Bun.file()` untuk I/O file yang efisien.
- - **Keamanan:** Selalu gunakan parameterisasi query melalui template literals di `Bun.sql` untuk mencegah SQL Injection secara otomatis.
- - **Pengujian:** Gunakan `bun:test` yang kompatibel dengan Jest namun jauh lebih cepat.
+ ### Best Practices
+ - **Performance:** Use `Bun.serve()` directly or Hono for HTTP — avoid Express (slower compat layer). Use `Bun.file()` for efficient file I/O.
+ - **Security:** Always parameterize queries via template literals in `Bun.sql` (automatically prevents SQL injection).
+ - **Testing:** Use `bun:test` — it's Jest-compatible and significantly faster.
---
- <a name="english"></a>
- ## English
+ <a name="bahasa-indonesia"></a>
+ ## Bahasa Indonesia
- Expert-level guidance for building high-performance applications with the Bun JavaScript/TypeScript runtime (v1.1+). Covers Bun's built-in HTTP server, database clients, bundler, test runner, package manager, and Node.js migration strategies.
+ Panduan tingkat ahli untuk membangun aplikasi berkinerja tinggi menggunakan runtime JavaScript/TypeScript Bun (v1.1+). Mencakup server HTTP bawaan, klien database, bundler, test runner, package manager, dan strategi migrasi dari Node.js.
- ### Trigger Conditions
- - Use when scaffolding a new project with Bun as the runtime.
- - Use when building HTTP servers or APIs with `Bun.serve()`.
- - Use when querying databases with `Bun.sql` (PostgreSQL, MySQL, SQLite).
- - Use when interacting with S3-compatible object storage via `Bun.s3`.
- - Use when bundling frontend or backend code with `bun build`.
- - Use when writing tests with `bun:test`.
- - Use when migrating an existing Node.js project to Bun.
- - Use when optimizing package installation speed or lockfile management.
+ ### Kondisi Pemicu
+ - Gunakan saat merancang proyek baru menggunakan Bun sebagai runtime.
+ - Gunakan saat membangun server HTTP atau API dengan `Bun.serve()`.
+ - Gunakan saat melakukan query database dengan `Bun.sql` (PostgreSQL, MySQL, SQLite).
+ - Gunakan saat berinteraksi dengan object storage yang kompatibel dengan S3 via `Bun.s3`.
+ - Gunakan saat membundel kode frontend atau backend dengan `bun build`.
+ - Gunakan saat menulis pengujian (testing) menggunakan `bun:test`.
+ - Gunakan saat memigrasikan proyek Node.js ke Bun.
+ - Gunakan saat mengoptimalkan kecepatan instalasi paket atau manajemen lockfile.
- ### Core Architecture
+ ### Arsitektur Inti
- #### Why Bun?
- Bun is a batteries-included JavaScript/TypeScript runtime that replaces Node.js, npm, Webpack/Vite, and Jest in a single binary:
+ #### Mengapa Bun?
+ Bun adalah runtime JavaScript/TypeScript serba ada yang menggantikan Node.js, npm, Webpack/Vite, dan Jest dalam satu berkas biner tunggal:
- | Capability | Bun Built-in | Node.js Equivalent |
+ | Kemampuan | Bawaan Bun | Setara di Node.js |
|---|---|---|
| Runtime | `bun run` | `node` |
| Package Manager | `bun install` | `npm` / `pnpm` / `yarn` |
| Bundler | `bun build` | Webpack / Vite / esbuild |
| Test Runner | `bun test` | Jest / Vitest |
| HTTP Server | `Bun.serve()` | Express / Fastify |
| SQL Client | `Bun.sql` | `pg` / `mysql2` / `better-sqlite3` |
| S3 Client | `Bun.s3` | `@aws-sdk/client-s3` |
| Redis Client | Built-in | `ioredis` |
- | TypeScript | Native (zero config) | `ts-node` / `tsx` |
+ | TypeScript | Native (tanpa config) | `ts-node` / `tsx` |
| `.env` loading | Native | `dotenv` |
- ### Quick Start
+ ### Memulai Cepat
- #### 1. Install Bun
+ #### 1. Instal Bun
```bash
- # macOS / Linux
- curl -fsSL https://bun.sh/install | bash
-
# Windows (PowerShell)
powershell -c "irm bun.sh/install.ps1 | iex"
- # Verify installation
+ # macOS / Linux
+ curl -fsSL https://bun.sh/install | bash
+
+ # Verifikasi instalasi
bun --version
```
- #### 2. Initialize a New Project
+ #### 2. Inisialisasi Proyek Baru
```bash
bun init
```
- This generates `package.json`, `tsconfig.json`, and an `index.ts` entry point. TypeScript works out of the box with zero configuration.
+ Ini menghasilkan `package.json`, `tsconfig.json`, dan file entry point `index.ts`. TypeScript langsung berfungsi tanpa konfigurasi tambahan.
- #### 3. Install Dependencies
+ #### 3. Instal Dependensi
```bash
- # Install all dependencies (10-100x faster than npm)
+ # Mengmenginstal semua dependensi (10-100x lebih cepat dari npm)
bun install
- # Add a package
+ # Menambahkan paket
bun add hono zod drizzle-orm
- # Add dev dependency
+ # Menambahkan dev dependency
bun add -d @types/bun vitest
```
- ### Bun.serve() — High-Performance HTTP Server
- `Bun.serve()` is a zero-dependency HTTP server with built-in TLS, WebSocket support, and hot module reloading.
+ ### Bun.serve() — HTTP Server Berkinerja Tinggi
+ `Bun.serve()` adalah server HTTP tanpa dependensi eksternal dengan dukungan TLS bawaan, WebSocket, dan hot module reloading.
- #### Basic HTTP Server
+ #### Server HTTP Dasar
```typescript
Bun.serve({
port: 3000,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/api/health') {
return Response.json({ status: 'ok', runtime: 'bun' });
}
return new Response('Not Found', { status: 404 });
},
});
```
- ### Bun.sql — Unified Database Client
- Zero-dependency SQL client supporting PostgreSQL, MySQL/MariaDB, and SQLite via tagged template literals.
+ ### Bun.sql — Klien Database Terpadu
+ Klien SQL tanpa dependensi eksternal yang mendukung PostgreSQL, MySQL/MariaDB, dan SQLite melalui tagged template literals.
#### PostgreSQL
```typescript
import { sql } from 'bun';
const users = await sql`SELECT * FROM users WHERE active = ${true}`;
```
- ### Best Practices
- - **Performance:** Use `Bun.serve()` directly or Hono for HTTP — avoid Express (slower compat layer). Use `Bun.file()` for efficient file I/O.
- - **Security:** Always parameterize queries via template literals in `Bun.sql` (automatically prevents SQL injection).
- - **Testing:** Use `bun:test` — it's Jest-compatible and significantly faster.
+ ### Praktik Terbaik
+ - **Performa:** Gunakan `Bun.serve()` secara langsung atau bersama Hono — hindari Express (karena lapisan kompatibilitasnya lebih lambat). Gunakan `Bun.file()` untuk I/O file yang efisien.
+ - **Keamanan:** Selalu gunakan parameterisasi query melalui template literals di `Bun.sql` untuk mencegah SQL Injection secara otomatis.
+ - **Pengujian:** Gunakan `bun:test` yang kompatibel dengan Jest namun jauh lebih cepat.
---
### Limitations / Batasan
- Use this skill only when the task involves the Bun runtime specifically.
- Bun's Node.js compatibility is extensive but not 100%. Always verify critical `node:*` API usage.