Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
e84b4b4
refactor: rename src/bun.js/ to src/buntime/
Dec 30, 2025
e0ae768
refactor: create src/transpiler/ for JS/TS transpiler
Dec 30, 2025
5fea6eb
refactor: create src/test_runner/ for bun:test
Dec 30, 2025
781a3f9
refactor: move console files to api/console/
Dec 30, 2025
7227eef
refactor: move inspector files to api/inspector/
Dec 30, 2025
0620ff5
refactor: move error files to api/error/
Dec 30, 2025
e306d9d
refactor: move cookie files to api/cookie/
Dec 30, 2025
bfc99fa
refactor: reorganize api/ subdirectories (step 4.5-4.14)
Dec 30, 2025
d8b43c2
refactor: move v8 compat to compat/v8/
Dec 30, 2025
ced6ba6
refactor: move webcrypto to webcore/webcrypto/
Dec 30, 2025
772533a
refactor: move node bindings to buntime/node/
Dec 30, 2025
c4205a4
refactor: move libuv and webcore to dedicated directories
Dec 30, 2025
b9af431
refactor: move napi and module files to dedicated directories
Dec 30, 2025
73abb99
refactor: move process files to api/process/
Dec 30, 2025
0197c54
refactor: move Bun core files to core/
Dec 30, 2025
57a92ae
refactor: move fetch-related files to web/fetch/
Dec 30, 2025
a8a15fe
refactor: move URL-related files to web/url/
Dec 30, 2025
f0db7ce
refactor: move blob-related files to web/blob/
Dec 30, 2025
f066c98
refactor: move encoding-related files to web/encoding/
Dec 30, 2025
f13396c
refactor: move compression files to web/compression/
Dec 30, 2025
cf86901
refactor: move event-related files to web/events/
Dec 30, 2025
c9bb8b1
refactor: move stream-related files to web/streams/
Dec 30, 2025
c67d618
refactor: move Response/Request/Body files to web/http/
Dec 30, 2025
5a33924
Move blob files to web/blob/
Dec 30, 2025
52407bc
Move Performance files to web/performance/
Dec 30, 2025
9ffbb5c
Move WebSocket files to web/websocket/
Dec 30, 2025
8696c55
Move S3 Zig files to api/s3/
Dec 30, 2025
313f714
Move Worker files to web/workers/
Dec 30, 2025
2194724
Move MessageChannel files to web/messaging/
Dec 30, 2025
f040a82
Move MIME files to web/mime/
Dec 30, 2025
e3cb63e
Move serialization files to web/serialization/
Dec 30, 2025
16e9854
Move HTTP parser files to web/http/
Dec 30, 2025
02a022f
Move CookieMap.zig to api/cookie/
Dec 30, 2025
834605e
Move FileReader.zig to web/blob/
Dec 30, 2025
018f9e0
Move AbortController/AbortSignal C++ files to web/events/
Dec 30, 2025
e993178
Move QueuingStrategy files to web/streams/
Dec 30, 2025
8c2ce7f
Move error-related files to api/error/
Dec 30, 2025
ff72b95
Move Node-related C++ files to node/
Dec 30, 2025
70daa60
Move JSNodePerformanceHooksHistogram files to node/
Dec 30, 2025
a02748e
Move Buffer-related C++ files to node/
Dec 30, 2025
742b0f0
Move Path files to node/
Dec 30, 2025
8fa79c2
Move X509Certificate files to node/crypto_bindings/
Dec 30, 2025
49fd4dc
Move ncrypto files to node/crypto_bindings/
Dec 30, 2025
f66d82a
Move debugger/profiler files to api/inspector/
Dec 30, 2025
64c75fe
Move Cookie C++ files to api/cookie/
Dec 30, 2025
0f2441f
Move CallSite/StackTrace files to api/error/
Dec 30, 2025
dc1bf7b
Move AsyncContextFrame to node/
Dec 30, 2025
ef9f4af
Move JSSocketAddressDTO to api/server/
Dec 30, 2025
8cf859f
Move ImportMetaObject to module/
Dec 30, 2025
31cf2e9
Move Serialization.cpp to web/serialization/
Dec 30, 2025
8e8d854
Move CodeCoverage.cpp to api/test/
Dec 30, 2025
5c76c0f
Move OsBinding.cpp to node/
Dec 30, 2025
9a1791d
Move DOMException to api/error/
Dec 30, 2025
f2ce862
Move JSNextTickQueue to node/
Dec 30, 2025
e137723
Move JSEnvironmentVariableMap to api/process/
Dec 30, 2025
c412073
Move BunProcessReportObjectWindows to api/process/
Dec 30, 2025
24b38f1
Move Crypto.zig to webcore/webcrypto/
Dec 30, 2025
ae4dd4e
Move prompt.zig to api/console/
Dec 30, 2025
2dfbeec
Move CPUFeatures to core/
Dec 30, 2025
289c26a
Move RegularExpression to core/
Dec 30, 2025
877c361
Move DoubleFormatter to core/
Dec 30, 2025
0efcfaa
Move CachedBytecode to module/
Dec 30, 2025
07d6e07
Move simdutf files to core/
Dec 30, 2025
25be9ea
Move highway_strings to core/
Dec 30, 2025
ff2ba59
Move stripANSI to api/console/
Dec 30, 2025
655038a
Move JSCTaskScheduler to core/
Dec 30, 2025
872a5a3
chore: move ZigException and ZigStackFrame files to api/error/
Dec 30, 2025
03c3949
chore: move uuid.zig to webcore/webcrypto/
Dec 30, 2025
2ad1284
chore: move Debugger.zig to api/inspector/
Dec 30, 2025
1f47e3f
chore: move ProcessAutoKiller.zig to api/process/
Dec 30, 2025
e4a2d75
chore: move web_worker.zig to web/workers/
Dec 30, 2025
cef59de
chore: move ipc.zig to api/ipc/
Dec 30, 2025
7952647
chore: move BuildMessage.zig to api/error/
Dec 30, 2025
eede4ef
chore: move ResolveMessage.zig to api/error/
Dec 30, 2025
790887e
chore: move HardcodedModule.zig to module/
Dec 30, 2025
601e9db
chore: move Counters.zig to core/
Dec 30, 2025
c88d0d2
chore: move config.zig to core/
Dec 30, 2025
793682b
chore: move ZigException.cpp to api/error/
Dec 30, 2025
5bdb625
chore: move spawn.cpp to api/bun/
Dec 30, 2025
ef906c3
chore: move linux_perf_tracing.cpp to api/inspector/
Dec 30, 2025
695db55
chore: move coroutine.cpp to core/
Dec 30, 2025
0d11a4e
chore: move JSBakeResponse.cpp to bake/
Dec 30, 2025
fca5b78
chore: move BakeAdditionsToGlobalObject files to bake/
Dec 30, 2025
0847104
chore: move EventLoopTask files to core/
Dec 30, 2025
d4adbae
chore: move ZigSourceProvider files to module/
Dec 30, 2025
e4a34a4
chore: move Sink.h and StreamGlobals.h to web/streams/
Dec 31, 2025
158d805
chore: move ares_build.h to api/bun/
Dec 31, 2025
316087d
chore: move dh-primes.h to node/crypto_bindings/
Dec 31, 2025
7ceb58f
chore: move uv-posix-polyfills.h to compat/libuv/
Dec 31, 2025
6f4fcfa
chore: move generated_perf_trace_events.h to api/inspector/
Dec 31, 2025
2936b29
chore: move CachedScript.h to module/
Dec 31, 2025
53b587a
chore: move memory allocator headers to core/
Dec 31, 2025
2a40325
chore: move string utility headers to core/
Dec 31, 2025
6c5f834
chore: move string utility headers to src/string/
Dec 31, 2025
a7797a7
chore: move debug-helpers.h to api/inspector/
Dec 31, 2025
b9a2852
chore: move Algo/Tuple.h to core/Algo/
Dec 31, 2025
9419868
refactor: move ModuleLoader, AsyncModule, RuntimeTranspilerStore/Cach…
Dec 31, 2025
fd84244
refactor: move SavedSourceMap.zig to module/
Dec 31, 2025
9dab6a8
refactor: move Strong.zig, Weak.zig, DeprecatedStrong.zig to bindings/
Dec 31, 2025
44727cb
refactor: move event_loop.zig and event_loop/ to core/
Dec 31, 2025
456176d
refactor: move jsc/ files to bindings/ and remove jsc/ directory
Dec 31, 2025
6e5ef1b
refactor: move rare_data.zig and hot_reloader.zig to core/
Dec 31, 2025
e7c861c
refactor: move bindgen files and JSC C API to bindings/
Dec 31, 2025
1fa3829
refactor: move VirtualMachine and virtual_machine_exports to core/
Dec 31, 2025
00ba826
refactor: move webcrypto from webcore/ to web/
Dec 31, 2025
c7ed08f
refactor: move string utility files to src/string/
Dec 31, 2025
fedccb4
refactor: move HTMLEntryPoint.cpp to src/bake/
Dec 31, 2025
d07c1bb
refactor: dissolve bindings/ into jsc/ directory with subdirectories
Dec 31, 2025
ab2f5a2
refactor: dissolve webcore/ directory into jsc/interop/
Dec 31, 2025
b40b442
refactor: organize node/ C++ files into domain subdirectories
Dec 31, 2025
9e71f44
refactor: move event_loop/ from core/ to buntime/ root
Dec 31, 2025
fd57125
refactor: complete core/ dissolution and fix documentation paths
Dec 31, 2025
3a1be14
refactor: rename transpiler files with js_ prefix for consistency
Dec 31, 2025
e48a998
docs: update CLAUDE.md with new source organization
Dec 31, 2025
e6db500
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 31, 2025
c2403a8
fix: correct JSONLineBuffer import path after rebase
Dec 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .claude/commands/upgrade-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Bun reports a Node.js version for compatibility with the Node.js ecosystem. This
- `NODEJS_ABI_VERSION` - The ABI version number (find using command below)

