CLAUDE.md
src/js/CLAUDE.mdCLAUDE.md
Quality
85/100
Scores the file, not the repository.Length
316 words
8 headings · 5 code blocksRepository
95k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# JavaScript Builtins in Bun23Write JS builtins for Bun's Node.js compatibility and APIs. Run `bun bd` after changes.45## Directory Structure67- `builtins/` - Individual functions (`*CodeGenerator(vm)` in C++)8- `node/` - Node.js modules (`node:fs`, `node:path`)9- `bun/` - Bun modules (`bun:ffi`, `bun:sqlite`)10- `thirdparty/` - NPM replacements (`ws`, `node-fetch`)11- `internal/` - Internal modules1213## Writing Modules1415Modules are NOT ES modules:1617```typescript18const EventEmitter = require("node:events"); // String literals only19const { validateFunction } = require("internal/validators");2021export default {22 myFunction() {23 if (!$isCallable(callback)) {24 throw $ERR_INVALID_ARG_TYPE("cb", "function", callback);25 }26 },27};28```2930## Writing Builtin Functions3132```typescript33// Fifo.ts34export function createFIFO<T>(): Dequeue<T> {35 const Dequeue = require("internal/fifo");36 return new Dequeue();37}38```3940C++ access:4142```cpp43object->putDirectBuiltinFunction(vm, globalObject, identifier,44 fifoCreateFIFOCodeGenerator(vm), 0);45```4647## $ Globals and Special Syntax4849**CRITICAL**: Use `.$call` and `.$apply`, never `.call` or `.apply`:5051```typescript52// ✗ WRONG - User can tamper53callback.call(undefined, arg1);54fn.apply(undefined, args);5556// ✓ CORRECT - Tamper-proof57callback.$call(undefined, arg1);58fn.$apply(undefined, args);5960// $ prefix for private APIs61const arr = $Array.from(...); // Private globals62map.$set(key, value); // Private methods63const newArr = $newArrayWithSize(5); // JSC intrinsics64$debug("Module loaded:", name); // Debug (stripped in release)65$assert(condition, "message"); // Assertions (stripped in release)66```6768**Platform detection**: `process.platform` and `process.arch` are inlined and dead-code eliminated6970## Validation and Errors7172```typescript73const { validateFunction } = require("internal/validators");7475function myAPI(callback) {76 if (!$isCallable(callback)) {77 throw $ERR_INVALID_ARG_TYPE("callback", "function", callback);78 }79}80```8182## Build Process8384`Source TS/JS → Preprocessor → Bundler → C++ Headers`85861. Assign numeric IDs (A-Z sorted)872. Replace `$` with `__intrinsic__`, `require("x")` with `$requireId(n)`883. Bundle, convert `export default` to `return`894. Replace `__intrinsic__` with `@`, inline into C++9091ModuleLoader.rs loads modules by numeric ID via `InternalModuleRegistry.cpp`.9293## Key Rules9495- Use `.$call`/`.$apply` not `.call`/`.apply`96- String literal `require()` only97- Export via `export default {}`98- Use JSC intrinsics for performance99- Run `bun bd` after changes100
Also in oven-sh/bun
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| oven-sh/bun.github/workflows/CLAUDE.md · 95k | CLAUDE.md | testlint-formatarchgit+2 | 81/100 | today | |
| oven-sh/bunCLAUDE.md · 95k | CLAUDE.md | buildteststylearch+3 | 96/100 | 3 days ago | |
| oven-sh/bunscripts/verify-baseline-static/CLAUDE.md · 95k | CLAUDE.md | buildtesting-strategy | 65/100 | 3 days ago | |
| oven-sh/bunsrc/CLAUDE.md · 95k | CLAUDE.md | setupbuildstyletypes+2 | 76/100 | 3 days ago | |
| oven-sh/bunsrc/jsc/bindings/v8/AGENTS.md · 95k | AGENTS.md | buildtestarchtesting-strategy+4 | 81/100 | 3 days ago | |
| oven-sh/bunsrc/jsc/bindings/v8/CLAUDE.md · 95k | CLAUDE.md | buildtestarchtesting-strategy+4 | 81/100 | 3 days ago | |
| oven-sh/buntest/CLAUDE.md · 95k | CLAUDE.md | teststyletesting-strategydo-not | 97/100 | 3 days ago | |
| oven-sh/buntest/js/node/test/parallel/CLAUDE.md · 95k | CLAUDE.md | test | 43/100 | 3 days ago |
Diff against .github/workflows/CLAUDE.md Diff against CLAUDE.md Diff against scripts/verify-baseline-static/CLAUDE.md Diff against src/CLAUDE.md Diff against src/jsc/bindings/v8/AGENTS.md Diff against src/jsc/bindings/v8/CLAUDE.md Diff against test/CLAUDE.md Diff against test/js/node/test/parallel/CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| bagisto/bagistoCLAUDE.md · 28k | CLAUDE.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| livewire/livewireCLAUDE.md · 24k | CLAUDE.md | setupbuildteststyle+4 | 100/100 | 3 days ago | |
| microsoft/playwrightCLAUDE.md · 94k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| dotCMS/corecore-web/CLAUDE.md · 949 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| nimbalyst/nimbalystpackages/android/CLAUDE.md · 1.4k | CLAUDE.md | setupbuildstylearch+2 | 100/100 | 3 days ago | |
| filamentphp/filamentCLAUDE.md · 32k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| Adit-Jain-srm/NightmareNetCLAUDE.md · 45 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 3 days ago | |
| dotCMS/coreCLAUDE.md · 949 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | today |
