mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
update CLAUDE.md
This commit is contained in:
56
CLAUDE.md
56
CLAUDE.md
@@ -177,47 +177,6 @@ Built-in JavaScript modules use special syntax and are organized as:
|
|||||||
- `internal/` - Internal modules not exposed to users
|
- `internal/` - Internal modules not exposed to users
|
||||||
- `builtins/` - Core JavaScript builtins (streams, console, etc.)
|
- `builtins/` - Core JavaScript builtins (streams, console, etc.)
|
||||||
|
|
||||||
### Special Syntax in Built-in Modules
|
|
||||||
|
|
||||||
1. **`$` prefix** - Access to private properties and JSC intrinsics:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const arr = $Array.from(...); // Private global
|
|
||||||
map.$set(...); // Private method
|
|
||||||
const arr2 = $newArrayWithSize(5); // JSC intrinsic
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **`require()`** - Must use string literals, resolved at compile time:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const fs = require("fs"); // Directly loads by numeric ID
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Debug helpers**:
|
|
||||||
- `$debug()` - Like console.log but stripped in release builds
|
|
||||||
- `$assert()` - Assertions stripped in release builds
|
|
||||||
- `if($debug) {}` - Check if debug env var is set
|
|
||||||
|
|
||||||
4. **Platform detection**: `process.platform` and `process.arch` are inlined and dead-code eliminated
|
|
||||||
|
|
||||||
5. **Export syntax**: Use `export default` which gets converted to a return statement:
|
|
||||||
```js
|
|
||||||
export default {
|
|
||||||
readFile,
|
|
||||||
writeFile,
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: These are NOT ES modules. The preprocessor converts `$` to `@` (JSC's actual syntax) and handles the special functions.
|
|
||||||
|
|
||||||
## CI
|
|
||||||
|
|
||||||
Bun uses BuildKite for CI. To get the status of a PR, you can use the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bun ci
|
|
||||||
```
|
|
||||||
|
|
||||||
## Important Development Notes
|
## Important Development Notes
|
||||||
|
|
||||||
1. **Never use `bun test` or `bun <file>` directly** - always use `bun bd test` or `bun bd <command>`. `bun bd` compiles & runs the debug build.
|
1. **Never use `bun test` or `bun <file>` directly** - always use `bun bd test` or `bun bd <command>`. `bun bd` compiles & runs the debug build.
|
||||||
@@ -229,19 +188,6 @@ bun ci
|
|||||||
7. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools
|
7. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools
|
||||||
8. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup
|
8. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup
|
||||||
9. **Cross-platform** - Run `bun run zig:check-all` to compile the Zig code on all platforms when making platform-specific changes
|
9. **Cross-platform** - Run `bun run zig:check-all` to compile the Zig code on all platforms when making platform-specific changes
|
||||||
10. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_<scope>=1` to enable specific scopes
|
10. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_<scope>=1` to enable specific `Output.scoped(.${scopeName}, .visible)`s
|
||||||
11. **Be humble & honest** - NEVER overstate what you got done or what actually works in commits, PRs or in messages to the user.
|
11. **Be humble & honest** - NEVER overstate what you got done or what actually works in commits, PRs or in messages to the user.
|
||||||
12. **Branch names must start with `claude/`** - This is a requirement for the CI to work.
|
12. **Branch names must start with `claude/`** - This is a requirement for the CI to work.
|
||||||
|
|
||||||
## Key APIs and Features
|
|
||||||
|
|
||||||
### Bun-Specific APIs
|
|
||||||
|
|
||||||
- **Bun.serve()** - High-performance HTTP server
|
|
||||||
- **Bun.spawn()** - Process spawning with better performance than Node.js
|
|
||||||
- **Bun.file()** - Fast file I/O operations
|
|
||||||
- **Bun.write()** - Unified API for writing to files, stdout, etc.
|
|
||||||
- **Bun.$ (Shell)** - Cross-platform shell scripting
|
|
||||||
- **Bun.SQLite** - Native SQLite integration
|
|
||||||
- **Bun.FFI** - Call native libraries from JavaScript
|
|
||||||
- **Bun.Glob** - Fast file pattern matching
|
|
||||||
|
|||||||
1
src/AGENTS.md
Symbolic link
1
src/AGENTS.md
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
CLAUDE.md
|
||||||
5
src/CLAUDE.md
Normal file
5
src/CLAUDE.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
## Zig
|
||||||
|
|
||||||
|
- Prefer `@import` at the **bottom** of the file.
|
||||||
|
- It's `@import("bun")` not `@import("root").bun`
|
||||||
|
- You must be patient with the build.
|
||||||
@@ -72,6 +72,8 @@ $debug("Module loaded:", name); // Debug (stripped in release)
|
|||||||
$assert(condition, "message"); // Assertions (stripped in release)
|
$assert(condition, "message"); // Assertions (stripped in release)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Platform detection**: `process.platform` and `process.arch` are inlined and dead-code eliminated
|
||||||
|
|
||||||
## Validation and Errors
|
## Validation and Errors
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
|||||||
Reference in New Issue
Block a user