### 3. Version Strings
- `src/bun.js/bindings/BunProcess.cpp`
- `src/buntime/bindings/BunProcess.cpp`
- Update `Bun__versions_node` with the Node.js version
- Update `Bun__versions_v8` with the V8 version (find using command below)

Expand All @@ -33,7 +33,7 @@ Bun reports a Node.js version for compatibility with the Node.js ecosystem. This
## Files That May Need Updates

Only check these if the build fails or tests crash after updating version numbers:
- V8 compatibility files in `src/bun.js/bindings/v8/` (if V8 API changed)
- V8 compatibility files in `src/buntime/bindings/v8/` (if V8 API changed)
- Test files (if Node.js requires newer C++ standard)

## Quick Commands to Find Version Info
Expand Down
4 changes: 2 additions & 2 deletions .claude/skills/implementing-jsc-classes-cpp/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ No public constructor? Only Prototype and class needed.

Classes with C++ fields need subspaces in:

- `src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h`
- `src/bun.js/bindings/webcore/DOMIsoSubspaces.h`
- `src/buntime/bindings/webcore/DOMClientIsoSubspaces.h`
- `src/buntime/bindings/webcore/DOMIsoSubspaces.h`

```cpp
template<typename MyClassT, JSC::SubspaceAccess mode>
Expand Down
4 changes: 2 additions & 2 deletions .claude/skills/implementing-jsc-classes-zig/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub const TextDecoder = struct {
- Use `bun.JSError!JSValue` return type for error handling
- Use `globalObject` not `ctx`
- `deinit()` for cleanup, `finalize()` called by GC
- Update `src/bun.js/bindings/generated_classes_list.zig`
- Update `src/buntime/bindings/generated_classes_list.zig`

## CallFrame Access

Expand Down Expand Up @@ -196,7 +196,7 @@ pub const MyClass = struct {
};
```

