(From the opentui repo)
Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Bun automatically loads .env, so don't use dotenv.
Bun.serve()supports WebSockets, HTTPS, and routes. Don't useexpress.bun:sqlitefor SQLite. Don't usebetter-sqlite3.Bun.redisfor Redis. Don't useioredis.Bun.sqlfor Postgres. Don't usepgorpostgres.js.WebSocketis built-in. Don't usews.- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead of execa.
Use bun test to run tests.
import { test, expect } from "bun:test";
test("hello world", () => {
expect(1).toBe(1);
});For more information, read the Bun API docs in node_modules/bun-types/docs/**.md.
bun test- Run all testsbun test <file>- Run specific test file (e.g.,bun test src/animation/Timeline.test.ts)cd src/zig && zig build- Build Zig components (production)cd src/zig && zig build -Doptimize=Debug- Build Zig components (debug)cd src/zig && zig build -Doptimize=ReleaseFast- Build Zig components (optimized)
- Runtime: Bun with TypeScript
- Formatting: Prettier (semi: false, printWidth: 120)
- Imports: Use explicit imports, group by: built-ins, external deps, internal modules
- Types: Strict TypeScript, use interfaces for options/configs, explicit return types for public APIs
- Naming: camelCase for variables/functions, PascalCase for classes/interfaces, UPPER_CASE for constants
- Error Handling: Use proper Error objects, avoid silent failures
- Async: Prefer async/await over Promises, handle errors explicitly
- Comments: Minimal comments, focus on JSDoc for public APIs only
- File Structure: Index files for clean exports, group related functionality
- Testing: Bun test framework, descriptive test names, use beforeEach/afterEach for setup