feat: Add Bun runtime compatibility layer#5877
feat: Add Bun runtime compatibility layer#5877lalalune wants to merge 1 commit intocloudflare:mainfrom
Conversation
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
While we appreciate outside contributions, at this time we do not intend to impl (or add someone else's impl) of any bun-specific APIs to the Workers runtime. It is something we've discussed and have currently ruled out. There is just simply not enough ecosystem demand to justify the effort that would be needed to maintain it. It's conceivable that at some future point in time we might reconsider but it's unlikely to be any time soon. (I left this comment in the original PR as well) |
Adds a Bun-compatible API layer enabling Bun applications to run on workerd.
## Features
- Hash functions: wyhash, crc32, adler32, cityhash, murmur (JS implementations)
- Password hashing: PBKDF2 via WebCrypto
- File operations: node:fs with /tmp via nodejs_compat (lazy-loaded)
- DNS: DNS-over-HTTPS via Cloudflare/Google
- Utilities: deepEquals, escapeHTML, inspect, stringWidth, sleep
- Stream utilities: readableStreamToText/Array/ArrayBuffer/Blob/JSON
- ArrayBufferSink for buffer accumulation
## Not Supported
- bun:sqlite (throws error, directs to Cloudflare D1)
- bun:ffi (throws error, directs to WASM)
- bun:test (stubs only)
## Usage
```javascript
import Bun from './bun-bundle.js'
export default {
async fetch(request) {
const hash = Bun.hash('hello')
await Bun.write('/tmp/data.txt', 'Hello')
return new Response(await Bun.file('/tmp/data.txt').text())
}
}
```
## Files
- src/bun/ - TypeScript implementation
- dist/bun/bun-bundle.js - Bundled compatibility layer
- samples/helloworld-bun/ - Sample worker
Tested: 198 unit tests pass, verified in real workerd
0c9270d to
c25f530
Compare
|
okay makes sense, will close |
Summary
This adds a Bun-compatible API layer for workerd, enabling Bun applications to run on Cloudflare Workers infrastructure.
Usage
Features
node:fs(same filesystem limitations asnodejs_compat; typically/tmpwithenable_web_file_system)Samples
samples/bun-bundle/- Demonstrates bundled compatibility layersamples/bun-hello/- Demonstrates nativebun:*importsFiles Changed
src/bun/- TypeScript implementation (14 files)src/workerd/api/bun/- C++ integration (2 files)src/workerd/api/modules.h- Module registrationsrc/workerd/api/BUILD.bazel- Build dependenciessamples/bun-bundle/andsamples/bun-hello/- Sample workersTest Results
bun.test.ts: 180 tests passedsqlite.test.ts: 26 tests passeddns.test.ts: 15 tests passed