3. Add to `src/bun.js/bindings/generated_classes_list.zig`
3. Add to `src/buntime/bindings/generated_classes_list.zig`

## Generated Components

Expand Down
187 changes: 116 additions & 71 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,84 +102,129 @@ test("(multi-file test) my feature", async () => {

## Code Architecture

### Directory Structure Overview

The codebase is organized so you can **guess where code lives**:

| Task | Location |
| --------------------- | ----------------------------------- |
| Fix the transpiler | `src/transpiler/` |
| Fix the test runner | `src/test_runner/` |
| Fix the bundler | `src/bundler/` |
| Fix bun install | `src/install/` |
| Fix CSS parsing | `src/css/` |
| Fix the shell | `src/shell/` |
| Fix Postgres | `src/sql/postgres/` |
| Fix MySQL | `src/sql/mysql/` |
| Fix Valkey/Redis | `src/valkey/` |
| Fix S3 | `src/s3/` or `src/buntime/api/s3/` |
| Fix Bake | `src/bake/` |
| Fix Bun.serve() | `src/buntime/api/server/` |
| Fix fetch() | `src/buntime/web/fetch/` |
| Fix WebSocket | `src/buntime/web/websocket/` |
| Fix node:fs | `src/buntime/node/fs/` |
| Fix node:crypto | `src/buntime/node/crypto/` |
| Fix crypto.subtle | `src/buntime/web/webcrypto/` |
| Fix N-API | `src/buntime/compat/napi/` |
| Fix V8 compat | `src/buntime/compat/v8/` |

### Language Structure

- **Zig code** (`src/*.zig`): Core runtime, JavaScript bindings, package manager
- **C++ code** (`src/bun.js/bindings/*.cpp`): JavaScriptCore bindings, Web APIs
- **TypeScript** (`src/js/`): Built-in JavaScript modules with special syntax (see JavaScript Modules section)
- **Generated code**: Many files are auto-generated from `.classes.ts` and other sources. Bun will automatically rebuild these files when you make changes to them.

### Core Source Organization

#### Runtime Core (`src/`)

- `bun.zig` - Main entry point
- `cli.zig` - CLI command orchestration
- `js_parser.zig`, `js_lexer.zig`, `js_printer.zig` - JavaScript parsing/printing
- `transpiler.zig` - Wrapper around js_parser with sourcemap support
- `resolver/` - Module resolution system
- `allocators/` - Custom memory allocators for performance

#### JavaScript Runtime (`src/bun.js/`)

- `bindings/` - C++ JavaScriptCore bindings
- Generated classes from `.classes.ts` files
- Manual bindings for complex APIs
- `api/` - Bun-specific APIs
- `server.zig` - HTTP server implementation
- `FFI.zig` - Foreign Function Interface
- `crypto.zig` - Cryptographic operations
- `glob.zig` - File pattern matching
- `node/` - Node.js compatibility layer
- Module implementations (fs, path, crypto, etc.)
- Process and Buffer APIs
- `webcore/` - Web API implementations
- `fetch.zig` - Fetch API
- `streams.zig` - Web Streams
- `Blob.zig`, `Response.zig`, `Request.zig`
- `event_loop/` - Event loop and task management

#### Build Tools & Package Manager

- `src/bundler/` - JavaScript bundler
- Advanced tree-shaking
- CSS processing
- HTML handling
- `src/install/` - Package manager
- `lockfile/` - Lockfile handling
- `npm.zig` - npm registry client
- `lifecycle_script_runner.zig` - Package scripts

#### Other Key Components

- `src/shell/` - Cross-platform shell implementation
- `src/css/` - CSS parser and processor
- `src/http/` - HTTP client implementation
- `websocket_client/` - WebSocket client (including deflate support)
- `src/sql/` - SQL database integrations
- `src/bake/` - Server-side rendering framework

### JavaScript Class Implementation (C++)

When implementing JavaScript classes in C++:

1. Create three classes if there's a public constructor:
- `class Foo : public JSC::JSDestructibleObject` (if has C++ fields)
- `class FooPrototype : public JSC::JSNonFinalObject`
- `class FooConstructor : public JSC::InternalFunction`

2. Define properties using HashTableValue arrays
3. Add iso subspaces for classes with C++ fields
4. Cache structures in ZigGlobalObject
- **C++ code** (`src/buntime/**/*.cpp`): JavaScriptCore bindings, Web APIs
- **TypeScript** (`src/js/`): Built-in JavaScript modules with special syntax
- **Generated code**: Auto-generated from `.classes.ts` files during build

### Top-Level Source Organization

```
src/
├── transpiler/ # JS/TS transpiler (js_parser, js_lexer, js_printer)
├── test_runner/ # bun:test implementation
├── bundler/ # bun build
├── resolver/ # Module resolution
├── install/ # Package manager (bun install)
├── css/ # CSS parser
├── shell/ # Bun.$ shell
├── bake/ # Bake framework
├── sql/ # SQL clients (postgres/, mysql/)
├── s3/ # S3 core
├── valkey/ # Valkey/Redis
├── http/ # HTTP client
├── string/ # String utilities
├── ast/ # AST types
├── js/ # TypeScript built-in modules
│
└── buntime/ # JavaScript runtime
├── api/ # Bun.* APIs
│ ├── server/ # Bun.serve()
│ ├── console/ # console.*
│ ├── inspector/ # Debugger, profiler
│ ├── error/ # Error handling, stack traces
│ ├── cookie/ # Cookie parsing
│ ├── s3/ # S3 JS bindings
│ ├── ffi/ # Bun.FFI
│ ├── sqlite/ # bun:sqlite
│ ├── sql/ # SQL bindings
│ ├── shell/ # Shell bindings
│ ├── ipc/ # IPC
│ ├── plugin/ # Bundler plugins
│ ├── secrets/ # Secrets API
│ └── test/ # Test helpers
│
├── web/ # Web Standards
│ ├── fetch/ # Fetch API
│ ├── url/ # URL, URLSearchParams
│ ├── blob/ # Blob, File, FormData
│ ├── encoding/ # TextEncoder/Decoder
│ ├── compression/ # CompressionStream
│ ├── events/ # EventTarget, CustomEvent
│ ├── streams/ # ReadableStream, WritableStream
│ ├── performance/ # Performance API
│ ├── websocket/ # WebSocket
│ └── webcrypto/ # crypto.subtle
│
├── node/ # Node.js Compatibility
│ ├── buffer/ # Buffer
│ ├── process/ # process.*
│ ├── vm/ # node:vm
│ ├── crypto/ # node:crypto
│ ├── http/ # node:http
│ ├── fs/ # node:fs helpers
│ ├── os/ # node:os
│ ├── path/ # node:path
│ ├── util/ # node:util
│ ├── timers/ # Timers
│ ├── async_hooks/ # AsyncLocalStorage
│ ├── perf_hooks/ # Performance hooks
│ └── constants/ # Constants
│
├── compat/ # Native Addon Compatibility
│ ├── napi/ # N-API
│ ├── v8/ # V8 C++ API
│ ├── libuv/ # libuv polyfills
│ └── windows/ # Windows-specific
│
├── jsc/ # JavaScriptCore Integration
│ ├── types/ # JSValue, JSString, JSArray, etc.
│ ├── global/ # ZigGlobalObject, BunGlobalScope
│ ├── gc/ # GC helpers, weak refs
│ ├── interop/ # C++/Zig bindings, IDL
│ └── generated/ # Generated bindings
│
├── module/ # Module system (CommonJS, ESM)
├── event_loop/ # Event loop, tasks, timers
└── core/ # VirtualMachine, config
```
Comment on lines +140 to +218

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add languages to new fenced code blocks to satisfy markdownlint

markdownlint is flagging several of the newly-added fenced blocks (directory tree and command snippets) for missing languages (MD040). To keep docs lint‑clean and improve rendering, consider:

  • Using ```text (or ```plaintext) for the directory tree under “Top-Level Source Organization”.
  • Using ```bash for shell command examples (e.g., the bun bd verification snippet).
  • Using an appropriate language (e.g., ```zig) if you later add Zig examples to these sections.

This is purely documentation hygiene; structure and content look good.

Also applies to: 220-229

🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

164-164: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


176-176: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


185-185: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


196-196: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


208-208: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
In CLAUDE.md around lines 140-218 (and also lines 220-229), the newly added
fenced code blocks lack language tags which triggers markdownlint MD040; update
the blocks by adding appropriate language identifiers — use ```text or
```plaintext for the directory tree block, use ```bash for any shell/command
snippets (e.g., bun bd verification), and use ```zig (or another specific
language) if you later add Zig examples — apply these changes to each offending
fenced block in the specified ranges.


### Code Generation

Code generation happens automatically as part of the build process. The main scripts are:
Code generation happens automatically during build. Main scripts:

- `src/codegen/generate-classes.ts` - Generates Zig & C++ bindings from `*.classes.ts` files
- `src/codegen/generate-jssink.ts` - Generates stream-related classes
- `src/codegen/bundle-modules.ts` - Bundles built-in modules like `node:fs`
- `src/codegen/bundle-functions.ts` - Bundles global functions like `ReadableStream`
- `src/codegen/generate-classes.ts` - Generates Zig & C++ from `*.classes.ts`
- `src/codegen/generate-jssink.ts` - Stream-related classes
- `src/codegen/bundle-modules.ts` - Built-in modules like `node:fs`
- `src/codegen/bundle-functions.ts` - Global functions like `ReadableStream`

In development, bundled modules can be reloaded without rebuilding Zig by running `bun run build`.

Expand Down
Loading