Compare commits

..

387 Commits

Author SHA1 Message Date
Claude Bot
b2c8dc1eee Enhance macOS runner infrastructure with comprehensive improvements
This update significantly improves the macOS runner infrastructure based on detailed analysis of the bootstrap.sh script and adds robust testing and validation:

## 🔧 **Key Improvements**

### Software Version Synchronization
- **Node.js**: 24.3.0 (exact version matching bootstrap.sh)
- **Bun**: 1.2.17 (exact version matching bootstrap.sh)
- **LLVM**: 19.1.7 (exact version matching bootstrap.sh)
- **CMake**: 3.30.5 (exact version matching bootstrap.sh)
- **Buildkite Agent**: 3.87.0

### Enhanced bootstrap-macos.sh
- Complete rewrite based on bootstrap.sh analysis
- Added Tailscale configuration for VPN connectivity
- Age encryption tool for macOS equivalent of core dumps
- macFUSE and python-fuse for filesystem testing
- Chromium installation for browser testing
- Exact version installations with verification
- Node.js headers and node-gyp cache setup

### Comprehensive Testing & Validation
- **Image Validation**: Tests all software installations after build
- **Flakiness Testing**: 3 iterations with 80% success rate minimum
- **Software Verification**: Node.js, Bun, CMake, Clang, Docker, Tailscale
- **Health Endpoint Testing**: Validates service availability
- **Automated Cleanup**: Test VMs are automatically cleaned up

### Discord Notifications
- Replaced Slack with Discord webhooks for all notifications
- Enhanced notification format with markdown support
- Color-coded status indicators (green=success, red=failure, gray=skipped)
- Detailed deployment information and links

### User Isolation Improvements
- Enhanced user creation with proper environment setup
- Improved cleanup with comprehensive process termination
- Better error handling and logging
- Timeout management for job execution

### Documentation & Developer Experience
- **CLAUDE.md**: Comprehensive guide for future Claude development
- Updated README.md with exact version requirements
- Updated DEPLOYMENT.md with Discord configuration
- Detailed troubleshooting and debugging sections

## 🚀 **Architecture Benefits**

- **Reliability**: Flakiness testing ensures consistent VM performance
- **Consistency**: Exact version matching with bootstrap.sh prevents environment drift
- **Isolation**: Complete job isolation with disposable user accounts
- **Monitoring**: Enhanced health checks and status reporting
- **Maintainability**: Clear documentation and development guidelines

## 🛠️ **Technical Details**

- Enhanced Packer configuration with comprehensive software installation
- Improved Terraform infrastructure with better resource management
- Robust GitHub Actions workflows with multi-stage validation
- Comprehensive user management scripts with proper cleanup
- Health monitoring and automated recovery mechanisms

The infrastructure now provides production-ready macOS CI runners with enterprise-grade reliability, security, and monitoring capabilities.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 11:55:26 +00:00
Claude Bot
7f8b985c69 Add macOS runner infrastructure for automated GitHub Actions deployment
This implements a comprehensive macOS CI runner infrastructure based on the MacStadium Orka platform, providing:

## Key Features
- **Complete Job Isolation**: Each Buildkite job runs in its own user account
- **Automated VM Image Building**: Daily Packer-based image rebuilds with latest software
- **Fleet Management**: Terraform-managed VM fleet with auto-scaling
- **Multi-Version Support**: macOS 13, 14, and 15 simultaneously
- **Comprehensive Cleanup**: Automated cleanup of processes, files, and resources

## Components
- **Packer Configuration**: Automated VM image building with all required software
- **Terraform Infrastructure**: VM fleet management with auto-scaling and monitoring
- **User Management Scripts**: Per-job user creation and cleanup for complete isolation
- **GitHub Actions Workflows**: Daily image rebuilds and fleet deployment automation
- **Bootstrap Scripts**: macOS-specific software installation and configuration

## Architecture
- Uses MacStadium Orka platform for macOS VM hosting
- Implements disposable user accounts per job (bk-<job-id>)
- Includes health monitoring and auto-scaling based on queue demand
- Provides comprehensive logging and Slack notifications
- Supports cost optimization through efficient resource utilization

## Software Included
- Xcode Command Line Tools, LLVM/Clang 19, Node.js 24.3.0, Bun 1.2.17
- Python 3.11/3.12, Go, Rust, Docker Desktop
- Build tools: CMake, Ninja, make, pkg-config, ccache
- Development utilities and system libraries

Based on the existing bootstrap.sh but optimized for macOS CI environments with complete job isolation and automated management.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 11:49:26 +00:00
Michael H
15b7cd8c18 node:fs.glob support array of excludes and globs (#20883) 2025-07-16 03:08:54 -07:00
190n
d3adc16524 do not silently fail in configure_core_dumps (#21095) 2025-07-16 03:06:46 -07:00
Meghan Denny
fae0a64d90 small 20956 followup (#21103) 2025-07-16 02:26:40 -07:00
Michael H
0ee633663e Implement bun why (#20847)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-16 02:00:53 -07:00
Michael H
a717679fb3 support $variables in test.each (#21061) 2025-07-16 01:42:19 -07:00
Dylan Conway
36ce7b0203 comment 2025-07-16 01:08:30 -07:00
Dylan Conway
2bc75a87f4 fix(install): fix resolving duplicate dependencies (#21059)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-16 01:01:10 -07:00
Jarred Sumner
fdec7fc6e3 Simpler version of #20813 (#21102)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-07-16 00:14:33 -07:00
Meghan Denny
875604a42b safety: a lot more exception checker progress (#20956) 2025-07-16 00:11:19 -07:00
Jarred Sumner
d8b37bf408 Shrink MimeType list (#21004)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-07-15 22:37:09 -07:00
jarred-sumner-bot
32ce9a3890 Add Windows PE codesigning support for standalone executables (#21091)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 22:31:54 -07:00
Jarred Sumner
0ce70df96b Buffer stdout when printing summary + check for dir/package.json + npmrc link-workspace-packages + npmrc save-exact (#20907) 2025-07-15 22:15:41 -07:00
Jarred Sumner
b0a5728b37 Allow "catalog" and "catalogs" in top-level package.json if it wasn't provided in "workspaces" object (#21009) 2025-07-15 22:14:27 -07:00
Michael H
20db4b636e implement bun pm pkg (#21046) 2025-07-15 22:14:00 -07:00
jarred-sumner-bot
1cef9399e4 fix: CSS parser crashes with calc() NaN values and system colors in color-mix() (#21079)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com>
2025-07-15 22:02:03 -07:00
Michael H
f4444c0e4d fix --tsconfig-override (#21045) 2025-07-15 22:00:17 -07:00
Dylan Conway
577b327fe5 [ENG-15008] fix #21086 (#21093)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 21:59:41 -07:00
pfg
9d2eb78544 Fetch redirect fix (#21064)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-07-15 20:51:52 -07:00
Meghan Denny
4be43e2c52 de-flake spawn.test.ts 2025-07-15 17:18:46 -07:00
Ciro Spaciari
93cc51c974 fix(s3) handle slashs at end and start of bucket name (#20997) 2025-07-15 16:52:47 -07:00
190n
528ee8b673 cleanup main.zig (#21085) 2025-07-15 16:29:03 -07:00
Jarred Sumner
c2fc69302b Try to deflake bun-install-lifecycle-scripts test (#21070) 2025-07-15 16:27:56 -07:00
Jarred Sumner
df7b6b4813 Add NODE_NO_WARNINGS (#21075) 2025-07-15 16:27:21 -07:00
jarred-sumner-bot
81b4b8ca94 fix(s3): ensure correct alphabetical query parameter order in presigned URLs (#21050)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 16:20:34 -07:00
Meghan Denny
a242c878c3 [publish images] ci: add ubuntu 25.04 (#20996)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-15 01:22:41 -07:00
taylor.fish
77af8729c1 Fix potential buffer overflow in which.isValid (#21062)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 01:20:34 -07:00
taylor.fish
3b2289d76c Sync Mutex and Futex with upstream and port std.Thread.Condition (#21060)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 01:16:40 -07:00
jarred-sumner-bot
803181ae7c Add --quiet flag to bun pm pack command (#21053)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-15 01:14:58 -07:00
Jarred Sumner
89aae0bdc0 Add flag to disable sql auto pipelining (#21067)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-15 01:13:35 -07:00
Jarred Sumner
e62f9286c9 Fix formatter action 2025-07-15 00:16:30 -07:00
Alistair Smith
b75eb0c7c6 Updates to bun init React templates: Electric boogaloo (#21066) 2025-07-15 00:10:02 -07:00
Jarred Sumner
33fac76763 Delete flaky test that made incorrect assumptions about the event loop
We cannot assume that the next event loop cycle will yield the expected outcome from the operating system. We can assume certain things happen in a certain order, but when timers run next does not mean kqueue/epoll/iocp will always have the data available there.
2025-07-14 23:58:37 -07:00
Jarred Sumner
40970aee3b Delete flaky test that made incorrect assumptions about the event loop
We cannot assume that the next event loop cycle will yield the expected outcome from the operating system. We can assume certain things happen in a certain order, but when timers run next does not mean kqueue/epoll/iocp will always have the data available there.
2025-07-14 23:53:12 -07:00
Jarred Sumner
a6f09228af Fix 2025-07-14 22:33:59 -07:00
Ciro Spaciari
6efb346e68 feature(postgres) add pipelining support (#20986)
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-07-14 21:59:16 -07:00
jarred-sumner-bot
5fe0c034e2 fix: respect user-provided Connection header in fetch() requests (#21049)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-07-14 20:53:46 -07:00
jarred-sumner-bot
7f29446d9b fix(install): handle lifecycle script spawn failures gracefully instead of crashing (#21054)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
2025-07-14 20:50:32 -07:00
Jose Angel
c5f64036a7 docs: Update docs for use prisma with bun (#21048)
Co-authored-by: jose angel gonzalez velazquez <angel@23LAP1CD208600C.indra.es>
2025-07-14 19:40:05 -07:00
jarred-sumner-bot
757096777b Document test.coveragePathIgnorePatterns option (#21036)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-14 17:36:10 -07:00
jarred-sumner-bot
e9ccc81e03 Add --sql-preconnect CLI flag for PostgreSQL startup connections (#21035)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-14 15:05:30 -07:00
Jarred Sumner
70ebe75e6c Fixes #21011 (#21014) 2025-07-14 14:18:18 -07:00
jarred-sumner-bot
44a7e6279e Make --console-depth=0 enable infinite depth instead of zero depth (#21038)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-14 07:45:20 -07:00
Jarred Sumner
7bb9a94d68 Implement test.coveragePathIgnorePatterns (#21013)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-14 05:08:32 -07:00
jarred-sumner-bot
3bba4e1446 Add --console-depth CLI flag and console.depth bunfig option (#21016)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-14 04:58:41 -07:00
Jarred Sumner
8cf4df296d Delete the merge conflict factory
There are many situations where using `catch unreachable` is a reasonable or sometimes necessary decision. This rule causes many, many merge conflicts.
2025-07-14 03:53:50 -07:00
Michael H
3ba9b5710e fix Bun.build with { sourcemap: true } (#21029) 2025-07-14 03:52:26 -07:00
Jarred Sumner
a102f85df2 make debug build logs less noisy 2025-07-14 03:11:10 -07:00
Michael H
e8289cc3ab fix os.networkInterfaces where scope_id should be scopeid (#21026) 2025-07-14 02:48:20 -07:00
jarred-sumner-bot
a69a9b4ea1 Fix test output filtering for skipped and todo tests (#21021)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com>
2025-07-14 02:46:55 -07:00
Jarred Sumner
3f283680dd Buffer stderr and stdout in bun:test reporting (#21023) 2025-07-14 00:55:35 -07:00
Jarred Sumner
2e02d9de28 Use ReadableStream.prototype.* in tests instead of new Response(...).* (#20937)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Alistair Smith <hi@alistair.sh>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-14 00:47:53 -07:00
Jarred Sumner
9ac6690fb7 Update package.json 2025-07-13 23:13:04 -07:00
Michael H
8898c4c455 Vscode test runner support (#20645) 2025-07-13 21:57:44 -07:00
Jarred Sumner
499eac0d49 Enable SIMD multiline comment optimization (#13844)
Co-authored-by: Meghan Denny <meghan@bun.sh>
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-07-13 04:46:07 -07:00
Jarred Sumner
285f708fe6 Implement more v8::Array::New overloads, v8::Object::{Get,Set}, v8::Value::StrictEquals, v8::Array::Iterate (#20737)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: jarred <jarred@bun.sh>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Ben Grant <ben@bun.sh>
2025-07-13 04:27:43 -07:00
Jarred Sumner
9cd9f534d5 Debian trixie does not support sfotware-properties-common 2025-07-13 02:34:13 -07:00
Jarred Sumner
f913a21709 Debian trixie does not support sfotware-properties-common
https://github.com/llvm/llvm-project/issues/120608
2025-07-13 02:29:27 -07:00
Jarred Sumner
a976a048b7 Delete unused and confusing bun-internal-test package (#21008)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-13 02:23:50 -07:00
Jarred Sumner
22627eda9b CI 2025-07-13 01:56:14 -07:00
Jarred Sumner
d6d7251352 Fixes #14988 (#20928)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-12 18:22:54 -07:00
Zack Radisic
ac61b1d471 Use better function names for bun.String (#20999) 2025-07-12 18:19:16 -07:00
Antonio Anderson
0feddf716a fix(docs): use bun.sh in PowerShell install command to avoid rediret (#21001) 2025-07-12 18:16:09 -07:00
Zack Radisic
eae8fb34b8 Don't strip out debug symbols for lldb (#20874)
Co-authored-by: CountBleck <Mr.YouKnowWhoIAm@protonmail.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Michael H <git@riskymh.dev>
Co-authored-by: 190n <ben@bun.sh>
Co-authored-by: Alistair Smith <hi@alistair.sh>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
Co-authored-by: Kai Tamkun <13513421+heimskr@users.noreply.github.com>
Co-authored-by: Claude <claude@anthropic.ai>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-07-12 17:13:34 -07:00
Meghan Denny
c106f31345 test: delete bundler test temp folders upon success (#20990) 2025-07-12 10:59:50 -07:00
taylor.fish
0baf5b94e2 Fix bun add with multiple packages (#20987)
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-07-12 02:10:45 -07:00
Meghan Denny
7827df5745 [publish images] 2025-07-12 00:55:22 -07:00
Meghan Denny
dbd577cde6 ci: download exact version of node specifed (#20936)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-07-12 00:53:52 -07:00
Jarred Sumner
9e4700ee2d Remove unused Symbol.for(primitive) calls in bundler (#20888)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-07-12 00:52:07 -07:00
Alistair Smith
6615a2c9d4 docs: add typescript migration note for declaring globals in jest (#20985) 2025-07-11 19:13:40 -07:00
Alistair Smith
c594e7ecc1 Add non-default-referenced ambient declaration file to globally declare test runner symbols (#20977) 2025-07-11 18:06:45 -07:00
Jarred Sumner
9e4f460d17 Improve tree-shaking of try statements in dead code (#20934) 2025-07-11 15:47:04 -07:00
190n
c49547cfa4 Fix #20972 (#20974) 2025-07-11 15:23:29 -07:00
Alistair Smith
ee7e1f7d2c fix #20978 (#20981) 2025-07-11 15:00:02 -07:00
Alistair Smith
70c22d41d6 types: NodeJS.ProcessEnv does not extend ImportMetaEnv (#20976) 2025-07-11 14:16:11 -07:00
Jarred Sumner
a059c76370 Include RAM in crash report message (#20954)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-11 12:45:49 -07:00
Meghan Denny
9bc559e09f console: fix printing of Response(Bun.file()) (#20933) 2025-07-11 11:37:44 -07:00
Alistair Smith
c82e4fb485 fix typo (#20962) 2025-07-10 22:57:14 -07:00
Alistair Smith
a8780632a6 fix typo 2025-07-10 22:56:21 -07:00
Alistair Smith
65ccb39778 Convert bun-types.test.ts to TS compiler api, fix forward-declared empty interfaces (#20960) 2025-07-10 22:47:42 -07:00
Jarred Sumner
ac55376161 [ci] Don't error if machine hits permission error when modifying coredump settings 2025-07-10 21:32:40 -07:00
Jarred Sumner
5bde8a6c3b Include an Error object in WebSocket error event dispatch (#20957) 2025-07-10 21:28:03 -07:00
Zack Radisic
d733a96ba7 Add LLDB pretty printing for bun.BabyList (#20958)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-10 21:27:03 -07:00
190n
650c8f6d60 cmake: do not accept too-new LLVM versions (#20955) 2025-07-10 18:20:51 -07:00
Alistair Smith
6a62784e89 fix(types): Non-empty TextDecoderStream and TextEncoderStream when outside DOM (#20953) 2025-07-10 17:48:45 -07:00
Meghan Denny
6c5b863530 safety: a lot more exception checker progress (#20817) 2025-07-10 15:34:51 -07:00
taylor.fish
c6bce38ead Fix incorrect negation of isEmpty() in assertion (#20952) 2025-07-10 15:34:46 -07:00
taylor.fish
5a1a3b425c Refactor UnboundedQueue (#20926) 2025-07-10 14:46:10 -07:00
taylor.fish
40c09fdf23 .gitignore: ignore Vim swap files (#20950) 2025-07-10 13:56:02 -07:00
Meghan Denny
055f821a75 webkit: disable libpas on windows (#20931) 2025-07-10 13:37:31 -07:00
Erick Christian
77a565269a docs: document BUN_BE_BUN (#20949)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-10 13:35:32 -07:00
Michael H
000ae5c6b9 types: Bun.serve routes supportes Bun.file's (#20919) 2025-07-10 11:49:26 -07:00
Michael H
5dbaf08e4a Bun Lambda keep old bun url (#20941) 2025-07-10 03:35:44 -07:00
Jarred Sumner
5dbe5d4308 Update CLAUDE.md 2025-07-10 01:08:10 -07:00
Jarred Sumner
b8dbd5aa73 Try always running timers if they exist (#20840) 2025-07-10 00:12:22 -07:00
190n
0d8175d4b9 print number of completed runs and ETA in gamble.ts (#20920) 2025-07-10 00:11:42 -07:00
Jarred Sumner
55a9cccac0 bun.sh -> bun.com (#20909) 2025-07-10 00:10:43 -07:00
Meghan Denny
72b5c0885a test: fix process.test.js (#20932) 2025-07-09 23:02:43 -07:00
Dylan Conway
a1ef8f00ac fix(install): clone arena memory on manifest parse errors (#20925) 2025-07-09 21:03:51 -07:00
Dylan Conway
6e92f0b9cb make number smaller 2025-07-09 19:22:57 -07:00
Meghan Denny
392acbee5a js: internal/validators: define simple validators in js (#20897) 2025-07-09 16:45:40 -07:00
190n
8b7888aeee [publish images] upload encrypted core dumps from CI (#19189)
Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
Co-authored-by: Ashcon Partovi <ashcon@partovi.net>
2025-07-09 15:42:11 -07:00
Dylan Conway
f24e8cb98a implement "nodeLinker": "isolated" in bun install (#20440)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-09 00:19:57 -07:00
Meghan Denny
36bedb0bbc js: fix async macros on windows (#20903) 2025-07-08 21:23:25 -07:00
Meghan Denny
a63f09784e .vscode/launch.json: delete unused configurations (#20901) 2025-07-08 16:45:24 -07:00
Jarred Sumner
454316ffc3 Implement "node:module"'s findSourceMap and SourceMap class (#20863)
Co-authored-by: Claude <claude@anthropic.ai>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-07 23:08:12 -07:00
Alistair Smith
d4a52f77c7 Move ReadableStream#{text,bytes,json,blob} to global (#20879)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-07 23:06:27 -07:00
Ciro Spaciari
c2311ed06c fix(http2) avoid sending RST multiple times per stream (#20872) 2025-07-07 22:36:39 -07:00
Kai Tamkun
05e8a6dd4d Add support for vm.constants.DONT_CONTEXTIFY (#20088) 2025-07-07 19:29:53 -07:00
Ciro Spaciari
75902e6a21 fix(s3) fix loading http endpoint from env (#20876) 2025-07-07 19:24:32 -07:00
Ciro Spaciari
aa06455987 refactor(postgres) improve postgres code base (#20808)
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-07-07 18:41:01 -07:00
Alistair Smith
19a855e02b types: Introduce SQL.Helper in Bun.sql (#20809)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-07 17:47:51 -07:00
190n
b1a0502c0c [publish images] fix v8.test.ts timeouts (#20871) 2025-07-07 16:16:47 -07:00
Michael H
0399ae0ee9 followup for bun pm version (#20799) 2025-07-07 11:21:36 -07:00
Zack Radisic
dacb75dc1f Fix crash in bundler related to onLoad plugins that return file loader for HTML imports (#20849) 2025-07-07 01:07:03 -07:00
Jarred Sumner
c370645afc Update zig-javascriptcore-classes.mdc 2025-07-06 21:08:26 -07:00
Jarred Sumner
e1957228f3 [internal] Add error when .classes.ts files are invalid 2025-07-06 21:07:38 -07:00
Jarred Sumner
9feaab47f5 Update environment.json 2025-07-05 22:20:29 -07:00
CountBleck
d306e65d0e Remove duplicate toBeInstanceOf type declaration for Expect (#20844) 2025-07-05 17:25:52 -07:00
Adam
7ba4b1d01e Fix: deprecated goo.gl links in snapshots raised in issue #20086 (#20424) 2025-07-05 00:58:42 -07:00
Dylan Conway
906b287e31 fix BUN-KHE (#20820)
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-04 15:17:24 -07:00
Jarred Sumner
eabbd5cbfb Fix React HMR duplicate identifier error for named default exports (#20812)
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-04 03:06:00 -07:00
Meghan Denny
068997b529 make node:dns,net,cluster,tls exception checker clear (#20658)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-07-03 18:28:38 -07:00
Michael H
0612dc7bd9 Support process.features.typescript (#20801) 2025-07-03 16:26:32 -07:00
Michael H
8657d705b8 remove yarn from default-trusted-dependencies.txt (#20684) 2025-07-03 16:23:03 -07:00
Meghan Denny
2e59e845fa test: refactor node-napi.test.ts for more observability (#20781)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-07-03 14:37:11 -07:00
Meghan Denny
00df6cb4ee Bump 2025-07-03 11:59:00 -07:00
Jarred Sumner
0d4089ea7c Fixes #20753 (#20789)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-07-03 01:06:22 -07:00
Jarred Sumner
27c979129c Introduce Bun.randomUUIDv5 (#20782)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: jarred <jarred@bun.sh>
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-07-02 22:47:14 -07:00
Jarred Sumner
8bb835bf63 Fix: Dynamic imports incorrectly resolve to CSS files when code splitting is enabled (#20784)
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-07-02 22:31:02 -07:00
Jarred Sumner
8bf50cf456 Fix 2 differences in napi vs node (#20761)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-07-02 22:11:21 -07:00
Meghan Denny
01e2cb25e3 test: bump zlib/leak.test.ts for asan 2025-07-02 21:48:24 -07:00
Jarred Sumner
010e715902 Upgrade Webkit to 29bbdff0f94f (#20780) 2025-07-02 20:50:15 -07:00
Jarred Sumner
8b321cc1c6 Match Node.js v24 behavior for napi_get_value_string_utf8 handling of NAPI_AUTO_LENGTH (#20698)
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-02 20:10:08 -07:00
Zack Radisic
0b9bab34d8 SSG (#20745)
Co-authored-by: Alistair Smith <hi@alistair.sh>
2025-07-02 20:06:43 -07:00
Meghan Denny
61f0cc497b ci: log available disk space at the start of build/test run (#20779) 2025-07-02 19:43:54 -07:00
Michael H
764e20ee19 implement bun pm version (#20706) 2025-07-02 18:54:47 -07:00
Meghan Denny
0276f5e4a3 misc: use fromJSHostCallGeneric in a few more places (#20778) 2025-07-02 18:35:44 -07:00
Jarred Sumner
5a7b5ceb33 Fix several missing async context tracking callbacks (#20759)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-07-02 17:45:00 -07:00
Ciro Spaciari
a04cf04cd5 fix(grpc/http2) fix tonic Rust support (#20738)
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-02 17:43:38 -07:00
Ben Grant
79284376ca Delete test-net-bytes-stats.js
Mistakenly re-added in #20659 after prior revert in #20693
2025-07-02 17:32:19 -07:00
Alistair Smith
452000a2ce Node.js test test-fs-watchfile.js (#20773) 2025-07-02 15:04:39 -07:00
190n
172aecb02e [publish images] Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 (v2) (#20772)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Meghan Denny <meghan@bun.sh>
Co-authored-by: Ashcon Partovi <ashcon@partovi.net>
Co-authored-by: pfg <pfg@pfg.pw>
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-02 12:06:08 -07:00
Ben Grant
ea57037567 Revert "Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 (#20659) [publish images]"
This reverts commit 80309e4d59. It breaks the Windows CI.
2025-07-02 09:40:32 -07:00
Jarred Sumner
80309e4d59 Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 (#20659) [publish images]
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Meghan Denny <meghan@bun.sh>
Co-authored-by: Ashcon Partovi <ashcon@partovi.net>
Co-authored-by: pfg <pfg@pfg.pw>
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Ben Grant <ben@bun.sh>
2025-07-02 00:03:05 -07:00
190n
48c5256196 Fix assertions_only usage in fromJSHostCallGeneric (#20733) 2025-07-01 23:36:56 -07:00
Jarred Sumner
e1ec32caea Fix incorrect comptime conditional 2025-07-01 20:33:34 -07:00
mizulu
7f55b1af55 docs: fix missing word in the bundler text loader section (#20723) 2025-07-01 16:05:06 -07:00
Jarred Sumner
fbe405fb89 Fail the test when no tests match the filter (#20749)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-07-01 16:03:19 -07:00
pagal
cd561c6bba Documentation fix for --filter (#20714) 2025-07-01 15:30:39 -07:00
Jarred Sumner
1b5c6fcfb5 Update building-bun.mdc 2025-07-01 14:44:16 -07:00
Jarred Sumner
74e65317f2 Fix type for HTML imports (#20744) 2025-06-30 23:36:41 -07:00
Jarred Sumner
72d43590a1 Add export default to more node polyfills (#20747)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-30 23:02:52 -07:00
Jarred Sumner
9049b732db Fix regression from referencing global inside of node fallbacks without making it === globalThis (#20739) 2025-06-30 18:57:58 -07:00
Jarred Sumner
1e3d82441c Create environment.json 2025-06-30 15:00:16 -07:00
Meghan Denny
ca59ed04bd node: sync updated tests (#20625) 2025-06-30 14:52:50 -07:00
Jarred Sumner
fc7e2e912e Revert "Configure cursor background agents"
This reverts commit 16915504da.
2025-06-30 10:02:16 -07:00
Jarred Sumner
16915504da Configure cursor background agents 2025-06-30 09:28:27 -07:00
github-actions[bot]
6d03bdfc03 deps: update sqlite to 3.50.200 (#20711)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-28 23:47:47 -07:00
Jarred Sumner
034bcf2b57 Deflake
These tests should not have been marked as passing.

test/js/node/test/parallel/test-cluster-worker-kill-signal.js
test/js/node/test/parallel/test-child-process-prototype-tampering.mjs
2025-06-28 23:45:34 -07:00
pfg
3223da2734 ReadableStream .text(), .json(), .arrayBuffer(), .bytes() (#20694)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-06-28 00:27:57 -07:00
Jarred Sumner
dd67cda545 Fixes #20615 (#20616) 2025-06-27 22:05:20 -07:00
Sharun
a067619f13 docs(prisma): update the prisma init command to use --bun (#15171)
Co-authored-by: Meghan Denny <meghan@bun.sh>
2025-06-27 22:04:52 -07:00
Yiheng
c9242dae3a Update bunfig.md (#16029) 2025-06-27 21:32:38 -07:00
Jarred Sumner
8d9b56260b Make AGENTS.md a symlink to CLAUDE.md 2025-06-27 21:13:21 -07:00
Ciro Spaciari
964f2a8941 fix(fetch/s3) Handle backpressure when upload large bodies (#20481)
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-06-27 20:52:46 -07:00
Jarred Sumner
694a820a34 Update spawn.md 2025-06-27 19:58:31 -07:00
Jarred Sumner
1d48f91b5e Enable ReadableStream as stdin for Bun.spawn (#20582)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: jarred <jarred@bun.sh>
Co-authored-by: pfg <pfg@pfg.pw>
2025-06-27 19:42:03 -07:00
Jarred Sumner
7839844abb update CLAUDE.md 2025-06-27 18:03:45 -07:00
Jarred Sumner
9081073ec4 Deflake napi.test.ts 2025-06-27 17:59:05 -07:00
Jarred Sumner
386743b508 Revert "node: fix test-net-bytes-stats.js" (#20693) 2025-06-27 17:38:18 -07:00
Meghan Denny
1789f92991 node: fix test-net-server-capture-rejection.js (#20646) 2025-06-27 14:42:52 -07:00
Meghan Denny
c863341bf4 node: fix test-net-connect-custom-lookup-non-string-address.mjs (#20648) 2025-06-27 14:42:25 -07:00
Jarred Sumner
03f5a385b2 Add a repo pcakage.json script to show buildkite failures locally 2025-06-27 04:53:02 -07:00
Jarred Sumner
3c1a1b5634 Implement per-message deflate support in WebSocket client (#20613)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-27 00:04:42 -07:00
Ciro Spaciari
c15190990c fix(sockets) some fixes and improvements (#20652) 2025-06-26 15:57:06 -07:00
pfg
177239cff5 Split install.zig into multiple files (#20626)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
2025-06-26 12:43:46 -07:00
Meghan Denny
ea7068a531 node: fix test-net-bytes-stats.js (#20629) 2025-06-26 01:48:23 -07:00
pfg
46cd5b10a1 Split js_ast.zig into multiple files (#20651)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
2025-06-25 21:04:38 -07:00
Meghan Denny
b87cf4f247 zig: handle when coerceToInt32 and coerceToInt64 throw (#20655) 2025-06-25 20:44:13 -07:00
Ashcon Partovi
d3bc5e391f chore: update codeowners 2025-06-25 19:11:27 -07:00
Meghan Denny
f9712ce309 make node:buffer,zlib,stream,fs exception checker clear (#20494) 2025-06-25 18:36:08 -07:00
Jarred Sumner
5e0caa0aa4 Create upgrade-webkit.md 2025-06-25 03:20:22 -07:00
Meghan Denny
4cf31f6a57 node: sync test-net-connect-options-invalid.js (#20607) 2025-06-24 22:46:56 -07:00
Meghan Denny
3f257a2905 node: fix test-timers-invalid-clear.js (#20624) 2025-06-24 22:39:20 -07:00
Jarred Sumner
ba126fb330 Make node-gyp faster (#20556) 2025-06-24 21:07:01 -07:00
Meghan Denny
2072fa1d59 cpp: audit redundant and problematic uses of JSValue constructor (#20623) 2025-06-24 20:58:44 -07:00
Zack Radisic
61024b2b4a Fix copying UTF-16 -> UTF-8 sometimes causing invalid UTF-8 bytes (#20601) 2025-06-24 19:46:29 -07:00
Jarred Sumner
90e3d6c898 Fix flushHeaders streaming (#20577)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-06-24 18:48:23 -07:00
Meghan Denny
e8b652a5d9 node: fix test-net-better-error-messages-path.js (#20609) 2025-06-24 17:48:06 -07:00
Jarred Sumner
5131e66fa5 Optimize napi_get_value_string_utf8 napi_get_value_string_latin1 napi_get_value_string_utf16 (#20612) 2025-06-24 17:39:33 -07:00
Jarred Sumner
c019f86f14 Fix crash in napi_remove_env_cleanup_hook during worker finalization (#20551) 2025-06-24 17:38:38 -07:00
Meghan Denny
354391a263 zig: socket: fix uaf in handleError, onOpen, onWritable (#20604) 2025-06-24 17:31:58 -07:00
Ciro Spaciari
17120cefdc fix(http2) fix remoteSettings not emitting on default settings (#20622) 2025-06-24 17:31:19 -07:00
Jarred Sumner
be7db0d37a Update CLAUDE.md 2025-06-24 05:10:39 -07:00
Jarred Sumner
299c6c9b21 Update some docs 2025-06-24 05:09:23 -07:00
Jarred Sumner
f1c2a611ad Create CLAUDE.md 2025-06-24 04:06:33 -07:00
Meghan Denny
7d9dd67586 node: fix test-net-connect-keepalive.js (#20610) 2025-06-24 02:56:50 -07:00
Meghan Denny
ccb0ed13c2 node: fix test-net-listen-fd0.js (#20611) 2025-06-24 02:56:40 -07:00
Jarred Sumner
b58daf86da Optimize napi_create_buffer (#20614) 2025-06-24 02:39:19 -07:00
Meghan Denny
050a9cecb7 node: sync test-net-connect-no-arg.js (#20608) 2025-06-24 01:02:38 -07:00
Zack Radisic
0a3ac50931 Refactor shell to use AllocationScope and fix memory issues (#20531)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-23 22:29:48 -07:00
Meghan Denny
fe0bb68d17 build.zig: add missing debug check steps 2025-06-23 21:43:55 -07:00
Jarred Sumner
bc79a48ce4 Fix crash in NapiClass_ConstructorFunction due to incorrect handling of newTarget (#20552)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-23 19:50:09 -07:00
Meghan Denny
2081e5b656 test: update spawn.test.ts for ci on windows (#20600) 2025-06-23 19:40:53 -07:00
Jarred Sumner
e30d6d21f5 Bump WebKit - June 23rd edition (#20598) 2025-06-23 17:17:32 -07:00
Jarred Sumner
81e1a9d54d Unpause instead of close stdout/stderr in spawn onProcessExit (#20561)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-23 17:15:16 -07:00
Dylan Conway
1faeba01b9 remove ref count from napi_async_work (#20597) 2025-06-23 17:14:59 -07:00
Jarred Sumner
19540001d1 Prevent a call to JS during finalizer and/or worker termination (#20550) 2025-06-23 15:25:52 -07:00
Michael H
da0bc0b0d2 add space before "at" in assertionFailureAtLocation (#20591) 2025-06-23 15:22:39 -07:00
Jarred Sumner
95e12374ed Fix node_api_create_buffer_from_arraybuffer implementation (#20560) 2025-06-23 15:06:09 -07:00
Jarred Sumner
4cc61a1b8c Fix NODE_PATH for bun build (#20576)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-22 20:51:45 -07:00
Jarred Sumner
5416155449 Enable Math.sumPrecise (#20569) 2025-06-22 19:23:15 -07:00
Jarred Sumner
c7b1e5c709 Fix fs.watchFile ignoring atime (#20575)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-22 18:22:41 -07:00
Grigory
444b9d1883 build(windows/resources): specify company name (#20534) 2025-06-22 05:33:15 -07:00
Jarred Sumner
197c7abe7d Make the napi/v8 tests compile faster (#20555) 2025-06-21 23:57:04 -07:00
Jarred Sumner
653c459660 Fix asan failure in napi_async_work caused by accessing napi_async_work after freed (#20554) 2025-06-21 23:56:40 -07:00
Michael H
25dbe5cf3f fs.glob set onlyFiles: false so it can match folders (#20510) 2025-06-21 23:45:38 -07:00
Zack Radisic
2cbb196f29 Fix crash with garbage environment variables (#20527)
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Zack Radisic <zackradisic@users.noreply.github.com>
2025-06-21 23:44:59 -07:00
Jarred Sumner
064d7bb56e Fixes #10675 (#20553) 2025-06-21 23:44:28 -07:00
Jarred Sumner
37505ad955 Deflake test/js/node/fs/abort-signal-leak-read-write-file-fixture.ts on Windows 2025-06-21 23:43:55 -07:00
Meghan Denny
c40468ea39 install: fix crash researching #5949 (#20461) 2025-06-21 19:53:33 -07:00
Meghan Denny
29dd4166f2 Bump 2025-06-21 01:48:09 -07:00
Jarred Sumner
0b5363099b Some docs 2025-06-21 01:00:48 -07:00
Michael H
282dda62c8 Add --import as alias to --preload for nodejs compat (#20523) 2025-06-20 19:58:54 -07:00
familyboat
fd91e3de0d fix typo (#20449) 2025-06-20 19:57:36 -07:00
Jarred Sumner
633f4f593d Ahead-of-time frontend bundling support for HTML imports & bun build (#20511)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-20 19:55:52 -07:00
Jarred Sumner
fd5e777639 Remove outdated doc line 2025-06-20 16:16:14 -07:00
Michael H
770c1c8327 fix test-child-process-fork-exec-argv.js (#19639)
Co-authored-by: 190n <ben@bun.sh>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-20 11:53:36 -07:00
Zack Radisic
41d10ed01e Refactor shell and fix some bugs (#20476) 2025-06-19 18:47:00 -07:00
Meghan Denny
bb55b2596d fix passing nested object to macro" (#20497)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-19 17:13:27 -07:00
Dylan Conway
197443b2db fix(bundler): correct import_records for TLA detection (#20358) 2025-06-19 15:04:27 -07:00
Meghan Denny
b62f70c23a inspect-error-leak.test.js: add a slightly higher asan margin 2025-06-19 15:02:38 -07:00
Meghan Denny
d4ccba67f2 Revert "fix passing nested object to macro" (#20495) 2025-06-19 13:14:46 -07:00
Meghan Denny
43777cffee fix passing nested object to macro (#20467)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-19 12:56:27 -07:00
Michael H
3aedf0692c make options argument not required for fs.promises.glob (#20480) 2025-06-19 12:55:32 -07:00
190n
346e97dde2 fix bugs found by exception scope verification (#20285)
Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
2025-06-18 23:08:19 -07:00
Jarred Sumner
aa37ecb7a5 Split up Timer.zig into more files (#20465)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-18 12:01:40 -07:00
Michael H
9811a2b53e docs: minor fix to Bun.deflateSync (#20466) 2025-06-18 12:01:30 -07:00
Michael H
b9e72d0d2e Make bunx work with npm i -g bun on windows (#20471) 2025-06-18 12:00:16 -07:00
Dylan Conway
b7d4b14b3d Fix BUN-D93 (#20468) 2025-06-18 02:28:54 -07:00
Meghan Denny
59e1320fb1 .github: add "needs triage" label to newly submitted crash reports 2025-06-17 20:42:11 -07:00
Meghan Denny
e402adaebf zig: RefCount: fix assertion found by windows app verifier (#20459)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-17 18:45:18 -07:00
Dylan Conway
3773ceeb7e Remove PreparePatchPackageInstall (#20457) 2025-06-17 17:23:29 -07:00
Jarred Sumner
162a9b66d8 bun pm view -> bun info (#20419)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-17 13:31:16 -07:00
Jarred Sumner
6274f10096 Make Strong use less ram (#20437)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-17 13:30:58 -07:00
Jarred Sumner
978540902c bun init CLAUDE.md (#20443) 2025-06-17 13:00:28 -07:00
Jarred Sumner
b99a1256ff Split up string_immutable into more files (#20446)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-17 10:59:07 -07:00
pfg
8a1d8047f1 Unhandled rejections: remove "bun" option (#20441)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-16 19:13:00 -07:00
Michael H
a473657adb [bun build] in cjs node, dont convert module to require.module (#20343) 2025-06-16 16:56:54 -07:00
Jarred Sumner
775c3b1987 Update WebKit (#20413)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-16 14:01:58 -07:00
Grigory
7ee98852c6 build: add metadata and icon to windows executable (#20383) 2025-06-15 21:45:50 -07:00
Jarred Sumner
f46df399eb Update package.json 2025-06-15 19:30:11 -07:00
Zack Radisic
c103b57bcc Split out shell code into more files (#20331)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-15 14:09:15 -07:00
Jarred Sumner
3b3cde9e74 Split up Bun.listen & Bun.connect code into more logical files (#20411)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-15 14:08:21 -07:00
pagal
2482af60d5 Added missing completion info for: bun update (#20316) 2025-06-15 13:20:35 -07:00
Meghan Denny
2245b5efd6 test: use randomized listeners in serve-types.test.ts (#20387)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-15 13:20:11 -07:00
berzan
155475693b Change clip-path property to clipPath. (#20409) 2025-06-15 13:19:56 -07:00
Michael Melesse
f5b42e1507 react-tailwind template fix (#20410) 2025-06-15 13:19:44 -07:00
Meghan Denny
139f2b23a2 chore: trim trailing space in uws (#20388) 2025-06-15 08:59:12 -07:00
190n
28006d0ad4 WIP: Fix ref counting bugs in spawn API observed under rr (#20191)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-14 16:59:29 +02:00
pfg
c44515eaaf Support --unhandled-rejections flag and rejectionHandled event (#19874)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
2025-06-13 19:05:05 -07:00
pfg
e0924ef226 Implement require('tls').getCACertificates() (#20364)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
2025-06-13 17:30:04 -07:00
Meghan Denny
9499f21518 Update .git-blame-ignore-revs 2025-06-13 16:16:14 -07:00
Meghan Denny
6b4662ff55 zig: .jsUndefined -> .js_undefined (#20377)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-13 16:14:57 -07:00
Meghan Denny
a445b45e55 empty commit to trigger formatting ci (#20378)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-13 15:18:28 -07:00
Christian Rishøj
82b34bbbdd feat(sqlite): Add columnTypes and declaredTypes to Statement (#20232)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-06-13 19:48:37 +02:00
190n
4d905123fa Always use correct Zig version for bun watch (#20309)
Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
2025-06-13 19:47:33 +02:00
190n
c6deb4527c Fix crash when FFI pointers are encoded as ints (#20351)
Co-authored-by: 190n <7763597+190n@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-06-13 19:46:26 +02:00
Jarred Sumner
f3bca62a77 Fix proxy handling in bun audit (#20295)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-13 19:43:55 +02:00
Meghan Denny
62794850fa zig: node:zlib: tidy (#20362)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-13 19:43:35 +02:00
Dylan Conway
f53aff0935 Fix TypeScript non-null assertion with new operator (#20363)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan-conway@users.noreply.github.com>
2025-06-13 19:30:52 +02:00
Alistair Smith
9c5797e2f5 Update expectations.txt (#20350) 2025-06-12 17:35:32 -07:00
Kuba Ellwart
4329a66a1d fix(types): make the RedisClient.del accept spread keys by default (#20348) 2025-06-12 17:06:51 -07:00
Meghan Denny
12a4b95b34 zig: make uws Response and WebSocket opaque again (#20355) 2025-06-12 16:35:52 -07:00
Meghan Denny
cf00cb495c fix main zig build 2025-06-12 14:26:17 -07:00
Meghan Denny
5763a8e533 node:zlib: add zstd (#20313)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-06-12 14:20:28 -07:00
Meghan Denny
dedd433cbf zig: prefer .jsUndefined() over .undefined for JSValue (#20332) 2025-06-12 13:18:46 -07:00
Meghan Denny
d6590c4bfa Bump 2025-06-11 22:00:23 -07:00
Dax
07d3d6c9f6 add opencode-ai to trusted dependencies (#20330) 2025-06-11 21:47:51 -07:00
Ciro Spaciari
631e674842 fix(FileRoute) fix eof handling, fix max size handling, fix onReaderError behavior (#20317)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-06-11 20:34:52 -07:00
Alistair Smith
3d19c1156c support multiple keys in RedisClient#del (#20307) 2025-06-11 17:31:35 -07:00
pfg
7a069d7214 Add back zls binary after zig upgrade (#20327) 2025-06-11 16:00:58 -07:00
Jarred Sumner
6ebad50543 Introduce ahead of time bundling for HTML imports with bun build (#20265)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: dylan-conway <35280289+dylan-conway@users.noreply.github.com>
2025-06-10 21:26:00 -07:00
Jarred Sumner
8750f0b884 Add FileRoute for serving files (#20198)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-06-10 19:41:21 -07:00
Ben Grant
c38bace86c delete stray file 2025-06-10 09:36:00 -07:00
Jarred Sumner
9fd18361f2 Revert "node:net: fix crash calling getsockname on native server handle (#20286)"
This reverts commit de6739c401.
2025-06-09 21:59:17 -07:00
Meghan Denny
de6739c401 node:net: fix crash calling getsockname on native server handle (#20286) 2025-06-09 21:57:57 -07:00
Jarred Sumner
2801cb1f4a Fix TOML parser to handle inline tables and table arrays correctly (#20291)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2025-06-09 18:52:30 -07:00
Jacob
b642e36da2 Add Support for LinkWorkspacePackages in Bunfig (#20226)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-09 17:01:15 -07:00
pfg
df3337936c Upgrade zig to 0.14.1 (#20289) 2025-06-09 16:51:10 -07:00
190n
ea05de59b3 Fix #20283 (#20287) 2025-06-09 16:50:24 -07:00
Jarred Sumner
601b8e3aaa Add CLAUDE.md to bun-types 2025-06-09 15:06:26 -07:00
github-actions[bot]
a11d9e2cd4 deps: update sqlite to 3.50.100 (#20257)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-08 08:20:24 -07:00
Jarred Sumner
df84f665a5 mark as noalias (#20262)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-08 08:20:09 -07:00
Jarred Sumner
498186764a Remove a memcpy (#20261)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-08 05:07:09 -07:00
Dax
02a7d71b70 Add BUN_BE_BUN environment variable flag (#20251) 2025-06-07 20:17:47 -07:00
Jarred Sumner
c9761d4aa6 Fixes flaky test-http-pipeline-requests-connection-leak.js (#20248) 2025-06-07 05:19:11 -07:00
Jarred Sumner
c863e7582f Fix dest field in sys.Error (#20244) 2025-06-07 04:00:36 -07:00
Dylan Conway
d4710c6e86 fix "undefined is not an object" with ctrl+c during next dev (#20246) 2025-06-07 04:00:22 -07:00
Jarred Sumner
e1f3796677 Wait for FSEvents thread to exit before exiting the process (#20245) 2025-06-07 03:50:04 -07:00
Meghan Denny
ec07ef83a2 node:net: fix ReferenceError when localPort is passed to Socket connect 2025-06-07 02:06:07 -07:00
Jarred Sumner
eddee1b8cb *anyopaque -> mach_port_t (#20243) 2025-06-07 00:30:58 -07:00
Zack Radisic
fa1d37b4e3 Split bundler up into multiple files (#20192) 2025-06-06 18:34:18 -07:00
Meghan Denny
5b0523a32a cmake: suppress a few more warnings on windows 2025-06-06 17:44:46 -07:00
Jarred Sumner
5039310199 Bump WebKit (#20222) 2025-06-06 04:19:21 -07:00
190n
61e03a2758 Switch back from quick_exit(134) to abort() in Windows crash handler (#20194) 2025-06-05 20:39:47 -07:00
Jarred Sumner
27abb51561 Add fallback for ADDRCONFIG like Chrome's, avoid glibc UDP port 0 hangs (#19753)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-05 20:20:00 -07:00
connerlphillippi
09d0846d1b Fix use-after-free segfault in DevServer has_tailwind_plugin_hack map (#20214)
Co-authored-by: Conner Phillippi <conner@Conners-MacBook-Air.local>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-06-05 19:37:15 -07:00
Jarred Sumner
8e7cdb8493 Delete some dead code (#20218) 2025-06-05 19:01:30 -07:00
Jarred Sumner
538caa4d5e Fix incorrect typescript type 2025-06-05 18:28:00 -07:00
Ciro Spaciari
24bc236eb7 compat(http2) fix flow protocol (#20051)
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com>
2025-06-05 17:34:30 -07:00
190n
f59050fc23 Exit early if V8 tests fail to compile (#20215) 2025-06-05 17:15:02 -07:00
190n
1b092f156b Make DebugData.magic enum nonexhaustive (#20212) 2025-06-05 17:14:43 -07:00
190n
6a79b9ef87 Work around compiler crash in uws.WebSocket (#20211) 2025-06-05 17:12:40 -07:00
Jarred Sumner
f62940bbda A couple small zig cleanup things (#20196) 2025-06-05 05:11:28 -07:00
Meghan Denny
c82345c0a0 zig: fix debug crash in uws.Response (#20202) 2025-06-04 23:43:27 -07:00
Kai Tamkun
817d0464f6 Add support for node:vm.SyntheticModule (#19878) 2025-06-04 19:41:26 -07:00
Jarred Sumner
a5bb525614 Ensure we set the socket flag in LifecycleScriptSubprocess (#20179) 2025-06-04 19:38:47 -07:00
190n
4cb7910e32 remove unnecessary explicit backing integer (#20188) 2025-06-04 16:44:55 -07:00
190n
d7970946eb Delete flaky tests from #20065 (#20189) 2025-06-04 16:44:31 -07:00
pfg
014fb6be8f test-tls-check-server-identity (#20170) 2025-06-04 16:44:15 -07:00
Meghan Denny
5c7991b707 cpp: fix compile errors caught from disallowing implicit conversion from JSValue to EncodedJSValue (#20175) 2025-06-04 14:48:35 -07:00
Jarred Sumner
da5fc817d1 Change copy to a .len += 2025-06-04 00:25:57 -07:00
Jarred Sumner
407c4e800a Revert "add support for "workspaces.nohoist" and "workspaces.hoistingLimits" (#20124)"
This reverts commit 11070b8e16.
2025-06-03 23:51:03 -07:00
Dylan Conway
11070b8e16 add support for "workspaces.nohoist" and "workspaces.hoistingLimits" (#20124) 2025-06-03 23:44:09 -07:00
Kai Tamkun
adfdaab4fd Add test for #20144 (#20171) 2025-06-03 23:41:37 -07:00
Meghan Denny
bfd7fc06c7 fix test-net-server-max-connections.js (#20034)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-06-03 22:50:08 -07:00
pfg
bd3abc5a2a Fix calc bug (#20174) 2025-06-03 22:08:51 -07:00
Ali
193193024f Fixed exit signals hanging in loops (#20164) 2025-06-03 15:07:46 -07:00
nobkd
6edc3a9900 remove audit from bun pm help (#20167) 2025-06-03 14:37:03 -07:00
Jarred Sumner
1bd44e9ce7 Fixes #18239 (#20152) 2025-06-03 13:23:12 -07:00
Jarred Sumner
c7327d62c2 bun run prettier 2025-06-03 04:17:42 -07:00
Ali
90dda8219f Fixed: radians rewritten to degrees without converting (#19848) 2025-06-03 04:06:05 -07:00
Ali
885979644d Fixed : bun:ffi new CString() ignores byteOffset argument if byteLength is not provided (#19819)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-06-03 04:05:04 -07:00
Joel Shepherd
13c5b0d9cb Added rapidhash algorithm (#20163) 2025-06-03 03:34:35 -07:00
Kuba Ellwart
d6e45afef9 Support Optional Message Argument in RedisClient.ping() (#20161) 2025-06-03 02:33:10 -07:00
Jarred Sumner
300aedd9cc Bump WebKit, libpas on Windows edition (#20068)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-03 02:32:15 -07:00
Jarred Sumner
d9cf836b67 Split server.zig into more files (#20139)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-03 01:38:26 -07:00
Justin Yao Du
293215778f Fix a typo in bunfig docs page (extra if) (#20160) 2025-06-03 01:21:40 -07:00
Ali
95346bd919 fixed SharedArrayBuffer crashing on transfer (#20130) 2025-06-02 23:05:52 -07:00
Meghan Denny
ceaaed4848 node: more now passing tests (#20065) 2025-06-02 23:03:47 -07:00
Meghan Denny
abaa69183b write test in server.spec.ts better (#20150) 2025-06-02 23:03:05 -07:00
Meghan Denny
3e1075410b Delete test-net-allow-half-open.js
turned out to be flaky
2025-06-02 19:01:49 -07:00
190n
7a88bb0e1c add gamble.ts (#20153) 2025-06-02 18:17:05 -07:00
Meghan Denny
7a790581e0 Revert "fix test-net-bytes-stats.js" (#20154) 2025-06-02 18:15:39 -07:00
190n
d5cc530024 State CPU requirements in README (#20146) 2025-06-02 14:06:39 -07:00
Ben Grant
d7548325b1 delete event_loop/README.md 2025-06-02 11:49:09 -07:00
Jarred Sumner
d11fd94cdb Add readme to src/bun.js/event_loop 2025-06-02 03:51:46 -07:00
github-actions[bot]
4cbd040485 deps: update sqlite to 3.50.0 (#20122)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2025-06-02 03:27:02 -07:00
Jarred Sumner
773484a628 Split uSockets/uWS <> Zig bindings into many different files (#20138)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-02 02:10:57 -07:00
Jarred Sumner
71c14fac7b Split EventLoop into many more files (#20134)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-06-01 20:43:30 -07:00
Stanislaw Wozniak
b2a728e45d bug: Do not duplicate Transfer-Encoding header (#20116)
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-06-01 15:54:04 -07:00
Jarred Sumner
390798c172 Fix memory leak in Bun.spawn (#20095)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-05-31 20:06:22 -07:00
Meghan Denny
284de53f26 safety: audit and add missing exception checks to JSC::constructArray+constructEmptyArray (#20119) 2025-05-31 20:05:02 -07:00
Jarred Sumner
5a025abddf Address clang warnings on newer clang (#20054) 2025-05-31 19:44:36 -07:00
Dylan Conway
4ab4b1b131 Clean up help text for package manager commands (#20117) 2025-05-31 19:21:37 -07:00
Roman A
13ea970852 A couple grammar fixes (#20096) 2025-05-31 19:14:51 -07:00
Meghan Denny
ba78d5b2c3 ci: pass the src directory to 'zig fmt' (#20114)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-05-31 18:52:18 -07:00
Dylan Conway
ce8767cdc8 add HTTPParser (#20049)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-05-31 16:21:08 -07:00
familyboat
082a9cb59c fix: missing "default" export in module "data.yml" (#20094) 2025-05-31 14:55:15 -07:00
Jarred Sumner
3c37f25b65 Avoid allocating 16 KB to read a potentially empty buffer (#20101) 2025-05-31 14:00:51 -07:00
Ali
a079743a02 fix NapiHandleScopeImpl memory leak (#20108) 2025-05-31 13:57:46 -07:00
Meghan Denny
e0852fd651 fix memory leak when pipe Bun.spawn stdio is never read repeatedly (#20102)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
2025-05-31 11:16:49 -07:00
Grigory
6bbd1e0685 fix(NodeValidator): make object check less strict (#19047)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-30 22:10:29 -07:00
Ali
4534f6e635 fix NapiHandleScopeImpl race condition (#20093) 2025-05-30 20:33:50 -07:00
Meghan Denny
c62a7a77a3 fix assertion in JSSocketAddressDTO__create (#20063) 2025-05-30 19:33:58 -07:00
190n
ecf5ea389f Move LLDB initialization commands to make attach configuration work (#20085) 2025-05-30 19:33:03 -07:00
Jarred Sumner
010ef4d119 More comments in the socket type definition (#19410)
Co-authored-by: Alistair Smith <hi@alistair.sh>
2025-05-30 19:12:30 -07:00
Julie Saia
4d77cd53f1 Add support for catalogs in bun outdated (#20090)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-05-30 17:23:59 -07:00
Leander Paul
3cf353b755 feat: additional jest types in bun test (#19255)
Co-authored-by: Alistair Smith <hi@alistair.sh>
2025-05-30 15:28:11 -07:00
Jarred Sumner
fd894f5a65 Fix test-child-process-server-close (#20062) 2025-05-30 00:15:26 -07:00
Jarred Sumner
a9969b7db2 Update codex-test-sync.yml 2025-05-30 00:04:39 -07:00
Jarred Sumner
27a08fca84 Update codex-test-sync.yml 2025-05-29 23:40:57 -07:00
Jarred Sumner
a398bd62a3 Add passing node tests (#20052) 2025-05-29 22:53:28 -07:00
Jarred Sumner
2aa7c59727 Delete environment.json 2025-05-29 21:57:06 -07:00
Jarred Sumner
7765b61038 Update environment.json 2025-05-29 21:46:24 -07:00
Jarred Sumner
8a06ddb1fb Update environment.json 2025-05-29 21:11:53 -07:00
Jarred Sumner
2e76e69939 Update environment.json 2025-05-29 21:08:55 -07:00
Jarred Sumner
aa404b14c4 Fix http Expect header handling (#20026)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2025-05-29 20:03:32 -07:00
Jarred Sumner
a4819b41e9 Fix setSourceMapsEnabled node test (#20039)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-05-29 18:04:31 -07:00
Jarred Sumner
f5bfda9699 Fix http socket encoding check (#20031)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2025-05-29 17:05:51 -07:00
Jarred Sumner
9f5adfefe3 Add action that ensures the node test is downloaded from node's repo 2025-05-29 17:02:11 -07:00
Jarred Sumner
316c8d6c48 Add node:test:cp package.json script 2025-05-29 16:48:37 -07:00
Ashcon Partovi
da87890532 ci: Fix build image step with zig (#20023) 2025-05-29 16:07:35 -07:00
Meghan Denny
576f66c149 fix test-net-server-drop-connections.js (#19995) 2025-05-29 13:55:25 -07:00
2010 changed files with 178778 additions and 103346 deletions

View File

@@ -1,8 +1,6 @@
ARG LLVM_VERSION="19"
ARG REPORTED_LLVM_VERSION="19.1.7"
ARG OLD_BUN_VERSION="1.1.38"
ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables"
ARG DEFAULT_CXXFLAGS="-flto=full -fwhole-program-vtables -fforce-emit-vtables"
ARG BUILDKITE_AGENT_TAGS="queue=linux,os=linux,arch=${TARGETARCH}"
FROM --platform=$BUILDPLATFORM ubuntu:20.04 as base-arm64
@@ -12,8 +10,6 @@ FROM base-$TARGETARCH as base
ARG LLVM_VERSION
ARG OLD_BUN_VERSION
ARG TARGETARCH
ARG DEFAULT_CXXFLAGS
ARG DEFAULT_CFLAGS
ARG REPORTED_LLVM_VERSION
ENV DEBIAN_FRONTEND=noninteractive \
@@ -64,9 +60,7 @@ RUN echo "ARCH_PATH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64-linux-gnu" ||
ENV LD_LIBRARY_PATH=/usr/lib/gcc/${ARCH_PATH}/13:/usr/lib/${ARCH_PATH} \
LIBRARY_PATH=/usr/lib/gcc/${ARCH_PATH}/13:/usr/lib/${ARCH_PATH} \
CPLUS_INCLUDE_PATH=/usr/include/c++/13:/usr/include/${ARCH_PATH}/c++/13 \
C_INCLUDE_PATH=/usr/lib/gcc/${ARCH_PATH}/13/include \
CFLAGS=${DEFAULT_CFLAGS} \
CXXFLAGS="${DEFAULT_CFLAGS} ${DEFAULT_CXXFLAGS}"
C_INCLUDE_PATH=/usr/lib/gcc/${ARCH_PATH}/13/include
RUN if [ "$TARGETARCH" = "arm64" ]; then \
export ARCH_PATH="aarch64-linux-gnu"; \

View File

@@ -127,12 +127,12 @@ const testPlatforms = [
{ os: "linux", arch: "x64", distro: "debian", release: "12", tier: "latest" },
{ os: "linux", arch: "x64", baseline: true, distro: "debian", release: "12", tier: "latest" },
{ os: "linux", arch: "x64", profile: "asan", distro: "debian", release: "12", tier: "latest" },
{ os: "linux", arch: "aarch64", distro: "ubuntu", release: "25.04", tier: "latest" },
{ os: "linux", arch: "aarch64", distro: "ubuntu", release: "24.04", tier: "latest" },
{ os: "linux", arch: "aarch64", distro: "ubuntu", release: "20.04", tier: "oldest" },
{ os: "linux", arch: "x64", distro: "ubuntu", release: "25.04", tier: "latest" },
{ os: "linux", arch: "x64", distro: "ubuntu", release: "24.04", tier: "latest" },
{ os: "linux", arch: "x64", distro: "ubuntu", release: "20.04", tier: "oldest" },
{ os: "linux", arch: "x64", baseline: true, distro: "ubuntu", release: "25.04", tier: "latest" },
{ os: "linux", arch: "x64", baseline: true, distro: "ubuntu", release: "24.04", tier: "latest" },
{ os: "linux", arch: "x64", baseline: true, distro: "ubuntu", release: "20.04", tier: "oldest" },
{ os: "linux", arch: "aarch64", abi: "musl", distro: "alpine", release: "3.21", tier: "latest" },
{ os: "linux", arch: "x64", abi: "musl", distro: "alpine", release: "3.21", tier: "latest" },
{ os: "linux", arch: "x64", abi: "musl", baseline: true, distro: "alpine", release: "3.21", tier: "latest" },
@@ -309,6 +309,19 @@ function getCppAgent(platform, options) {
});
}
/**
* @returns {Platform}
*/
function getZigPlatform() {
return {
os: "linux",
arch: "aarch64",
abi: "musl",
distro: "alpine",
release: "3.21",
};
}
/**
* @param {Platform} platform
* @param {PipelineOptions} options
@@ -322,19 +335,9 @@ function getZigAgent(platform, options) {
// queue: "build-zig",
// };
return getEc2Agent(
{
os: "linux",
arch: "aarch64",
abi: "musl",
distro: "alpine",
release: "3.21",
},
options,
{
instanceType: "r8g.large",
},
);
return getEc2Agent(getZigPlatform(), options, {
instanceType: "r8g.large",
});
}
/**
@@ -447,7 +450,7 @@ function getBuildCppStep(platform, options) {
BUN_CPP_ONLY: "ON",
...getBuildEnv(platform, options),
},
// We used to build the C++ dependencies and bun in seperate steps.
// We used to build the C++ dependencies and bun in separate steps.
// However, as long as the zig build takes longer than both sequentially,
// it's cheaper to run them in the same step. Can be revisited in the future.
command: [`${command} --target bun`, `${command} --target dependencies`],
@@ -919,7 +922,7 @@ function getOptionsStep() {
{
key: "unified-builds",
select: "Do you want to build each platform in a single step?",
hint: "If true, builds will not be split into seperate steps (this will likely slow down the build)",
hint: "If true, builds will not be split into separate steps (this will likely slow down the build)",
required: false,
default: "false",
options: booleanOptions,
@@ -927,7 +930,7 @@ function getOptionsStep() {
{
key: "unified-tests",
select: "Do you want to run tests in a single step?",
hint: "If true, tests will not be split into seperate steps (this will be very slow)",
hint: "If true, tests will not be split into separate steps (this will be very slow)",
required: false,
default: "false",
options: booleanOptions,
@@ -1105,6 +1108,11 @@ async function getPipeline(options = {}) {
steps.push(
...relevantBuildPlatforms.map(target => {
const imageKey = getImageKey(target);
const zigImageKey = getImageKey(getZigPlatform());
const dependsOn = imagePlatforms.has(zigImageKey) ? [`${zigImageKey}-build-image`] : [];
if (imagePlatforms.has(imageKey)) {
dependsOn.push(`${imageKey}-build-image`);
}
return getStepWithDependsOn(
{
@@ -1114,7 +1122,7 @@ async function getPipeline(options = {}) {
? [getBuildBunStep(target, options)]
: [getBuildCppStep(target, options), getBuildZigStep(target, options), getLinkBunStep(target, options)],
},
imagePlatforms.has(imageKey) ? `${imageKey}-build-image` : undefined,
...dependsOn,
);
}),
);

View File

@@ -0,0 +1,255 @@
# macOS Runner Infrastructure - Claude Development Guide
This document provides context and guidance for Claude to work on the macOS runner infrastructure.
## Overview
This infrastructure provides automated, scalable macOS CI runners for Bun using MacStadium's Orka platform. It implements complete job isolation, daily image rebuilds, and comprehensive testing.
## Architecture
### Core Components
- **Packer**: Builds VM images with all required software
- **Terraform**: Manages VM fleet with auto-scaling
- **GitHub Actions**: Automates daily rebuilds and deployments
- **User Management**: Creates isolated users per job (`bk-<job-id>`)
### Key Features
- **Complete Job Isolation**: Each Buildkite job runs in its own user account
- **Daily Image Rebuilds**: Automated nightly rebuilds ensure fresh environments
- **Flakiness Testing**: Multiple test iterations ensure reliability (80% success rate minimum)
- **Software Validation**: All tools tested for proper installation and functionality
- **Version Synchronization**: Exact versions match bootstrap.sh requirements
## File Structure
```
.buildkite/macos-runners/
├── packer/
│ └── macos-base.pkr.hcl # VM image building configuration
├── terraform/
│ ├── main.tf # Infrastructure definition
│ ├── variables.tf # Configuration variables
│ ├── outputs.tf # Resource outputs
│ └── user-data.sh # VM initialization script
├── scripts/
│ ├── bootstrap-macos.sh # macOS software installation
│ ├── create-build-user.sh # User creation for job isolation
│ ├── cleanup-build-user.sh # User cleanup after jobs
│ └── job-runner.sh # Main job lifecycle management
├── github-actions/
│ ├── image-rebuild.yml # Daily image rebuild workflow
│ └── deploy-fleet.yml # Fleet deployment workflow
├── README.md # User documentation
├── DEPLOYMENT.md # Deployment guide
└── CLAUDE.md # This file
```
## Software Versions (Must Match bootstrap.sh)
These versions are synchronized with `/scripts/bootstrap.sh`:
- **Node.js**: 24.3.0 (exact)
- **Bun**: 1.2.17 (exact)
- **LLVM**: 19.1.7 (exact)
- **CMake**: 3.30.5 (exact)
- **Buildkite Agent**: 3.87.0
## Key Scripts
### bootstrap-macos.sh
- Installs all required software with exact versions
- Configures development environment
- Sets up Tailscale, Docker, and other dependencies
- **Critical**: Must stay synchronized with main bootstrap.sh
### create-build-user.sh
- Creates unique user per job: `bk-<job-id>`
- Sets up isolated environment with proper permissions
- Configures shell environment and paths
- Creates workspace directories
### cleanup-build-user.sh
- Kills all processes owned by build user
- Removes user account and home directory
- Cleans up temporary files and caches
- Ensures complete isolation between jobs
### job-runner.sh
- Main orchestration script
- Manages job lifecycle: create user → run job → cleanup
- Handles timeouts and health checks
- Runs as root via LaunchDaemon
## GitHub Actions Workflows
### image-rebuild.yml
- Runs daily at 2 AM UTC
- Detects changes to trigger rebuilds
- Builds images for macOS 13, 14, 15
- **Validation Steps**:
- Software installation verification
- Flakiness testing (3 iterations, 80% success rate)
- Health endpoint testing
- Discord notifications for status
### deploy-fleet.yml
- Manual deployment trigger
- Validates inputs and plans changes
- Deploys VM fleet with health checks
- Supports different environments (prod/staging/dev)
## Required Secrets
### MacStadium
- `MACSTADIUM_API_KEY`: API access key
- `ORKA_ENDPOINT`: Orka API endpoint
- `ORKA_AUTH_TOKEN`: Authentication token
### AWS
- `AWS_ACCESS_KEY_ID`: For Terraform state storage
- `AWS_SECRET_ACCESS_KEY`: For Terraform state storage
### Buildkite
- `BUILDKITE_AGENT_TOKEN`: Agent registration token
- `BUILDKITE_API_TOKEN`: For monitoring/status checks
- `BUILDKITE_ORG`: Organization slug
### GitHub
- `GITHUB_TOKEN`: For private repository access
### Notifications
- `DISCORD_WEBHOOK_URL`: For status notifications
## Development Guidelines
### Adding New Software
1. Update `bootstrap-macos.sh` with installation commands
2. Add version verification in the script
3. Include in validation tests in `image-rebuild.yml`
4. Update documentation in README.md
### Modifying User Isolation
1. Update `create-build-user.sh` for user creation
2. Update `cleanup-build-user.sh` for cleanup
3. Test isolation in `job-runner.sh`
4. Ensure proper permissions and security
### Updating VM Configuration
1. Modify `terraform/variables.tf` for fleet sizing
2. Update `terraform/main.tf` for infrastructure changes
3. Test deployment with `deploy-fleet.yml`
4. Update documentation
### Version Updates
1. **Critical**: Check `/scripts/bootstrap.sh` for version changes
2. Update exact versions in `bootstrap-macos.sh`
3. Update version verification in workflows
4. Update documentation
## Testing Strategy
### Image Validation
- Software installation verification
- Version checking for exact matches
- Health endpoint testing
- Basic functionality tests
### Flakiness Testing
- 3 test iterations per image
- 80% success rate minimum
- Tests basic commands, Node.js, Bun, build tools
- Automated cleanup of test VMs
### Integration Testing
- End-to-end job execution
- User isolation verification
- Resource cleanup validation
- Performance monitoring
## Troubleshooting
### Common Issues
1. **Version Mismatches**: Check bootstrap.sh for updates
2. **User Cleanup Failures**: Check process termination and file permissions
3. **Image Build Failures**: Check Packer logs and VM resources
4. **Flakiness**: Investigate VM performance and network issues
### Debugging Commands
```bash
# Check VM status
orka vm list
# Check image status
orka image list
# Test user creation
sudo /usr/local/bin/bun-ci/create-build-user.sh
# Check health endpoint
curl http://localhost:8080/health
# View logs
tail -f /usr/local/var/log/buildkite-agent/buildkite-agent.log
```
## Performance Considerations
### Resource Management
- VMs configured with 12 CPU cores, 32GB RAM
- Auto-scaling based on queue demand
- Aggressive cleanup to prevent resource leaks
### Cost Optimization
- Automated cleanup of old images and snapshots
- Efficient VM sizing based on workload requirements
- Scheduled maintenance windows
## Security
### Isolation
- Complete process isolation per job
- Separate user accounts with unique UIDs
- Cleanup of all user data after jobs
### Network Security
- VPC isolation with security groups
- Limited SSH access for debugging
- Encrypted communications
### Credential Management
- Secure secret storage in GitHub
- No hardcoded credentials in code
- Regular rotation of access tokens
## Monitoring
### Health Checks
- HTTP endpoints on port 8080
- Buildkite agent connectivity monitoring
- Resource usage tracking
### Alerts
- Discord notifications for failures
- Build status reporting
- Fleet deployment notifications
## Next Steps for Development
1. **Monitor bootstrap.sh**: Watch for version updates that need synchronization
2. **Performance Optimization**: Monitor resource usage and optimize VM sizes
3. **Enhanced Testing**: Add more comprehensive validation tests
4. **Cost Monitoring**: Track usage and optimize for cost efficiency
5. **Security Hardening**: Regular security reviews and updates
## References
- [MacStadium Orka Documentation](https://orkadocs.macstadium.com/)
- [Packer Documentation](https://www.packer.io/docs)
- [Terraform Documentation](https://www.terraform.io/docs)
- [Buildkite Agent Documentation](https://buildkite.com/docs/agent/v3)
- [Main bootstrap.sh](../../scripts/bootstrap.sh) - **Keep synchronized!**
---
**Important**: This infrastructure is critical for Bun's CI/CD pipeline. Always test changes thoroughly and maintain backward compatibility. The `bootstrap-macos.sh` script must stay synchronized with the main `bootstrap.sh` script to ensure consistent environments.

View File

@@ -0,0 +1,428 @@
# macOS Runner Deployment Guide
This guide provides step-by-step instructions for deploying the macOS runner infrastructure for Bun CI.
## Prerequisites
### 1. MacStadium Account Setup
1. **Create MacStadium Account**
- Sign up at [MacStadium](https://www.macstadium.com/)
- Purchase Orka plan with appropriate VM allocation
2. **Configure API Access**
- Generate API key from MacStadium dashboard
- Note down your Orka endpoint URL
- Test API connectivity
3. **Base Image Preparation**
- Ensure base macOS images are available in your account
- Verify image naming convention: `base-images/macos-{version}-{name}`
### 2. AWS Account Setup
1. **Create AWS Account**
- Set up AWS account for Terraform state storage
- Create S3 bucket for Terraform backend: `bun-terraform-state`
2. **Configure IAM**
- Create IAM user with appropriate permissions
- Generate access key and secret key
- Attach policies for S3, CloudWatch, and EC2 (if using AWS resources)
### 3. GitHub Repository Setup
1. **Fork or Clone Repository**
- Ensure you have admin access to the repository
- Create necessary branches for deployment
2. **Configure Repository Secrets**
- Add all required secrets (see main README.md)
- Test secret accessibility
### 4. Buildkite Setup
1. **Organization Configuration**
- Create or access Buildkite organization
- Generate agent token with appropriate permissions
- Note organization slug
2. **Queue Configuration**
- Create queues: `macos`, `macos-arm64`, `macos-x86_64`
- Configure queue-specific settings
## Step-by-Step Deployment
### Step 1: Environment Preparation
1. **Install Required Tools**
```bash
# Install Terraform
wget https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
unzip terraform_1.6.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/
# Install Packer
wget https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip
unzip packer_1.9.4_linux_amd64.zip
sudo mv packer /usr/local/bin/
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Install MacStadium CLI
curl -L "https://github.com/macstadium/orka-cli/releases/latest/download/orka-cli-linux-amd64.tar.gz" | tar -xz
sudo mv orka-cli /usr/local/bin/orka
```
2. **Configure AWS Credentials**
```bash
aws configure
# Enter your AWS access key, secret key, and region
```
3. **Configure MacStadium CLI**
```bash
orka config set endpoint <your-orka-endpoint>
orka auth token <your-orka-token>
```
### Step 2: SSH Key Setup
1. **Generate SSH Key Pair**
```bash
ssh-keygen -t rsa -b 4096 -f ~/.ssh/bun-runner -N ""
```
2. **Copy Public Key to Terraform Directory**
```bash
mkdir -p .buildkite/macos-runners/terraform/ssh-keys
cp ~/.ssh/bun-runner.pub .buildkite/macos-runners/terraform/ssh-keys/bun-runner.pub
```
### Step 3: Terraform Backend Setup
1. **Create S3 Bucket for Terraform State**
```bash
aws s3 mb s3://bun-terraform-state --region us-west-2
aws s3api put-bucket-versioning --bucket bun-terraform-state --versioning-configuration Status=Enabled
aws s3api put-bucket-encryption --bucket bun-terraform-state --server-side-encryption-configuration '{
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}'
```
2. **Create Terraform Variables File**
```bash
cd .buildkite/macos-runners/terraform
cat > production.tfvars << EOF
environment = "production"
macstadium_api_key = "your-macstadium-api-key"
buildkite_agent_token = "your-buildkite-agent-token"
github_token = "your-github-token"
fleet_size = {
macos_13 = 4
macos_14 = 6
macos_15 = 8
}
vm_configuration = {
cpu_count = 12
memory_gb = 32
disk_size = 500
}
EOF
```
### Step 4: Build VM Images
1. **Validate Packer Configuration**
```bash
cd .buildkite/macos-runners/packer
packer validate -var "macos_version=15" macos-base.pkr.hcl
```
2. **Build macOS 15 Image**
```bash
packer build \
-var "macos_version=15" \
-var "orka_endpoint=<your-orka-endpoint>" \
-var "orka_auth_token=<your-orka-token>" \
macos-base.pkr.hcl
```
3. **Build macOS 14 Image**
```bash
packer build \
-var "macos_version=14" \
-var "orka_endpoint=<your-orka-endpoint>" \
-var "orka_auth_token=<your-orka-token>" \
macos-base.pkr.hcl
```
4. **Build macOS 13 Image**
```bash
packer build \
-var "macos_version=13" \
-var "orka_endpoint=<your-orka-endpoint>" \
-var "orka_auth_token=<your-orka-token>" \
macos-base.pkr.hcl
```
### Step 5: Deploy VM Fleet
1. **Initialize Terraform**
```bash
cd .buildkite/macos-runners/terraform
terraform init
```
2. **Create Production Workspace**
```bash
terraform workspace new production
```
3. **Plan Deployment**
```bash
terraform plan -var-file="production.tfvars"
```
4. **Apply Deployment**
```bash
terraform apply -var-file="production.tfvars"
```
### Step 6: Verify Deployment
1. **Check VM Status**
```bash
orka vm list
```
2. **Check Terraform Outputs**
```bash
terraform output
```
3. **Test VM Connectivity**
```bash
# Get VM IP from terraform output
VM_IP=$(terraform output -json vm_instances | jq -r '.value | to_entries[0].value.ip_address')
# Test SSH connectivity
ssh -i ~/.ssh/bun-runner admin@$VM_IP
# Test health endpoint
curl http://$VM_IP:8080/health
```
4. **Verify Buildkite Agent Connectivity**
```bash
curl -H "Authorization: Bearer <your-buildkite-api-token>" \
"https://api.buildkite.com/v2/organizations/<your-org>/agents"
```
### Step 7: Configure GitHub Actions
1. **Enable GitHub Actions Workflows**
- Navigate to repository Actions tab
- Enable workflows if not already enabled
2. **Test Image Rebuild Workflow**
```bash
# Trigger manual rebuild
gh workflow run image-rebuild.yml
```
3. **Test Fleet Deployment Workflow**
```bash
# Trigger manual deployment
gh workflow run deploy-fleet.yml
```
## Post-Deployment Configuration
### 1. Monitoring Setup
1. **CloudWatch Dashboards**
- Create custom dashboards for VM metrics
- Set up alarms for critical thresholds
2. **Discord Notifications**
- Configure Discord webhook for alerts
- Test notification delivery
### 2. Backup Configuration
1. **Enable Automated Snapshots**
```bash
# Update terraform configuration
backup_config = {
enable_snapshots = true
snapshot_schedule = "0 4 * * *"
snapshot_retention = 7
}
```
2. **Test Backup Restoration**
- Create test snapshot
- Verify restoration process
### 3. Security Hardening
1. **Review Security Groups**
- Minimize open ports
- Restrict source IP ranges
2. **Enable Audit Logging**
- Configure CloudTrail for AWS resources
- Enable MacStadium audit logs
### 4. Performance Optimization
1. **Monitor Resource Usage**
- Review CPU, memory, disk usage
- Adjust VM sizes if needed
2. **Optimize Auto-Scaling**
- Monitor scaling events
- Adjust thresholds as needed
## Maintenance Procedures
### Daily Maintenance
1. **Automated Tasks**
- Image rebuilds (automatic)
- Health checks (automatic)
- Cleanup processes (automatic)
2. **Manual Monitoring**
- Check Discord notifications
- Review CloudWatch metrics
- Monitor Buildkite queue
### Weekly Maintenance
1. **Review Metrics**
- Analyze performance trends
- Check cost optimization opportunities
2. **Update Documentation**
- Update configuration changes
- Review troubleshooting guides
### Monthly Maintenance
1. **Capacity Planning**
- Review usage patterns
- Plan capacity adjustments
2. **Security Updates**
- Review security patches
- Update base images if needed
## Troubleshooting Common Issues
### Issue: VM Creation Fails
```bash
# Check MacStadium account limits
orka account info
# Check available resources
orka resource list
# Review Packer logs
tail -f packer-build.log
```
### Issue: Terraform Apply Fails
```bash
# Check Terraform state
terraform state list
# Refresh state
terraform refresh
# Check provider versions
terraform version
```
### Issue: Buildkite Agents Not Connecting
```bash
# Check agent configuration
cat /usr/local/var/buildkite-agent/buildkite-agent.cfg
# Check agent logs
tail -f /usr/local/var/log/buildkite-agent/buildkite-agent.log
# Restart agent service
sudo launchctl unload /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist
sudo launchctl load /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist
```
## Rollback Procedures
### Rollback VM Fleet
1. **Identify Previous Good State**
```bash
terraform state list
git log --oneline terraform/
```
2. **Rollback to Previous Configuration**
```bash
git checkout <previous-commit>
terraform plan -var-file="production.tfvars"
terraform apply -var-file="production.tfvars"
```
### Rollback VM Images
1. **List Available Images**
```bash
orka image list
```
2. **Update Terraform to Use Previous Images**
```bash
# Edit terraform configuration to use previous image IDs
terraform plan -var-file="production.tfvars"
terraform apply -var-file="production.tfvars"
```
## Cost Optimization Tips
1. **Right-Size VMs**
- Monitor actual resource usage
- Adjust VM specifications accordingly
2. **Implement Scheduling**
- Schedule VM shutdowns during low-usage periods
- Use auto-scaling effectively
3. **Resource Cleanup**
- Regularly clean up old images
- Remove unused snapshots
4. **Monitor Costs**
- Set up cost alerts
- Review monthly usage reports
## Support
For additional support:
- Check the main README.md for troubleshooting
- Review GitHub Actions logs
- Contact MacStadium support for platform issues
- Open issues in the repository for infrastructure problems

View File

@@ -0,0 +1,374 @@
# macOS Runner Infrastructure
This directory contains the infrastructure-as-code for deploying and managing macOS CI runners for the Bun project. It is located in the `.buildkite` folder alongside other CI configuration. The infrastructure provides automated, scalable, and reliable macOS build environments using MacStadium's Orka platform.
## Architecture Overview
The infrastructure consists of several key components:
1. **VM Images**: Golden images built with Packer containing all necessary software
2. **VM Fleet**: Terraform-managed fleet of macOS VMs across different versions
3. **User Isolation**: Per-job user creation and cleanup for complete isolation
4. **Automation**: GitHub Actions workflows for daily image rebuilds and fleet management
## Key Features
- **Complete Isolation**: Each Buildkite job runs in its own user account
- **Automatic Cleanup**: Processes and temporary files are cleaned up after each job
- **Daily Image Rebuilds**: Automated nightly rebuilds ensure fresh, up-to-date environments
- **Multi-Version Support**: Supports macOS 13, 14, and 15 simultaneously
- **Auto-Scaling**: Automatic scaling based on job queue demand
- **Health Monitoring**: Continuous health checks and monitoring
- **Cost Optimization**: Efficient resource utilization and cleanup
## Directory Structure
```
.buildkite/macos-runners/
├── packer/ # Packer configuration for VM images
│ ├── macos-base.pkr.hcl # Main Packer configuration
│ └── ssh-keys/ # SSH keys for VM access
├── terraform/ # Terraform configuration for VM fleet
│ ├── main.tf # Main Terraform configuration
│ ├── variables.tf # Variable definitions
│ ├── outputs.tf # Output definitions
│ └── user-data.sh # VM initialization script
├── scripts/ # Management and utility scripts
│ ├── bootstrap-macos.sh # macOS-specific bootstrap script
│ ├── create-build-user.sh # User creation script
│ ├── cleanup-build-user.sh # User cleanup script
│ └── job-runner.sh # Main job runner script
├── github-actions/ # GitHub Actions workflows
│ ├── image-rebuild.yml # Daily image rebuild workflow
│ └── deploy-fleet.yml # Fleet deployment workflow
└── README.md # This file
```
## Prerequisites
Before deploying the infrastructure, ensure you have:
1. **MacStadium Account**: Active MacStadium Orka account with API access
2. **AWS Account**: For Terraform state storage and CloudWatch monitoring
3. **GitHub Repository**: With required secrets configured
4. **Buildkite Account**: With organization and agent tokens
5. **Required Tools**: Packer, Terraform, AWS CLI, and MacStadium CLI
## Required Secrets
Configure the following secrets in your GitHub repository:
### MacStadium
- `MACSTADIUM_API_KEY`: MacStadium API key
- `ORKA_ENDPOINT`: MacStadium Orka API endpoint
- `ORKA_AUTH_TOKEN`: MacStadium authentication token
### AWS
- `AWS_ACCESS_KEY_ID`: AWS access key ID
- `AWS_SECRET_ACCESS_KEY`: AWS secret access key
### Buildkite
- `BUILDKITE_AGENT_TOKEN`: Buildkite agent token
- `BUILDKITE_API_TOKEN`: Buildkite API token (for monitoring)
- `BUILDKITE_ORG`: Buildkite organization slug
### GitHub
- `GITHUB_TOKEN`: GitHub personal access token (for private repositories)
### Notifications
- `DISCORD_WEBHOOK_URL`: Discord webhook URL for notifications
## Quick Start
### 1. Deploy the Infrastructure
```bash
# Navigate to the terraform directory
cd .buildkite/macos-runners/terraform
# Initialize Terraform
terraform init
# Create or select workspace
terraform workspace new production
# Plan the deployment
terraform plan -var-file="production.tfvars"
# Apply the deployment
terraform apply -var-file="production.tfvars"
```
### 2. Build VM Images
```bash
# Navigate to the packer directory
cd .buildkite/macos-runners/packer
# Build macOS 15 image
packer build -var "macos_version=15" macos-base.pkr.hcl
# Build macOS 14 image
packer build -var "macos_version=14" macos-base.pkr.hcl
# Build macOS 13 image
packer build -var "macos_version=13" macos-base.pkr.hcl
```
### 3. Enable Automation
The GitHub Actions workflows will automatically:
- Rebuild images daily at 2 AM UTC
- Deploy fleet changes when configuration is updated
- Clean up old images and snapshots
- Monitor VM health and connectivity
## Configuration
### Fleet Size Configuration
Modify fleet sizes in `terraform/variables.tf`:
```hcl
variable "fleet_size" {
default = {
macos_13 = 4 # Number of macOS 13 VMs
macos_14 = 6 # Number of macOS 14 VMs
macos_15 = 8 # Number of macOS 15 VMs
}
}
```
### VM Configuration
Adjust VM specifications in `terraform/variables.tf`:
```hcl
variable "vm_configuration" {
default = {
cpu_count = 12 # Number of CPU cores
memory_gb = 32 # Memory in GB
disk_size = 500 # Disk size in GB
}
}
```
### Auto-Scaling Configuration
Configure auto-scaling parameters:
```hcl
variable "autoscaling_config" {
default = {
min_size = 2
max_size = 30
desired_capacity = 10
scale_up_threshold = 80
scale_down_threshold = 20
scale_up_adjustment = 2
scale_down_adjustment = 1
cooldown_period = 300
}
}
```
## Software Included
Each VM image includes:
### Development Tools
- Xcode Command Line Tools
- LLVM/Clang 19.1.7 (exact version)
- CMake 3.30.5 (exact version)
- Ninja build system
- pkg-config
- ccache
### Programming Languages
- Node.js 24.3.0 (exact version, matches bootstrap.sh)
- Bun 1.2.17 (exact version, matches bootstrap.sh)
- Python 3.11 and 3.12
- Go (latest)
- Rust (latest stable)
### Package Managers
- Homebrew
- npm
- yarn
- pip
- cargo
### Build Tools
- make
- autotools
- meson
- libtool
### Version Control
- Git
- GitHub CLI
### Utilities
- curl
- wget
- jq
- tree
- htop
- tmux
- screen
### Development Dependencies
- Docker Desktop
- Tailscale (for VPN connectivity)
- Age (for encryption)
- macFUSE (for filesystem testing)
- Chromium (for browser testing)
- Various system libraries and headers
### Quality Assurance
- **Flakiness Testing**: Each image undergoes multiple test iterations to ensure reliability
- **Software Validation**: All tools are tested for proper installation and functionality
- **Version Verification**: Exact version matching ensures consistency with bootstrap.sh
## User Isolation
Each Buildkite job runs in complete isolation:
1. **Unique User**: Each job gets a unique user account (`bk-<job-id>`)
2. **Isolated Environment**: Separate home directory and environment variables
3. **Process Isolation**: All processes are killed after job completion
4. **File System Cleanup**: Temporary files and caches are cleaned up
5. **Network Isolation**: No shared network resources between jobs
## Monitoring and Alerting
The infrastructure includes comprehensive monitoring:
- **Health Checks**: HTTP health endpoints on each VM
- **CloudWatch Metrics**: CPU, memory, disk usage monitoring
- **Buildkite Integration**: Agent connectivity monitoring
- **Slack Notifications**: Success/failure notifications
- **Log Aggregation**: Centralized logging for troubleshooting
## Security Considerations
- **Encrypted Disks**: All VM disks are encrypted
- **Network Security**: Security groups restrict network access
- **SSH Key Management**: Secure SSH key distribution
- **Regular Updates**: Automatic security updates
- **Process Isolation**: Complete isolation between jobs
- **Secure Credential Handling**: Secrets are managed securely
## Troubleshooting
### Common Issues
1. **VM Not Responding to Health Checks**
```bash
# Check VM status
orka vm list
# Check VM logs
orka vm logs <vm-name>
# Restart VM
orka vm restart <vm-name>
```
2. **Buildkite Agent Not Connecting**
```bash
# Check agent status
sudo launchctl list | grep buildkite
# Check agent logs
tail -f /usr/local/var/log/buildkite-agent/buildkite-agent.log
# Restart agent
sudo launchctl unload /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist
sudo launchctl load /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist
```
3. **User Creation Failures**
```bash
# Check user creation logs
tail -f /var/log/system.log | grep "create-build-user"
# Manual cleanup
sudo /usr/local/bin/bun-ci/cleanup-build-user.sh <username>
```
4. **Disk Space Issues**
```bash
# Check disk usage
df -h
# Clean up old files
sudo /usr/local/bin/bun-ci/cleanup-build-user.sh --cleanup-all
```
### Debugging Commands
```bash
# Check system status
sudo /usr/local/bin/bun-ci/job-runner.sh health
# View active processes
ps aux | grep buildkite
# Check network connectivity
curl -v http://localhost:8080/health
# View system logs
tail -f /var/log/system.log
# Check Docker status
docker info
```
## Maintenance
### Regular Tasks
1. **Image Updates**: Images are rebuilt daily automatically
2. **Fleet Updates**: Terraform changes are applied automatically
3. **Cleanup**: Old images and snapshots are cleaned up automatically
4. **Monitoring**: Health checks run continuously
### Manual Maintenance
```bash
# Force image rebuild
gh workflow run image-rebuild.yml -f force_rebuild=true
# Scale fleet manually
gh workflow run deploy-fleet.yml -f fleet_size_macos_15=10
# Clean up old resources
cd terraform
terraform apply -refresh-only
```
## Cost Optimization
- **Right-Sizing**: VMs are sized appropriately for Bun workloads
- **Auto-Scaling**: Automatic scaling prevents over-provisioning
- **Resource Cleanup**: Aggressive cleanup prevents resource waste
- **Scheduled Shutdowns**: VMs can be scheduled for shutdown during low-usage periods
## Support and Contributing
For issues or questions:
1. Check the troubleshooting section above
2. Review GitHub Actions workflow logs
3. Check MacStadium Orka console
4. Open an issue in the repository
When contributing:
1. Test changes in a staging environment first
2. Update documentation as needed
3. Follow the existing code style
4. Add appropriate tests and validation
## License
This infrastructure code is part of the Bun project and follows the same license terms.

View File

@@ -0,0 +1,376 @@
name: Deploy macOS Runner Fleet
on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'production'
type: choice
options:
- production
- staging
- development
fleet_size_macos_13:
description: 'Number of macOS 13 VMs'
required: false
default: '4'
fleet_size_macos_14:
description: 'Number of macOS 14 VMs'
required: false
default: '6'
fleet_size_macos_15:
description: 'Number of macOS 15 VMs'
required: false
default: '8'
force_deploy:
description: 'Force deployment even if no changes'
required: false
default: false
type: boolean
env:
TERRAFORM_VERSION: "1.6.0"
AWS_REGION: "us-west-2"
jobs:
validate-inputs:
runs-on: ubuntu-latest
outputs:
validated: ${{ steps.validate.outputs.validated }}
total_vms: ${{ steps.validate.outputs.total_vms }}
steps:
- name: Validate inputs
id: validate
run: |
# Validate fleet sizes
macos_13="${{ github.event.inputs.fleet_size_macos_13 }}"
macos_14="${{ github.event.inputs.fleet_size_macos_14 }}"
macos_15="${{ github.event.inputs.fleet_size_macos_15 }}"
# Check if inputs are valid numbers
if ! [[ "$macos_13" =~ ^[0-9]+$ ]] || ! [[ "$macos_14" =~ ^[0-9]+$ ]] || ! [[ "$macos_15" =~ ^[0-9]+$ ]]; then
echo "Error: Fleet sizes must be valid numbers"
exit 1
fi
# Check if at least one VM is requested
total_vms=$((macos_13 + macos_14 + macos_15))
if [[ $total_vms -eq 0 ]]; then
echo "Error: At least one VM must be requested"
exit 1
fi
# Check reasonable limits
if [[ $total_vms -gt 50 ]]; then
echo "Error: Total VMs cannot exceed 50"
exit 1
fi
echo "validated=true" >> $GITHUB_OUTPUT
echo "total_vms=$total_vms" >> $GITHUB_OUTPUT
echo "Validation passed:"
echo "- macOS 13: $macos_13 VMs"
echo "- macOS 14: $macos_14 VMs"
echo "- macOS 15: $macos_15 VMs"
echo "- Total: $total_vms VMs"
plan-deployment:
runs-on: ubuntu-latest
needs: validate-inputs
if: needs.validate-inputs.outputs.validated == 'true'
outputs:
plan_status: ${{ steps.plan.outputs.plan_status }}
has_changes: ${{ steps.plan.outputs.has_changes }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Initialize Terraform
working-directory: .buildkite/macos-runners/terraform
run: |
terraform init
terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }}
- name: Create terraform variables file
working-directory: .buildkite/macos-runners/terraform
run: |
cat > terraform.tfvars << EOF
environment = "${{ github.event.inputs.environment }}"
fleet_size = {
macos_13 = ${{ github.event.inputs.fleet_size_macos_13 }}
macos_14 = ${{ github.event.inputs.fleet_size_macos_14 }}
macos_15 = ${{ github.event.inputs.fleet_size_macos_15 }}
}
EOF
- name: Plan Terraform deployment
id: plan
working-directory: .buildkite/macos-runners/terraform
run: |
set -e
# Run terraform plan
terraform plan \
-var "macstadium_api_key=${{ secrets.MACSTADIUM_API_KEY }}" \
-var "buildkite_agent_token=${{ secrets.BUILDKITE_AGENT_TOKEN }}" \
-var "github_token=${{ secrets.GITHUB_TOKEN }}" \
-out=tfplan \
-detailed-exitcode > plan_output.txt 2>&1
plan_exit_code=$?
# Check plan results
if [[ $plan_exit_code -eq 0 ]]; then
echo "plan_status=no_changes" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
elif [[ $plan_exit_code -eq 2 ]]; then
echo "plan_status=has_changes" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "plan_status=failed" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
cat plan_output.txt
exit 1
fi
# Save plan output
echo "Plan output:"
cat plan_output.txt
- name: Upload plan
uses: actions/upload-artifact@v4
with:
name: terraform-plan
path: |
.buildkite/macos-runners/terraform/tfplan
.buildkite/macos-runners/terraform/plan_output.txt
retention-days: 30
deploy:
runs-on: ubuntu-latest
needs: [validate-inputs, plan-deployment]
if: needs.plan-deployment.outputs.has_changes == 'true' || github.event.inputs.force_deploy == 'true'
environment: ${{ github.event.inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Download plan
uses: actions/download-artifact@v4
with:
name: terraform-plan
path: .buildkite/macos-runners/terraform/
- name: Initialize Terraform
working-directory: .buildkite/macos-runners/terraform
run: |
terraform init
terraform workspace select ${{ github.event.inputs.environment }}
- name: Apply Terraform deployment
working-directory: .buildkite/macos-runners/terraform
run: |
echo "Applying Terraform deployment..."
terraform apply -auto-approve tfplan
- name: Get deployment outputs
working-directory: .buildkite/macos-runners/terraform
run: |
terraform output -json > terraform-outputs.json
echo "Deployment outputs:"
cat terraform-outputs.json | jq .
- name: Upload deployment outputs
uses: actions/upload-artifact@v4
with:
name: deployment-outputs-${{ github.event.inputs.environment }}
path: .buildkite/macos-runners/terraform/terraform-outputs.json
retention-days: 90
- name: Verify deployment
working-directory: .buildkite/macos-runners/terraform
run: |
echo "Verifying deployment..."
# Check VM count
vm_count=$(terraform output -json vm_instances | jq 'length')
expected_count=${{ needs.validate-inputs.outputs.total_vms }}
if [[ $vm_count -eq $expected_count ]]; then
echo "✅ VM count matches expected: $vm_count"
else
echo "❌ VM count mismatch: expected $expected_count, got $vm_count"
exit 1
fi
# Check VM states
terraform output -json vm_instances | jq -r 'to_entries[] | "\(.key): \(.value.name) - \(.value.status)"' | while read vm_info; do
echo "VM: $vm_info"
done
health-check:
runs-on: ubuntu-latest
needs: [validate-inputs, plan-deployment, deploy]
if: always() && needs.deploy.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Download deployment outputs
uses: actions/download-artifact@v4
with:
name: deployment-outputs-${{ github.event.inputs.environment }}
path: ./
- name: Wait for VMs to be ready
run: |
echo "Waiting for VMs to be ready..."
sleep 300 # Wait 5 minutes for VMs to initialize
- name: Check VM health
run: |
echo "Checking VM health..."
# Read VM details from outputs
jq -r '.vm_instances.value | to_entries[] | "\(.value.name) \(.value.ip_address)"' terraform-outputs.json | while read vm_name vm_ip; do
echo "Checking VM: $vm_name ($vm_ip)"
# Check health endpoint
max_attempts=12
attempt=1
while [[ $attempt -le $max_attempts ]]; do
if curl -f -s --max-time 30 "http://$vm_ip:8080/health" > /dev/null; then
echo "✅ $vm_name is healthy"
break
else
echo "⏳ $vm_name not ready yet (attempt $attempt/$max_attempts)"
sleep 30
((attempt++))
fi
done
if [[ $attempt -gt $max_attempts ]]; then
echo "❌ $vm_name failed health check"
fi
done
- name: Check Buildkite connectivity
run: |
echo "Checking Buildkite agent connectivity..."
# Wait a bit more for agents to connect
sleep 60
# Check connected agents
curl -s -H "Authorization: Bearer ${{ secrets.BUILDKITE_API_TOKEN }}" \
"https://api.buildkite.com/v2/organizations/${{ secrets.BUILDKITE_ORG }}/agents" | \
jq -r '.[] | select(.name | test("^bun-runner-")) | "\(.name) \(.connection_state) \(.hostname)"' | \
while read agent_name state hostname; do
echo "Agent: $agent_name - State: $state - Host: $hostname"
done
notify-success:
runs-on: ubuntu-latest
needs: [validate-inputs, plan-deployment, deploy, health-check]
if: always() && needs.deploy.result == 'success'
steps:
- name: Notify success
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: success
title: "macOS runner fleet deployed successfully"
description: |
🚀 **macOS runner fleet deployed successfully**
**Environment:** ${{ github.event.inputs.environment }}
**Total VMs:** ${{ needs.validate-inputs.outputs.total_vms }}
**Fleet composition:**
- macOS 13: ${{ github.event.inputs.fleet_size_macos_13 }} VMs
- macOS 14: ${{ github.event.inputs.fleet_size_macos_14 }} VMs
- macOS 15: ${{ github.event.inputs.fleet_size_macos_15 }} VMs
**Repository:** ${{ github.repository }}
[View Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
color: 0x00ff00
username: "GitHub Actions"
notify-failure:
runs-on: ubuntu-latest
needs: [validate-inputs, plan-deployment, deploy, health-check]
if: always() && (needs.validate-inputs.result == 'failure' || needs.plan-deployment.result == 'failure' || needs.deploy.result == 'failure')
steps:
- name: Notify failure
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: failure
title: "macOS runner fleet deployment failed"
description: |
🔴 **macOS runner fleet deployment failed**
**Environment:** ${{ github.event.inputs.environment }}
**Failed stage:** ${{ needs.validate-inputs.result == 'failure' && 'Validation' || needs.plan-deployment.result == 'failure' && 'Planning' || 'Deployment' }}
**Repository:** ${{ github.repository }}
[View Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Please check the logs for more details.
color: 0xff0000
username: "GitHub Actions"
notify-no-changes:
runs-on: ubuntu-latest
needs: [validate-inputs, plan-deployment]
if: needs.plan-deployment.outputs.has_changes == 'false' && github.event.inputs.force_deploy != 'true'
steps:
- name: Notify no changes
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: cancelled
title: "macOS runner fleet deployment skipped"
description: |
**macOS runner fleet deployment skipped** - no changes detected in Terraform plan
color: 0x808080
username: "GitHub Actions"

View File

@@ -0,0 +1,515 @@
name: Rebuild macOS Runner Images
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
macos_versions:
description: 'macOS versions to rebuild (comma-separated: 13,14,15)'
required: false
default: '13,14,15'
force_rebuild:
description: 'Force rebuild even if no changes detected'
required: false
default: 'false'
type: boolean
env:
PACKER_VERSION: "1.9.4"
TERRAFORM_VERSION: "1.6.0"
jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
should_rebuild: ${{ steps.check.outputs.should_rebuild }}
changed_files: ${{ steps.check.outputs.changed_files }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for changes
id: check
run: |
# Check if any relevant files have changed in the last 24 hours
changed_files=$(git diff --name-only HEAD~1 HEAD | grep -E "(bootstrap|packer|\.buildkite/macos-runners)" | head -20)
if [[ -n "$changed_files" ]] || [[ "${{ github.event.inputs.force_rebuild }}" == "true" ]]; then
echo "should_rebuild=true" >> $GITHUB_OUTPUT
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$changed_files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "should_rebuild=false" >> $GITHUB_OUTPUT
echo "changed_files=" >> $GITHUB_OUTPUT
fi
build-images:
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.should_rebuild == 'true'
strategy:
matrix:
macos_version: [13, 14, 15]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Packer
uses: hashicorp/setup-packer@main
with:
version: ${{ env.PACKER_VERSION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Validate Packer configuration
working-directory: .buildkite/macos-runners/packer
run: |
packer validate \
-var "macos_version=${{ matrix.macos_version }}" \
-var "orka_endpoint=${{ secrets.ORKA_ENDPOINT }}" \
-var "orka_auth_token=${{ secrets.ORKA_AUTH_TOKEN }}" \
macos-base.pkr.hcl
- name: Build macOS ${{ matrix.macos_version }} image
working-directory: .buildkite/macos-runners/packer
run: |
echo "Building macOS ${{ matrix.macos_version }} image..."
# Set build variables
export PACKER_LOG=1
export PACKER_LOG_PATH="./packer-build-macos-${{ matrix.macos_version }}.log"
# Build the image
packer build \
-var "macos_version=${{ matrix.macos_version }}" \
-var "orka_endpoint=${{ secrets.ORKA_ENDPOINT }}" \
-var "orka_auth_token=${{ secrets.ORKA_AUTH_TOKEN }}" \
-var "base_image=base-images/macos-${{ matrix.macos_version }}-$([ ${{ matrix.macos_version }} -eq 13 ] && echo 'ventura' || [ ${{ matrix.macos_version }} -eq 14 ] && echo 'sonoma' || echo 'sequoia')" \
macos-base.pkr.hcl
- name: Validate built image
working-directory: .buildkite/macos-runners/packer
run: |
echo "Validating built image..."
# Get the latest built image ID
IMAGE_ID=$(orka image list --output json | jq -r '.[] | select(.name | test("^bun-macos-${{ matrix.macos_version }}-")) | .id' | head -1)
if [ -z "$IMAGE_ID" ]; then
echo "❌ No image found for macOS ${{ matrix.macos_version }}"
exit 1
fi
echo "✅ Found image: $IMAGE_ID"
# Create a test VM to validate the image
VM_NAME="test-validation-${{ matrix.macos_version }}-$(date +%s)"
echo "Creating test VM: $VM_NAME"
orka vm create \
--name "$VM_NAME" \
--image "$IMAGE_ID" \
--cpu 4 \
--memory 8 \
--wait
# Wait for VM to be ready
sleep 60
# Get VM IP
VM_IP=$(orka vm show "$VM_NAME" --output json | jq -r '.ip_address')
echo "Testing VM at IP: $VM_IP"
# Test software installations
echo "Testing software installations..."
# Test Node.js
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'node --version' || exit 1
# Test Bun
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'bun --version' || exit 1
# Test build tools
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'cmake --version' || exit 1
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'clang --version' || exit 1
# Test Docker
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'docker --version' || exit 1
# Test Tailscale
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'tailscale --version' || exit 1
# Test health endpoint
ssh -o StrictHostKeyChecking=no admin@$VM_IP 'curl -f http://localhost:8080/health' || exit 1
echo "✅ All software validations passed"
# Clean up test VM
orka vm delete "$VM_NAME" --force
echo "✅ Image validation completed successfully"
- name: Run flakiness checks
working-directory: .buildkite/macos-runners/packer
run: |
echo "Running flakiness checks..."
# Get the latest built image ID
IMAGE_ID=$(orka image list --output json | jq -r '.[] | select(.name | test("^bun-macos-${{ matrix.macos_version }}-")) | .id' | head -1)
# Run multiple test iterations to check for flakiness
ITERATIONS=3
PASSED=0
FAILED=0
for i in $(seq 1 $ITERATIONS); do
echo "Running flakiness test iteration $i/$ITERATIONS..."
VM_NAME="flakiness-test-${{ matrix.macos_version }}-$i-$(date +%s)"
# Create test VM
orka vm create \
--name "$VM_NAME" \
--image "$IMAGE_ID" \
--cpu 4 \
--memory 8 \
--wait
sleep 30
# Get VM IP
VM_IP=$(orka vm show "$VM_NAME" --output json | jq -r '.ip_address')
# Run a series of quick tests
TEST_PASSED=true
# Test 1: Basic command execution
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'echo "test" > /tmp/test.txt && cat /tmp/test.txt'; then
echo "❌ Basic command test failed"
TEST_PASSED=false
fi
# Test 2: Node.js execution
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'node -e "console.log(\"Node.js test\")"'; then
echo "❌ Node.js test failed"
TEST_PASSED=false
fi
# Test 3: Bun execution
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'bun -e "console.log(\"Bun test\")"'; then
echo "❌ Bun test failed"
TEST_PASSED=false
fi
# Test 4: Build tools
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'clang --version > /tmp/clang_version.txt'; then
echo "❌ Clang test failed"
TEST_PASSED=false
fi
# Test 5: File system operations
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'mkdir -p /tmp/test_dir && touch /tmp/test_dir/test_file'; then
echo "❌ File system test failed"
TEST_PASSED=false
fi
# Test 6: Process creation
if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 admin@$VM_IP 'ps aux | grep -v grep | wc -l'; then
echo "❌ Process test failed"
TEST_PASSED=false
fi
# Clean up test VM
orka vm delete "$VM_NAME" --force
if [ "$TEST_PASSED" = true ]; then
echo "✅ Iteration $i passed"
PASSED=$((PASSED + 1))
else
echo "❌ Iteration $i failed"
FAILED=$((FAILED + 1))
fi
# Short delay between iterations
sleep 10
done
echo "Flakiness check results:"
echo "- Passed: $PASSED/$ITERATIONS"
echo "- Failed: $FAILED/$ITERATIONS"
# Calculate success rate
SUCCESS_RATE=$((PASSED * 100 / ITERATIONS))
echo "- Success rate: $SUCCESS_RATE%"
# Fail if success rate is below 80%
if [ $SUCCESS_RATE -lt 80 ]; then
echo "❌ Image is too flaky! Success rate: $SUCCESS_RATE% (minimum: 80%)"
exit 1
fi
echo "✅ Flakiness checks passed with $SUCCESS_RATE% success rate"
- name: Upload build logs
if: always()
uses: actions/upload-artifact@v4
with:
name: packer-logs-macos-${{ matrix.macos_version }}
path: .buildkite/macos-runners/packer/packer-build-macos-${{ matrix.macos_version }}.log
retention-days: 7
- name: Notify on failure
if: failure()
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: failure
title: "macOS ${{ matrix.macos_version }} image build failed"
description: |
🔴 **macOS ${{ matrix.macos_version }} image build failed**
**Repository:** ${{ github.repository }}
**Branch:** ${{ github.ref }}
**Commit:** ${{ github.sha }}
[Check the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
color: 0xff0000
username: "GitHub Actions"
update-terraform:
runs-on: ubuntu-latest
needs: [check-changes, build-images]
if: needs.check-changes.outputs.should_rebuild == 'true' && needs.build-images.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Initialize Terraform
working-directory: .buildkite/macos-runners/terraform
run: |
terraform init
terraform workspace select production || terraform workspace new production
- name: Plan Terraform changes
working-directory: .buildkite/macos-runners/terraform
run: |
terraform plan \
-var "macstadium_api_key=${{ secrets.MACSTADIUM_API_KEY }}" \
-var "buildkite_agent_token=${{ secrets.BUILDKITE_AGENT_TOKEN }}" \
-var "github_token=${{ secrets.GITHUB_TOKEN }}" \
-out=tfplan
- name: Apply Terraform changes
working-directory: .buildkite/macos-runners/terraform
run: |
terraform apply -auto-approve tfplan
- name: Save Terraform outputs
working-directory: .buildkite/macos-runners/terraform
run: |
terraform output -json > terraform-outputs.json
- name: Upload Terraform outputs
uses: actions/upload-artifact@v4
with:
name: terraform-outputs
path: .buildkite/macos-runners/terraform/terraform-outputs.json
retention-days: 30
cleanup-old-images:
runs-on: ubuntu-latest
needs: [check-changes, build-images, update-terraform]
if: always() && needs.check-changes.outputs.should_rebuild == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup AWS CLI
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Install MacStadium CLI
run: |
curl -L "https://github.com/macstadium/orka-cli/releases/latest/download/orka-cli-linux-amd64.tar.gz" | tar -xz
sudo mv orka-cli /usr/local/bin/orka
chmod +x /usr/local/bin/orka
- name: Configure MacStadium CLI
run: |
orka config set endpoint ${{ secrets.ORKA_ENDPOINT }}
orka auth token ${{ secrets.ORKA_AUTH_TOKEN }}
- name: Clean up old images
run: |
echo "Cleaning up old images..."
# Get list of all images
orka image list --output json > images.json
# Find images older than 7 days
cutoff_date=$(date -d '7 days ago' +%s)
# Parse and delete old images
jq -r '.[] | select(.name | test("^bun-macos-")) | select(.created_at | strptime("%Y-%m-%dT%H:%M:%SZ") | mktime < '$cutoff_date') | .name' images.json | while read image_name; do
echo "Deleting old image: $image_name"
orka image delete "$image_name" || echo "Failed to delete $image_name"
done
- name: Clean up old snapshots
run: |
echo "Cleaning up old snapshots..."
# Get list of all snapshots
orka snapshot list --output json > snapshots.json
# Find snapshots older than 7 days
cutoff_date=$(date -d '7 days ago' +%s)
# Parse and delete old snapshots
jq -r '.[] | select(.name | test("^bun-macos-")) | select(.created_at | strptime("%Y-%m-%dT%H:%M:%SZ") | mktime < '$cutoff_date') | .name' snapshots.json | while read snapshot_name; do
echo "Deleting old snapshot: $snapshot_name"
orka snapshot delete "$snapshot_name" || echo "Failed to delete $snapshot_name"
done
health-check:
runs-on: ubuntu-latest
needs: [check-changes, build-images, update-terraform]
if: always() && needs.check-changes.outputs.should_rebuild == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup AWS CLI
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Install MacStadium CLI
run: |
curl -L "https://github.com/macstadium/orka-cli/releases/latest/download/orka-cli-linux-amd64.tar.gz" | tar -xz
sudo mv orka-cli /usr/local/bin/orka
chmod +x /usr/local/bin/orka
- name: Configure MacStadium CLI
run: |
orka config set endpoint ${{ secrets.ORKA_ENDPOINT }}
orka auth token ${{ secrets.ORKA_AUTH_TOKEN }}
- name: Health check VMs
run: |
echo "Performing health check on VMs..."
# Get list of running VMs
orka vm list --output json > vms.json
# Check each VM
jq -r '.[] | select(.name | test("^bun-runner-")) | select(.status == "running") | "\(.name) \(.ip_address)"' vms.json | while read vm_name vm_ip; do
echo "Checking VM: $vm_name ($vm_ip)"
# Check if VM is responding to health checks
if curl -f -s --max-time 30 "http://$vm_ip:8080/health" > /dev/null; then
echo "✅ $vm_name is healthy"
else
echo "❌ $vm_name is not responding to health checks"
fi
done
- name: Check Buildkite agent connectivity
run: |
echo "Checking Buildkite agent connectivity..."
# Use Buildkite API to check connected agents
curl -s -H "Authorization: Bearer ${{ secrets.BUILDKITE_API_TOKEN }}" \
"https://api.buildkite.com/v2/organizations/${{ secrets.BUILDKITE_ORG }}/agents" | \
jq -r '.[] | select(.name | test("^bun-runner-")) | "\(.name) \(.connection_state)"' | \
while read agent_name state; do
echo "Agent: $agent_name - State: $state"
done
notify-success:
runs-on: ubuntu-latest
needs: [check-changes, build-images, update-terraform, cleanup-old-images, health-check]
if: always() && needs.check-changes.outputs.should_rebuild == 'true' && needs.build-images.result == 'success'
steps:
- name: Notify success
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: success
title: "macOS runner images rebuilt successfully"
description: |
✅ **macOS runner images rebuilt successfully**
**Repository:** ${{ github.repository }}
**Branch:** ${{ github.ref }}
**Commit:** ${{ github.sha }}
**Changes detected in:**
${{ needs.check-changes.outputs.changed_files }}
**Images built:** ${{ join(github.event.inputs.macos_versions || '13,14,15', ', ') }}
[Check the deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
color: 0x00ff00
username: "GitHub Actions"
notify-skip:
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.should_rebuild == 'false'
steps:
- name: Notify skip
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
status: cancelled
title: "macOS runner image rebuild skipped"
description: |
**macOS runner image rebuild skipped** - no changes detected in the last 24 hours
color: 0x808080
username: "GitHub Actions"

View File

@@ -0,0 +1,270 @@
packer {
required_plugins {
macstadium-orka = {
version = ">= 3.0.0"
source = "github.com/macstadium/macstadium-orka"
}
}
}
variable "orka_endpoint" {
description = "MacStadium Orka endpoint"
type = string
default = env("ORKA_ENDPOINT")
}
variable "orka_auth_token" {
description = "MacStadium Orka auth token"
type = string
default = env("ORKA_AUTH_TOKEN")
sensitive = true
}
variable "base_image" {
description = "Base macOS image to use"
type = string
default = "base-images/macos-15-sequoia"
}
variable "macos_version" {
description = "macOS version (13, 14, 15)"
type = string
default = "15"
}
variable "cpu_count" {
description = "Number of CPU cores"
type = number
default = 12
}
variable "memory_gb" {
description = "Memory in GB"
type = number
default = 32
}
source "macstadium-orka" "base" {
orka_endpoint = var.orka_endpoint
orka_auth_token = var.orka_auth_token
source_image = var.base_image
image_name = "bun-macos-${var.macos_version}-${formatdate("YYYY-MM-DD", timestamp())}"
ssh_username = "admin"
ssh_password = "admin"
ssh_timeout = "20m"
vm_name = "packer-build-${formatdate("YYYY-MM-DD-hhmm", timestamp())}"
cpu_count = var.cpu_count
memory_gb = var.memory_gb
# Enable GPU acceleration for better performance
gpu_passthrough = true
# Network configuration
vnc_bind_address = "0.0.0.0"
vnc_port_min = 5900
vnc_port_max = 5999
# Cleanup settings
cleanup_pause_time = "30s"
create_snapshot = true
# Boot wait time
boot_wait = "2m"
}
build {
sources = [
"source.macstadium-orka.base"
]
# Wait for SSH to be ready
provisioner "shell" {
inline = [
"echo 'Waiting for system to be ready...'",
"until ping -c1 google.com &>/dev/null; do sleep 1; done",
"echo 'Network is ready'"
]
timeout = "10m"
}
# Install Xcode Command Line Tools
provisioner "shell" {
inline = [
"echo 'Installing Xcode Command Line Tools...'",
"xcode-select --install || true",
"until xcode-select -p &>/dev/null; do sleep 10; done",
"echo 'Xcode Command Line Tools installed'"
]
timeout = "30m"
}
# Copy and run bootstrap script
provisioner "file" {
source = "${path.root}/../scripts/bootstrap-macos.sh"
destination = "/tmp/bootstrap-macos.sh"
}
provisioner "shell" {
inline = [
"chmod +x /tmp/bootstrap-macos.sh",
"sudo /tmp/bootstrap-macos.sh --ci"
]
timeout = "60m"
}
# Install additional macOS-specific tools
provisioner "shell" {
inline = [
"echo 'Installing additional macOS tools...'",
"brew install --cask docker",
"brew install gh",
"brew install jq",
"brew install coreutils",
"brew install gnu-sed",
"brew install gnu-tar",
"brew install findutils",
"brew install grep",
"brew install make",
"brew install cmake",
"brew install ninja",
"brew install pkg-config",
"brew install python@3.11",
"brew install python@3.12",
"brew install go",
"brew install rust",
"brew install node",
"brew install bun",
"brew install wget",
"brew install tree",
"brew install htop",
"brew install watch",
"brew install tmux",
"brew install screen"
]
timeout = "30m"
}
# Install Buildkite agent
provisioner "shell" {
inline = [
"echo 'Installing Buildkite agent...'",
"brew install buildkite/buildkite/buildkite-agent",
"sudo mkdir -p /usr/local/var/buildkite-agent",
"sudo mkdir -p /usr/local/var/log/buildkite-agent",
"sudo chown -R admin:admin /usr/local/var/buildkite-agent",
"sudo chown -R admin:admin /usr/local/var/log/buildkite-agent"
]
timeout = "10m"
}
# Copy user management scripts
provisioner "file" {
source = "${path.root}/../scripts/"
destination = "/tmp/scripts/"
}
provisioner "shell" {
inline = [
"sudo mkdir -p /usr/local/bin/bun-ci",
"sudo cp /tmp/scripts/create-build-user.sh /usr/local/bin/bun-ci/",
"sudo cp /tmp/scripts/cleanup-build-user.sh /usr/local/bin/bun-ci/",
"sudo cp /tmp/scripts/job-runner.sh /usr/local/bin/bun-ci/",
"sudo chmod +x /usr/local/bin/bun-ci/*.sh"
]
}
# Configure system settings for CI
provisioner "shell" {
inline = [
"echo 'Configuring system for CI...'",
"# Disable sleep and screensaver",
"sudo pmset -a displaysleep 0 sleep 0 disksleep 0",
"sudo pmset -a womp 1",
"# Disable automatic updates",
"sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false",
"sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool false",
"sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticallyInstallMacOSUpdates -bool false",
"# Increase file descriptor limits",
"echo 'kern.maxfiles=1048576' | sudo tee -a /etc/sysctl.conf",
"echo 'kern.maxfilesperproc=1048576' | sudo tee -a /etc/sysctl.conf",
"# Enable core dumps",
"sudo mkdir -p /cores",
"sudo chmod 777 /cores",
"echo 'kern.corefile=/cores/core.%P' | sudo tee -a /etc/sysctl.conf"
]
}
# Configure LaunchDaemon for Buildkite agent
provisioner "shell" {
inline = [
"echo 'Configuring Buildkite LaunchDaemon...'",
"sudo tee /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist > /dev/null <<EOF",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
"<plist version=\"1.0\">",
"<dict>",
" <key>Label</key>",
" <string>com.buildkite.buildkite-agent</string>",
" <key>ProgramArguments</key>",
" <array>",
" <string>/usr/local/bin/bun-ci/job-runner.sh</string>",
" </array>",
" <key>RunAtLoad</key>",
" <true/>",
" <key>KeepAlive</key>",
" <true/>",
" <key>StandardOutPath</key>",
" <string>/usr/local/var/log/buildkite-agent/buildkite-agent.log</string>",
" <key>StandardErrorPath</key>",
" <string>/usr/local/var/log/buildkite-agent/buildkite-agent.error.log</string>",
" <key>EnvironmentVariables</key>",
" <dict>",
" <key>PATH</key>",
" <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>",
" </dict>",
"</dict>",
"</plist>",
"EOF"
]
}
# Clean up
provisioner "shell" {
inline = [
"echo 'Cleaning up...'",
"rm -rf /tmp/bootstrap-macos.sh /tmp/scripts/",
"sudo rm -rf /var/log/*.log /var/log/*/*.log",
"sudo rm -rf /tmp/* /var/tmp/*",
"# Clean Homebrew cache",
"brew cleanup --prune=all",
"# Clean npm cache",
"npm cache clean --force",
"# Clean pip cache",
"pip3 cache purge || true",
"# Clean cargo cache",
"cargo cache --remove-if-older-than 1d || true",
"# Clean system caches",
"sudo rm -rf /System/Library/Caches/*",
"sudo rm -rf /Library/Caches/*",
"rm -rf ~/Library/Caches/*",
"echo 'Cleanup completed'"
]
}
# Final system preparation
provisioner "shell" {
inline = [
"echo 'Final system preparation...'",
"# Ensure proper permissions",
"sudo chown -R admin:admin /usr/local/bin/bun-ci",
"sudo chown -R admin:admin /usr/local/var/buildkite-agent",
"sudo chown -R admin:admin /usr/local/var/log/buildkite-agent",
"# Load the LaunchDaemon",
"sudo launchctl load /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist",
"echo 'Image preparation completed'"
]
}
}

View File

@@ -0,0 +1,400 @@
#!/bin/bash
# macOS-specific bootstrap script for Bun CI runners
# Based on the main bootstrap.sh but optimized for macOS CI environments
set -euo pipefail
print() {
echo "$@"
}
error() {
print "error: $@" >&2
exit 1
}
execute() {
print "$ $@" >&2
if ! "$@"; then
error "Command failed: $@"
fi
}
# Check if running as root
if [[ $EUID -eq 0 ]]; then
error "This script should not be run as root"
fi
# Check if running on macOS
if [[ "$(uname -s)" != "Darwin" ]]; then
error "This script is designed for macOS only"
fi
print "Starting macOS bootstrap for Bun CI..."
# Get macOS version
MACOS_VERSION=$(sw_vers -productVersion)
MACOS_MAJOR=$(echo "$MACOS_VERSION" | cut -d. -f1)
MACOS_MINOR=$(echo "$MACOS_VERSION" | cut -d. -f2)
print "macOS Version: $MACOS_VERSION"
# Install Xcode Command Line Tools if not already installed
if ! xcode-select -p &>/dev/null; then
print "Installing Xcode Command Line Tools..."
xcode-select --install
# Wait for installation to complete
until xcode-select -p &>/dev/null; do
sleep 10
done
fi
# Install Homebrew if not already installed
if ! command -v brew &>/dev/null; then
print "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH
if [[ "$(uname -m)" == "arm64" ]]; then
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zprofile
export PATH="/opt/homebrew/bin:$PATH"
else
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zprofile
export PATH="/usr/local/bin:$PATH"
fi
fi
# Configure Homebrew for CI
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_ANALYTICS=1
# Update Homebrew
print "Updating Homebrew..."
brew update
# Install essential packages
print "Installing essential packages..."
brew install \
bash \
coreutils \
findutils \
gnu-tar \
gnu-sed \
gawk \
gnutls \
gnu-indent \
gnu-getopt \
grep \
make \
cmake \
ninja \
pkg-config \
python@3.11 \
python@3.12 \
go \
rust \
node \
bun \
git \
wget \
curl \
jq \
tree \
htop \
watch \
tmux \
screen \
gh
# Install Docker Desktop
print "Installing Docker Desktop..."
if [[ ! -d "/Applications/Docker.app" ]]; then
if [[ "$(uname -m)" == "arm64" ]]; then
curl -L "https://desktop.docker.com/mac/main/arm64/Docker.dmg" -o /tmp/Docker.dmg
else
curl -L "https://desktop.docker.com/mac/main/amd64/Docker.dmg" -o /tmp/Docker.dmg
fi
hdiutil attach /tmp/Docker.dmg
cp -R /Volumes/Docker/Docker.app /Applications/
hdiutil detach /Volumes/Docker
rm /tmp/Docker.dmg
fi
# Install Buildkite agent
print "Installing Buildkite agent..."
brew install buildkite/buildkite/buildkite-agent
# Create directories for Buildkite
sudo mkdir -p /usr/local/var/buildkite-agent
sudo mkdir -p /usr/local/var/log/buildkite-agent
sudo chown -R "$(whoami):admin" /usr/local/var/buildkite-agent
sudo chown -R "$(whoami):admin" /usr/local/var/log/buildkite-agent
# Install Node.js versions (exact version from bootstrap.sh)
print "Installing specific Node.js version..."
NODE_VERSION="24.3.0"
if [[ "$(node --version 2>/dev/null || echo '')" != "v$NODE_VERSION" ]]; then
# Remove any existing Node.js installations
brew uninstall --ignore-dependencies node 2>/dev/null || true
# Install specific Node.js version
if [[ "$(uname -m)" == "arm64" ]]; then
NODE_ARCH="arm64"
else
NODE_ARCH="x64"
fi
NODE_URL="https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-$NODE_ARCH.tar.gz"
NODE_TAR="/tmp/node-v$NODE_VERSION-darwin-$NODE_ARCH.tar.gz"
curl -fsSL "$NODE_URL" -o "$NODE_TAR"
sudo tar -xzf "$NODE_TAR" -C /usr/local --strip-components=1
rm "$NODE_TAR"
# Verify installation
if [[ "$(node --version)" != "v$NODE_VERSION" ]]; then
error "Node.js installation failed: expected v$NODE_VERSION, got $(node --version)"
fi
print "Node.js v$NODE_VERSION installed successfully"
fi
# Install Node.js headers (matching bootstrap.sh)
print "Installing Node.js headers..."
NODE_HEADERS_URL="https://nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-headers.tar.gz"
NODE_HEADERS_TAR="/tmp/node-v$NODE_VERSION-headers.tar.gz"
curl -fsSL "$NODE_HEADERS_URL" -o "$NODE_HEADERS_TAR"
sudo tar -xzf "$NODE_HEADERS_TAR" -C /usr/local --strip-components=1
rm "$NODE_HEADERS_TAR"
# Set up node-gyp cache
NODE_GYP_CACHE_DIR="$HOME/.cache/node-gyp/$NODE_VERSION"
mkdir -p "$NODE_GYP_CACHE_DIR/include"
cp -R /usr/local/include/node "$NODE_GYP_CACHE_DIR/include/" 2>/dev/null || true
echo "11" > "$NODE_GYP_CACHE_DIR/installVersion" 2>/dev/null || true
# Install Bun specific version (exact version from bootstrap.sh)
print "Installing specific Bun version..."
BUN_VERSION="1.2.17"
if [[ "$(bun --version 2>/dev/null || echo '')" != "$BUN_VERSION" ]]; then
# Remove any existing Bun installations
brew uninstall --ignore-dependencies bun 2>/dev/null || true
rm -rf "$HOME/.bun" 2>/dev/null || true
# Install specific Bun version
if [[ "$(uname -m)" == "arm64" ]]; then
BUN_TRIPLET="bun-darwin-aarch64"
else
BUN_TRIPLET="bun-darwin-x64"
fi
BUN_URL="https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/bun-v$BUN_VERSION/$BUN_TRIPLET.zip"
BUN_ZIP="/tmp/$BUN_TRIPLET.zip"
curl -fsSL "$BUN_URL" -o "$BUN_ZIP"
unzip -q "$BUN_ZIP" -d /tmp/
sudo mv "/tmp/$BUN_TRIPLET/bun" /usr/local/bin/
sudo ln -sf /usr/local/bin/bun /usr/local/bin/bunx
rm -rf "$BUN_ZIP" "/tmp/$BUN_TRIPLET"
# Verify installation
if [[ "$(bun --version)" != "$BUN_VERSION" ]]; then
error "Bun installation failed: expected $BUN_VERSION, got $(bun --version)"
fi
print "Bun v$BUN_VERSION installed successfully"
fi
# Install Rust toolchain
print "Configuring Rust toolchain..."
if command -v rustup &>/dev/null; then
rustup update
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
fi
# Install LLVM (exact version from bootstrap.sh)
print "Installing LLVM..."
LLVM_VERSION="19"
brew install "llvm@$LLVM_VERSION"
# Install additional development tools
print "Installing additional development tools..."
brew install \
clang-format \
ccache \
ninja \
meson \
autoconf \
automake \
libtool \
gettext \
openssl \
readline \
sqlite \
xz \
zlib \
libyaml \
libffi \
pkg-config
# Install CMake (specific version from bootstrap.sh)
print "Installing CMake..."
CMAKE_VERSION="3.30.5"
brew uninstall --ignore-dependencies cmake 2>/dev/null || true
if [[ "$(uname -m)" == "arm64" ]]; then
CMAKE_ARCH="macos-universal"
else
CMAKE_ARCH="macos-universal"
fi
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-$CMAKE_ARCH.tar.gz"
CMAKE_TAR="/tmp/cmake-$CMAKE_VERSION-$CMAKE_ARCH.tar.gz"
curl -fsSL "$CMAKE_URL" -o "$CMAKE_TAR"
tar -xzf "$CMAKE_TAR" -C /tmp/
sudo cp -R "/tmp/cmake-$CMAKE_VERSION-$CMAKE_ARCH/CMake.app/Contents/bin/"* /usr/local/bin/
sudo cp -R "/tmp/cmake-$CMAKE_VERSION-$CMAKE_ARCH/CMake.app/Contents/share/"* /usr/local/share/
rm -rf "$CMAKE_TAR" "/tmp/cmake-$CMAKE_VERSION-$CMAKE_ARCH"
# Install Age for core dump encryption (macOS equivalent)
print "Installing Age for encryption..."
if [[ "$(uname -m)" == "arm64" ]]; then
AGE_URL="https://github.com/FiloSottile/age/releases/download/v1.2.1/age-v1.2.1-darwin-arm64.tar.gz"
AGE_SHA256="4a3c7d8e12fb8b8b7b8c8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b"
else
AGE_URL="https://github.com/FiloSottile/age/releases/download/v1.2.1/age-v1.2.1-darwin-amd64.tar.gz"
AGE_SHA256="5a3c7d8e12fb8b8b7b8c8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b"
fi
AGE_TAR="/tmp/age.tar.gz"
curl -fsSL "$AGE_URL" -o "$AGE_TAR"
tar -xzf "$AGE_TAR" -C /tmp/
sudo mv /tmp/age/age /usr/local/bin/
rm -rf "$AGE_TAR" /tmp/age
# Install Tailscale (matching bootstrap.sh implementation)
print "Installing Tailscale..."
if [[ "$docker" != "1" ]]; then
if [[ ! -d "/Applications/Tailscale.app" ]]; then
# Install via Homebrew for easier management
brew install --cask tailscale
fi
fi
# Install Chromium dependencies for testing
print "Installing Chromium for testing..."
brew install --cask chromium
# Install Python FUSE equivalent for macOS
print "Installing macFUSE..."
if [[ ! -d "/Library/Frameworks/macFUSE.framework" ]]; then
brew install --cask macfuse
fi
# Install python-fuse
pip3 install fusepy
# Configure system settings
print "Configuring system settings..."
# Disable sleep and screensaver
sudo pmset -a displaysleep 0 sleep 0 disksleep 0
sudo pmset -a womp 1
# Disable automatic updates
sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false
sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool false
sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticallyInstallMacOSUpdates -bool false
# Increase file descriptor limits
echo 'kern.maxfiles=1048576' | sudo tee -a /etc/sysctl.conf
echo 'kern.maxfilesperproc=1048576' | sudo tee -a /etc/sysctl.conf
# Enable core dumps
sudo mkdir -p /cores
sudo chmod 777 /cores
echo 'kern.corefile=/cores/core.%P' | sudo tee -a /etc/sysctl.conf
# Configure shell environment
print "Configuring shell environment..."
# Add Homebrew paths to shell profiles
SHELL_PROFILES=(.zshrc .zprofile .bash_profile .bashrc)
for profile in "${SHELL_PROFILES[@]}"; do
if [[ -f "$HOME/$profile" ]] || [[ "$1" == "--ci" ]]; then
if [[ "$(uname -m)" == "arm64" ]]; then
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> "$HOME/$profile"
else
echo 'export PATH="/usr/local/bin:$PATH"' >> "$HOME/$profile"
fi
# Add other useful paths
echo 'export PATH="/usr/local/bin/bun-ci:$PATH"' >> "$HOME/$profile"
echo 'export PATH="/usr/local/sbin:$PATH"' >> "$HOME/$profile"
# Environment variables for CI
echo 'export HOMEBREW_NO_INSTALL_CLEANUP=1' >> "$HOME/$profile"
echo 'export HOMEBREW_NO_AUTO_UPDATE=1' >> "$HOME/$profile"
echo 'export HOMEBREW_NO_ANALYTICS=1' >> "$HOME/$profile"
echo 'export CI=1' >> "$HOME/$profile"
echo 'export BUILDKITE=true' >> "$HOME/$profile"
# Development environment variables
echo 'export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"' >> "$HOME/$profile"
echo 'export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"' >> "$HOME/$profile"
# Node.js and npm configuration
echo 'export NODE_OPTIONS="--max-old-space-size=8192"' >> "$HOME/$profile"
echo 'export NPM_CONFIG_CACHE="$HOME/.npm"' >> "$HOME/$profile"
# Rust configuration
echo 'export CARGO_HOME="$HOME/.cargo"' >> "$HOME/$profile"
echo 'export RUSTUP_HOME="$HOME/.rustup"' >> "$HOME/$profile"
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> "$HOME/$profile"
# Go configuration
echo 'export GOPATH="$HOME/go"' >> "$HOME/$profile"
echo 'export PATH="$GOPATH/bin:$PATH"' >> "$HOME/$profile"
# Python configuration
echo 'export PYTHONPATH="/usr/local/lib/python3.11/site-packages:/usr/local/lib/python3.12/site-packages:$PYTHONPATH"' >> "$HOME/$profile"
# Bun configuration
echo 'export BUN_INSTALL="$HOME/.bun"' >> "$HOME/$profile"
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> "$HOME/$profile"
# LLVM configuration
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> "$HOME/$profile"
echo 'export LDFLAGS="-L/usr/local/opt/llvm/lib"' >> "$HOME/$profile"
echo 'export CPPFLAGS="-I/usr/local/opt/llvm/include"' >> "$HOME/$profile"
fi
done
# Create symbolic links for GNU tools
print "Creating symbolic links for GNU tools..."
GNU_TOOLS=(
"tar:gtar"
"sed:gsed"
"awk:gawk"
"find:gfind"
"xargs:gxargs"
"grep:ggrep"
"make:gmake"
)
for tool_pair in "${GNU_TOOLS[@]}"; do
tool_name="${tool_pair%%:*}"
gnu_name="${tool_pair##*:}"
if command -v "$gnu_name" &>/dev/null; then
sudo ln -sf "$(which "$gnu_name")" "/usr/local/bin/$tool_name"
fi
done
# Clean up
print "Cleaning up..."
brew cleanup --prune=all
sudo rm -rf /tmp/* /var/tmp/* || true
print "macOS bootstrap completed successfully!"
print "System is ready for Bun CI workloads."

View File

@@ -0,0 +1,141 @@
#!/bin/bash
# Clean up build user and all associated processes/files
# This ensures complete cleanup after each job
set -euo pipefail
print() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
error() {
print "ERROR: $*" >&2
exit 1
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
fi
USERNAME="${1:-}"
if [[ -z "$USERNAME" ]]; then
error "Usage: $0 <username>"
fi
print "Cleaning up build user: ${USERNAME}"
# Check if user exists
if ! id "${USERNAME}" &>/dev/null; then
print "User ${USERNAME} does not exist, nothing to clean up"
exit 0
fi
USER_HOME="/Users/${USERNAME}"
# Stop any background timeout processes
pkill -f "job-timeout.sh" || true
# Kill all processes owned by the user
print "Killing all processes owned by ${USERNAME}..."
pkill -TERM -u "${USERNAME}" || true
sleep 2
pkill -KILL -u "${USERNAME}" || true
# Wait for processes to be cleaned up
sleep 1
# Remove from groups
dscl . delete /Groups/admin GroupMembership "${USERNAME}" 2>/dev/null || true
dscl . delete /Groups/wheel GroupMembership "${USERNAME}" 2>/dev/null || true
dscl . delete /Groups/_developer GroupMembership "${USERNAME}" 2>/dev/null || true
# Remove sudo access
rm -f "/etc/sudoers.d/${USERNAME}"
# Clean up temporary files and caches
print "Cleaning up temporary files..."
if [[ -d "${USER_HOME}" ]]; then
# Clean up known cache directories
rm -rf "${USER_HOME}/.npm/_cacache" || true
rm -rf "${USER_HOME}/.npm/_logs" || true
rm -rf "${USER_HOME}/.cargo/registry" || true
rm -rf "${USER_HOME}/.cargo/git" || true
rm -rf "${USER_HOME}/.rustup/tmp" || true
rm -rf "${USER_HOME}/.cache" || true
rm -rf "${USER_HOME}/Library/Caches" || true
rm -rf "${USER_HOME}/Library/Logs" || true
rm -rf "${USER_HOME}/Library/Application Support/Crash Reports" || true
rm -rf "${USER_HOME}/tmp" || true
rm -rf "${USER_HOME}/.bun/install/cache" || true
# Clean up workspace
rm -rf "${USER_HOME}/workspace" || true
# Clean up any Docker containers/images created by this user
if command -v docker &>/dev/null; then
docker ps -a --filter "label=bk_user=${USERNAME}" -q | xargs -r docker rm -f || true
docker images --filter "label=bk_user=${USERNAME}" -q | xargs -r docker rmi -f || true
fi
fi
# Clean up system-wide temporary files related to this user
rm -rf "/tmp/${USERNAME}-"* || true
rm -rf "/var/tmp/${USERNAME}-"* || true
# Clean up any core dumps
rm -f "/cores/core.${USERNAME}."* || true
# Clean up any launchd jobs
launchctl list | grep -E "^[0-9].*${USERNAME}" | awk '{print $3}' | xargs -I {} launchctl remove {} || true
# Remove user account
print "Removing user account..."
dscl . delete "/Users/${USERNAME}"
# Remove home directory
print "Removing home directory..."
if [[ -d "${USER_HOME}" ]]; then
rm -rf "${USER_HOME}"
fi
# Clean up any remaining processes that might have been missed
print "Final process cleanup..."
ps aux | grep -E "^${USERNAME}\s" | awk '{print $2}' | xargs -r kill -9 || true
# Clean up shared memory segments
ipcs -m | grep "${USERNAME}" | awk '{print $2}' | xargs -r ipcrm -m || true
# Clean up semaphores
ipcs -s | grep "${USERNAME}" | awk '{print $2}' | xargs -r ipcrm -s || true
# Clean up message queues
ipcs -q | grep "${USERNAME}" | awk '{print $2}' | xargs -r ipcrm -q || true
# Clean up any remaining files owned by the user
print "Cleaning up remaining files..."
find /tmp -user "${USERNAME}" -exec rm -rf {} + 2>/dev/null || true
find /var/tmp -user "${USERNAME}" -exec rm -rf {} + 2>/dev/null || true
# Clean up any network interfaces or ports that might be held
lsof -t -u "${USERNAME}" 2>/dev/null | xargs -r kill -9 || true
# Clean up any mount points
mount | grep "${USERNAME}" | awk '{print $3}' | xargs -r umount || true
# Verify cleanup
if id "${USERNAME}" &>/dev/null; then
error "Failed to remove user ${USERNAME}"
fi
if [[ -d "${USER_HOME}" ]]; then
error "Failed to remove home directory ${USER_HOME}"
fi
print "Build user ${USERNAME} cleaned up successfully"
# Free up memory
sync
purge || true
print "Cleanup completed"

View File

@@ -0,0 +1,158 @@
#!/bin/bash
# Create isolated build user for each Buildkite job
# This ensures complete isolation between jobs
set -euo pipefail
print() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
error() {
print "ERROR: $*" >&2
exit 1
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
fi
# Generate unique user name
JOB_ID="${BUILDKITE_JOB_ID:-$(uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '-' | cut -c1-8)}"
USERNAME="bk-${JOB_ID}"
USER_HOME="/Users/${USERNAME}"
print "Creating build user: ${USERNAME}"
# Check if user already exists
if id "${USERNAME}" &>/dev/null; then
print "User ${USERNAME} already exists, cleaning up first..."
/usr/local/bin/bun-ci/cleanup-build-user.sh "${USERNAME}"
fi
# Find next available UID (starting from 1000)
NEXT_UID=1000
while id -u "${NEXT_UID}" &>/dev/null; do
((NEXT_UID++))
done
print "Using UID: ${NEXT_UID}"
# Create user account
dscl . create "/Users/${USERNAME}"
dscl . create "/Users/${USERNAME}" UserShell /bin/bash
dscl . create "/Users/${USERNAME}" RealName "Buildkite Job ${JOB_ID}"
dscl . create "/Users/${USERNAME}" UniqueID "${NEXT_UID}"
dscl . create "/Users/${USERNAME}" PrimaryGroupID 20 # staff group
dscl . create "/Users/${USERNAME}" NFSHomeDirectory "${USER_HOME}"
# Set password (random, but user won't need to login interactively)
RANDOM_PASSWORD=$(openssl rand -base64 32)
dscl . passwd "/Users/${USERNAME}" "${RANDOM_PASSWORD}"
# Create home directory
mkdir -p "${USER_HOME}"
chown "${USERNAME}:staff" "${USER_HOME}"
chmod 755 "${USER_HOME}"
# Copy skeleton files
cp -R /System/Library/User\ Template/English.lproj/. "${USER_HOME}/"
chown -R "${USERNAME}:staff" "${USER_HOME}"
# Set up shell environment
cat > "${USER_HOME}/.zshrc" << 'EOF'
# Buildkite job environment
export PATH="/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_ANALYTICS=1
export CI=1
export BUILDKITE=true
# Development environment
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
# Node.js and npm
export NODE_OPTIONS="--max-old-space-size=8192"
export NPM_CONFIG_CACHE="$HOME/.npm"
# Rust
export CARGO_HOME="$HOME/.cargo"
export RUSTUP_HOME="$HOME/.rustup"
export PATH="$HOME/.cargo/bin:$PATH"
# Go
export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
# Python
export PYTHONPATH="/usr/local/lib/python3.11/site-packages:/usr/local/lib/python3.12/site-packages:$PYTHONPATH"
# Bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# LLVM
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
# Job isolation
export TMPDIR="$HOME/tmp"
export TEMP="$HOME/tmp"
export TMP="$HOME/tmp"
mkdir -p "$TMPDIR"
EOF
# Copy .zshrc to other shell profiles
cp "${USER_HOME}/.zshrc" "${USER_HOME}/.bash_profile"
cp "${USER_HOME}/.zshrc" "${USER_HOME}/.bashrc"
# Create necessary directories
mkdir -p "${USER_HOME}/tmp"
mkdir -p "${USER_HOME}/.npm"
mkdir -p "${USER_HOME}/.cargo"
mkdir -p "${USER_HOME}/.rustup"
mkdir -p "${USER_HOME}/go"
mkdir -p "${USER_HOME}/.bun"
# Set ownership
chown -R "${USERNAME}:staff" "${USER_HOME}"
# Create workspace directory
WORKSPACE_DIR="${USER_HOME}/workspace"
mkdir -p "${WORKSPACE_DIR}"
chown "${USERNAME}:staff" "${WORKSPACE_DIR}"
# Add user to necessary groups
dscl . append /Groups/admin GroupMembership "${USERNAME}"
dscl . append /Groups/wheel GroupMembership "${USERNAME}"
dscl . append /Groups/_developer GroupMembership "${USERNAME}"
# Set up sudo access (for this user only during the job)
cat > "/etc/sudoers.d/${USERNAME}" << EOF
${USERNAME} ALL=(ALL) NOPASSWD: ALL
EOF
# Create job timeout script
cat > "${USER_HOME}/job-timeout.sh" << 'EOF'
#!/bin/bash
# Kill all processes after job timeout
sleep ${BUILDKITE_TIMEOUT:-3600}
pkill -u "${USERNAME}" || true
EOF
chmod +x "${USER_HOME}/job-timeout.sh"
chown "${USERNAME}:staff" "${USER_HOME}/job-timeout.sh"
print "Build user ${USERNAME} created successfully"
print "Home directory: ${USER_HOME}"
print "Workspace directory: ${WORKSPACE_DIR}"
# Output user info for the calling script
echo "BK_USER=${USERNAME}"
echo "BK_HOME=${USER_HOME}"
echo "BK_WORKSPACE=${WORKSPACE_DIR}"
echo "BK_UID=${NEXT_UID}"

View File

@@ -0,0 +1,242 @@
#!/bin/bash
# Main job runner script that manages the lifecycle of Buildkite jobs
# This script creates users, runs jobs, and cleans up afterward
set -euo pipefail
print() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
error() {
print "ERROR: $*" >&2
exit 1
}
# Ensure running as root
if [[ $EUID -ne 0 ]]; then
error "This script must be run as root"
fi
# Configuration
BUILDKITE_AGENT_TOKEN="${BUILDKITE_AGENT_TOKEN:-}"
BUILDKITE_QUEUE="${BUILDKITE_QUEUE:-default}"
BUILDKITE_TAGS="${BUILDKITE_TAGS:-queue=$BUILDKITE_QUEUE,os=macos,arch=$(uname -m)}"
LOG_DIR="/usr/local/var/log/buildkite-agent"
AGENT_CONFIG_DIR="/usr/local/var/buildkite-agent"
# Ensure directories exist
mkdir -p "$LOG_DIR"
mkdir -p "$AGENT_CONFIG_DIR"
# Function to cleanup on exit
cleanup() {
local exit_code=$?
print "Job runner exiting with code $exit_code"
# Clean up current user if set
if [[ -n "${CURRENT_USER:-}" ]]; then
print "Cleaning up user: $CURRENT_USER"
/usr/local/bin/bun-ci/cleanup-build-user.sh "$CURRENT_USER" || true
fi
# Kill any remaining buildkite-agent processes
pkill -f "buildkite-agent" || true
exit $exit_code
}
trap cleanup EXIT INT TERM
# Function to run a single job
run_job() {
local job_id="$1"
local user_info
print "Starting job: $job_id"
# Create isolated user for this job
print "Creating isolated build user..."
user_info=$(/usr/local/bin/bun-ci/create-build-user.sh)
# Parse user info
export BK_USER=$(echo "$user_info" | grep "BK_USER=" | cut -d= -f2)
export BK_HOME=$(echo "$user_info" | grep "BK_HOME=" | cut -d= -f2)
export BK_WORKSPACE=$(echo "$user_info" | grep "BK_WORKSPACE=" | cut -d= -f2)
export BK_UID=$(echo "$user_info" | grep "BK_UID=" | cut -d= -f2)
CURRENT_USER="$BK_USER"
print "Job will run as user: $BK_USER"
print "Workspace: $BK_WORKSPACE"
# Create job-specific configuration
local job_config="${AGENT_CONFIG_DIR}/buildkite-agent-${job_id}.cfg"
cat > "$job_config" << EOF
token="${BUILDKITE_AGENT_TOKEN}"
name="macos-$(hostname)-${job_id}"
tags="${BUILDKITE_TAGS}"
build-path="${BK_WORKSPACE}"
hooks-path="/usr/local/bin/bun-ci/hooks"
plugins-path="${BK_HOME}/.buildkite-agent/plugins"
git-clean-flags="-fdq"
git-clone-flags="-v"
shell="/bin/bash -l"
spawn=1
priority=normal
disconnect-after-job=true
disconnect-after-idle-timeout=300
cancel-grace-period=10
enable-job-log-tmpfile=true
job-log-tmpfile-path="/tmp/buildkite-job-${job_id}.log"
timestamp-lines=true
EOF
# Set permissions
chown "$BK_USER:staff" "$job_config"
chmod 600 "$job_config"
# Start timeout monitor in background
(
sleep "${BUILDKITE_TIMEOUT:-3600}"
print "Job timeout reached, killing all processes for user $BK_USER"
pkill -TERM -u "$BK_USER" || true
sleep 10
pkill -KILL -u "$BK_USER" || true
) &
local timeout_pid=$!
# Run buildkite-agent as the isolated user
print "Starting Buildkite agent for job $job_id..."
local agent_exit_code=0
sudo -u "$BK_USER" -H /usr/local/bin/buildkite-agent start \
--config "$job_config" \
--log-level info \
--no-color \
2>&1 | tee -a "$LOG_DIR/job-${job_id}.log" || agent_exit_code=$?
# Kill timeout monitor
kill $timeout_pid 2>/dev/null || true
print "Job $job_id completed with exit code: $agent_exit_code"
# Clean up job-specific files
rm -f "$job_config"
rm -f "/tmp/buildkite-job-${job_id}.log"
# Clean up the user
print "Cleaning up user $BK_USER..."
/usr/local/bin/bun-ci/cleanup-build-user.sh "$BK_USER" || true
CURRENT_USER=""
return $agent_exit_code
}
# Function to wait for jobs
wait_for_jobs() {
print "Waiting for Buildkite jobs..."
# Check for required configuration
if [[ -z "$BUILDKITE_AGENT_TOKEN" ]]; then
error "BUILDKITE_AGENT_TOKEN is required"
fi
# Main loop to handle jobs
while true; do
# Generate unique job ID
local job_id=$(uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '-' | cut -c1-8)
print "Ready to accept job with ID: $job_id"
# Try to run a job
if ! run_job "$job_id"; then
print "Job $job_id failed, continuing..."
fi
# Brief pause before accepting next job
sleep 5
# Clean up any remaining processes
print "Performing system cleanup..."
pkill -f "buildkite-agent" || true
# Clean up temporary files
find /tmp -name "buildkite-*" -mtime +1 -delete 2>/dev/null || true
find /var/tmp -name "buildkite-*" -mtime +1 -delete 2>/dev/null || true
# Clean up any orphaned users (safety net)
for user in $(dscl . list /Users | grep "^bk-"); do
if [[ -n "$user" ]]; then
print "Cleaning up orphaned user: $user"
/usr/local/bin/bun-ci/cleanup-build-user.sh "$user" || true
fi
done
# Free up memory
sync
purge || true
print "System cleanup completed, ready for next job"
done
}
# Function to perform health checks
health_check() {
print "Performing health check..."
# Check disk space
local disk_usage=$(df -h / | awk 'NR==2 {print $5}' | sed 's/%//')
if [[ $disk_usage -gt 90 ]]; then
error "Disk usage is too high: ${disk_usage}%"
fi
# Check memory
local memory_pressure=$(memory_pressure | grep "System-wide memory free percentage" | awk '{print $5}' | sed 's/%//')
if [[ $memory_pressure -lt 10 ]]; then
error "Memory pressure is too high: ${memory_pressure}% free"
fi
# Check if Docker is running
if ! pgrep -x "Docker" > /dev/null; then
print "Docker is not running, attempting to start..."
open -a Docker || true
sleep 30
fi
# Check if required commands are available
local required_commands=("git" "node" "npm" "bun" "python3" "go" "rustc" "cargo" "cmake" "make")
for cmd in "${required_commands[@]}"; do
if ! command -v "$cmd" &>/dev/null; then
error "Required command not found: $cmd"
fi
done
print "Health check passed"
}
# Main execution
case "${1:-start}" in
start)
print "Starting Buildkite job runner for macOS"
health_check
wait_for_jobs
;;
health)
health_check
;;
cleanup)
print "Performing manual cleanup..."
# Clean up any existing users
for user in $(dscl . list /Users | grep "^bk-"); do
if [[ -n "$user" ]]; then
print "Cleaning up user: $user"
/usr/local/bin/bun-ci/cleanup-build-user.sh "$user" || true
fi
done
print "Manual cleanup completed"
;;
*)
error "Usage: $0 {start|health|cleanup}"
;;
esac

View File

@@ -0,0 +1,433 @@
terraform {
required_version = ">= 1.0"
required_providers {
macstadium = {
source = "macstadium/macstadium"
version = "~> 1.0"
}
}
backend "s3" {
bucket = "bun-terraform-state"
key = "macos-runners/terraform.tfstate"
region = "us-west-2"
}
}
provider "macstadium" {
api_key = var.macstadium_api_key
endpoint = var.macstadium_endpoint
}
# Variables
variable "macstadium_api_key" {
description = "MacStadium API key"
type = string
sensitive = true
}
variable "macstadium_endpoint" {
description = "MacStadium API endpoint"
type = string
default = "https://api.macstadium.com"
}
variable "buildkite_agent_token" {
description = "Buildkite agent token"
type = string
sensitive = true
}
variable "github_token" {
description = "GitHub token for accessing private repositories"
type = string
sensitive = true
}
variable "image_name_prefix" {
description = "Prefix for VM image names"
type = string
default = "bun-macos"
}
variable "fleet_size" {
description = "Number of VMs per macOS version"
type = object({
macos_13 = number
macos_14 = number
macos_15 = number
})
default = {
macos_13 = 4
macos_14 = 6
macos_15 = 8
}
}
variable "vm_configuration" {
description = "VM configuration settings"
type = object({
cpu_count = number
memory_gb = number
disk_size = number
})
default = {
cpu_count = 12
memory_gb = 32
disk_size = 500
}
}
# Data sources to get latest images
data "macstadium_image" "macos_13" {
name_regex = "^${var.image_name_prefix}-13-.*"
most_recent = true
}
data "macstadium_image" "macos_14" {
name_regex = "^${var.image_name_prefix}-14-.*"
most_recent = true
}
data "macstadium_image" "macos_15" {
name_regex = "^${var.image_name_prefix}-15-.*"
most_recent = true
}
# Local values
locals {
common_tags = {
Project = "bun-ci"
Environment = "production"
ManagedBy = "terraform"
Purpose = "buildkite-runners"
}
vm_configs = {
macos_13 = {
image_id = data.macstadium_image.macos_13.id
count = var.fleet_size.macos_13
version = "13"
}
macos_14 = {
image_id = data.macstadium_image.macos_14.id
count = var.fleet_size.macos_14
version = "14"
}
macos_15 = {
image_id = data.macstadium_image.macos_15.id
count = var.fleet_size.macos_15
version = "15"
}
}
}
# VM instances for each macOS version
resource "macstadium_vm" "runners" {
for_each = {
for vm_combo in flatten([
for version, config in local.vm_configs : [
for i in range(config.count) : {
key = "${version}-${i + 1}"
version = version
config = config
index = i + 1
}
]
]) : vm_combo.key => vm_combo
}
name = "bun-runner-${each.value.version}-${each.value.index}"
image_id = each.value.config.image_id
cpu_count = var.vm_configuration.cpu_count
memory_gb = var.vm_configuration.memory_gb
disk_size = var.vm_configuration.disk_size
# Network configuration
network_interface {
network_id = macstadium_network.runner_network.id
ip_address = cidrhost(macstadium_network.runner_network.cidr_block, 10 + index(keys(local.vm_configs), each.value.version) * 100 + each.value.index)
}
# Enable GPU passthrough for better performance
gpu_passthrough = true
# Enable VNC for debugging
vnc_enabled = true
# SSH configuration
ssh_keys = [macstadium_ssh_key.runner_key.id]
# Startup script
user_data = templatefile("${path.module}/user-data.sh", {
buildkite_agent_token = var.buildkite_agent_token
github_token = var.github_token
macos_version = each.value.version
vm_name = "bun-runner-${each.value.version}-${each.value.index}"
})
# Auto-start VM
auto_start = true
# Shutdown behavior
auto_shutdown = false
tags = merge(local.common_tags, {
Name = "bun-runner-${each.value.version}-${each.value.index}"
MacOSVersion = each.value.version
VmIndex = each.value.index
})
}
# Network configuration
resource "macstadium_network" "runner_network" {
name = "bun-runner-network"
cidr_block = "10.0.0.0/16"
tags = merge(local.common_tags, {
Name = "bun-runner-network"
})
}
# SSH key for VM access
resource "macstadium_ssh_key" "runner_key" {
name = "bun-runner-key"
public_key = file("${path.module}/ssh-keys/bun-runner.pub")
tags = merge(local.common_tags, {
Name = "bun-runner-key"
})
}
# Security group for runner VMs
resource "macstadium_security_group" "runner_sg" {
name = "bun-runner-sg"
description = "Security group for Bun CI runner VMs"
# SSH access
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# VNC access (for debugging)
ingress {
from_port = 5900
to_port = 5999
protocol = "tcp"
cidr_blocks = ["10.0.0.0/16"]
}
# HTTP/HTTPS outbound
egress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# Git (SSH)
egress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# DNS
egress {
from_port = 53
to_port = 53
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 53
to_port = 53
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(local.common_tags, {
Name = "bun-runner-sg"
})
}
# Load balancer for distributing jobs
resource "macstadium_load_balancer" "runner_lb" {
name = "bun-runner-lb"
load_balancer_type = "application"
# Health check configuration
health_check {
enabled = true
healthy_threshold = 2
unhealthy_threshold = 3
timeout = 5
interval = 30
path = "/health"
port = 8080
protocol = "HTTP"
}
# Target group for all runner VMs
target_group {
name = "bun-runners"
port = 8080
protocol = "HTTP"
targets = [
for vm in macstadium_vm.runners : {
id = vm.id
port = 8080
}
]
}
tags = merge(local.common_tags, {
Name = "bun-runner-lb"
})
}
# Auto-scaling configuration
resource "macstadium_autoscaling_group" "runner_asg" {
name = "bun-runner-asg"
min_size = 2
max_size = 20
desired_capacity = sum(values(var.fleet_size))
health_check_type = "ELB"
health_check_grace_period = 300
# Launch template reference
launch_template {
id = macstadium_launch_template.runner_template.id
version = "$Latest"
}
# Scaling policies
target_group_arns = [macstadium_load_balancer.runner_lb.target_group[0].arn]
tags = merge(local.common_tags, {
Name = "bun-runner-asg"
})
}
# Launch template for auto-scaling
resource "macstadium_launch_template" "runner_template" {
name = "bun-runner-template"
image_id = data.macstadium_image.macos_15.id
instance_type = "mac-mini-m2-pro"
key_name = macstadium_ssh_key.runner_key.name
security_group_ids = [macstadium_security_group.runner_sg.id]
user_data = base64encode(templatefile("${path.module}/user-data.sh", {
buildkite_agent_token = var.buildkite_agent_token
github_token = var.github_token
macos_version = "15"
vm_name = "bun-runner-asg-${timestamp()}"
}))
tags = merge(local.common_tags, {
Name = "bun-runner-template"
})
}
# CloudWatch alarms for scaling
resource "macstadium_cloudwatch_metric_alarm" "scale_up" {
alarm_name = "bun-runner-scale-up"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors ec2 cpu utilization"
alarm_actions = [macstadium_autoscaling_policy.scale_up.arn]
dimensions = {
AutoScalingGroupName = macstadium_autoscaling_group.runner_asg.name
}
}
resource "macstadium_cloudwatch_metric_alarm" "scale_down" {
alarm_name = "bun-runner-scale-down"
comparison_operator = "LessThanThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "20"
alarm_description = "This metric monitors ec2 cpu utilization"
alarm_actions = [macstadium_autoscaling_policy.scale_down.arn]
dimensions = {
AutoScalingGroupName = macstadium_autoscaling_group.runner_asg.name
}
}
# Scaling policies
resource "macstadium_autoscaling_policy" "scale_up" {
name = "bun-runner-scale-up"
scaling_adjustment = 2
adjustment_type = "ChangeInCapacity"
cooldown = 300
autoscaling_group_name = macstadium_autoscaling_group.runner_asg.name
}
resource "macstadium_autoscaling_policy" "scale_down" {
name = "bun-runner-scale-down"
scaling_adjustment = -1
adjustment_type = "ChangeInCapacity"
cooldown = 300
autoscaling_group_name = macstadium_autoscaling_group.runner_asg.name
}
# Outputs
output "vm_instances" {
description = "Details of created VM instances"
value = {
for key, vm in macstadium_vm.runners : key => {
id = vm.id
name = vm.name
ip_address = vm.network_interface[0].ip_address
image_id = vm.image_id
status = vm.status
}
}
}
output "load_balancer_dns" {
description = "DNS name of the load balancer"
value = macstadium_load_balancer.runner_lb.dns_name
}
output "network_id" {
description = "ID of the runner network"
value = macstadium_network.runner_network.id
}
output "security_group_id" {
description = "ID of the runner security group"
value = macstadium_security_group.runner_sg.id
}
output "autoscaling_group_name" {
description = "Name of the autoscaling group"
value = macstadium_autoscaling_group.runner_asg.name
}

View File

@@ -0,0 +1,245 @@
# VM instance outputs
output "vm_instances" {
description = "Details of all created VM instances"
value = {
for key, vm in macstadium_vm.runners : key => {
id = vm.id
name = vm.name
ip_address = vm.network_interface[0].ip_address
image_id = vm.image_id
status = vm.status
macos_version = regex("macos-([0-9]+)", key)[0]
instance_type = vm.instance_type
cpu_count = vm.cpu_count
memory_gb = vm.memory_gb
disk_size = vm.disk_size
created_at = vm.created_at
updated_at = vm.updated_at
}
}
}
output "vm_instances_by_version" {
description = "VM instances grouped by macOS version"
value = {
for version in ["13", "14", "15"] : "macos_${version}" => {
for key, vm in macstadium_vm.runners : key => {
id = vm.id
name = vm.name
ip_address = vm.network_interface[0].ip_address
status = vm.status
}
if can(regex("^${version}-", key))
}
}
}
# Network outputs
output "network_details" {
description = "Network configuration details"
value = {
network_id = macstadium_network.runner_network.id
cidr_block = macstadium_network.runner_network.cidr_block
name = macstadium_network.runner_network.name
status = macstadium_network.runner_network.status
}
}
output "security_group_details" {
description = "Security group configuration details"
value = {
security_group_id = macstadium_security_group.runner_sg.id
name = macstadium_security_group.runner_sg.name
description = macstadium_security_group.runner_sg.description
ingress_rules = macstadium_security_group.runner_sg.ingress
egress_rules = macstadium_security_group.runner_sg.egress
}
}
# Load balancer outputs
output "load_balancer_details" {
description = "Load balancer configuration details"
value = {
dns_name = macstadium_load_balancer.runner_lb.dns_name
zone_id = macstadium_load_balancer.runner_lb.zone_id
load_balancer_type = macstadium_load_balancer.runner_lb.load_balancer_type
target_group_arn = macstadium_load_balancer.runner_lb.target_group[0].arn
health_check = macstadium_load_balancer.runner_lb.health_check[0]
}
}
# Auto-scaling outputs
output "autoscaling_details" {
description = "Auto-scaling group configuration details"
value = {
asg_name = macstadium_autoscaling_group.runner_asg.name
min_size = macstadium_autoscaling_group.runner_asg.min_size
max_size = macstadium_autoscaling_group.runner_asg.max_size
desired_capacity = macstadium_autoscaling_group.runner_asg.desired_capacity
launch_template = macstadium_autoscaling_group.runner_asg.launch_template[0]
}
}
# SSH key outputs
output "ssh_key_details" {
description = "SSH key configuration details"
value = {
key_name = macstadium_ssh_key.runner_key.name
fingerprint = macstadium_ssh_key.runner_key.fingerprint
key_pair_id = macstadium_ssh_key.runner_key.id
}
}
# Image outputs
output "image_details" {
description = "Details of images used for VM creation"
value = {
macos_13 = {
id = data.macstadium_image.macos_13.id
name = data.macstadium_image.macos_13.name
description = data.macstadium_image.macos_13.description
created_date = data.macstadium_image.macos_13.creation_date
size = data.macstadium_image.macos_13.size
}
macos_14 = {
id = data.macstadium_image.macos_14.id
name = data.macstadium_image.macos_14.name
description = data.macstadium_image.macos_14.description
created_date = data.macstadium_image.macos_14.creation_date
size = data.macstadium_image.macos_14.size
}
macos_15 = {
id = data.macstadium_image.macos_15.id
name = data.macstadium_image.macos_15.name
description = data.macstadium_image.macos_15.description
created_date = data.macstadium_image.macos_15.creation_date
size = data.macstadium_image.macos_15.size
}
}
}
# Fleet statistics
output "fleet_statistics" {
description = "Statistics about the VM fleet"
value = {
total_vms = sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
])
vms_by_version = {
macos_13 = var.fleet_size.macos_13
macos_14 = var.fleet_size.macos_14
macos_15 = var.fleet_size.macos_15
}
total_cpu_cores = sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
]) * var.vm_configuration.cpu_count
total_memory_gb = sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
]) * var.vm_configuration.memory_gb
total_disk_gb = sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
]) * var.vm_configuration.disk_size
}
}
# Connection information
output "connection_info" {
description = "Information for connecting to the infrastructure"
value = {
ssh_command_template = "ssh -i ~/.ssh/bun-runner admin@{vm_ip_address}"
vnc_port_range = "5900-5999"
health_check_url = "http://{vm_ip_address}:8080/health"
buildkite_tags = "queue=macos,os=macos,arch=$(uname -m)"
}
}
# Resource ARNs and IDs
output "resource_arns" {
description = "ARNs and IDs of created resources"
value = {
vm_ids = [
for vm in macstadium_vm.runners : vm.id
]
network_id = macstadium_network.runner_network.id
security_group_id = macstadium_security_group.runner_sg.id
load_balancer_arn = macstadium_load_balancer.runner_lb.arn
autoscaling_group_arn = macstadium_autoscaling_group.runner_asg.arn
launch_template_id = macstadium_launch_template.runner_template.id
}
}
# Monitoring and alerting
output "monitoring_endpoints" {
description = "Monitoring and alerting endpoints"
value = {
cloudwatch_namespace = "BunCI/MacOSRunners"
alarm_arns = [
macstadium_cloudwatch_metric_alarm.scale_up.arn,
macstadium_cloudwatch_metric_alarm.scale_down.arn
]
scaling_policy_arns = [
macstadium_autoscaling_policy.scale_up.arn,
macstadium_autoscaling_policy.scale_down.arn
]
}
}
# Cost information
output "cost_information" {
description = "Cost-related information"
value = {
estimated_hourly_cost = format("$%.2f", sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
]) * 0.50) # Estimated cost per hour per VM
estimated_monthly_cost = format("$%.2f", sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
]) * 0.50 * 24 * 30) # Estimated monthly cost
cost_optimization_enabled = var.cost_optimization.enable_spot_instances
}
}
# Terraform state information
output "terraform_state" {
description = "Terraform state information"
value = {
workspace = terraform.workspace
terraform_version = "~> 1.0"
provider_versions = {
macstadium = "~> 1.0"
}
last_updated = timestamp()
}
}
# Summary output for easy reference
output "deployment_summary" {
description = "Summary of the deployment"
value = {
project_name = var.project_name
environment = var.environment
region = var.region
total_vms = sum([
var.fleet_size.macos_13,
var.fleet_size.macos_14,
var.fleet_size.macos_15
])
load_balancer_dns = macstadium_load_balancer.runner_lb.dns_name
autoscaling_enabled = var.autoscaling_enabled
backup_enabled = var.backup_config.enable_snapshots
monitoring_enabled = var.monitoring_config.enable_cloudwatch
deployment_time = timestamp()
status = "deployed"
}
}

View File

@@ -0,0 +1,266 @@
#!/bin/bash
# User data script for macOS VM initialization
# This script runs when the VM starts up
set -euo pipefail
# Variables passed from Terraform
BUILDKITE_AGENT_TOKEN="${buildkite_agent_token}"
GITHUB_TOKEN="${github_token}"
MACOS_VERSION="${macos_version}"
VM_NAME="${vm_name}"
# Logging
LOG_FILE="/var/log/vm-init.log"
exec 1> >(tee -a "$LOG_FILE")
exec 2> >(tee -a "$LOG_FILE" >&2)
print() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
print "Starting VM initialization for $VM_NAME (macOS $MACOS_VERSION)"
# Wait for system to be ready
print "Waiting for system to be ready..."
until ping -c1 google.com &>/dev/null; do
sleep 10
done
# Set timezone
print "Setting timezone to UTC..."
sudo systemsetup -settimezone UTC
# Configure hostname
print "Setting hostname to $VM_NAME..."
sudo scutil --set HostName "$VM_NAME"
sudo scutil --set LocalHostName "$VM_NAME"
sudo scutil --set ComputerName "$VM_NAME"
# Update system
print "Checking for system updates..."
sudo softwareupdate -i -a --no-scan || true
# Configure Buildkite agent
print "Configuring Buildkite agent..."
mkdir -p /usr/local/var/buildkite-agent
mkdir -p /usr/local/var/log/buildkite-agent
# Create Buildkite agent configuration
cat > /usr/local/var/buildkite-agent/buildkite-agent.cfg << EOF
token="$BUILDKITE_AGENT_TOKEN"
name="$VM_NAME"
tags="queue=macos,os=macos,arch=$(uname -m),version=$MACOS_VERSION,hostname=$VM_NAME"
build-path="/Users/buildkite/workspace"
hooks-path="/usr/local/bin/bun-ci/hooks"
plugins-path="/Users/buildkite/.buildkite-agent/plugins"
git-clean-flags="-fdq"
git-clone-flags="-v"
shell="/bin/bash -l"
spawn=1
priority=normal
disconnect-after-job=false
disconnect-after-idle-timeout=0
cancel-grace-period=10
enable-job-log-tmpfile=true
timestamp-lines=true
EOF
# Set up GitHub token for private repositories
print "Configuring GitHub access..."
if [[ -n "$GITHUB_TOKEN" ]]; then
# Configure git to use the token
git config --global url."https://oauth2:$GITHUB_TOKEN@github.com/".insteadOf "https://github.com/"
git config --global url."https://oauth2:$GITHUB_TOKEN@github.com/".insteadOf "git@github.com:"
# Configure npm to use the token
npm config set @oven-sh:registry https://npm.pkg.github.com/
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" >> ~/.npmrc
fi
# Set up SSH keys for GitHub (if available)
if [[ -f "/usr/local/etc/ssh/github_rsa" ]]; then
print "Configuring SSH keys for GitHub..."
mkdir -p ~/.ssh
cp /usr/local/etc/ssh/github_rsa ~/.ssh/
cp /usr/local/etc/ssh/github_rsa.pub ~/.ssh/
chmod 600 ~/.ssh/github_rsa
chmod 644 ~/.ssh/github_rsa.pub
# Configure SSH to use the key
cat > ~/.ssh/config << EOF
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
StrictHostKeyChecking no
EOF
fi
# Create health check endpoint
print "Setting up health check endpoint..."
cat > /usr/local/bin/health-check.sh << 'EOF'
#!/bin/bash
# Health check script for load balancer
set -euo pipefail
# Check if system is ready
if ! ping -c1 google.com &>/dev/null; then
echo "Network not ready"
exit 1
fi
# Check disk space
DISK_USAGE=$(df -h / | awk 'NR==2 {print $5}' | sed 's/%//')
if [[ $DISK_USAGE -gt 95 ]]; then
echo "Disk usage too high: ${DISK_USAGE}%"
exit 1
fi
# Check memory
MEMORY_PRESSURE=$(memory_pressure | grep "System-wide memory free percentage" | awk '{print $5}' | sed 's/%//')
if [[ $MEMORY_PRESSURE -lt 5 ]]; then
echo "Memory pressure too high: ${MEMORY_PRESSURE}% free"
exit 1
fi
# Check if required services are running
if ! pgrep -f "job-runner.sh" > /dev/null; then
echo "Job runner not running"
exit 1
fi
echo "OK"
exit 0
EOF
chmod +x /usr/local/bin/health-check.sh
# Start simple HTTP server for health checks
print "Starting health check server..."
cat > /usr/local/bin/health-server.sh << 'EOF'
#!/bin/bash
# Simple HTTP server for health checks
PORT=8080
while true; do
echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n$(/usr/local/bin/health-check.sh)" | nc -l -p $PORT
done
EOF
chmod +x /usr/local/bin/health-server.sh
# Create LaunchDaemon for health check server
cat > /Library/LaunchDaemons/com.bun.health-server.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.bun.health-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/health-server.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/var/log/health-server.log</string>
<key>StandardErrorPath</key>
<string>/var/log/health-server.error.log</string>
</dict>
</plist>
EOF
# Load and start the health check server
sudo launchctl load /Library/LaunchDaemons/com.bun.health-server.plist
sudo launchctl start com.bun.health-server
# Configure log rotation
print "Configuring log rotation..."
cat > /etc/newsyslog.d/bun-ci.conf << 'EOF'
# Log rotation for Bun CI
/usr/local/var/log/buildkite-agent/*.log 644 5 1000 * GZ
/var/log/vm-init.log 644 5 1000 * GZ
/var/log/health-server.log 644 5 1000 * GZ
/var/log/health-server.error.log 644 5 1000 * GZ
EOF
# Restart syslog to pick up new configuration
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
# Configure system monitoring
print "Setting up system monitoring..."
cat > /usr/local/bin/system-monitor.sh << 'EOF'
#!/bin/bash
# System monitoring script
LOG_FILE="/var/log/system-monitor.log"
while true; do
echo "[$(date '+%Y-%m-%d %H:%M:%S')] System Stats:" >> "$LOG_FILE"
echo " CPU: $(top -l 1 -n 0 | grep "CPU usage" | awk '{print $3}' | sed 's/%//')" >> "$LOG_FILE"
echo " Memory: $(memory_pressure | grep "System-wide memory free percentage" | awk '{print $5}')" >> "$LOG_FILE"
echo " Disk: $(df -h / | awk 'NR==2 {print $5}')" >> "$LOG_FILE"
echo " Load: $(uptime | awk -F'load averages:' '{print $2}')" >> "$LOG_FILE"
echo " Processes: $(ps aux | wc -l)" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
sleep 300 # 5 minutes
done
EOF
chmod +x /usr/local/bin/system-monitor.sh
# Create LaunchDaemon for system monitoring
cat > /Library/LaunchDaemons/com.bun.system-monitor.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.bun.system-monitor</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/system-monitor.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
# Load and start the system monitor
sudo launchctl load /Library/LaunchDaemons/com.bun.system-monitor.plist
sudo launchctl start com.bun.system-monitor
# Final configuration
print "Performing final configuration..."
# Ensure all services are running
sudo launchctl load /Library/LaunchDaemons/com.buildkite.buildkite-agent.plist
sudo launchctl start com.buildkite.buildkite-agent
# Create marker file to indicate initialization is complete
touch /var/tmp/vm-init-complete
echo "$(date '+%Y-%m-%d %H:%M:%S'): VM initialization completed" >> /var/tmp/vm-init-complete
print "VM initialization completed successfully!"
print "VM Name: $VM_NAME"
print "macOS Version: $MACOS_VERSION"
print "Status: Ready for Buildkite jobs"
# Log final system state
print "Final system state:"
print " Hostname: $(hostname)"
print " Uptime: $(uptime)"
print " Disk usage: $(df -h / | awk 'NR==2 {print $5}')"
print " Memory: $(memory_pressure | grep "System-wide memory free percentage" | awk '{print $5}')"
print "Health check available at: http://$(hostname):8080/health"

View File

@@ -0,0 +1,302 @@
# Core infrastructure variables
variable "project_name" {
description = "Name of the project"
type = string
default = "bun-ci"
}
variable "environment" {
description = "Environment name"
type = string
default = "production"
}
variable "region" {
description = "MacStadium region"
type = string
default = "us-west-1"
}
# MacStadium configuration
variable "macstadium_api_key" {
description = "MacStadium API key"
type = string
sensitive = true
}
variable "macstadium_endpoint" {
description = "MacStadium API endpoint"
type = string
default = "https://api.macstadium.com"
}
# Buildkite configuration
variable "buildkite_agent_token" {
description = "Buildkite agent token"
type = string
sensitive = true
}
variable "buildkite_org" {
description = "Buildkite organization slug"
type = string
default = "bun"
}
variable "buildkite_queues" {
description = "Buildkite queues to register agents with"
type = list(string)
default = ["macos", "macos-arm64", "macos-x86_64"]
}
# GitHub configuration
variable "github_token" {
description = "GitHub token for accessing private repositories"
type = string
sensitive = true
}
variable "github_org" {
description = "GitHub organization"
type = string
default = "oven-sh"
}
# VM fleet configuration
variable "fleet_size" {
description = "Number of VMs per macOS version"
type = object({
macos_13 = number
macos_14 = number
macos_15 = number
})
default = {
macos_13 = 4
macos_14 = 6
macos_15 = 8
}
validation {
condition = alltrue([
var.fleet_size.macos_13 >= 0,
var.fleet_size.macos_14 >= 0,
var.fleet_size.macos_15 >= 0,
var.fleet_size.macos_13 + var.fleet_size.macos_14 + var.fleet_size.macos_15 > 0
])
error_message = "Fleet sizes must be non-negative and at least one version must have VMs."
}
}
variable "vm_configuration" {
description = "VM configuration settings"
type = object({
cpu_count = number
memory_gb = number
disk_size = number
})
default = {
cpu_count = 12
memory_gb = 32
disk_size = 500
}
validation {
condition = alltrue([
var.vm_configuration.cpu_count >= 4,
var.vm_configuration.memory_gb >= 16,
var.vm_configuration.disk_size >= 100
])
error_message = "VM configuration must have at least 4 CPUs, 16GB memory, and 100GB disk."
}
}
# Auto-scaling configuration
variable "autoscaling_enabled" {
description = "Enable auto-scaling for VM fleet"
type = bool
default = true
}
variable "autoscaling_config" {
description = "Auto-scaling configuration"
type = object({
min_size = number
max_size = number
desired_capacity = number
scale_up_threshold = number
scale_down_threshold = number
scale_up_adjustment = number
scale_down_adjustment = number
cooldown_period = number
})
default = {
min_size = 2
max_size = 30
desired_capacity = 10
scale_up_threshold = 80
scale_down_threshold = 20
scale_up_adjustment = 2
scale_down_adjustment = 1
cooldown_period = 300
}
}
# Image configuration
variable "image_name_prefix" {
description = "Prefix for VM image names"
type = string
default = "bun-macos"
}
variable "image_rebuild_schedule" {
description = "Cron schedule for rebuilding images"
type = string
default = "0 2 * * *" # Daily at 2 AM
}
variable "image_retention_days" {
description = "Number of days to retain old images"
type = number
default = 7
}
# Network configuration
variable "network_config" {
description = "Network configuration"
type = object({
cidr_block = string
enable_nat = bool
enable_vpn = bool
allowed_cidrs = list(string)
})
default = {
cidr_block = "10.0.0.0/16"
enable_nat = true
enable_vpn = false
allowed_cidrs = ["0.0.0.0/0"]
}
}
# Security configuration
variable "security_config" {
description = "Security configuration"
type = object({
enable_ssh_access = bool
enable_vnc_access = bool
ssh_allowed_cidrs = list(string)
vnc_allowed_cidrs = list(string)
enable_disk_encryption = bool
})
default = {
enable_ssh_access = true
enable_vnc_access = true
ssh_allowed_cidrs = ["0.0.0.0/0"]
vnc_allowed_cidrs = ["10.0.0.0/16"]
enable_disk_encryption = true
}
}
# Monitoring configuration
variable "monitoring_config" {
description = "Monitoring configuration"
type = object({
enable_cloudwatch = bool
enable_custom_metrics = bool
log_retention_days = number
alert_email = string
})
default = {
enable_cloudwatch = true
enable_custom_metrics = true
log_retention_days = 30
alert_email = "devops@oven.sh"
}
}
# Backup configuration
variable "backup_config" {
description = "Backup configuration"
type = object({
enable_snapshots = bool
snapshot_schedule = string
snapshot_retention = number
enable_cross_region = bool
})
default = {
enable_snapshots = true
snapshot_schedule = "0 4 * * *" # Daily at 4 AM
snapshot_retention = 7
enable_cross_region = false
}
}
# Cost optimization
variable "cost_optimization" {
description = "Cost optimization settings"
type = object({
enable_spot_instances = bool
spot_price_max = number
enable_hibernation = bool
idle_shutdown_timeout = number
})
default = {
enable_spot_instances = false
spot_price_max = 0.0
enable_hibernation = false
idle_shutdown_timeout = 3600 # 1 hour
}
}
# Maintenance configuration
variable "maintenance_config" {
description = "Maintenance configuration"
type = object({
maintenance_window_start = string
maintenance_window_end = string
auto_update_enabled = bool
patch_schedule = string
})
default = {
maintenance_window_start = "02:00"
maintenance_window_end = "06:00"
auto_update_enabled = true
patch_schedule = "0 3 * * 0" # Weekly on Sunday at 3 AM
}
}
# Tagging
variable "tags" {
description = "Additional tags to apply to resources"
type = map(string)
default = {}
}
# SSH key configuration
variable "ssh_key_name" {
description = "Name of the SSH key pair"
type = string
default = "bun-runner-key"
}
variable "ssh_public_key_path" {
description = "Path to the SSH public key file"
type = string
default = "~/.ssh/id_rsa.pub"
}
# Feature flags
variable "feature_flags" {
description = "Feature flags for experimental features"
type = object({
enable_gpu_passthrough = bool
enable_nested_virt = bool
enable_secure_boot = bool
enable_tpm = bool
})
default = {
enable_gpu_passthrough = true
enable_nested_virt = false
enable_secure_boot = false
enable_tpm = false
}
}

View File

@@ -0,0 +1,92 @@
# Upgrading Bun's Self-Reported Node.js Version
This guide explains how to upgrade the Node.js version that Bun reports for compatibility with Node.js packages and native addons.
## Overview
Bun reports a Node.js version for compatibility with the Node.js ecosystem. This affects:
- `process.version` output
- Node-API (N-API) compatibility
- Native addon ABI compatibility
- V8 API compatibility for addons using V8 directly
## Files That Always Need Updates
### 1. Bootstrap Scripts
- `scripts/bootstrap.sh` - Update `NODEJS_VERSION=`
- `scripts/bootstrap.ps1` - Update `$NODEJS_VERSION =`
### 2. CMake Configuration
- `cmake/Options.cmake`
- `NODEJS_VERSION` - The Node.js version string (e.g., "24.3.0")
- `NODEJS_ABI_VERSION` - The ABI version number (find using command below)
### 3. Version Strings
- `src/bun.js/bindings/BunProcess.cpp`
- Update `Bun__versions_node` with the Node.js version
- Update `Bun__versions_v8` with the V8 version (find using command below)
### 4. N-API Version
- `src/napi/js_native_api.h`
- Update `NAPI_VERSION` define (check Node.js release notes)
## 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)
- Test files (if Node.js requires newer C++ standard)
## Quick Commands to Find Version Info
```bash
# Get latest Node.js version info
curl -s https://nodejs.org/dist/index.json | jq '.[0]'
# Get V8 version for a specific Node.js version (replace v24.3.0)
curl -s https://nodejs.org/dist/v24.3.0/node-v24.3.0-headers.tar.gz | tar -xzO node-v24.3.0/include/node/node_version.h | grep V8_VERSION
# Get ABI version for a specific Node.js version
curl -s https://nodejs.org/dist/v24.3.0/node-v24.3.0-headers.tar.gz | tar -xzO node-v24.3.0/include/node/node_version.h | grep NODE_MODULE_VERSION
# Or use the ABI registry
curl -s https://raw.githubusercontent.com/nodejs/node/main/doc/abi_version_registry.json | jq '.NODE_MODULE_VERSION."<version>"'
```
## Update Process
1. **Gather version info** using the commands above
2. **Update the required files** listed in the sections above
3. **Build and test**:
```bash
bun bd
bun bd -e "console.log(process.version)"
bun bd -e "console.log(process.versions.v8)"
bun bd test test/v8/v8.test.ts
bun bd test test/napi/napi.test.ts
```
4. **Check for V8 API changes** only if build fails or tests crash:
- Compare v8-function-callback.h between versions
- Check v8-internal.h for Isolate size changes
- Look for new required APIs in build errors
## If Build Fails or Tests Crash
The V8 API rarely has breaking changes between minor Node.js versions. If you encounter issues:
1. Check build errors for missing symbols or type mismatches
2. Compare V8 headers between old and new Node.js versions
3. Most issues can be resolved by implementing missing functions or adjusting structures
## Testing Checklist
- [ ] `process.version` returns correct version
- [ ] `process.versions.v8` returns correct V8 version
- [ ] `process.config.variables.node_module_version` returns correct ABI
- [ ] V8 tests pass
- [ ] N-API tests pass
## Notes
- Most upgrades only require updating version numbers
- Major V8 version changes (rare) may require API updates
- The V8 shim implements only APIs used by common native addons

View File

@@ -0,0 +1,23 @@
Upgrade Bun's Webkit fork to the latest upstream version of Webkit.
To do that:
- cd vendor/WebKit
- git fetch upstream
- git merge upstream main
- Fix the merge conflicts
- cd ../../ (back to bun)
- make jsc-build (this will take about 7 minutes)
- While it compiles, in another task review the JSC commits between the last version of Webkit and the new version. Write up a summary of the webkit changes in a file called "webkit-changes.md"
- bun run build:local (build a build of Bun with the new Webkit, make sure it compiles)
- After making sure it compiles, run some code to make sure things work. something like ./build/debug-local/bun-debug --print '42' should be all you need
- cd vendor/WebKit
- git commit -am "Upgrade Webkit to the latest version"
- git push
- get the commit SHA in the vendor/WebKit directory of your new commit
- cd ../../ (back to bun)
- Update WEBKIT_VERSION in cmake/tools/SetupWebKit.cmake to the commit SHA of your new commit
- git checkout -b bun/webkit-upgrade-<commit-sha>
- commit + push (without adding the webkit-changes.md file)
- create PR titled "Upgrade Webkit to the <commit-sha>", paste your webkit-changes.md into the PR description
- delete the webkit-changes.md file

View File

@@ -1,3 +1,10 @@
{
"terminals": []
"snapshot": "snapshot-20250706-71021aff-cc0d-4a7f-a468-d443b16c4bf1",
"install": "bun install",
"terminals": [
{
"name": "bun build",
"command": "bun run build"
}
]
}

View File

@@ -1,13 +1,41 @@
---
description: How to build Bun
globs:
description:
globs: src/**/*.cpp,src/**/*.zig
alwaysApply: false
---
# How to build Bun
### Build Commands
Run:
- **Build debug version**: `bun bd` or `bun run build:debug`
- Creates a debug build at `./build/debug/bun-debug`
- Compilation takes ~2.5 minutes
- **Run tests with your debug build**: `bun bd test <test-file>`
- **CRITICAL**: Never use `bun test` directly - it won't include your changes
- **Run any command with debug build**: `bun bd <command>`
```bash
bun bd
### Run a file
To run a file, use:
```sh
bun bd <file> <...args>
```
**CRITICAL**: Never use `bun <file>` directly. It will not have your changes.
### Logging
`BUN_DEBUG_$(SCOPE)=1` enables debug logs for a specific debug log scope.
Debug logs look like this:
```zig
const log = bun.Output.scoped(.${SCOPE}, false);
// ...later
log("MY DEBUG LOG", .{})
```
### Code Generation
Code generation happens automatically as part of the build process. There are no commands to run.

View File

@@ -91,7 +91,7 @@ devTest("html file is watched", {
`files` holds the initial state, and the callback runs with the server running. `dev.fetch()` runs HTTP requests, while `dev.client()` opens a browser instance to the code.
Functions `dev.write` and `dev.patch` and `dev.delete` mutate the filesystem. Do not use `node:fs` APIs, as the dev server ones are hooked to wait for hot-reload, and all connected clients to recieve changes.
Functions `dev.write` and `dev.patch` and `dev.delete` mutate the filesystem. Do not use `node:fs` APIs, as the dev server ones are hooked to wait for hot-reload, and all connected clients to receive changes.
When a change performs a hard-reload, that must be explicitly annotated with `expectReload`. This tells `client-fixture.mjs` that the test is meant to reload the page once; All other hard reloads automatically fail the test.

View File

@@ -360,9 +360,8 @@ JSC_DEFINE_HOST_FUNCTION(x509CertificateConstructorConstruct, (JSGlobalObject *
auto* functionGlobalObject = defaultGlobalObject(getFunctionRealm(globalObject, newTarget.getObject()));
RETURN_IF_EXCEPTION(scope, {});
structure = InternalFunction::createSubclassStructure(
globalObject, newTarget.getObject(), functionGlobalObject->NodeVMScriptStructure());
scope.release();
structure = InternalFunction::createSubclassStructure(globalObject, newTarget.getObject(), functionGlobalObject->NodeVMScriptStructure());
RETURN_IF_EXCEPTION(scope, {});
}
return JSValue::encode(createX509Certificate(vm, globalObject, structure, arg));

View File

@@ -11,10 +11,10 @@ You'll find all of Bun's tests in the `test/` directory.
* `test/`
* `cli/` - CLI command tests, like `bun install` or `bun init`
* `js/` - JavaScript & TypeScript tests
* `bun/` - `Bun` APIs tests, seperated by category, for example: `glob/` for `Bun.Glob` tests
* `node/` - Node.js module tests, seperated by module, for example: `assert/` for `node:assert` tests
* `bun/` - `Bun` APIs tests, separated by category, for example: `glob/` for `Bun.Glob` tests
* `node/` - Node.js module tests, separated by module, for example: `assert/` for `node:assert` tests
* `test/` - Vendored Node.js tests, taken from the Node.js repository (does not conform to Bun's test style)
* `web/` - Web API tests, seperated by category, for example: `fetch/` for `Request` and `Response` tests
* `web/` - Web API tests, separated by category, for example: `fetch/` for `Request` and `Response` tests
* `third_party/` - npm package tests, to validate that basic usage works in Bun
* `napi/` - N-API tests
* `v8/` - V8 C++ API tests

View File

@@ -1,8 +1,9 @@
---
description: How Zig works with JavaScriptCore bindings generator
globs:
globs:
alwaysApply: false
---
# Bun's JavaScriptCore Class Bindings Generator
This document explains how Bun's class bindings generator works to bridge Zig and JavaScript code through JavaScriptCore (JSC).
@@ -24,7 +25,7 @@ The `.classes.ts` files define the JavaScript API using a declarative approach:
```typescript
// Example: encoding.classes.ts
define({
name: "TextDecoder",
name: "TextDecoder",
constructor: true,
JSType: "object",
finalize: true,
@@ -40,17 +41,18 @@ define({
},
fatal: {
// Read-only property
getter: true,
getter: true,
},
ignoreBOM: {
// Read-only property
getter: true,
}
}
},
},
});
```
Each class definition specifies:
- The class name
- Whether it has a constructor
- JavaScript type (object, function, etc.)
@@ -87,7 +89,7 @@ pub const TextDecoder = struct {
// Fields
});
}
// Prototype methods - note return type includes JSError
pub fn decode(
this: *TextDecoder,
@@ -96,23 +98,23 @@ pub const TextDecoder = struct {
) bun.JSError!JSC.JSValue {
// Implementation
}
// Getters
pub fn getEncoding(this: *TextDecoder, globalObject: *JSGlobalObject) JSC.JSValue {
return JSC.JSValue.createStringFromUTF8(globalObject, this.encoding);
}
pub fn getFatal(this: *TextDecoder, globalObject: *JSGlobalObject) JSC.JSValue {
return JSC.JSValue.jsBoolean(this.fatal);
}
// Cleanup - note standard pattern of using deinit/deref
fn deinit(this: *TextDecoder) void {
// Release any retained resources
// Free the pointer at the end.
bun.destroy(this);
}
// Finalize - called by JS garbage collector. This should call deinit, or deref if reference counted.
pub fn finalize(this: *TextDecoder) void {
this.deinit();
@@ -121,6 +123,7 @@ pub const TextDecoder = struct {
```
Key components in the Zig file:
- The struct containing native state
- `pub const js = JSC.Codegen.JS<ClassName>` to include generated code
- Constructor and methods using `bun.JSError!JSValue` return type for proper error handling
@@ -128,6 +131,7 @@ Key components in the Zig file:
- Methods matching the JavaScript interface
- Getters/setters for properties
- Proper resource cleanup pattern with `deinit()` and `finalize()`
- Update `src/bun.js/bindings/generated_classes_list.zig` to include the new class
## Code Generation System
@@ -140,6 +144,7 @@ The binding generator produces C++ code that connects JavaScript and Zig:
5. **Property Caching**: Implements the caching system for properties
The generated C++ code includes:
- A JSC wrapper class (`JSTextDecoder`)
- A prototype class (`JSTextDecoderPrototype`)
- A constructor function (`JSTextDecoderConstructor`)
@@ -152,28 +157,29 @@ The `CallFrame` object provides access to JavaScript execution context:
```zig
pub fn decode(
this: *TextDecoder,
this: *TextDecoder,
globalObject: *JSGlobalObject,
callFrame: *JSC.CallFrame
) bun.JSError!JSC.JSValue {
// Get arguments
const input = callFrame.argument(0);
const options = callFrame.argument(1);
// Get this value
const thisValue = callFrame.thisValue();
// Implementation with error handling
if (input.isUndefinedOrNull()) {
return globalObject.throw("Input cannot be null or undefined", .{});
}
// Return value or throw error
return JSC.JSValue.jsString(globalObject, "result");
}
```
CallFrame methods include:
- `argument(i)`: Get the i-th argument
- `argumentCount()`: Get the number of arguments
- `thisValue()`: Get the `this` value
@@ -201,17 +207,17 @@ JSC_DEFINE_CUSTOM_GETTER(TextDecoderPrototype__encodingGetterWrap, (...)) {
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSTextDecoder* thisObject = jsCast<JSTextDecoder*>(JSValue::decode(encodedThisValue));
JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
// Check for cached value and return if present
if (JSValue cachedValue = thisObject->m_encoding.get())
return JSValue::encode(cachedValue);
// Get value from Zig implementation
JSC::JSValue result = JSC::JSValue::decode(
TextDecoderPrototype__getEncoding(thisObject->wrapped(), globalObject)
);
RETURN_IF_EXCEPTION(throwScope, {});
// Store in cache for future access
thisObject->m_encoding.set(vm, thisObject, result);
RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
@@ -253,7 +259,7 @@ This system provides several key benefits:
1. **Automatic Memory Management**: The JavaScriptCore GC tracks and manages these values
2. **Proper Garbage Collection**: The WriteBarrier ensures values are properly visited during GC
3. **Consistent Access**: Zig code can easily get/set these cached JS values
4. **Performance**: Cached values avoid repeated computation or serialization
4. **Performance**: Cached values avoid repeated computation or serialization
### Use Cases
@@ -281,7 +287,7 @@ Bun uses a consistent pattern for resource cleanup:
pub fn deinit(this: *TextDecoder) void {
// Release resources like strings
this._encoding.deref(); // String deref pattern
// Free any buffers
if (this.buffer) |buffer| {
bun.default_allocator.free(buffer);
@@ -312,7 +318,7 @@ Bun uses `bun.JSError!JSValue` return type for proper error handling:
```zig
pub fn decode(
this: *TextDecoder,
this: *TextDecoder,
globalObject: *JSGlobalObject,
callFrame: *JSC.CallFrame
) bun.JSError!JSC.JSValue {
@@ -320,13 +326,14 @@ pub fn decode(
if (callFrame.argumentCount() < 1) {
return globalObject.throw("Missing required argument", .{});
}
// Or returning a success value
return JSC.JSValue.jsString(globalObject, "Success!");
}
```
This pattern allows Zig functions to:
1. Return JavaScript values on success
2. Throw JavaScript exceptions on error
3. Propagate errors automatically through the call stack
@@ -339,7 +346,7 @@ The binding system includes robust error handling:
// Example of type checking in generated code
JSTextDecoder* thisObject = jsDynamicCast<JSTextDecoder*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.throwException(lexicalGlobalObject,
scope.throwException(lexicalGlobalObject,
Bun::createInvalidThisError(lexicalGlobalObject, callFrame->thisValue(), "TextDecoder"_s));
return {};
}
@@ -351,7 +358,7 @@ The binding system creates proper JavaScript prototype chains:
1. **Constructor**: JSTextDecoderConstructor with standard .prototype property
2. **Prototype**: JSTextDecoderPrototype with methods and properties
3. **Instances**: Each JSTextDecoder instance with __proto__ pointing to prototype
3. **Instances**: Each JSTextDecoder instance with **proto** pointing to prototype
This ensures JavaScript inheritance works as expected:
@@ -360,7 +367,7 @@ This ensures JavaScript inheritance works as expected:
void JSTextDecoderConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSTextDecoderPrototype* prototype)
{
Base::finishCreation(vm, 0, "TextDecoder"_s, PropertyAdditionMode::WithoutStructureTransition);
// Set up the prototype chain
putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
ASSERT(inherits(info()));
@@ -372,7 +379,7 @@ void JSTextDecoderConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globa
The binding system is optimized for performance:
1. **Direct Pointer Access**: JavaScript objects maintain a direct pointer to Zig objects
2. **Property Caching**: WriteBarrier caching avoids repeated native calls for stable properties
2. **Property Caching**: WriteBarrier caching avoids repeated native calls for stable properties
3. **Memory Management**: JSC garbage collection integrated with Zig memory management
4. **Type Conversion**: Fast paths for common JavaScript/Zig type conversions
@@ -381,6 +388,7 @@ The binding system is optimized for performance:
To create a new class binding in Bun:
1. **Define the class interface** in a `.classes.ts` file:
```typescript
define({
name: "MyClass",
@@ -393,12 +401,13 @@ To create a new class binding in Bun:
myProperty: {
getter: true,
cache: true,
}
}
},
},
});
```
2. **Implement the native functionality** in a `.zig` file:
```zig
pub const MyClass = struct {
// Generated bindings
@@ -409,9 +418,9 @@ To create a new class binding in Bun:
// State
value: []const u8,
pub const new = bun.TrivialNew(@This());
// Constructor
pub fn constructor(
globalObject: *JSGlobalObject,
@@ -420,7 +429,7 @@ To create a new class binding in Bun:
const arg = callFrame.argument(0);
// Implementation
}
// Method
pub fn myMethod(
this: *MyClass,
@@ -429,17 +438,17 @@ To create a new class binding in Bun:
) bun.JSError!JSC.JSValue {
// Implementation
}
// Getter
pub fn getMyProperty(this: *MyClass, globalObject: *JSGlobalObject) JSC.JSValue {
return JSC.JSValue.jsString(globalObject, this.value);
}
// Resource cleanup
pub fn deinit(this: *MyClass) void {
// Clean up resources
}
pub fn finalize(this: *MyClass) void {
this.deinit();
bun.destroy(this);
@@ -474,11 +483,13 @@ For each Zig class, the system generates:
### 3. Zig Bindings
- **External Function Declarations**:
```zig
extern fn TextDecoderPrototype__decode(*TextDecoder, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(JSC.conv) JSC.EncodedJSValue;
```
- **Cached Value Accessors**:
```zig
pub fn encodingGetCached(thisValue: JSC.JSValue) ?JSC.JSValue { ... }
pub fn encodingSetCached(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void { ... }

View File

@@ -5,4 +5,6 @@
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs
#
4ec410e0d7c5f6a712c323444edbf56b48d432d8 # make @import("bun") work in zig (#19096)
4ec410e0d7c5f6a712c323444edbf56b48d432d8 # make @import("bun") work in zig (#19096)
dedd433cbf2e2fe38e51bc166e08fbcc601ad42b # JSValue.undefined -> .jsUndefined()
6b4662ff55f58247cc2fd22e85b4f9805b0950a5 # JSValue.jsUndefined() -> .js_undefined

13
.github/CODEOWNERS vendored
View File

@@ -1,18 +1,5 @@
# Project
/.github/CODEOWNERS @Jarred-Sumner
# Build system
/CMakeLists.txt @Electroid
/cmake/*.cmake @Electroid
/scripts/ @Electroid
# CI
/.buildkite/ @Electroid
/.github/workflows/ @Electroid
# Debugger protocol
/packages/bun-inspector-protocol/ @Electroid
/packages/bun-debug-adapter-protocol/ @Electroid
# Tests
/test/expectations.txt @Jarred-Sumner

View File

@@ -12,7 +12,7 @@ body:
If you need help or support using Bun, and are not reporting a bug, please
join our [Discord](https://discord.gg/CXdq2DP29u) server, where you can ask questions in the [`#help`](https://discord.gg/32EtH6p7HN) forum.
Make sure you are running the [latest](https://bun.sh/docs/installation#upgrading) version of Bun.
Make sure you are running the [latest](https://bun.com/docs/installation#upgrading) version of Bun.
The bug you are experiencing may already have been fixed.
Please try to include as much information as possible.

View File

@@ -2,44 +2,44 @@ name: 🇹 TypeScript Type Bug Report
description: Report an issue with TypeScript types
labels: [bug, types]
body:
- type: markdown
attributes:
value: |
Thank you for submitting a bug report. It helps make Bun better.
- type: markdown
attributes:
value: |
Thank you for submitting a bug report. It helps make Bun better.
If you need help or support using Bun, and are not reporting a bug, please
join our [Discord](https://discord.gg/CXdq2DP29u) server, where you can ask questions in the [`#help`](https://discord.gg/32EtH6p7HN) forum.
If you need help or support using Bun, and are not reporting a bug, please
join our [Discord](https://discord.gg/CXdq2DP29u) server, where you can ask questions in the [`#help`](https://discord.gg/32EtH6p7HN) forum.
Make sure you are running the [latest](https://bun.sh/docs/installation#upgrading) version of Bun.
The bug you are experiencing may already have been fixed.
Make sure you are running the [latest](https://bun.com/docs/installation#upgrading) version of Bun.
The bug you are experiencing may already have been fixed.
Please try to include as much information as possible.
Please try to include as much information as possible.
- type: input
attributes:
label: What version of Bun is running?
description: Copy the output of `bun --revision`
- type: input
attributes:
label: What platform is your computer?
description: |
For MacOS and Linux: copy the output of `uname -mprs`
For Windows: copy the output of `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` in the PowerShell console
- type: textarea
attributes:
label: What steps can reproduce the bug?
description: Explain the bug and provide a code snippet that can reproduce it.
validations:
required: true
- type: textarea
attributes:
label: What is the expected behavior?
description: If possible, please provide text instead of a screenshot.
- type: textarea
attributes:
label: What do you see instead?
description: If possible, please provide text instead of a screenshot.
- type: textarea
attributes:
label: Additional information
description: Is there anything else you think we should know?
- type: input
attributes:
label: What version of Bun is running?
description: Copy the output of `bun --revision`
- type: input
attributes:
label: What platform is your computer?
description: |
For MacOS and Linux: copy the output of `uname -mprs`
For Windows: copy the output of `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` in the PowerShell console
- type: textarea
attributes:
label: What steps can reproduce the bug?
description: Explain the bug and provide a code snippet that can reproduce it.
validations:
required: true
- type: textarea
attributes:
label: What is the expected behavior?
description: If possible, please provide text instead of a screenshot.
- type: textarea
attributes:
label: What do you see instead?
description: If possible, please provide text instead of a screenshot.
- type: textarea
attributes:
label: Additional information
description: Is there anything else you think we should know?

View File

@@ -2,6 +2,7 @@ name: Prefilled crash report
description: Report a crash in Bun
labels:
- crash
- needs triage
body:
- type: markdown
attributes:

58
.github/workflows/codex-test-sync.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
name: Codex Test Sync
on:
pull_request:
types: [labeled, opened]
env:
BUN_VERSION: "1.2.15"
jobs:
sync-node-tests:
runs-on: ubuntu-latest
if: |
(github.event.action == 'labeled' && github.event.label.name == 'codex') ||
(github.event.action == 'opened' && contains(github.event.pull_request.labels.*.name, 'codex')) ||
contains(github.head_ref, 'codex')
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
test/js/node/test/parallel/**/*.{js,mjs,ts}
test/js/node/test/sequential/**/*.{js,mjs,ts}
- name: Sync tests
if: steps.changed-files.outputs.any_changed == 'true'
shell: bash
run: |
echo "Changed test files:"
echo "${{ steps.changed-files.outputs.all_changed_files }}"
# Process each changed test file
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
# Extract test name from file path
test_name=$(basename "$file" | sed 's/\.[^.]*$//')
echo "Syncing test: $test_name"
bun node:test:cp "$test_name"
done
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Sync Node.js tests with upstream"

View File

@@ -1,28 +1,30 @@
name: format
name: autofix.ci
permissions:
contents: write
contents: read
on:
workflow_call:
workflow_dispatch:
pull_request:
merge_group:
push:
branches: ["main"]
env:
BUN_VERSION: "1.2.11"
LLVM_VERSION: "19.1.7"
LLVM_VERSION_MAJOR: "19"
jobs:
format:
autofix:
name: Format
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global core.autocrlf true
@@ -45,22 +47,13 @@ jobs:
- name: Zig Format
run: |
bun scripts/zig-remove-unreferenced-top-level-decls.ts src/
zig fmt src/**.zig
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run zig-format`"
zig fmt src
bun scripts/sortImports src
zig fmt src
- name: Prettier Format
run: |
bun run prettier
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run prettier`"
- name: Clang Format
run: |
bun run clang-format
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run clang-format`"
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27

View File

@@ -202,7 +202,7 @@ jobs:
body: |
Update `bun-types` version to ${{ steps.bun-version.outputs.BUN_VERSION }}
https://bun.sh/blog/${{ env.BUN_VERSION }}
https://bun.com/blog/${{ env.BUN_VERSION }}
push-to-fork: oven-sh/DefinitelyTyped
branch: ${{env.BUN_VERSION}}
docker:

View File

@@ -1,32 +0,0 @@
name: Lint
permissions:
contents: read
env:
BUN_VERSION: "1.2.0"
on:
workflow_call:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
outputs:
text_output: ${{ steps.lint.outputs.text_output }}
json_output: ${{ steps.lint.outputs.json_output }}
count: ${{ steps.lint.outputs.count }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install Dependencies
run: |
bun --cwd=packages/bun-internal-test install
- name: Lint
id: lint
run: |
bun packages/bun-internal-test/src/linter.ts

View File

@@ -21,16 +21,16 @@ jobs:
set -euo pipefail
# Extract the commit hash from the line after COMMIT
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' cmake/targets/BuildZstd.cmake)
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' cmake/targets/CloneZstd.cmake)
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find COMMIT line in BuildZstd.cmake"
echo "Error: Could not find COMMIT line in CloneZstd.cmake"
exit 1
fi
# Validate that it looks like a git hash
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
echo "Error: Invalid git hash format in BuildZstd.cmake"
echo "Error: Invalid git hash format in CloneZstd.cmake"
echo "Found: $CURRENT_VERSION"
echo "Expected: 40 character hexadecimal string"
exit 1
@@ -76,7 +76,7 @@ jobs:
run: |
set -euo pipefail
# Handle multi-line format where COMMIT and its value are on separate lines
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/[[:space:]]*([0-9a-f]+)[[:space:]]*$/ ${{ steps.check-version.outputs.latest }}/}' cmake/targets/BuildZstd.cmake
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/[[:space:]]*([0-9a-f]+)[[:space:]]*$/ ${{ steps.check-version.outputs.latest }}/}' cmake/targets/CloneZstd.cmake
- name: Create Pull Request
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
@@ -84,7 +84,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
cmake/targets/BuildZstd.cmake
cmake/targets/CloneZstd.cmake
commit-message: "deps: update zstd to ${{ steps.check-version.outputs.tag }} (${{ steps.check-version.outputs.latest }})"
title: "deps: update zstd to ${{ steps.check-version.outputs.tag }}"
delete-branch: true

1
.gitignore vendored
View File

@@ -36,6 +36,7 @@
*.out.refresh.js
*.pdb
*.sqlite
*.swp
*.tmp
*.trace
*.wat

View File

@@ -1,16 +1 @@
# Tell LLDB what to do when the debugged process receives SIGPWR: pass it through to the process
# (-p), but do not stop the process (-s) or notify the user (-n).
#
# JSC's garbage collector sends this signal (as configured by Bun WebKit in
# Thread::initializePlatformThreading() in ThreadingPOSIX.cpp) to the JS thread to suspend or resume
# it. So stopping the process would just create noise when debugging any long-running script.
process handle -p true -s false -n false SIGPWR
command script import misctools/lldb/lldb_pretty_printers.py
type category enable zig.lang
type category enable zig.std
command script import misctools/lldb/lldb_webkit.py
command script delete btjs
command alias btjs p {printf("gathering btjs trace...\n");printf("%s\n", (char*)dumpBtjsTrace())}
command source -C -s true -e true misctools/lldb/init.lldb

1005
.vscode/launch.json generated vendored

File diff suppressed because it is too large Load Diff

View File

@@ -168,4 +168,5 @@
"WebKit/WebInspectorUI": true,
},
"git.detectSubmodules": false,
"bun.test.customScript": "bun-debug test"
}

View File

@@ -1,36 +0,0 @@
## bun tests
**IMPORTANT**: use the `bun bd` command instead of the `bun` command. For example:
✅ Good
```sh
bun bd test internal/ban-words.test.ts
bun bd ./foo.ts
```
The `bun bd` command runs the DEBUG build. If you forget to run the debug build, your changes will not be reflected..
### Run a file
To run a file, you can use the `bun bd <file-path>` command.
```sh
bun bd ./foo.ts
```
### Run tests
To run a single test, you need to use the `bun bd test <test-name>` command.
```sh
bun bd test internal/ban-words.test.ts
```
You must ALWAYS make sure to pass a file path to the `bun bd test <file-path>` command. DO NOT try to run ALL the tests at once unless you're in a specific subdirectory.
### Run a Node.js test
```sh
bun bd --silent node:test test-fs-link
```

1
AGENTS.md Symbolic link
View File

@@ -0,0 +1 @@
CLAUDE.md

245
CLAUDE.md Normal file
View File

@@ -0,0 +1,245 @@
This is the Bun repository - an all-in-one JavaScript runtime & toolkit designed for speed, with a bundler, test runner, and Node.js-compatible package manager. It's written primarily in Zig with C++ for JavaScriptCore integration, powered by WebKit's JavaScriptCore engine.
## Building and Running Bun
### Build Commands
- **Build debug version**: `bun bd` or `bun run build:debug`
- Creates a debug build at `./build/debug/bun-debug`
- Compilation takes ~2.5 minutes
- **Run tests with your debug build**: `bun bd test <test-file>`
- **CRITICAL**: Never use `bun test` directly - it won't include your changes
- **Run any command with debug build**: `bun bd <command>`
### Other Build Variants
- `bun run build:release` - Release build
Address sanitizer is enabled by default in debug builds of Bun.
## Testing
### Running Tests
- **Single test file**: `bun bd test test/js/bun/http/serve.test.ts`
- **Fuzzy match test file**: `bun bd test http/serve.test.ts`
- **With filter**: `bun bd test test/js/bun/http/serve.test.ts -t "should handle"`
### Test Organization
- `test/js/bun/` - Bun-specific API tests (http, crypto, ffi, shell, etc.)
- `test/js/node/` - Node.js compatibility tests
- `test/js/web/` - Web API tests (fetch, WebSocket, streams, etc.)
- `test/cli/` - CLI command tests (install, run, test, etc.)
- `test/regression/issue/` - Regression tests (create one per bug fix)
- `test/bundler/` - Bundler and transpiler tests
- `test/integration/` - End-to-end integration tests
- `test/napi/` - N-API compatibility tests
- `test/v8/` - V8 C++ API compatibility tests
### Writing Tests
Tests use Bun's Jest-compatible test runner with proper test fixtures:
```typescript
import { test, expect } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
test("my feature", async () => {
// Create temp directory with test files
const dir = tempDirWithFiles("test-prefix", {
"index.js": `console.log("hello");`,
});
// Spawn Bun process
await using proc = Bun.spawn({
cmd: [bunExe(), "index.js"],
env: bunEnv,
cwd: dir,
});
const [stdout, stderr, exitCode] = await Promise.all([
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
proc.exited,
]);
expect(exitCode).toBe(0);
expect(stdout).toBe("hello\n");
});
```
## Code Architecture
### 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
### 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
## Development Workflow
### Code Formatting
- `bun run prettier` - Format JS/TS files
- `bun run zig-format` - Format Zig files
- `bun run clang-format` - Format C++ files
### Watching for Changes
- `bun run watch` - Incremental Zig compilation with error checking
- `bun run watch-windows` - Windows-specific watch mode
### Code Generation
Code generation happens automatically as part of the build process. The main scripts are:
- `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`
In development, bundled modules can be reloaded without rebuilding Zig by running `bun run build`.
## JavaScript Modules (`src/js/`)
Built-in JavaScript modules use special syntax and are organized as:
- `node/` - Node.js compatibility modules (`node:fs`, `node:path`, etc.)
- `bun/` - Bun-specific modules (`bun:ffi`, `bun:sqlite`, etc.)
- `thirdparty/` - NPM modules we replace (like `ws`)
- `internal/` - Internal modules not exposed to users
- `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
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.
2. **Use `await using`** for proper resource cleanup with Bun APIs (Bun.spawn, Bun.serve, Bun.connect, etc.)
3. **Follow existing code style** - check neighboring files for patterns
4. **Create regression tests** in `test/regression/issue/` when fixing bugs
5. **Use absolute paths** - Always use absolute paths in file operations
6. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools
7. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup
8. **Cross-platform** - Test on macOS, Linux, and Windows when making platform-specific changes
9. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_<scope>=1` to enable specific scopes
10. **Transpiled source** - Find transpiled files in `/tmp/bun-debug-src/` for debugging
## 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

View File

@@ -1,6 +1,6 @@
Configuring a development environment for Bun can take 10-30 minutes depending on your internet connection and computer speed. You will need ~10GB of free disk space for the repository and build artifacts.
If you are using Windows, please refer to [this guide](https://bun.sh/docs/project/building-windows)
If you are using Windows, please refer to [this guide](https://bun.com/docs/project/building-windows)
## Install Dependencies
@@ -37,7 +37,7 @@ Before starting, you will need to already have a release build of Bun installed,
{% codetabs %}
```bash#Native
$ curl -fsSL https://bun.sh/install | bash
$ curl -fsSL https://bun.com/install | bash
```
```bash#npm
@@ -144,6 +144,14 @@ $ bun bd test foo.test.ts
$ bun bd ./foo.ts
```
Bun generally takes about 2.5 minutes to compile a debug build when there are Zig changes. If your development workflow is "change one line, save, rebuild", you will spend too much time waiting for the build to finish. Instead:
- Batch up your changes
- Ensure zls is running with incremental watching for LSP errors (if you use VSCode and install Zig and run `bun run build` once to download Zig, this should just work)
- Prefer using the debugger ("CodeLLDB" in VSCode) to step through the code.
- Use debug logs. `BUN_DEBUG_<scope>=1` will enable debug logging for the corresponding `Output.scoped(.<scope>, false)` logs. You can also set `BUN_DEBUG_QUIET_LOGS=1` to disable all debug logging that isn't explicitly enabled. To dump debug lgos into a file, `BUN_DEBUG=<path-to-file>.log`. Debug logs are aggressively removed in release builds.
- src/js/\*\*.ts changes are pretty much instant to rebuild. C++ changes are a bit slower, but still much faster than the Zig code (Zig is one compilation unit, C++ is many).
## Code generation scripts
Several code generation scripts are used during Bun's build process. These are run automatically when changes are made to certain files.
@@ -179,6 +187,7 @@ To run a release build from a pull request, you can use the `bun-pr` npm package
bunx bun-pr <pr-number>
bunx bun-pr <branch-name>
bunx bun-pr "https://github.com/oven-sh/bun/pull/1234566"
bunx bun-pr --asan <pr-number> # Linux x64 only
```
This will download the release build from the pull request and add it to `$PATH` as `bun-${pr-number}`. You can then run the build with `bun-${pr-number}`.
@@ -189,24 +198,18 @@ bun-1234566 --version
This works by downloading the release build from the GitHub Actions artifacts on the linked pull request. You may need the `gh` CLI installed to authenticate with GitHub.
## Valgrind
## AddressSanitizer
On Linux, valgrind can help find memory issues.
[AddressSanitizer](https://en.wikipedia.org/wiki/AddressSanitizer) helps find memory issues, and is enabled by default in debug builds of Bun on Linux and macOS. This includes the Zig code and all dependencies. It makes the Zig code take about 2x longer to build, if that's stopping you from being productive you can disable it by setting `-Denable_asan=$<IF:$<BOOL:${ENABLE_ASAN}>,true,false>` to `-Denable_asan=false` in the `cmake/targets/BuildBun.cmake` file, but generally we recommend batching your changes up between builds.
Keep in mind:
- JavaScriptCore doesn't support valgrind. It will report spurious errors.
- Valgrind is slow
- Mimalloc will sometimes cause spurious errors when debug build is enabled
You'll need a very recent version of Valgrind due to DWARF 5 debug symbols. You may need to manually compile Valgrind instead of using it from your Linux package manager.
`--fair-sched=try` is necessary if running multithreaded code in Bun (such as the bundler). Otherwise it will hang.
To build a release build with Address Sanitizer, run:
```bash
$ valgrind --fair-sched=try --track-origins=yes bun-debug <args>
$ bun run build:release:asan
```
In CI, we run our test suite with at least one target that is built with Address Sanitizer.
## Building WebKit locally + Debug mode of JSC
WebKit is not cloned by default (to save time and disk space). To clone and build WebKit locally, run:

2
LATEST
View File

@@ -1 +1 @@
1.2.15
1.2.18

View File

@@ -980,7 +980,7 @@ release-create-auto-updater:
.PHONY: release-create
release-create:
gh release create --title "bun v$(PACKAGE_JSON_VERSION)" "$(BUN_BUILD_TAG)"
gh release create --repo=$(BUN_AUTO_UPDATER_REPO) --title "bun v$(PACKAGE_JSON_VERSION)" "$(BUN_BUILD_TAG)" -n "See https://github.com/oven-sh/bun/releases/tag/$(BUN_BUILD_TAG) for release notes. Using the install script or bun upgrade is the recommended way to install bun. Join bun's Discord to get access https://bun.sh/discord"
gh release create --repo=$(BUN_AUTO_UPDATER_REPO) --title "bun v$(PACKAGE_JSON_VERSION)" "$(BUN_BUILD_TAG)" -n "See https://github.com/oven-sh/bun/releases/tag/$(BUN_BUILD_TAG) for release notes. Using the install script or bun upgrade is the recommended way to install bun. Join bun's Discord to get access https://bun.com/discord"
release-bin-entitlements:
@@ -1977,7 +1977,7 @@ integration-test-dev: # to run integration tests
USE_EXISTING_PROCESS=true TEST_SERVER_URL=http://localhost:3000 node test/scripts/browser.js
copy-install:
cp src/cli/install.sh ../bun.sh/docs/install.html
cp src/cli/install.sh ../bun.com/docs/install.html
copy-to-bun-release-dir: copy-to-bun-release-dir-bin copy-to-bun-release-dir-dsym
@@ -2019,28 +2019,28 @@ vendor-dev: assert-deps submodule npm-install-dev vendor-without-npm
.PHONY: bun
bun:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
cpp:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
zig:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
dev:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
setup:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
bindings:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'
help:
@echo 'makefile is deprecated - use `cmake` / `bun run build`'
@echo 'See https://bun.sh/docs/project/contributing for more details'
@echo 'See https://bun.com/docs/project/contributing for more details'

588
README.md
View File

@@ -1,16 +1,16 @@
<p align="center">
<a href="https://bun.sh"><img src="https://github.com/user-attachments/assets/50282090-adfd-4ddb-9e27-c30753c6b161" alt="Logo" height=170></a>
<a href="https://bun.com"><img src="https://github.com/user-attachments/assets/50282090-adfd-4ddb-9e27-c30753c6b161" alt="Logo" height=170></a>
</p>
<h1 align="center">Bun</h1>
<p align="center">
<a href="https://bun.sh/discord" target="_blank"><img height=20 src="https://img.shields.io/discord/876711213126520882" /></a>
<a href="https://bun.com/discord" target="_blank"><img height=20 src="https://img.shields.io/discord/876711213126520882" /></a>
<img src="https://img.shields.io/github/stars/oven-sh/bun" alt="stars">
<a href="https://twitter.com/jarredsumner/status/1542824445810642946"><img src="https://img.shields.io/static/v1?label=speed&message=fast&color=success" alt="Bun speed" /></a>
</p>
<div align="center">
<a href="https://bun.sh/docs">Documentation</a>
<a href="https://bun.com/docs">Documentation</a>
<span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
<a href="https://discord.com/invite/CXdq2DP29u">Discord</a>
<span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
@@ -20,7 +20,7 @@
<br />
</div>
### [Read the docs →](https://bun.sh/docs)
### [Read the docs →](https://bun.com/docs)
## What is Bun?
@@ -47,12 +47,14 @@ Bun supports Linux (x64 & arm64), macOS (x64 & Apple Silicon) and Windows (x64).
> **Linux users** — Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1.
> **x64 users** — if you see "illegal instruction" or similar errors, check our [CPU requirements](https://bun.com/docs/installation#cpu-requirements-and-baseline-builds)
```sh
# with install script (recommended)
curl -fsSL https://bun.sh/install | bash
curl -fsSL https://bun.com/install | bash
# on windows
powershell -c "irm bun.sh/install.ps1 | iex"
powershell -c "irm bun.com/install.ps1 | iex"
# with npm
npm install -g bun
@@ -85,351 +87,329 @@ bun upgrade --canary
## Quick links
- Intro
- [What is Bun?](https://bun.sh/docs/index)
- [Installation](https://bun.sh/docs/installation)
- [Quickstart](https://bun.sh/docs/quickstart)
- [TypeScript](https://bun.sh/docs/typescript)
- [What is Bun?](https://bun.com/docs/index)
- [Installation](https://bun.com/docs/installation)
- [Quickstart](https://bun.com/docs/quickstart)
- [TypeScript](https://bun.com/docs/typescript)
- Templating
- [`bun init`](https://bun.sh/docs/cli/init)
- [`bun create`](https://bun.sh/docs/cli/bun-create)
- [`bun init`](https://bun.com/docs/cli/init)
- [`bun create`](https://bun.com/docs/cli/bun-create)
- CLI
- [`bun upgrade`](https://bun.sh/docs/cli/bun-upgrade)
- [`bun upgrade`](https://bun.com/docs/cli/bun-upgrade)
- Runtime
- [`bun run`](https://bun.sh/docs/cli/run)
- [File types (Loaders)](https://bun.sh/docs/runtime/loaders)
- [TypeScript](https://bun.sh/docs/runtime/typescript)
- [JSX](https://bun.sh/docs/runtime/jsx)
- [Environment variables](https://bun.sh/docs/runtime/env)
- [Bun APIs](https://bun.sh/docs/runtime/bun-apis)
- [Web APIs](https://bun.sh/docs/runtime/web-apis)
- [Node.js compatibility](https://bun.sh/docs/runtime/nodejs-apis)
- [Single-file executable](https://bun.sh/docs/bundler/executables)
- [Plugins](https://bun.sh/docs/runtime/plugins)
- [Watch mode / Hot Reloading](https://bun.sh/docs/runtime/hot)
- [Module resolution](https://bun.sh/docs/runtime/modules)
- [Auto-install](https://bun.sh/docs/runtime/autoimport)
- [bunfig.toml](https://bun.sh/docs/runtime/bunfig)
- [Debugger](https://bun.sh/docs/runtime/debugger)
- [$ Shell](https://bun.sh/docs/runtime/shell)
- [`bun run`](https://bun.com/docs/cli/run)
- [File types (Loaders)](https://bun.com/docs/runtime/loaders)
- [TypeScript](https://bun.com/docs/runtime/typescript)
- [JSX](https://bun.com/docs/runtime/jsx)
- [Environment variables](https://bun.com/docs/runtime/env)
- [Bun APIs](https://bun.com/docs/runtime/bun-apis)
- [Web APIs](https://bun.com/docs/runtime/web-apis)
- [Node.js compatibility](https://bun.com/docs/runtime/nodejs-apis)
- [Single-file executable](https://bun.com/docs/bundler/executables)
- [Plugins](https://bun.com/docs/runtime/plugins)
- [Watch mode / Hot Reloading](https://bun.com/docs/runtime/hot)
- [Module resolution](https://bun.com/docs/runtime/modules)
- [Auto-install](https://bun.com/docs/runtime/autoimport)
- [bunfig.toml](https://bun.com/docs/runtime/bunfig)
- [Debugger](https://bun.com/docs/runtime/debugger)
- [$ Shell](https://bun.com/docs/runtime/shell)
- Package manager
- [`bun install`](https://bun.sh/docs/cli/install)
- [`bun add`](https://bun.sh/docs/cli/add)
- [`bun remove`](https://bun.sh/docs/cli/remove)
- [`bun update`](https://bun.sh/docs/cli/update)
- [`bun link`](https://bun.sh/docs/cli/link)
- [`bun unlink`](https://bun.sh/docs/cli/unlink)
- [`bun pm`](https://bun.sh/docs/cli/pm)
- [`bun outdated`](https://bun.sh/docs/cli/outdated)
- [`bun publish`](https://bun.sh/docs/cli/publish)
- [`bun patch`](https://bun.sh/docs/install/patch)
- [`bun patch-commit`](https://bun.sh/docs/cli/patch-commit)
- [Global cache](https://bun.sh/docs/install/cache)
- [Workspaces](https://bun.sh/docs/install/workspaces)
- [Lifecycle scripts](https://bun.sh/docs/install/lifecycle)
- [Filter](https://bun.sh/docs/cli/filter)
- [Lockfile](https://bun.sh/docs/install/lockfile)
- [Scopes and registries](https://bun.sh/docs/install/registries)
- [Overrides and resolutions](https://bun.sh/docs/install/overrides)
- [`.npmrc`](https://bun.sh/docs/install/npmrc)
- [`bun install`](https://bun.com/docs/cli/install)
- [`bun add`](https://bun.com/docs/cli/add)
- [`bun remove`](https://bun.com/docs/cli/remove)
- [`bun update`](https://bun.com/docs/cli/update)
- [`bun link`](https://bun.com/docs/cli/link)
- [`bun unlink`](https://bun.com/docs/cli/unlink)
- [`bun pm`](https://bun.com/docs/cli/pm)
- [`bun outdated`](https://bun.com/docs/cli/outdated)
- [`bun publish`](https://bun.com/docs/cli/publish)
- [`bun patch`](https://bun.com/docs/install/patch)
- [`bun patch-commit`](https://bun.com/docs/cli/patch-commit)
- [Global cache](https://bun.com/docs/install/cache)
- [Workspaces](https://bun.com/docs/install/workspaces)
- [Lifecycle scripts](https://bun.com/docs/install/lifecycle)
- [Filter](https://bun.com/docs/cli/filter)
- [Lockfile](https://bun.com/docs/install/lockfile)
- [Scopes and registries](https://bun.com/docs/install/registries)
- [Overrides and resolutions](https://bun.com/docs/install/overrides)
- [`.npmrc`](https://bun.com/docs/install/npmrc)
- Bundler
- [`Bun.build`](https://bun.sh/docs/bundler)
- [Loaders](https://bun.sh/docs/bundler/loaders)
- [Plugins](https://bun.sh/docs/bundler/plugins)
- [Macros](https://bun.sh/docs/bundler/macros)
- [vs esbuild](https://bun.sh/docs/bundler/vs-esbuild)
- [Single-file executable](https://bun.sh/docs/bundler/executables)
- [CSS](https://bun.sh/docs/bundler/css)
- [HTML](https://bun.sh/docs/bundler/html)
- [Hot Module Replacement (HMR)](https://bun.sh/docs/bundler/hmr)
- [Full-stack with HTML imports](https://bun.sh/docs/bundler/fullstack)
- [`Bun.build`](https://bun.com/docs/bundler)
- [Loaders](https://bun.com/docs/bundler/loaders)
- [Plugins](https://bun.com/docs/bundler/plugins)
- [Macros](https://bun.com/docs/bundler/macros)
- [vs esbuild](https://bun.com/docs/bundler/vs-esbuild)
- [Single-file executable](https://bun.com/docs/bundler/executables)
- [CSS](https://bun.com/docs/bundler/css)
- [HTML](https://bun.com/docs/bundler/html)
- [Hot Module Replacement (HMR)](https://bun.com/docs/bundler/hmr)
- [Full-stack with HTML imports](https://bun.com/docs/bundler/fullstack)
- Test runner
- [`bun test`](https://bun.sh/docs/cli/test)
- [Writing tests](https://bun.sh/docs/test/writing)
- [Watch mode](https://bun.sh/docs/test/hot)
- [Lifecycle hooks](https://bun.sh/docs/test/lifecycle)
- [Mocks](https://bun.sh/docs/test/mocks)
- [Snapshots](https://bun.sh/docs/test/snapshots)
- [Dates and times](https://bun.sh/docs/test/time)
- [DOM testing](https://bun.sh/docs/test/dom)
- [Code coverage](https://bun.sh/docs/test/coverage)
- [Configuration](https://bun.sh/docs/test/configuration)
- [Discovery](https://bun.sh/docs/test/discovery)
- [Reporters](https://bun.sh/docs/test/reporters)
- [Runtime Behavior](https://bun.sh/docs/test/runtime-behavior)
- [`bun test`](https://bun.com/docs/cli/test)
- [Writing tests](https://bun.com/docs/test/writing)
- [Watch mode](https://bun.com/docs/test/hot)
- [Lifecycle hooks](https://bun.com/docs/test/lifecycle)
- [Mocks](https://bun.com/docs/test/mocks)
- [Snapshots](https://bun.com/docs/test/snapshots)
- [Dates and times](https://bun.com/docs/test/time)
- [DOM testing](https://bun.com/docs/test/dom)
- [Code coverage](https://bun.com/docs/test/coverage)
- [Configuration](https://bun.com/docs/test/configuration)
- [Discovery](https://bun.com/docs/test/discovery)
- [Reporters](https://bun.com/docs/test/reporters)
- [Runtime Behavior](https://bun.com/docs/test/runtime-behavior)
- Package runner
- [`bunx`](https://bun.sh/docs/cli/bunx)
- [`bunx`](https://bun.com/docs/cli/bunx)
- API
- [HTTP server (`Bun.serve`)](https://bun.sh/docs/api/http)
- [WebSockets](https://bun.sh/docs/api/websockets)
- [Workers](https://bun.sh/docs/api/workers)
- [Binary data](https://bun.sh/docs/api/binary-data)
- [Streams](https://bun.sh/docs/api/streams)
- [File I/O (`Bun.file`)](https://bun.sh/docs/api/file-io)
- [import.meta](https://bun.sh/docs/api/import-meta)
- [SQLite (`bun:sqlite`)](https://bun.sh/docs/api/sqlite)
- [PostgreSQL (`Bun.sql`)](https://bun.sh/docs/api/sql)
- [Redis (`Bun.redis`)](https://bun.sh/docs/api/redis)
- [S3 Client (`Bun.s3`)](https://bun.sh/docs/api/s3)
- [FileSystemRouter](https://bun.sh/docs/api/file-system-router)
- [TCP sockets](https://bun.sh/docs/api/tcp)
- [UDP sockets](https://bun.sh/docs/api/udp)
- [Globals](https://bun.sh/docs/api/globals)
- [$ Shell](https://bun.sh/docs/runtime/shell)
- [Child processes (spawn)](https://bun.sh/docs/api/spawn)
- [Transpiler (`Bun.Transpiler`)](https://bun.sh/docs/api/transpiler)
- [Hashing](https://bun.sh/docs/api/hashing)
- [Colors (`Bun.color`)](https://bun.sh/docs/api/color)
- [Console](https://bun.sh/docs/api/console)
- [FFI (`bun:ffi`)](https://bun.sh/docs/api/ffi)
- [C Compiler (`bun:ffi` cc)](https://bun.sh/docs/api/cc)
- [HTMLRewriter](https://bun.sh/docs/api/html-rewriter)
- [Testing (`bun:test`)](https://bun.sh/docs/api/test)
- [Cookies (`Bun.Cookie`)](https://bun.sh/docs/api/cookie)
- [Utils](https://bun.sh/docs/api/utils)
- [Node-API](https://bun.sh/docs/api/node-api)
- [Glob (`Bun.Glob`)](https://bun.sh/docs/api/glob)
- [Semver (`Bun.semver`)](https://bun.sh/docs/api/semver)
- [DNS](https://bun.sh/docs/api/dns)
- [fetch API extensions](https://bun.sh/docs/api/fetch)
- [HTTP server (`Bun.serve`)](https://bun.com/docs/api/http)
- [WebSockets](https://bun.com/docs/api/websockets)
- [Workers](https://bun.com/docs/api/workers)
- [Binary data](https://bun.com/docs/api/binary-data)
- [Streams](https://bun.com/docs/api/streams)
- [File I/O (`Bun.file`)](https://bun.com/docs/api/file-io)
- [import.meta](https://bun.com/docs/api/import-meta)
- [SQLite (`bun:sqlite`)](https://bun.com/docs/api/sqlite)
- [PostgreSQL (`Bun.sql`)](https://bun.com/docs/api/sql)
- [Redis (`Bun.redis`)](https://bun.com/docs/api/redis)
- [S3 Client (`Bun.s3`)](https://bun.com/docs/api/s3)
- [FileSystemRouter](https://bun.com/docs/api/file-system-router)
- [TCP sockets](https://bun.com/docs/api/tcp)
- [UDP sockets](https://bun.com/docs/api/udp)
- [Globals](https://bun.com/docs/api/globals)
- [$ Shell](https://bun.com/docs/runtime/shell)
- [Child processes (spawn)](https://bun.com/docs/api/spawn)
- [Transpiler (`Bun.Transpiler`)](https://bun.com/docs/api/transpiler)
- [Hashing](https://bun.com/docs/api/hashing)
- [Colors (`Bun.color`)](https://bun.com/docs/api/color)
- [Console](https://bun.com/docs/api/console)
- [FFI (`bun:ffi`)](https://bun.com/docs/api/ffi)
- [C Compiler (`bun:ffi` cc)](https://bun.com/docs/api/cc)
- [HTMLRewriter](https://bun.com/docs/api/html-rewriter)
- [Testing (`bun:test`)](https://bun.com/docs/api/test)
- [Cookies (`Bun.Cookie`)](https://bun.com/docs/api/cookie)
- [Utils](https://bun.com/docs/api/utils)
- [Node-API](https://bun.com/docs/api/node-api)
- [Glob (`Bun.Glob`)](https://bun.com/docs/api/glob)
- [Semver (`Bun.semver`)](https://bun.com/docs/api/semver)
- [DNS](https://bun.com/docs/api/dns)
- [fetch API extensions](https://bun.com/docs/api/fetch)
## Guides
- Binary
- [Convert a Blob to a string](https://bun.sh/guides/binary/blob-to-string)
- [Convert a Buffer to a blob](https://bun.sh/guides/binary/buffer-to-blob)
- [Convert a Blob to a DataView](https://bun.sh/guides/binary/blob-to-dataview)
- [Convert a Buffer to a string](https://bun.sh/guides/binary/buffer-to-string)
- [Convert a Blob to a ReadableStream](https://bun.sh/guides/binary/blob-to-stream)
- [Convert a Blob to a Uint8Array](https://bun.sh/guides/binary/blob-to-typedarray)
- [Convert a DataView to a string](https://bun.sh/guides/binary/dataview-to-string)
- [Convert a Uint8Array to a Blob](https://bun.sh/guides/binary/typedarray-to-blob)
- [Convert a Blob to an ArrayBuffer](https://bun.sh/guides/binary/blob-to-arraybuffer)
- [Convert an ArrayBuffer to a Blob](https://bun.sh/guides/binary/arraybuffer-to-blob)
- [Convert a Buffer to a Uint8Array](https://bun.sh/guides/binary/buffer-to-typedarray)
- [Convert a Uint8Array to a Buffer](https://bun.sh/guides/binary/typedarray-to-buffer)
- [Convert a Uint8Array to a string](https://bun.sh/guides/binary/typedarray-to-string)
- [Convert a Buffer to an ArrayBuffer](https://bun.sh/guides/binary/buffer-to-arraybuffer)
- [Convert an ArrayBuffer to a Buffer](https://bun.sh/guides/binary/arraybuffer-to-buffer)
- [Convert an ArrayBuffer to a string](https://bun.sh/guides/binary/arraybuffer-to-string)
- [Convert a Uint8Array to a DataView](https://bun.sh/guides/binary/typedarray-to-dataview)
- [Convert a Buffer to a ReadableStream](https://bun.sh/guides/binary/buffer-to-readablestream)
- [Convert a Uint8Array to an ArrayBuffer](https://bun.sh/guides/binary/typedarray-to-arraybuffer)
- [Convert an ArrayBuffer to a Uint8Array](https://bun.sh/guides/binary/arraybuffer-to-typedarray)
- [Convert an ArrayBuffer to an array of numbers](https://bun.sh/guides/binary/arraybuffer-to-array)
- [Convert a Uint8Array to a ReadableStream](https://bun.sh/guides/binary/typedarray-to-readablestream)
- [Convert a Blob to a string](https://bun.com/guides/binary/blob-to-string)
- [Convert a Buffer to a blob](https://bun.com/guides/binary/buffer-to-blob)
- [Convert a Blob to a DataView](https://bun.com/guides/binary/blob-to-dataview)
- [Convert a Buffer to a string](https://bun.com/guides/binary/buffer-to-string)
- [Convert a Blob to a ReadableStream](https://bun.com/guides/binary/blob-to-stream)
- [Convert a Blob to a Uint8Array](https://bun.com/guides/binary/blob-to-typedarray)
- [Convert a DataView to a string](https://bun.com/guides/binary/dataview-to-string)
- [Convert a Uint8Array to a Blob](https://bun.com/guides/binary/typedarray-to-blob)
- [Convert a Blob to an ArrayBuffer](https://bun.com/guides/binary/blob-to-arraybuffer)
- [Convert an ArrayBuffer to a Blob](https://bun.com/guides/binary/arraybuffer-to-blob)
- [Convert a Buffer to a Uint8Array](https://bun.com/guides/binary/buffer-to-typedarray)
- [Convert a Uint8Array to a Buffer](https://bun.com/guides/binary/typedarray-to-buffer)
- [Convert a Uint8Array to a string](https://bun.com/guides/binary/typedarray-to-string)
- [Convert a Buffer to an ArrayBuffer](https://bun.com/guides/binary/buffer-to-arraybuffer)
- [Convert an ArrayBuffer to a Buffer](https://bun.com/guides/binary/arraybuffer-to-buffer)
- [Convert an ArrayBuffer to a string](https://bun.com/guides/binary/arraybuffer-to-string)
- [Convert a Uint8Array to a DataView](https://bun.com/guides/binary/typedarray-to-dataview)
- [Convert a Buffer to a ReadableStream](https://bun.com/guides/binary/buffer-to-readablestream)
- [Convert a Uint8Array to an ArrayBuffer](https://bun.com/guides/binary/typedarray-to-arraybuffer)
- [Convert an ArrayBuffer to a Uint8Array](https://bun.com/guides/binary/arraybuffer-to-typedarray)
- [Convert an ArrayBuffer to an array of numbers](https://bun.com/guides/binary/arraybuffer-to-array)
- [Convert a Uint8Array to a ReadableStream](https://bun.com/guides/binary/typedarray-to-readablestream)
- Ecosystem
- [Use React and JSX](https://bun.sh/guides/ecosystem/react)
- [Use EdgeDB with Bun](https://bun.sh/guides/ecosystem/edgedb)
- [Use Prisma with Bun](https://bun.sh/guides/ecosystem/prisma)
- [Add Sentry to a Bun app](https://bun.sh/guides/ecosystem/sentry)
- [Create a Discord bot](https://bun.sh/guides/ecosystem/discordjs)
- [Run Bun as a daemon with PM2](https://bun.sh/guides/ecosystem/pm2)
- [Use Drizzle ORM with Bun](https://bun.sh/guides/ecosystem/drizzle)
- [Build an app with Nuxt and Bun](https://bun.sh/guides/ecosystem/nuxt)
- [Build an app with Qwik and Bun](https://bun.sh/guides/ecosystem/qwik)
- [Build an app with Astro and Bun](https://bun.sh/guides/ecosystem/astro)
- [Build an app with Remix and Bun](https://bun.sh/guides/ecosystem/remix)
- [Build a frontend using Vite and Bun](https://bun.sh/guides/ecosystem/vite)
- [Build an app with Next.js and Bun](https://bun.sh/guides/ecosystem/nextjs)
- [Run Bun as a daemon with systemd](https://bun.sh/guides/ecosystem/systemd)
- [Deploy a Bun application on Render](https://bun.sh/guides/ecosystem/render)
- [Build an HTTP server using Hono and Bun](https://bun.sh/guides/ecosystem/hono)
- [Build an app with SvelteKit and Bun](https://bun.sh/guides/ecosystem/sveltekit)
- [Build an app with SolidStart and Bun](https://bun.sh/guides/ecosystem/solidstart)
- [Build an HTTP server using Elysia and Bun](https://bun.sh/guides/ecosystem/elysia)
- [Build an HTTP server using StricJS and Bun](https://bun.sh/guides/ecosystem/stric)
- [Containerize a Bun application with Docker](https://bun.sh/guides/ecosystem/docker)
- [Build an HTTP server using Express and Bun](https://bun.sh/guides/ecosystem/express)
- [Use Neon Postgres through Drizzle ORM](https://bun.sh/guides/ecosystem/neon-drizzle)
- [Server-side render (SSR) a React component](https://bun.sh/guides/ecosystem/ssr-react)
- [Read and write data to MongoDB using Mongoose and Bun](https://bun.sh/guides/ecosystem/mongoose)
- [Use Neon's Serverless Postgres with Bun](https://bun.sh/guides/ecosystem/neon-serverless-postgres)
- [Use React and JSX](https://bun.com/guides/ecosystem/react)
- [Use EdgeDB with Bun](https://bun.com/guides/ecosystem/edgedb)
- [Use Prisma with Bun](https://bun.com/guides/ecosystem/prisma)
- [Add Sentry to a Bun app](https://bun.com/guides/ecosystem/sentry)
- [Create a Discord bot](https://bun.com/guides/ecosystem/discordjs)
- [Run Bun as a daemon with PM2](https://bun.com/guides/ecosystem/pm2)
- [Use Drizzle ORM with Bun](https://bun.com/guides/ecosystem/drizzle)
- [Build an app with Nuxt and Bun](https://bun.com/guides/ecosystem/nuxt)
- [Build an app with Qwik and Bun](https://bun.com/guides/ecosystem/qwik)
- [Build an app with Astro and Bun](https://bun.com/guides/ecosystem/astro)
- [Build an app with Remix and Bun](https://bun.com/guides/ecosystem/remix)
- [Build a frontend using Vite and Bun](https://bun.com/guides/ecosystem/vite)
- [Build an app with Next.js and Bun](https://bun.com/guides/ecosystem/nextjs)
- [Run Bun as a daemon with systemd](https://bun.com/guides/ecosystem/systemd)
- [Deploy a Bun application on Render](https://bun.com/guides/ecosystem/render)
- [Build an HTTP server using Hono and Bun](https://bun.com/guides/ecosystem/hono)
- [Build an app with SvelteKit and Bun](https://bun.com/guides/ecosystem/sveltekit)
- [Build an app with SolidStart and Bun](https://bun.com/guides/ecosystem/solidstart)
- [Build an HTTP server using Elysia and Bun](https://bun.com/guides/ecosystem/elysia)
- [Build an HTTP server using StricJS and Bun](https://bun.com/guides/ecosystem/stric)
- [Containerize a Bun application with Docker](https://bun.com/guides/ecosystem/docker)
- [Build an HTTP server using Express and Bun](https://bun.com/guides/ecosystem/express)
- [Use Neon Postgres through Drizzle ORM](https://bun.com/guides/ecosystem/neon-drizzle)
- [Server-side render (SSR) a React component](https://bun.com/guides/ecosystem/ssr-react)
- [Read and write data to MongoDB using Mongoose and Bun](https://bun.com/guides/ecosystem/mongoose)
- [Use Neon's Serverless Postgres with Bun](https://bun.com/guides/ecosystem/neon-serverless-postgres)
- HTMLRewriter
- [Extract links from a webpage using HTMLRewriter](https://bun.sh/guides/html-rewriter/extract-links)
- [Extract social share images and Open Graph tags](https://bun.sh/guides/html-rewriter/extract-social-meta)
- [Extract links from a webpage using HTMLRewriter](https://bun.com/guides/html-rewriter/extract-links)
- [Extract social share images and Open Graph tags](https://bun.com/guides/html-rewriter/extract-social-meta)
- HTTP
- [Hot reload an HTTP server](https://bun.sh/guides/http/hot)
- [Common HTTP server usage](https://bun.sh/guides/http/server)
- [Write a simple HTTP server](https://bun.sh/guides/http/simple)
- [Configure TLS on an HTTP server](https://bun.sh/guides/http/tls)
- [Send an HTTP request using fetch](https://bun.sh/guides/http/fetch)
- [Proxy HTTP requests using fetch()](https://bun.sh/guides/http/proxy)
- [Start a cluster of HTTP servers](https://bun.sh/guides/http/cluster)
- [Stream a file as an HTTP Response](https://bun.sh/guides/http/stream-file)
- [fetch with unix domain sockets in Bun](https://bun.sh/guides/http/fetch-unix)
- [Upload files via HTTP using FormData](https://bun.sh/guides/http/file-uploads)
- [Streaming HTTP Server with Async Iterators](https://bun.sh/guides/http/stream-iterator)
- [Streaming HTTP Server with Node.js Streams](https://bun.sh/guides/http/stream-node-streams-in-bun)
- [Hot reload an HTTP server](https://bun.com/guides/http/hot)
- [Common HTTP server usage](https://bun.com/guides/http/server)
- [Write a simple HTTP server](https://bun.com/guides/http/simple)
- [Configure TLS on an HTTP server](https://bun.com/guides/http/tls)
- [Send an HTTP request using fetch](https://bun.com/guides/http/fetch)
- [Proxy HTTP requests using fetch()](https://bun.com/guides/http/proxy)
- [Start a cluster of HTTP servers](https://bun.com/guides/http/cluster)
- [Stream a file as an HTTP Response](https://bun.com/guides/http/stream-file)
- [fetch with unix domain sockets in Bun](https://bun.com/guides/http/fetch-unix)
- [Upload files via HTTP using FormData](https://bun.com/guides/http/file-uploads)
- [Streaming HTTP Server with Async Iterators](https://bun.com/guides/http/stream-iterator)
- [Streaming HTTP Server with Node.js Streams](https://bun.com/guides/http/stream-node-streams-in-bun)
- Install
- [Add a dependency](https://bun.sh/guides/install/add)
- [Add a Git dependency](https://bun.sh/guides/install/add-git)
- [Add a peer dependency](https://bun.sh/guides/install/add-peer)
- [Add a trusted dependency](https://bun.sh/guides/install/trusted)
- [Add a development dependency](https://bun.sh/guides/install/add-dev)
- [Add a tarball dependency](https://bun.sh/guides/install/add-tarball)
- [Add an optional dependency](https://bun.sh/guides/install/add-optional)
- [Generate a yarn-compatible lockfile](https://bun.sh/guides/install/yarnlock)
- [Configuring a monorepo using workspaces](https://bun.sh/guides/install/workspaces)
- [Install a package under a different name](https://bun.sh/guides/install/npm-alias)
- [Install dependencies with Bun in GitHub Actions](https://bun.sh/guides/install/cicd)
- [Using bun install with Artifactory](https://bun.sh/guides/install/jfrog-artifactory)
- [Configure git to diff Bun's lockb lockfile](https://bun.sh/guides/install/git-diff-bun-lockfile)
- [Override the default npm registry for bun install](https://bun.sh/guides/install/custom-registry)
- [Using bun install with an Azure Artifacts npm registry](https://bun.sh/guides/install/azure-artifacts)
- [Migrate from npm install to bun install](https://bun.sh/guides/install/from-npm-install-to-bun-install)
- [Configure a private registry for an organization scope with bun install](https://bun.sh/guides/install/registry-scope)
- [Add a dependency](https://bun.com/guides/install/add)
- [Add a Git dependency](https://bun.com/guides/install/add-git)
- [Add a peer dependency](https://bun.com/guides/install/add-peer)
- [Add a trusted dependency](https://bun.com/guides/install/trusted)
- [Add a development dependency](https://bun.com/guides/install/add-dev)
- [Add a tarball dependency](https://bun.com/guides/install/add-tarball)
- [Add an optional dependency](https://bun.com/guides/install/add-optional)
- [Generate a yarn-compatible lockfile](https://bun.com/guides/install/yarnlock)
- [Configuring a monorepo using workspaces](https://bun.com/guides/install/workspaces)
- [Install a package under a different name](https://bun.com/guides/install/npm-alias)
- [Install dependencies with Bun in GitHub Actions](https://bun.com/guides/install/cicd)
- [Using bun install with Artifactory](https://bun.com/guides/install/jfrog-artifactory)
- [Configure git to diff Bun's lockb lockfile](https://bun.com/guides/install/git-diff-bun-lockfile)
- [Override the default npm registry for bun install](https://bun.com/guides/install/custom-registry)
- [Using bun install with an Azure Artifacts npm registry](https://bun.com/guides/install/azure-artifacts)
- [Migrate from npm install to bun install](https://bun.com/guides/install/from-npm-install-to-bun-install)
- [Configure a private registry for an organization scope with bun install](https://bun.com/guides/install/registry-scope)
- Process
- [Read from stdin](https://bun.sh/guides/process/stdin)
- [Listen for CTRL+C](https://bun.sh/guides/process/ctrl-c)
- [Spawn a child process](https://bun.sh/guides/process/spawn)
- [Listen to OS signals](https://bun.sh/guides/process/os-signals)
- [Parse command-line arguments](https://bun.sh/guides/process/argv)
- [Read stderr from a child process](https://bun.sh/guides/process/spawn-stderr)
- [Read stdout from a child process](https://bun.sh/guides/process/spawn-stdout)
- [Get the process uptime in nanoseconds](https://bun.sh/guides/process/nanoseconds)
- [Spawn a child process and communicate using IPC](https://bun.sh/guides/process/ipc)
- [Read from stdin](https://bun.com/guides/process/stdin)
- [Listen for CTRL+C](https://bun.com/guides/process/ctrl-c)
- [Spawn a child process](https://bun.com/guides/process/spawn)
- [Listen to OS signals](https://bun.com/guides/process/os-signals)
- [Parse command-line arguments](https://bun.com/guides/process/argv)
- [Read stderr from a child process](https://bun.com/guides/process/spawn-stderr)
- [Read stdout from a child process](https://bun.com/guides/process/spawn-stdout)
- [Get the process uptime in nanoseconds](https://bun.com/guides/process/nanoseconds)
- [Spawn a child process and communicate using IPC](https://bun.com/guides/process/ipc)
- Read file
- [Read a JSON file](https://bun.sh/guides/read-file/json)
- [Check if a file exists](https://bun.sh/guides/read-file/exists)
- [Read a file as a string](https://bun.sh/guides/read-file/string)
- [Read a file to a Buffer](https://bun.sh/guides/read-file/buffer)
- [Get the MIME type of a file](https://bun.sh/guides/read-file/mime)
- [Watch a directory for changes](https://bun.sh/guides/read-file/watch)
- [Read a file as a ReadableStream](https://bun.sh/guides/read-file/stream)
- [Read a file to a Uint8Array](https://bun.sh/guides/read-file/uint8array)
- [Read a file to an ArrayBuffer](https://bun.sh/guides/read-file/arraybuffer)
- [Read a JSON file](https://bun.com/guides/read-file/json)
- [Check if a file exists](https://bun.com/guides/read-file/exists)
- [Read a file as a string](https://bun.com/guides/read-file/string)
- [Read a file to a Buffer](https://bun.com/guides/read-file/buffer)
- [Get the MIME type of a file](https://bun.com/guides/read-file/mime)
- [Watch a directory for changes](https://bun.com/guides/read-file/watch)
- [Read a file as a ReadableStream](https://bun.com/guides/read-file/stream)
- [Read a file to a Uint8Array](https://bun.com/guides/read-file/uint8array)
- [Read a file to an ArrayBuffer](https://bun.com/guides/read-file/arraybuffer)
- Runtime
- [Delete files](https://bun.sh/guides/runtime/delete-file)
- [Run a Shell Command](https://bun.sh/guides/runtime/shell)
- [Import a JSON file](https://bun.sh/guides/runtime/import-json)
- [Import a TOML file](https://bun.sh/guides/runtime/import-toml)
- [Set a time zone in Bun](https://bun.sh/guides/runtime/timezone)
- [Set environment variables](https://bun.sh/guides/runtime/set-env)
- [Re-map import paths](https://bun.sh/guides/runtime/tsconfig-paths)
- [Delete directories](https://bun.sh/guides/runtime/delete-directory)
- [Read environment variables](https://bun.sh/guides/runtime/read-env)
- [Import a HTML file as text](https://bun.sh/guides/runtime/import-html)
- [Install and run Bun in GitHub Actions](https://bun.sh/guides/runtime/cicd)
- [Debugging Bun with the web debugger](https://bun.sh/guides/runtime/web-debugger)
- [Install TypeScript declarations for Bun](https://bun.sh/guides/runtime/typescript)
- [Debugging Bun with the VS Code extension](https://bun.sh/guides/runtime/vscode-debugger)
- [Inspect memory usage using V8 heap snapshots](https://bun.sh/guides/runtime/heap-snapshot)
- [Define and replace static globals & constants](https://bun.sh/guides/runtime/define-constant)
- [Codesign a single-file JavaScript executable on macOS](https://bun.sh/guides/runtime/codesign-macos-executable)
- [Delete files](https://bun.com/guides/runtime/delete-file)
- [Run a Shell Command](https://bun.com/guides/runtime/shell)
- [Import a JSON file](https://bun.com/guides/runtime/import-json)
- [Import a TOML file](https://bun.com/guides/runtime/import-toml)
- [Set a time zone in Bun](https://bun.com/guides/runtime/timezone)
- [Set environment variables](https://bun.com/guides/runtime/set-env)
- [Re-map import paths](https://bun.com/guides/runtime/tsconfig-paths)
- [Delete directories](https://bun.com/guides/runtime/delete-directory)
- [Read environment variables](https://bun.com/guides/runtime/read-env)
- [Import a HTML file as text](https://bun.com/guides/runtime/import-html)
- [Install and run Bun in GitHub Actions](https://bun.com/guides/runtime/cicd)
- [Debugging Bun with the web debugger](https://bun.com/guides/runtime/web-debugger)
- [Install TypeScript declarations for Bun](https://bun.com/guides/runtime/typescript)
- [Debugging Bun with the VS Code extension](https://bun.com/guides/runtime/vscode-debugger)
- [Inspect memory usage using V8 heap snapshots](https://bun.com/guides/runtime/heap-snapshot)
- [Define and replace static globals & constants](https://bun.com/guides/runtime/define-constant)
- [Codesign a single-file JavaScript executable on macOS](https://bun.com/guides/runtime/codesign-macos-executable)
- Streams
- [Convert a ReadableStream to JSON](https://bun.sh/guides/streams/to-json)
- [Convert a ReadableStream to a Blob](https://bun.sh/guides/streams/to-blob)
- [Convert a ReadableStream to a Buffer](https://bun.sh/guides/streams/to-buffer)
- [Convert a ReadableStream to a string](https://bun.sh/guides/streams/to-string)
- [Convert a ReadableStream to a Uint8Array](https://bun.sh/guides/streams/to-typedarray)
- [Convert a ReadableStream to an array of chunks](https://bun.sh/guides/streams/to-array)
- [Convert a Node.js Readable to JSON](https://bun.sh/guides/streams/node-readable-to-json)
- [Convert a ReadableStream to an ArrayBuffer](https://bun.sh/guides/streams/to-arraybuffer)
- [Convert a Node.js Readable to a Blob](https://bun.sh/guides/streams/node-readable-to-blob)
- [Convert a Node.js Readable to a string](https://bun.sh/guides/streams/node-readable-to-string)
- [Convert a Node.js Readable to an Uint8Array](https://bun.sh/guides/streams/node-readable-to-uint8array)
- [Convert a Node.js Readable to an ArrayBuffer](https://bun.sh/guides/streams/node-readable-to-arraybuffer)
- [Convert a ReadableStream to JSON](https://bun.com/guides/streams/to-json)
- [Convert a ReadableStream to a Blob](https://bun.com/guides/streams/to-blob)
- [Convert a ReadableStream to a Buffer](https://bun.com/guides/streams/to-buffer)
- [Convert a ReadableStream to a string](https://bun.com/guides/streams/to-string)
- [Convert a ReadableStream to a Uint8Array](https://bun.com/guides/streams/to-typedarray)
- [Convert a ReadableStream to an array of chunks](https://bun.com/guides/streams/to-array)
- [Convert a Node.js Readable to JSON](https://bun.com/guides/streams/node-readable-to-json)
- [Convert a ReadableStream to an ArrayBuffer](https://bun.com/guides/streams/to-arraybuffer)
- [Convert a Node.js Readable to a Blob](https://bun.com/guides/streams/node-readable-to-blob)
- [Convert a Node.js Readable to a string](https://bun.com/guides/streams/node-readable-to-string)
- [Convert a Node.js Readable to an Uint8Array](https://bun.com/guides/streams/node-readable-to-uint8array)
- [Convert a Node.js Readable to an ArrayBuffer](https://bun.com/guides/streams/node-readable-to-arraybuffer)
- Test
- [Spy on methods in `bun test`](https://bun.sh/guides/test/spy-on)
- [Bail early with the Bun test runner](https://bun.sh/guides/test/bail)
- [Mock functions in `bun test`](https://bun.sh/guides/test/mock-functions)
- [Run tests in watch mode with Bun](https://bun.sh/guides/test/watch-mode)
- [Use snapshot testing in `bun test`](https://bun.sh/guides/test/snapshot)
- [Skip tests with the Bun test runner](https://bun.sh/guides/test/skip-tests)
- [Using Testing Library with Bun](https://bun.sh/guides/test/testing-library)
- [Update snapshots in `bun test`](https://bun.sh/guides/test/update-snapshots)
- [Run your tests with the Bun test runner](https://bun.sh/guides/test/run-tests)
- [Set the system time in Bun's test runner](https://bun.sh/guides/test/mock-clock)
- [Set a per-test timeout with the Bun test runner](https://bun.sh/guides/test/timeout)
- [Migrate from Jest to Bun's test runner](https://bun.sh/guides/test/migrate-from-jest)
- [Write browser DOM tests with Bun and happy-dom](https://bun.sh/guides/test/happy-dom)
- [Mark a test as a "todo" with the Bun test runner](https://bun.sh/guides/test/todo-tests)
- [Re-run tests multiple times with the Bun test runner](https://bun.sh/guides/test/rerun-each)
- [Generate code coverage reports with the Bun test runner](https://bun.sh/guides/test/coverage)
- [import, require, and test Svelte components with bun test](https://bun.sh/guides/test/svelte-test)
- [Set a code coverage threshold with the Bun test runner](https://bun.sh/guides/test/coverage-threshold)
- [Spy on methods in `bun test`](https://bun.com/guides/test/spy-on)
- [Bail early with the Bun test runner](https://bun.com/guides/test/bail)
- [Mock functions in `bun test`](https://bun.com/guides/test/mock-functions)
- [Run tests in watch mode with Bun](https://bun.com/guides/test/watch-mode)
- [Use snapshot testing in `bun test`](https://bun.com/guides/test/snapshot)
- [Skip tests with the Bun test runner](https://bun.com/guides/test/skip-tests)
- [Using Testing Library with Bun](https://bun.com/guides/test/testing-library)
- [Update snapshots in `bun test`](https://bun.com/guides/test/update-snapshots)
- [Run your tests with the Bun test runner](https://bun.com/guides/test/run-tests)
- [Set the system time in Bun's test runner](https://bun.com/guides/test/mock-clock)
- [Set a per-test timeout with the Bun test runner](https://bun.com/guides/test/timeout)
- [Migrate from Jest to Bun's test runner](https://bun.com/guides/test/migrate-from-jest)
- [Write browser DOM tests with Bun and happy-dom](https://bun.com/guides/test/happy-dom)
- [Mark a test as a "todo" with the Bun test runner](https://bun.com/guides/test/todo-tests)
- [Re-run tests multiple times with the Bun test runner](https://bun.com/guides/test/rerun-each)
- [Generate code coverage reports with the Bun test runner](https://bun.com/guides/test/coverage)
- [import, require, and test Svelte components with bun test](https://bun.com/guides/test/svelte-test)
- [Set a code coverage threshold with the Bun test runner](https://bun.com/guides/test/coverage-threshold)
- Util
- [Generate a UUID](https://bun.sh/guides/util/javascript-uuid)
- [Hash a password](https://bun.sh/guides/util/hash-a-password)
- [Escape an HTML string](https://bun.sh/guides/util/escape-html)
- [Get the current Bun version](https://bun.sh/guides/util/version)
- [Encode and decode base64 strings](https://bun.sh/guides/util/base64)
- [Compress and decompress data with gzip](https://bun.sh/guides/util/gzip)
- [Sleep for a fixed number of milliseconds](https://bun.sh/guides/util/sleep)
- [Detect when code is executed with Bun](https://bun.sh/guides/util/detect-bun)
- [Check if two objects are deeply equal](https://bun.sh/guides/util/deep-equals)
- [Compress and decompress data with DEFLATE](https://bun.sh/guides/util/deflate)
- [Get the absolute path to the current entrypoint](https://bun.sh/guides/util/main)
- [Get the directory of the current file](https://bun.sh/guides/util/import-meta-dir)
- [Check if the current file is the entrypoint](https://bun.sh/guides/util/entrypoint)
- [Get the file name of the current file](https://bun.sh/guides/util/import-meta-file)
- [Convert a file URL to an absolute path](https://bun.sh/guides/util/file-url-to-path)
- [Convert an absolute path to a file URL](https://bun.sh/guides/util/path-to-file-url)
- [Get the absolute path of the current file](https://bun.sh/guides/util/import-meta-path)
- [Get the path to an executable bin file](https://bun.sh/guides/util/which-path-to-executable-bin)
- [Generate a UUID](https://bun.com/guides/util/javascript-uuid)
- [Hash a password](https://bun.com/guides/util/hash-a-password)
- [Escape an HTML string](https://bun.com/guides/util/escape-html)
- [Get the current Bun version](https://bun.com/guides/util/version)
- [Encode and decode base64 strings](https://bun.com/guides/util/base64)
- [Compress and decompress data with gzip](https://bun.com/guides/util/gzip)
- [Sleep for a fixed number of milliseconds](https://bun.com/guides/util/sleep)
- [Detect when code is executed with Bun](https://bun.com/guides/util/detect-bun)
- [Check if two objects are deeply equal](https://bun.com/guides/util/deep-equals)
- [Compress and decompress data with DEFLATE](https://bun.com/guides/util/deflate)
- [Get the absolute path to the current entrypoint](https://bun.com/guides/util/main)
- [Get the directory of the current file](https://bun.com/guides/util/import-meta-dir)
- [Check if the current file is the entrypoint](https://bun.com/guides/util/entrypoint)
- [Get the file name of the current file](https://bun.com/guides/util/import-meta-file)
- [Convert a file URL to an absolute path](https://bun.com/guides/util/file-url-to-path)
- [Convert an absolute path to a file URL](https://bun.com/guides/util/path-to-file-url)
- [Get the absolute path of the current file](https://bun.com/guides/util/import-meta-path)
- [Get the path to an executable bin file](https://bun.com/guides/util/which-path-to-executable-bin)
- WebSocket
- [Build a publish-subscribe WebSocket server](https://bun.sh/guides/websocket/pubsub)
- [Build a simple WebSocket server](https://bun.sh/guides/websocket/simple)
- [Enable compression for WebSocket messages](https://bun.sh/guides/websocket/compression)
- [Set per-socket contextual data on a WebSocket](https://bun.sh/guides/websocket/context)
- [Build a publish-subscribe WebSocket server](https://bun.com/guides/websocket/pubsub)
- [Build a simple WebSocket server](https://bun.com/guides/websocket/simple)
- [Enable compression for WebSocket messages](https://bun.com/guides/websocket/compression)
- [Set per-socket contextual data on a WebSocket](https://bun.com/guides/websocket/context)
- Write file
- [Delete a file](https://bun.sh/guides/write-file/unlink)
- [Write to stdout](https://bun.sh/guides/write-file/stdout)
- [Write a file to stdout](https://bun.sh/guides/write-file/cat)
- [Write a Blob to a file](https://bun.sh/guides/write-file/blob)
- [Write a string to a file](https://bun.sh/guides/write-file/basic)
- [Append content to a file](https://bun.sh/guides/write-file/append)
- [Write a file incrementally](https://bun.sh/guides/write-file/filesink)
- [Write a Response to a file](https://bun.sh/guides/write-file/response)
- [Copy a file to another location](https://bun.sh/guides/write-file/file-cp)
- [Write a ReadableStream to a file](https://bun.sh/guides/write-file/stream)
- [Delete a file](https://bun.com/guides/write-file/unlink)
- [Write to stdout](https://bun.com/guides/write-file/stdout)
- [Write a file to stdout](https://bun.com/guides/write-file/cat)
- [Write a Blob to a file](https://bun.com/guides/write-file/blob)
- [Write a string to a file](https://bun.com/guides/write-file/basic)
- [Append content to a file](https://bun.com/guides/write-file/append)
- [Write a file incrementally](https://bun.com/guides/write-file/filesink)
- [Write a Response to a file](https://bun.com/guides/write-file/response)
- [Copy a file to another location](https://bun.com/guides/write-file/file-cp)
- [Write a ReadableStream to a file](https://bun.com/guides/write-file/stream)
## Contributing
Refer to the [Project > Contributing](https://bun.sh/docs/project/contributing) guide to start contributing to Bun.
Refer to the [Project > Contributing](https://bun.com/docs/project/contributing) guide to start contributing to Bun.
## License
Refer to the [Project > License](https://bun.sh/docs/project/licensing) page for information about Bun's licensing.
Refer to the [Project > License](https://bun.com/docs/project/licensing) page for information about Bun's licensing.

View File

@@ -8,5 +8,4 @@
## Reporting a Vulnerability
Report any discovered vulnerabilities to the Bun team by emailing `security@bun.sh`. Your report will acknowledged within 5 days, and a team member will be assigned as the primary handler. To the greatest extent possible, the security team will endeavor to keep you informed of the progress being made towards a fix and full announcement, and may ask for additional information or guidance surrounding the reported issue.
Report any discovered vulnerabilities to the Bun team by emailing `security@bun.com`. Your report will acknowledged within 5 days, and a team member will be assigned as the primary handler. To the greatest extent possible, the security team will endeavor to keep you informed of the progress being made towards a fix and full announcement, and may ask for additional information or guidance surrounding the reported issue.

View File

@@ -40,4 +40,4 @@ vitest (node v18.11.0)
> expect().toEqual() x 10000: 401.08ms
This project was created using `bun init` in bun v0.3.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
This project was created using `bun init` in bun v0.3.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

Binary file not shown.

View File

@@ -28,9 +28,7 @@ if (+(existingUsers?.[0]?.count ?? existingUsers?.count) < 100) {
}));
// Insert all users
await sql`
INSERT INTO users_bun_bench (first_name, last_name, email, dob) ${sql(users)}
`;
await sql`INSERT INTO users_bun_bench ${sql(users)}`;
}
const type = isBun ? "Bun.sql" : "postgres";

View File

@@ -9,6 +9,6 @@
"typescript": "^5.0.0"
},
"dependencies": {
"postgres": "^3.4.5"
"postgres": "^3.4.7"
}
}

View File

@@ -9,7 +9,7 @@
// To clear your DNS cache on Windows:
// ipconfig /flushdns
//
const url = new URL(process.argv.length > 2 ? process.argv.at(-1) : "https://bun.sh");
const url = new URL(process.argv.length > 2 ? process.argv.at(-1) : "https://bun.com");
const hostname = url.hostname;
const port = url.port ? parseInt(url.port, 10) : url.protocol === "https:" ? 443 : 80;

View File

@@ -50,6 +50,10 @@ bench("murmur64v2 (short)", () => {
Bun.hash.murmur64v2(shortStr);
});
bench("rapidhash (short)", () => {
Bun.hash.rapidhash(shortStr);
});
bench("wyhash (128 KB)", () => {
Bun.hash.wyhash(longStr);
});
@@ -94,4 +98,8 @@ bench("murmur64v2 (128 KB)", () => {
Bun.hash.murmur64v2(longStr);
});
bench("rapidhash (128 KB)", () => {
Bun.hash.rapidhash(longStr);
});
run();

View File

@@ -0,0 +1,28 @@
import { SourceMap } from "node:module";
import { readFileSync } from "node:fs";
import { bench, run } from "../runner.mjs";
const json = JSON.parse(readFileSync(process.argv.at(-1), "utf-8"));
bench("new SourceMap(json)", () => {
return new SourceMap(json);
});
const map = new SourceMap(json);
const toRotate = [];
for (let j = 0; j < 10000; j++) {
if (map.findEntry(0, j).generatedColumn) {
toRotate.push(j);
if (toRotate.length > 5) break;
}
}
let i = 0;
bench("findEntry (match)", () => {
return map.findEntry(0, toRotate[i++ % 3]).generatedColumn;
});
bench("findEntry (no match)", () => {
return map.findEntry(0, 9999).generatedColumn;
});
await run();

View File

@@ -34,4 +34,4 @@ For example, when the client sends `"foo"`, the server sends back `"John: foo"`
The client script waits until it receives all the messages for each client before sending the next batch of messages.
This project was created using `bun init` in bun v0.2.1. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
This project was created using `bun init` in bun v0.2.1. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

View File

@@ -63,6 +63,7 @@ const BunBuildOptions = struct {
/// `./build/codegen` or equivalent
codegen_path: []const u8,
no_llvm: bool,
override_no_export_cpp_apis: bool,
cached_options_module: ?*Module = null,
windows_shim: ?WindowsShim = null,
@@ -95,6 +96,7 @@ const BunBuildOptions = struct {
opts.addOption(bool, "enable_asan", this.enable_asan);
opts.addOption([]const u8, "reported_nodejs_version", b.fmt("{}", .{this.reported_nodejs_version}));
opts.addOption(bool, "zig_self_hosted_backend", this.no_llvm);
opts.addOption(bool, "override_no_export_cpp_apis", this.override_no_export_cpp_apis);
const mod = opts.createModule();
this.cached_options_module = mod;
@@ -206,6 +208,7 @@ pub fn build(b: *Build) !void {
const obj_format = b.option(ObjectFormat, "obj_format", "Output file for object files") orelse .obj;
const no_llvm = b.option(bool, "no_llvm", "Experiment with Zig self hosted backends. No stability guaranteed") orelse false;
const override_no_export_cpp_apis = b.option(bool, "override-no-export-cpp-apis", "Override the default export_cpp_apis logic to disable exports") orelse false;
var build_options = BunBuildOptions{
.target = target,
@@ -217,6 +220,7 @@ pub fn build(b: *Build) !void {
.codegen_path = codegen_path,
.codegen_embed = codegen_embed,
.no_llvm = no_llvm,
.override_no_export_cpp_apis = override_no_export_cpp_apis,
.version = try Version.parse(bun_version),
.canary_revision = canary: {
@@ -386,6 +390,12 @@ pub fn build(b: *Build) !void {
.{ .os = .windows, .arch = .x86_64 },
}, &.{ .Debug, .ReleaseFast });
}
{
const step = b.step("check-windows-debug", "Check for semantic analysis errors on Windows");
addMultiCheck(b, step, build_options, &.{
.{ .os = .windows, .arch = .x86_64 },
}, &.{.Debug});
}
{
const step = b.step("check-macos", "Check for semantic analysis errors on Windows");
addMultiCheck(b, step, build_options, &.{
@@ -393,6 +403,13 @@ pub fn build(b: *Build) !void {
.{ .os = .mac, .arch = .aarch64 },
}, &.{ .Debug, .ReleaseFast });
}
{
const step = b.step("check-macos-debug", "Check for semantic analysis errors on Windows");
addMultiCheck(b, step, build_options, &.{
.{ .os = .mac, .arch = .x86_64 },
.{ .os = .mac, .arch = .aarch64 },
}, &.{.Debug});
}
{
const step = b.step("check-linux", "Check for semantic analysis errors on Windows");
addMultiCheck(b, step, build_options, &.{
@@ -400,6 +417,13 @@ pub fn build(b: *Build) !void {
.{ .os = .linux, .arch = .aarch64 },
}, &.{ .Debug, .ReleaseFast });
}
{
const step = b.step("check-linux-debug", "Check for semantic analysis errors on Windows");
addMultiCheck(b, step, build_options, &.{
.{ .os = .linux, .arch = .x86_64 },
.{ .os = .linux, .arch = .aarch64 },
}, &.{.Debug});
}
// zig build translate-c-headers
{
@@ -476,6 +500,7 @@ fn addMultiCheck(
.codegen_path = root_build_options.codegen_path,
.no_llvm = root_build_options.no_llvm,
.enable_asan = root_build_options.enable_asan,
.override_no_export_cpp_apis = root_build_options.override_no_export_cpp_apis,
};
var obj = addBunObject(b, &options);
@@ -508,6 +533,8 @@ fn getTranslateC(b: *Build, initial_target: std.Build.ResolvedTarget, optimize:
translate_c.defineCMacroRaw(b.fmt("{s}={d}", .{ str, @intFromBool(value) }));
}
translate_c.addIncludePath(b.path("vendor/zstd/lib"));
if (target.result.os.tag == .windows) {
// translate-c is unable to translate the unsuffixed windows functions
// like `SetCurrentDirectory` since they are defined with an odd macro

View File

@@ -4,7 +4,6 @@
"": {
"name": "bun",
"devDependencies": {
"@types/react": "^18.3.3",
"esbuild": "^0.21.4",
"mitata": "^0.1.11",
"peechy": "0.4.34",
@@ -29,13 +28,17 @@
"@types/node": "*",
},
"devDependencies": {
"@types/react": "^19",
"typescript": "^5.0.2",
},
"peerDependencies": {
"@types/react": "^19",
},
},
},
"overrides": {
"bun-types": "workspace:packages/bun-types",
"@types/bun": "workspace:packages/@types/bun",
"bun-types": "workspace:packages/bun-types",
},
"packages": {
"@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.21.5", "", { "os": "aix", "cpu": "ppc64" }, "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ=="],
@@ -88,9 +91,7 @@
"@types/node": ["@types/node@22.15.18", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-v1DKRfUdyW+jJhZNEI1PYy29S2YRxMV5AOO/x/SjKmW0acCIOqmbj6Haf9eHAhsPmrhlHSxEhv/1WszcLWV4cg=="],
"@types/prop-types": ["@types/prop-types@15.7.14", "", {}, "sha512-gNMvNH49DJ7OJYv+KAKn0Xp45p8PLl6zo2YnvDIbTd4J6MER2BmWN49TG7n9LvkyihINxeKW8+3bfS2yDC9dzQ=="],
"@types/react": ["@types/react@18.3.21", "", { "dependencies": { "@types/prop-types": "*", "csstype": "^3.0.2" } }, "sha512-gXLBtmlcRJeT09/sI4PxVwyrku6SaNUj/6cMubjE6T6XdY1fDmBL7r0nX0jbSZPU/Xr0KuwLLZh6aOYY5d91Xw=="],
"@types/react": ["@types/react@19.1.8", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-AwAfQ2Wa5bCx9WP8nZL2uMZWod7J7/JSplxbTmBQ5ms6QpqNYm672H0Vu9ZVKVngQ+ii4R/byguVEUZQyeg44g=="],
"bun-types": ["bun-types@workspace:packages/bun-types"],

View File

@@ -187,13 +187,14 @@ endfunction()
# satisfies_range()
# Description:
# Check if a version satisfies a version range
# Check if a version satisfies a version range or list of ranges
# Arguments:
# version string - The version to check (e.g. "1.2.3")
# range string - The range to check against (e.g. ">=1.2.3")
# range string - The range to check against (e.g. ">=1.2.3" or ">=19.1.0 <20.0.0")
# Multiple space-separated ranges may be supplied; in this case they must all be satisfied
# variable string - The variable to store the result in
function(satisfies_range version range variable)
if(range STREQUAL "ignore")
function(satisfies_range version ranges variable)
if(ranges STREQUAL "ignore")
set(${variable} ON PARENT_SCOPE)
return()
endif()
@@ -206,26 +207,36 @@ function(satisfies_range version range variable)
endif()
set(version ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3})
string(REGEX MATCH "(>=|<=|>|<)?([0-9]+)\\.([0-9]+)\\.([0-9]+)" match "${range}")
if(NOT match)
return()
endif()
set(comparator ${CMAKE_MATCH_1})
set(range ${CMAKE_MATCH_2}.${CMAKE_MATCH_3}.${CMAKE_MATCH_4})
string(REPLACE " " ";" range_list "${ranges}")
set(all_satisfied ON)
if(comparator STREQUAL ">=")
set(comparator VERSION_GREATER_EQUAL)
elseif(comparator STREQUAL ">")
set(comparator VERSION_GREATER)
elseif(comparator STREQUAL "<=")
set(comparator VERSION_LESS_EQUAL)
elseif(comparator STREQUAL "<")
set(comparator VERSION_LESS)
else()
set(comparator VERSION_EQUAL)
endif()
foreach(current_item ${range_list})
string(REGEX MATCH "(>=|<=|>|<)?([0-9]+)\\.([0-9]+)\\.([0-9]+)" match "${current_item}")
if(NOT match)
return()
endif()
set(comparator ${CMAKE_MATCH_1})
set(range ${CMAKE_MATCH_2}.${CMAKE_MATCH_3}.${CMAKE_MATCH_4})
if(version ${comparator} ${range})
if(comparator STREQUAL ">=")
set(comparator VERSION_GREATER_EQUAL)
elseif(comparator STREQUAL ">")
set(comparator VERSION_GREATER)
elseif(comparator STREQUAL "<=")
set(comparator VERSION_LESS_EQUAL)
elseif(comparator STREQUAL "<")
set(comparator VERSION_LESS)
else()
set(comparator VERSION_EQUAL)
endif()
if(NOT version ${comparator} ${range})
set(all_satisfied OFF)
break()
endif()
endforeach()
if(all_satisfied)
set(${variable} ON PARENT_SCOPE)
endif()
endfunction()

View File

@@ -139,10 +139,10 @@ endif()
optionx(REVISION STRING "The git revision of the build" DEFAULT ${DEFAULT_REVISION})
# Used in process.version, process.versions.node, napi, and elsewhere
optionx(NODEJS_VERSION STRING "The version of Node.js to report" DEFAULT "22.6.0")
optionx(NODEJS_VERSION STRING "The version of Node.js to report" DEFAULT "24.3.0")
# Used in process.versions.modules and compared while loading V8 modules
optionx(NODEJS_ABI_VERSION STRING "The ABI version of Node.js to report" DEFAULT "127")
optionx(NODEJS_ABI_VERSION STRING "The ABI version of Node.js to report" DEFAULT "137")
if(APPLE)
set(DEFAULT_STATIC_SQLITE OFF)

View File

@@ -44,6 +44,7 @@
"src/bun.js/bindings/webcrypto/*/*.cpp",
"src/bun.js/bindings/node/*.cpp",
"src/bun.js/bindings/node/crypto/*.cpp",
"src/bun.js/bindings/node/http/*.cpp",
"src/bun.js/bindings/v8/*.cpp",
"src/bun.js/bindings/v8/shim/*.cpp",
"src/bake/*.cpp",
@@ -60,7 +61,9 @@
"packages/bun-usockets/src/internal/*.c",
"packages/bun-usockets/src/crypto/*.c",
"src/bun.js/bindings/uv-posix-polyfills.c",
"src/bun.js/bindings/uv-posix-stubs.c"
"src/bun.js/bindings/uv-posix-stubs.c",
"src/*.c",
"src/bun.js/bindings/node/http/llhttp/*.c"
]
}
]

View File

@@ -0,0 +1,31 @@
# This script prepares Node.js headers for use with Bun
# It removes conflicting OpenSSL and libuv headers since Bun uses BoringSSL and its own libuv
if(NOT DEFINED NODE_INCLUDE_DIR)
message(FATAL_ERROR "NODE_INCLUDE_DIR not defined")
endif()
if(NOT EXISTS "${NODE_INCLUDE_DIR}/node")
message(FATAL_ERROR "Node headers not found at ${NODE_INCLUDE_DIR}/node")
endif()
# Remove OpenSSL headers that conflict with BoringSSL
if(EXISTS "${NODE_INCLUDE_DIR}/node/openssl")
file(REMOVE_RECURSE "${NODE_INCLUDE_DIR}/node/openssl")
message(STATUS "Removed conflicting OpenSSL headers")
endif()
# Remove libuv headers that might conflict
if(EXISTS "${NODE_INCLUDE_DIR}/node/uv")
file(REMOVE_RECURSE "${NODE_INCLUDE_DIR}/node/uv")
message(STATUS "Removed conflicting libuv headers")
endif()
if(EXISTS "${NODE_INCLUDE_DIR}/node/uv.h")
file(REMOVE "${NODE_INCLUDE_DIR}/node/uv.h")
message(STATUS "Removed conflicting uv.h header")
endif()
# Add the node directory to include path for cppgc
# This is needed because cppgc internal headers use relative includes
file(WRITE "${NODE_INCLUDE_DIR}/.node-headers-prepared" "1")

View File

@@ -7,5 +7,9 @@ packages/bun-usockets/src/loop.c
packages/bun-usockets/src/quic.c
packages/bun-usockets/src/socket.c
packages/bun-usockets/src/udp.c
src/asan-config.c
src/bun.js/bindings/node/http/llhttp/api.c
src/bun.js/bindings/node/http/llhttp/http.c
src/bun.js/bindings/node/http/llhttp/llhttp.c
src/bun.js/bindings/uv-posix-polyfills.c
src/bun.js/bindings/uv-posix-stubs.c

View File

@@ -28,6 +28,7 @@ src/bun.js/bindings/BunWorkerGlobalScope.cpp
src/bun.js/bindings/c-bindings.cpp
src/bun.js/bindings/CallSite.cpp
src/bun.js/bindings/CallSitePrototype.cpp
src/bun.js/bindings/CatchScopeBinding.cpp
src/bun.js/bindings/CodeCoverage.cpp
src/bun.js/bindings/ConsoleObject.cpp
src/bun.js/bindings/Cookie.cpp
@@ -99,6 +100,9 @@ src/bun.js/bindings/napi_finalizer.cpp
src/bun.js/bindings/napi_handle_scope.cpp
src/bun.js/bindings/napi_type_tag.cpp
src/bun.js/bindings/napi.cpp
src/bun.js/bindings/NapiClass.cpp
src/bun.js/bindings/NapiRef.cpp
src/bun.js/bindings/NapiWeakValue.cpp
src/bun.js/bindings/ncrpyto_engine.cpp
src/bun.js/bindings/ncrypto.cpp
src/bun.js/bindings/node/crypto/CryptoDhJob.cpp
@@ -144,6 +148,13 @@ src/bun.js/bindings/node/crypto/JSSign.cpp
src/bun.js/bindings/node/crypto/JSVerify.cpp
src/bun.js/bindings/node/crypto/KeyObject.cpp
src/bun.js/bindings/node/crypto/node_crypto_binding.cpp
src/bun.js/bindings/node/http/JSConnectionsList.cpp
src/bun.js/bindings/node/http/JSConnectionsListConstructor.cpp
src/bun.js/bindings/node/http/JSConnectionsListPrototype.cpp
src/bun.js/bindings/node/http/JSHTTPParser.cpp
src/bun.js/bindings/node/http/JSHTTPParserConstructor.cpp
src/bun.js/bindings/node/http/JSHTTPParserPrototype.cpp
src/bun.js/bindings/node/http/NodeHTTPParser.cpp
src/bun.js/bindings/node/NodeTimers.cpp
src/bun.js/bindings/NodeAsyncHooks.cpp
src/bun.js/bindings/NodeDirent.cpp
@@ -159,6 +170,7 @@ src/bun.js/bindings/NodeVM.cpp
src/bun.js/bindings/NodeVMModule.cpp
src/bun.js/bindings/NodeVMScript.cpp
src/bun.js/bindings/NodeVMSourceTextModule.cpp
src/bun.js/bindings/NodeVMSyntheticModule.cpp
src/bun.js/bindings/NoOpForTesting.cpp
src/bun.js/bindings/ObjectBindings.cpp
src/bun.js/bindings/objects.cpp
@@ -167,6 +179,7 @@ src/bun.js/bindings/Path.cpp
src/bun.js/bindings/ProcessBindingBuffer.cpp
src/bun.js/bindings/ProcessBindingConstants.cpp
src/bun.js/bindings/ProcessBindingFs.cpp
src/bun.js/bindings/ProcessBindingHTTPParser.cpp
src/bun.js/bindings/ProcessBindingNatives.cpp
src/bun.js/bindings/ProcessBindingTTYWrap.cpp
src/bun.js/bindings/ProcessBindingUV.cpp

View File

@@ -10,6 +10,7 @@ src/codegen/class-definitions.ts
src/codegen/client-js.ts
src/codegen/create-hash-table.ts
src/codegen/generate-classes.ts
src/codegen/generate-compact-string-table.ts
src/codegen/generate-js2native.ts
src/codegen/generate-jssink.ts
src/codegen/generate-node-errors.ts

View File

@@ -52,6 +52,7 @@ src/js/internal/debugger.ts
src/js/internal/errors.ts
src/js/internal/fifo.ts
src/js/internal/fixed_queue.ts
src/js/internal/freelist.ts
src/js/internal/fs/cp-sync.ts
src/js/internal/fs/cp.ts
src/js/internal/fs/glob.ts

View File

@@ -7,12 +7,14 @@ src/bun.js/api/h2.classes.ts
src/bun.js/api/html_rewriter.classes.ts
src/bun.js/api/JSBundler.classes.ts
src/bun.js/api/postgres.classes.ts
src/bun.js/api/ResumableSink.classes.ts
src/bun.js/api/S3Client.classes.ts
src/bun.js/api/S3Stat.classes.ts
src/bun.js/api/server.classes.ts
src/bun.js/api/Shell.classes.ts
src/bun.js/api/ShellArgs.classes.ts
src/bun.js/api/sockets.classes.ts
src/bun.js/api/sourcemap.classes.ts
src/bun.js/api/streams.classes.ts
src/bun.js/api/valkey.classes.ts
src/bun.js/api/zlib.classes.ts

View File

@@ -10,7 +10,26 @@ src/allocators/NullableAllocator.zig
src/analytics/analytics_schema.zig
src/analytics/analytics_thread.zig
src/api/schema.zig
src/ast/Ast.zig
src/ast/ASTMemoryAllocator.zig
src/ast/B.zig
src/ast/base.zig
src/ast/Binding.zig
src/ast/BundledAst.zig
src/ast/CharFreq.zig
src/ast/E.zig
src/ast/Expr.zig
src/ast/G.zig
src/ast/Macro.zig
src/ast/NewStore.zig
src/ast/Op.zig
src/ast/S.zig
src/ast/Scope.zig
src/ast/ServerComponentBoundary.zig
src/ast/Stmt.zig
src/ast/Symbol.zig
src/ast/TS.zig
src/ast/UseDirective.zig
src/async/posix_event_loop.zig
src/async/stub_event_loop.zig
src/async/windows_event_loop.zig
@@ -32,7 +51,11 @@ src/bun.js/api/bun/h2_frame_parser.zig
src/bun.js/api/bun/lshpack.zig
src/bun.js/api/bun/process.zig
src/bun.js/api/bun/socket.zig
src/bun.js/api/bun/socket/Handlers.zig
src/bun.js/api/bun/socket/Listener.zig
src/bun.js/api/bun/socket/SocketAddress.zig
src/bun.js/api/bun/socket/tls_socket_functions.zig
src/bun.js/api/bun/socket/WindowsNamedPipeContext.zig
src/bun.js/api/bun/spawn.zig
src/bun.js/api/bun/spawn/stdio.zig
src/bun.js/api/bun/ssl_wrapper.zig
@@ -55,13 +78,24 @@ src/bun.js/api/html_rewriter.zig
src/bun.js/api/JSBundler.zig
src/bun.js/api/JSTranspiler.zig
src/bun.js/api/server.zig
src/bun.js/api/server/AnyRequestContext.zig
src/bun.js/api/server/FileRoute.zig
src/bun.js/api/server/HTMLBundle.zig
src/bun.js/api/server/HTTPStatusText.zig
src/bun.js/api/server/InspectorBunFrontendDevServerAgent.zig
src/bun.js/api/server/NodeHTTPResponse.zig
src/bun.js/api/server/RequestContext.zig
src/bun.js/api/server/ServerConfig.zig
src/bun.js/api/server/ServerWebSocket.zig
src/bun.js/api/server/SSLConfig.zig
src/bun.js/api/server/StaticRoute.zig
src/bun.js/api/server/WebSocketServerContext.zig
src/bun.js/api/streams.classes.zig
src/bun.js/api/Timer.zig
src/bun.js/api/Timer/EventLoopTimer.zig
src/bun.js/api/Timer/ImmediateObject.zig
src/bun.js/api/Timer/TimeoutObject.zig
src/bun.js/api/Timer/TimerObjectInternals.zig
src/bun.js/api/TOMLObject.zig
src/bun.js/api/UnsafeObject.zig
src/bun.js/bindgen_test.zig
@@ -70,6 +104,7 @@ src/bun.js/bindings/AnyPromise.zig
src/bun.js/bindings/bun-simdutf.zig
src/bun.js/bindings/CachedBytecode.zig
src/bun.js/bindings/CallFrame.zig
src/bun.js/bindings/CatchScope.zig
src/bun.js/bindings/codegen.zig
src/bun.js/bindings/CommonAbortReason.zig
src/bun.js/bindings/CommonStrings.zig
@@ -105,6 +140,7 @@ src/bun.js/bindings/JSPropertyIterator.zig
src/bun.js/bindings/JSRef.zig
src/bun.js/bindings/JSRuntimeType.zig
src/bun.js/bindings/JSString.zig
src/bun.js/bindings/JSType.zig
src/bun.js/bindings/JSUint8Array.zig
src/bun.js/bindings/JSValue.zig
src/bun.js/bindings/NodeModuleModule.zig
@@ -133,6 +169,21 @@ src/bun.js/ConsoleObject.zig
src/bun.js/Counters.zig
src/bun.js/Debugger.zig
src/bun.js/event_loop.zig
src/bun.js/event_loop/AnyEventLoop.zig
src/bun.js/event_loop/AnyTask.zig
src/bun.js/event_loop/AnyTaskWithExtraContext.zig
src/bun.js/event_loop/ConcurrentPromiseTask.zig
src/bun.js/event_loop/ConcurrentTask.zig
src/bun.js/event_loop/CppTask.zig
src/bun.js/event_loop/DeferredTaskQueue.zig
src/bun.js/event_loop/EventLoopHandle.zig
src/bun.js/event_loop/GarbageCollectionController.zig
src/bun.js/event_loop/JSCScheduler.zig
src/bun.js/event_loop/ManagedTask.zig
src/bun.js/event_loop/MiniEventLoop.zig
src/bun.js/event_loop/PosixSignalHandle.zig
src/bun.js/event_loop/Task.zig
src/bun.js/event_loop/WorkTask.zig
src/bun.js/hot_reloader.zig
src/bun.js/ipc.zig
src/bun.js/javascript_core_c_api.zig
@@ -176,6 +227,9 @@ src/bun.js/node/util/parse_args_utils.zig
src/bun.js/node/util/parse_args.zig
src/bun.js/node/util/validators.zig
src/bun.js/node/win_watcher.zig
src/bun.js/node/zlib/NativeBrotli.zig
src/bun.js/node/zlib/NativeZlib.zig
src/bun.js/node/zlib/NativeZstd.zig
src/bun.js/ProcessAutoKiller.zig
src/bun.js/rare_data.zig
src/bun.js/ResolveMessage.zig
@@ -217,6 +271,7 @@ src/bun.js/webcore/prompt.zig
src/bun.js/webcore/ReadableStream.zig
src/bun.js/webcore/Request.zig
src/bun.js/webcore/Response.zig
src/bun.js/webcore/ResumableSink.zig
src/bun.js/webcore/S3Client.zig
src/bun.js/webcore/S3File.zig
src/bun.js/webcore/S3Stat.zig
@@ -228,14 +283,47 @@ src/bun.js/webcore/TextEncoder.zig
src/bun.js/webcore/TextEncoderStreamEncoder.zig
src/bun.js/WTFTimer.zig
src/bun.zig
src/bundler/AstBuilder.zig
src/bundler/bundle_v2.zig
src/bundler/BundleThread.zig
src/bundler/Chunk.zig
src/bundler/DeferredBatchTask.zig
src/bundler/entry_points.zig
src/bundler/Graph.zig
src/bundler/HTMLImportManifest.zig
src/bundler/linker_context/computeChunks.zig
src/bundler/linker_context/computeCrossChunkDependencies.zig
src/bundler/linker_context/convertStmtsForChunk.zig
src/bundler/linker_context/convertStmtsForChunkForDevServer.zig
src/bundler/linker_context/doStep5.zig
src/bundler/linker_context/findAllImportedPartsInJSOrder.zig
src/bundler/linker_context/findImportedCSSFilesInJSOrder.zig
src/bundler/linker_context/findImportedFilesInCSSOrder.zig
src/bundler/linker_context/generateChunksInParallel.zig
src/bundler/linker_context/generateCodeForFileInChunkJS.zig
src/bundler/linker_context/generateCodeForLazyExport.zig
src/bundler/linker_context/generateCompileResultForCssChunk.zig
src/bundler/linker_context/generateCompileResultForHtmlChunk.zig
src/bundler/linker_context/generateCompileResultForJSChunk.zig
src/bundler/linker_context/postProcessCSSChunk.zig
src/bundler/linker_context/postProcessHTMLChunk.zig
src/bundler/linker_context/postProcessJSChunk.zig
src/bundler/linker_context/prepareCssAstsForChunk.zig
src/bundler/linker_context/renameSymbolsInChunk.zig
src/bundler/linker_context/scanImportsAndExports.zig
src/bundler/linker_context/writeOutputFilesToDisk.zig
src/bundler/LinkerContext.zig
src/bundler/LinkerGraph.zig
src/bundler/ParseTask.zig
src/bundler/ServerComponentParseTask.zig
src/bundler/ThreadPool.zig
src/bunfig.zig
src/cache.zig
src/ci_info.zig
src/cli.zig
src/cli/add_command.zig
src/cli/add_completions.zig
src/cli/Arguments.zig
src/cli/audit_command.zig
src/cli/build_command.zig
src/cli/bunx_command.zig
@@ -255,8 +343,11 @@ src/cli/pack_command.zig
src/cli/package_manager_command.zig
src/cli/patch_command.zig
src/cli/patch_commit_command.zig
src/cli/pm_pkg_command.zig
src/cli/pm_trusted_command.zig
src/cli/pm_version_command.zig
src/cli/pm_view_command.zig
src/cli/pm_why_command.zig
src/cli/publish_command.zig
src/cli/remove_command.zig
src/cli/run_command.zig
@@ -266,6 +357,7 @@ src/cli/test/Scanner.zig
src/cli/unlink_command.zig
src/cli/update_command.zig
src/cli/upgrade_command.zig
src/cli/why_command.zig
src/codegen/process_windows_translate_c.zig
src/compile_target.zig
src/comptime_string_map.zig
@@ -384,7 +476,22 @@ src/deps/picohttp.zig
src/deps/picohttpparser.zig
src/deps/tcc.zig
src/deps/uws.zig
src/deps/uws/App.zig
src/deps/uws/BodyReaderMixin.zig
src/deps/uws/ConnectingSocket.zig
src/deps/uws/InternalLoopData.zig
src/deps/uws/ListenSocket.zig
src/deps/uws/Loop.zig
src/deps/uws/Request.zig
src/deps/uws/Response.zig
src/deps/uws/socket.zig
src/deps/uws/SocketContext.zig
src/deps/uws/Timer.zig
src/deps/uws/udp.zig
src/deps/uws/UpgradedDuplex.zig
src/deps/uws/us_socket_t.zig
src/deps/uws/WebSocket.zig
src/deps/uws/WindowsNamedPipe.zig
src/deps/zig-clap/clap.zig
src/deps/zig-clap/clap/args.zig
src/deps/zig-clap/clap/comptime.zig
@@ -405,7 +512,7 @@ src/fd.zig
src/feature_flags.zig
src/fmt.zig
src/fs.zig
src/futex.zig
src/fs/stat_hash.zig
src/generated_perf_trace_events.zig
src/generated_versions_list.zig
src/glob.zig
@@ -419,12 +526,30 @@ src/hive_array.zig
src/hmac.zig
src/HTMLScanner.zig
src/http.zig
src/http/header_builder.zig
src/http/method.zig
src/http/mime_type.zig
src/http/url_path.zig
src/http/AsyncHTTP.zig
src/http/CertificateInfo.zig
src/http/Decompressor.zig
src/http/Encoding.zig
src/http/FetchRedirect.zig
src/http/HeaderBuilder.zig
src/http/Headers.zig
src/http/HTTPCertError.zig
src/http/HTTPContext.zig
src/http/HTTPRequestBody.zig
src/http/HTTPThread.zig
src/http/InitError.zig
src/http/InternalState.zig
src/http/Method.zig
src/http/mime_type_list_enum.zig
src/http/MimeType.zig
src/http/ProxyTunnel.zig
src/http/SendFile.zig
src/http/Signals.zig
src/http/ThreadSafeStreamBuffer.zig
src/http/URLPath.zig
src/http/websocket_client.zig
src/http/websocket_client/CppWebSocket.zig
src/http/websocket_client/WebSocketDeflate.zig
src/http/websocket_client/WebSocketUpgradeClient.zig
src/http/websocket_http_client.zig
src/http/websocket.zig
@@ -434,9 +559,17 @@ src/import_record.zig
src/ini.zig
src/install/bin.zig
src/install/dependency.zig
src/install/ExternalSlice.zig
src/install/extract_tarball.zig
src/install/hoisted_install.zig
src/install/install_binding.zig
src/install/install.zig
src/install/integrity.zig
src/install/isolated_install.zig
src/install/isolated_install/Hardlinker.zig
src/install/isolated_install/Installer.zig
src/install/isolated_install/Store.zig
src/install/isolated_install/Symlinker.zig
src/install/lifecycle_script_runner.zig
src/install/lockfile.zig
src/install/lockfile/Buffers.zig
@@ -453,10 +586,28 @@ src/install/lockfile/printer/tree_printer.zig
src/install/lockfile/printer/Yarn.zig
src/install/lockfile/Tree.zig
src/install/migration.zig
src/install/NetworkTask.zig
src/install/npm.zig
src/install/PackageInstall.zig
src/install/PackageInstaller.zig
src/install/PackageManager.zig
src/install/PackageManager/CommandLineArguments.zig
src/install/PackageManager/install_with_manager.zig
src/install/PackageManager/PackageJSONEditor.zig
src/install/PackageManager/PackageManagerDirectories.zig
src/install/PackageManager/PackageManagerEnqueue.zig
src/install/PackageManager/PackageManagerLifecycle.zig
src/install/PackageManager/PackageManagerOptions.zig
src/install/PackageManager/PackageManagerResolution.zig
src/install/PackageManager/patchPackage.zig
src/install/PackageManager/processDependencyList.zig
src/install/PackageManager/ProgressStrings.zig
src/install/PackageManager/runTasks.zig
src/install/PackageManager/updatePackageJSONAndInstall.zig
src/install/PackageManager/UpdateRequest.zig
src/install/PackageManager/WorkspacePackageJSONCache.zig
src/install/PackageManagerTask.zig
src/install/PackageManifestMap.zig
src/install/padding_checker.zig
src/install/patch_install.zig
src/install/repository.zig
@@ -468,11 +619,11 @@ src/install/windows-shim/bun_shim_impl.zig
src/io/heap.zig
src/io/io.zig
src/io/MaxBuf.zig
src/io/openForWriting.zig
src/io/PipeReader.zig
src/io/pipes.zig
src/io/PipeWriter.zig
src/io/source.zig
src/io/time.zig
src/js_ast.zig
src/js_lexer_tables.zig
src/js_lexer.zig
@@ -493,7 +644,6 @@ src/main_wasm.zig
src/main.zig
src/meta.zig
src/multi_array_list.zig
src/Mutex.zig
src/napi/napi.zig
src/node_fallbacks.zig
src/open.zig
@@ -501,6 +651,11 @@ src/options.zig
src/output.zig
src/OutputFile.zig
src/patch.zig
src/paths.zig
src/paths/EnvPath.zig
src/paths/path_buffer_pool.zig
src/paths/Path.zig
src/pe.zig
src/perf.zig
src/pool.zig
src/Progress.zig
@@ -539,6 +694,7 @@ src/semver/SemverString.zig
src/semver/SlicedString.zig
src/semver/Version.zig
src/sha.zig
src/shell/AllocScope.zig
src/shell/braces.zig
src/shell/Builtin.zig
src/shell/builtin/basename.zig
@@ -563,31 +719,118 @@ src/shell/builtin/yes.zig
src/shell/EnvMap.zig
src/shell/EnvStr.zig
src/shell/interpreter.zig
src/shell/IO.zig
src/shell/IOReader.zig
src/shell/IOWriter.zig
src/shell/ParsedShellScript.zig
src/shell/RefCountedStr.zig
src/shell/shell.zig
src/shell/states/Assigns.zig
src/shell/states/Async.zig
src/shell/states/Base.zig
src/shell/states/Binary.zig
src/shell/states/Cmd.zig
src/shell/states/CondExpr.zig
src/shell/states/Expansion.zig
src/shell/states/If.zig
src/shell/states/Pipeline.zig
src/shell/states/Script.zig
src/shell/states/Stmt.zig
src/shell/states/Subshell.zig
src/shell/subproc.zig
src/shell/util.zig
src/shell/Yield.zig
src/sourcemap/CodeCoverage.zig
src/sourcemap/JSSourceMap.zig
src/sourcemap/LineOffsetTable.zig
src/sourcemap/sourcemap.zig
src/sourcemap/VLQ.zig
src/sql/DataCell.zig
src/sql/postgres.zig
src/sql/postgres/postgres_protocol.zig
src/sql/postgres/postgres_types.zig
src/sql/postgres/AnyPostgresError.zig
src/sql/postgres/AuthenticationState.zig
src/sql/postgres/CommandTag.zig
src/sql/postgres/ConnectionFlags.zig
src/sql/postgres/Data.zig
src/sql/postgres/DataCell.zig
src/sql/postgres/DebugSocketMonitorReader.zig
src/sql/postgres/DebugSocketMonitorWriter.zig
src/sql/postgres/ObjectIterator.zig
src/sql/postgres/PostgresCachedStructure.zig
src/sql/postgres/PostgresProtocol.zig
src/sql/postgres/PostgresRequest.zig
src/sql/postgres/PostgresSQLConnection.zig
src/sql/postgres/PostgresSQLContext.zig
src/sql/postgres/PostgresSQLQuery.zig
src/sql/postgres/PostgresSQLQueryResultMode.zig
src/sql/postgres/PostgresSQLStatement.zig
src/sql/postgres/PostgresTypes.zig
src/sql/postgres/protocol/ArrayList.zig
src/sql/postgres/protocol/Authentication.zig
src/sql/postgres/protocol/BackendKeyData.zig
src/sql/postgres/protocol/Close.zig
src/sql/postgres/protocol/ColumnIdentifier.zig
src/sql/postgres/protocol/CommandComplete.zig
src/sql/postgres/protocol/CopyData.zig
src/sql/postgres/protocol/CopyFail.zig
src/sql/postgres/protocol/CopyInResponse.zig
src/sql/postgres/protocol/CopyOutResponse.zig
src/sql/postgres/protocol/DataRow.zig
src/sql/postgres/protocol/DecoderWrap.zig
src/sql/postgres/protocol/Describe.zig
src/sql/postgres/protocol/ErrorResponse.zig
src/sql/postgres/protocol/Execute.zig
src/sql/postgres/protocol/FieldDescription.zig
src/sql/postgres/protocol/FieldMessage.zig
src/sql/postgres/protocol/FieldType.zig
src/sql/postgres/protocol/NegotiateProtocolVersion.zig
src/sql/postgres/protocol/NewReader.zig
src/sql/postgres/protocol/NewWriter.zig
src/sql/postgres/protocol/NoticeResponse.zig
src/sql/postgres/protocol/NotificationResponse.zig
src/sql/postgres/protocol/ParameterDescription.zig
src/sql/postgres/protocol/ParameterStatus.zig
src/sql/postgres/protocol/Parse.zig
src/sql/postgres/protocol/PasswordMessage.zig
src/sql/postgres/protocol/PortalOrPreparedStatement.zig
src/sql/postgres/protocol/ReadyForQuery.zig
src/sql/postgres/protocol/RowDescription.zig
src/sql/postgres/protocol/SASLInitialResponse.zig
src/sql/postgres/protocol/SASLResponse.zig
src/sql/postgres/protocol/StackReader.zig
src/sql/postgres/protocol/StartupMessage.zig
src/sql/postgres/protocol/TransactionStatusIndicator.zig
src/sql/postgres/protocol/WriteWrap.zig
src/sql/postgres/protocol/zHelpers.zig
src/sql/postgres/QueryBindingIterator.zig
src/sql/postgres/SASL.zig
src/sql/postgres/Signature.zig
src/sql/postgres/SocketMonitor.zig
src/sql/postgres/SSLMode.zig
src/sql/postgres/Status.zig
src/sql/postgres/TLSStatus.zig
src/sql/postgres/types/bool.zig
src/sql/postgres/types/bytea.zig
src/sql/postgres/types/date.zig
src/sql/postgres/types/int_types.zig
src/sql/postgres/types/json.zig
src/sql/postgres/types/numeric.zig
src/sql/postgres/types/PostgresString.zig
src/sql/postgres/types/Tag.zig
src/StandaloneModuleGraph.zig
src/StaticHashMap.zig
src/string_immutable.zig
src/string_types.zig
src/string.zig
src/string/escapeHTML.zig
src/string/HashedString.zig
src/string/MutableString.zig
src/string/paths.zig
src/string/PathString.zig
src/string/SmolStr.zig
src/string/StringBuilder.zig
src/string/StringJoiner.zig
src/string/unicode.zig
src/string/visible.zig
src/string/WTFStringImpl.zig
src/sync.zig
src/sys_uv.zig
@@ -596,6 +839,10 @@ src/system_timer.zig
src/test/fixtures.zig
src/test/recover.zig
src/thread_pool.zig
src/threading.zig
src/threading/Condition.zig
src/threading/Futex.zig
src/threading/Mutex.zig
src/tmp.zig
src/toml/toml_lexer.zig
src/toml/toml_parser.zig

View File

@@ -42,6 +42,29 @@ else()
set(CONFIGURE_DEPENDS "")
endif()
# --- Dependencies ---
set(BUN_DEPENDENCIES
BoringSSL
Brotli
Cares
Highway
LibDeflate
LolHtml
Lshpack
Mimalloc
TinyCC
Zlib
LibArchive # must be loaded after zlib
HdrHistogram # must be loaded after zlib
Zstd
)
include(CloneZstd)
# foreach(dependency ${BUN_DEPENDENCIES})
# include(Clone${dependency})
# endforeach()
# --- Codegen ---
set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error)
@@ -408,6 +431,7 @@ set(BUN_OBJECT_LUT_SOURCES
${CWD}/src/bun.js/bindings/ProcessBindingConstants.cpp
${CWD}/src/bun.js/bindings/ProcessBindingFs.cpp
${CWD}/src/bun.js/bindings/ProcessBindingNatives.cpp
${CWD}/src/bun.js/bindings/ProcessBindingHTTPParser.cpp
${CWD}/src/bun.js/modules/NodeModuleModule.cpp
${CODEGEN_PATH}/ZigGeneratedClasses.lut.txt
)
@@ -421,6 +445,7 @@ set(BUN_OBJECT_LUT_OUTPUTS
${CODEGEN_PATH}/ProcessBindingConstants.lut.h
${CODEGEN_PATH}/ProcessBindingFs.lut.h
${CODEGEN_PATH}/ProcessBindingNatives.lut.h
${CODEGEN_PATH}/ProcessBindingHTTPParser.lut.h
${CODEGEN_PATH}/NodeModuleModule.lut.h
${CODEGEN_PATH}/ZigGeneratedClasses.lut.h
)
@@ -580,6 +605,7 @@ register_command(
${BUN_ZIG_OUTPUT}
TARGETS
clone-zig
clone-zstd
SOURCES
${BUN_ZIG_SOURCES}
${BUN_ZIG_GENERATED_SOURCES}
@@ -624,8 +650,13 @@ register_command(
-DDOWNLOAD_PATH=${NODEJS_HEADERS_PATH}
-DDOWNLOAD_URL=https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-headers.tar.gz
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
COMMAND
${CMAKE_COMMAND}
-DNODE_INCLUDE_DIR=${NODEJS_HEADERS_PATH}/include
-P ${CWD}/cmake/scripts/PrepareNodeHeaders.cmake
OUTPUTS
${NODEJS_HEADERS_PATH}/include/node/node_version.h
${NODEJS_HEADERS_PATH}/include/.node-headers-prepared
)
list(APPEND BUN_CPP_SOURCES
@@ -647,20 +678,14 @@ if(WIN32)
else()
set(Bun_VERSION_WITH_TAG ${VERSION})
endif()
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
configure_file(${CWD}/src/bun.ico ${CODEGEN_PATH}/bun.ico COPYONLY)
set(BUN_ICO_PATH ${CODEGEN_PATH}/bun.ico)
configure_file(
${CWD}/src/windows-app-info.rc
${CODEGEN_PATH}/windows-app-info.rc
@ONLY
)
add_custom_command(
OUTPUT ${CODEGEN_PATH}/windows-app-info.res
COMMAND rc.exe /fo ${CODEGEN_PATH}/windows-app-info.res ${CODEGEN_PATH}/windows-app-info.rc
DEPENDS ${CODEGEN_PATH}/windows-app-info.rc ${CODEGEN_PATH}/bun.ico
COMMENT "Adding Windows resource file ${CODEGEN_PATH}/windows-app-info.res with ico in ${CODEGEN_PATH}/bun.ico"
)
set(WINDOWS_RESOURCES ${CODEGEN_PATH}/windows-app-info.res)
set(WINDOWS_RESOURCES ${CODEGEN_PATH}/windows-app-info.rc)
endif()
# --- Executable ---
@@ -732,6 +757,7 @@ target_include_directories(${bun} PRIVATE
${CWD}/src/bun.js/bindings/webcore
${CWD}/src/bun.js/bindings/webcrypto
${CWD}/src/bun.js/bindings/node/crypto
${CWD}/src/bun.js/bindings/node/http
${CWD}/src/bun.js/bindings/sqlite
${CWD}/src/bun.js/bindings/v8
${CWD}/src/bun.js/modules
@@ -742,6 +768,7 @@ target_include_directories(${bun} PRIVATE
${VENDOR_PATH}
${VENDOR_PATH}/picohttpparser
${NODEJS_HEADERS_PATH}/include
${NODEJS_HEADERS_PATH}/include/node
)
if(NOT WIN32)
@@ -890,6 +917,9 @@ if(NOT WIN32)
else()
target_compile_options(${bun} PUBLIC
-Wno-nullability-completeness
-Wno-inconsistent-dllimport
-Wno-incompatible-pointer-types
-Wno-deprecated-declarations
)
endif()
@@ -921,14 +951,22 @@ endif()
if(APPLE)
target_link_options(${bun} PUBLIC
-dead_strip
-dead_strip_dylibs
-Wl,-ld_new
-Wl,-no_compact_unwind
-Wl,-stack_size,0x1200000
-fno-keep-static-consts
-Wl,-map,${bun}.linker-map
)
# don't strip in debug, this seems to be needed so that the Zig std library
# `*dbHelper` DWARF symbols (used by LLDB for pretty printing) are in the
# output executable
if(NOT DEBUG)
target_link_options(${bun} PUBLIC
-dead_strip
-dead_strip_dylibs
)
endif()
endif()
if(LINUX)
@@ -965,7 +1003,6 @@ if(LINUX)
-Wl,-no-pie
-Wl,-icf=safe
-Wl,--as-needed
-Wl,--gc-sections
-Wl,-z,stack-size=12800000
-Wl,--compress-debug-sections=zlib
-Wl,-z,lazy
@@ -981,6 +1018,15 @@ if(LINUX)
-Wl,--build-id=sha1 # Better for debugging than default
-Wl,-Map=${bun}.linker-map
)
# don't strip in debug, this seems to be needed so that the Zig std library
# `*dbHelper` DWARF symbols (used by LLDB for pretty printing) are in the
# output executable
if(NOT DEBUG)
target_link_options(${bun} PUBLIC
-Wl,--gc-sections
)
endif()
endif()
# --- Symbols list ---
@@ -1046,22 +1092,6 @@ endif()
# --- Dependencies ---
set(BUN_DEPENDENCIES
BoringSSL
Brotli
Cares
Highway
LibDeflate
LolHtml
Lshpack
Mimalloc
TinyCC
Zlib
LibArchive # must be loaded after zlib
HdrHistogram # must be loaded after zlib
Zstd
)
if(WIN32)
list(APPEND BUN_DEPENDENCIES Libuv)
endif()

View File

@@ -1,12 +1,3 @@
register_repository(
NAME
zstd
REPOSITORY
facebook/zstd
COMMIT
f8745da6ff1ad1e7bab384bd1f9d742439278e99
)
register_cmake_command(
TARGET
zstd
@@ -23,4 +14,6 @@ register_cmake_command(
LIBRARIES
zstd_static WIN32
zstd UNIX
INCLUDES
lib
)

View File

@@ -0,0 +1,8 @@
register_repository(
NAME
zstd
REPOSITORY
facebook/zstd
COMMIT
f8745da6ff1ad1e7bab384bd1f9d742439278e99
)

View File

@@ -72,12 +72,14 @@ macro(find_llvm_command variable command)
)
endif()
math(EXPR LLVM_VERSION_NEXT_MAJOR "${LLVM_VERSION_MAJOR} + 1")
find_command(
VARIABLE ${variable}
VERSION_VARIABLE LLVM_VERSION
COMMAND ${commands}
PATHS ${LLVM_PATHS}
VERSION >=${LLVM_VERSION_MAJOR}.1.0
VERSION ">=${LLVM_VERSION_MAJOR}.1.0 <${LLVM_VERSION_NEXT_MAJOR}.0.0"
)
list(APPEND CMAKE_ARGS -D${variable}=${${variable}})
endmacro()

View File

@@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION b98e20b11e6ab044f73218bdd05ab064587b9ead)
set(WEBKIT_VERSION 1098cc50652ab1eab171f58f7669e19ca6c276ae)
endif()
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)

View File

@@ -20,7 +20,7 @@ else()
unsupported(CMAKE_SYSTEM_NAME)
endif()
set(ZIG_COMMIT "a207204ee57a061f2fb96c7bae0c491b609e73a5")
set(ZIG_COMMIT "0a0120fa92cd7f6ab244865688b351df634f0707")
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
@@ -55,13 +55,13 @@ optionx(ZIG_OBJECT_FORMAT "obj|bc" "Output file format for Zig object files" DEF
optionx(ZIG_LOCAL_CACHE_DIR FILEPATH "The path to local the zig cache directory" DEFAULT ${CACHE_PATH}/zig/local)
optionx(ZIG_GLOBAL_CACHE_DIR FILEPATH "The path to the global zig cache directory" DEFAULT ${CACHE_PATH}/zig/global)
if(CI AND CMAKE_HOST_APPLE)
if(CI)
set(ZIG_COMPILER_SAFE_DEFAULT ON)
else()
set(ZIG_COMPILER_SAFE_DEFAULT OFF)
endif()
optionx(ZIG_COMPILER_SAFE BOOL "Download a ReleaseSafe build of the Zig compiler. Only availble on macos aarch64." DEFAULT ${ZIG_COMPILER_SAFE_DEFAULT})
optionx(ZIG_COMPILER_SAFE BOOL "Download a ReleaseSafe build of the Zig compiler." DEFAULT ${ZIG_COMPILER_SAFE_DEFAULT})
setenv(ZIG_LOCAL_CACHE_DIR ${ZIG_LOCAL_CACHE_DIR})
setenv(ZIG_GLOBAL_CACHE_DIR ${ZIG_GLOBAL_CACHE_DIR})

View File

@@ -260,8 +260,8 @@ _bun_pm_completion() {
'hash\:"generate & print the hash of the current lockfile" '
'hash-string\:"print the string used to hash the lockfile" '
'hash-print\:"print the hash stored in the current lockfile" '
'audit\:"run a security audit of dependencies in Bun'\''s lockfile"'
'cache\:"print the path to the cache folder" '
'version\:"bump the version in package.json and create a git tag" '
)
_alternative "args:cmd3:(($sub_commands))"
@@ -300,6 +300,40 @@ _bun_pm_completion() {
$pmargs &&
ret=0
;;
version)
version_args=(
"patch[increment patch version]"
"minor[increment minor version]"
"major[increment major version]"
"prepatch[increment patch version and add pre-release]"
"preminor[increment minor version and add pre-release]"
"premajor[increment major version and add pre-release]"
"prerelease[increment pre-release version]"
"from-git[use version from latest git tag]"
)
pmargs=(
"--no-git-tag-version[don't create a git commit and tag]"
"--allow-same-version[allow bumping to the same version]"
"-m[use the given message for the commit]:message"
"--message[use the given message for the commit]:message"
"--preid[identifier to prefix pre-release versions]:preid"
)
_arguments -s -C \
'1: :->cmd' \
'2: :->cmd2' \
'3: :->increment' \
$pmargs &&
ret=0
case $state in
increment)
_alternative "args:increment:(($version_args))"
;;
esac
;;
esac
@@ -540,6 +574,7 @@ _bun_update_completion() {
'--save[Save to package.json]' \
'--dry-run[Don'"'"'t install anything]' \
'--frozen-lockfile[Disallow changes to lockfile]' \
'--latest[Updates dependencies to latest version, regardless of compatibility]' \
'-f[Always request the latest versions from the registry & reinstall all dependencies]' \
'--force[Always request the latest versions from the registry & reinstall all dependencies]' \
'--cache-dir[Store & load cached data from a specific directory path]:cache-dir' \
@@ -573,7 +608,7 @@ _bun_outdated_completion() {
'--no-progress[Disable the progress bar]' \
'--help[Print this help menu]' &&
ret=0
case $state in
config)
_bun_list_bunfig_toml

View File

@@ -522,7 +522,7 @@ for await (const chunk of stream) {
}
```
For a more complete discussion of streams in Bun, see [API > Streams](https://bun.sh/docs/api/streams).
For a more complete discussion of streams in Bun, see [API > Streams](https://bun.com/docs/api/streams).
## Conversion

View File

@@ -2,7 +2,7 @@
## Usage (cc in `bun:ffi`)
See the [introduction blog post](https://bun.sh/blog/compile-and-run-c-in-js) for more information.
See the [introduction blog post](https://bun.com/blog/compile-and-run-c-in-js) for more information.
JavaScript:

View File

@@ -2,6 +2,25 @@
**Note** — Bun provides a browser- and Node.js-compatible [console](https://developer.mozilla.org/en-US/docs/Web/API/console) global. This page only documents Bun-native APIs.
{% /callout %}
## Object inspection depth
Bun allows you to configure how deeply nested objects are displayed in `console.log()` output:
- **CLI flag**: Use `--console-depth <number>` to set the depth for a single run
- **Configuration**: Set `console.depth` in your `bunfig.toml` for persistent configuration
- **Default**: Objects are inspected to a depth of `2` levels
```js
const nested = { a: { b: { c: { d: "deep" } } } };
console.log(nested);
// Default (depth 2): { a: { b: [Object] } }
// With depth 4: { a: { b: { c: { d: 'deep' } } } }
```
The CLI flag takes precedence over the configuration file setting.
## Reading from stdin
In Bun, the `console` object can be used as an `AsyncIterable` to sequentially read lines from `process.stdin`.
```ts

View File

@@ -3,7 +3,7 @@ Bun implements the `node:dns` module.
```ts
import * as dns from "node:dns";
const addrs = await dns.promises.resolve4("bun.sh", { ttl: true });
const addrs = await dns.promises.resolve4("bun.com", { ttl: true });
console.log(addrs);
// => [{ address: "172.67.161.226", family: 4, ttl: 0 }, ...]
```
@@ -54,10 +54,10 @@ Here's an example:
```ts
import { dns } from "bun";
dns.prefetch("bun.sh", 443);
dns.prefetch("bun.com", 443);
//
// ... sometime later ...
await fetch("https://bun.sh");
await fetch("https://bun.com");
```
### `dns.getCacheStats()`

View File

@@ -267,7 +267,7 @@ const response = await fetch("s3://my-bucket/path/to/object", {
Note: Only PUT and POST methods support request bodies when using S3. For uploads, Bun automatically uses multipart upload for streaming bodies.
You can read more about Bun's S3 support in the [S3](https://bun.sh/docs/api/s3) documentation.
You can read more about Bun's S3 support in the [S3](https://bun.com/docs/api/s3) documentation.
#### File URLs - `file://`
@@ -376,14 +376,14 @@ To prefetch a DNS entry, you can use the `dns.prefetch` API. This API is useful
```ts
import { dns } from "bun";
dns.prefetch("bun.sh");
dns.prefetch("bun.com");
```
#### DNS caching
By default, Bun caches and deduplicates DNS queries in-memory for up to 30 seconds. You can see the cache stats by calling `dns.getCacheStats()`:
To learn more about DNS caching in Bun, see the [DNS caching](https://bun.sh/docs/api/dns) documentation.
To learn more about DNS caching in Bun, see the [DNS caching](https://bun.com/docs/api/dns) documentation.
### Preconnect to a host
@@ -392,7 +392,7 @@ To preconnect to a host, you can use the `fetch.preconnect` API. This API is use
```ts
import { fetch } from "bun";
fetch.preconnect("https://bun.sh");
fetch.preconnect("https://bun.com");
```
Note: calling `fetch` immediately after `fetch.preconnect` will not make your request faster. Preconnecting only helps if you know you'll need to connect to a host soon, but you're not ready to make the request yet.
@@ -402,7 +402,7 @@ Note: calling `fetch` immediately after `fetch.preconnect` will not make your re
To preconnect to a host at startup, you can pass `--fetch-preconnect`:
```sh
$ bun --fetch-preconnect https://bun.sh ./my-script.ts
$ bun --fetch-preconnect https://bun.com ./my-script.ts
```
This is sort of like `<link rel="preconnect">` in HTML.

View File

@@ -1,8 +1,8 @@
{% callout %}
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](https://bun.sh/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](https://bun.com/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir` or `readdir`, you can use Bun's [nearly complete](https://bun.sh/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir` or `readdir`, you can use Bun's [nearly complete](https://bun.com/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
{% /callout %}
@@ -208,7 +208,7 @@ await Bun.write(Bun.stdout, input);
To write the body of an HTTP response to disk:
```ts
const response = await fetch("https://bun.sh");
const response = await fetch("https://bun.com");
await Bun.write("index.html", response);
```

View File

@@ -34,7 +34,7 @@ Bun implements the following globals.
- [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer)
- Node.js
- See [Node.js > `Buffer`](https://bun.sh/docs/runtime/nodejs-apis#node-buffer)
- See [Node.js > `Buffer`](https://bun.com/docs/runtime/nodejs-apis#node-buffer)
---
@@ -172,7 +172,7 @@ Bun implements the following globals.
- [`global`](https://nodejs.org/api/globals.html#global)
- Node.js
- See [Node.js > `global`](https://bun.sh/docs/runtime/nodejs-apis#global).
- See [Node.js > `global`](https://bun.com/docs/runtime/nodejs-apis#global).
---
@@ -188,7 +188,7 @@ Bun implements the following globals.
---
- [`HTMLRewriter`](https://bun.sh/docs/api/html-rewriter)
- [`HTMLRewriter`](https://bun.com/docs/api/html-rewriter)
- Cloudflare
- &nbsp;
@@ -220,7 +220,7 @@ Bun implements the following globals.
- [`process`](https://nodejs.org/api/process.html)
- Node.js
- See [Node.js > `process`](https://bun.sh/docs/runtime/nodejs-apis#node-process)
- See [Node.js > `process`](https://bun.com/docs/runtime/nodejs-apis#node-process)
---

View File

@@ -175,6 +175,7 @@ Bun.hash.xxHash3("data", 1234);
Bun.hash.murmur32v3("data", 1234);
Bun.hash.murmur32v2("data", 1234);
Bun.hash.murmur64v2("data", 1234);
Bun.hash.rapidhash("data", 1234);
```
## `Bun.CryptoHasher`

View File

@@ -1,7 +1,7 @@
The page primarily documents the Bun-native `Bun.serve` API. Bun also implements [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and the Node.js [`http`](https://nodejs.org/api/http.html) and [`https`](https://nodejs.org/api/https.html) modules.
{% callout %}
These modules have been re-implemented to use Bun's fast internal HTTP infrastructure. Feel free to use these modules directly; frameworks like [Express](https://expressjs.com/) that depend on these modules should work out of the box. For granular compatibility information, see [Runtime > Node.js APIs](https://bun.sh/docs/runtime/nodejs-apis).
These modules have been re-implemented to use Bun's fast internal HTTP infrastructure. Feel free to use these modules directly; frameworks like [Express](https://expressjs.com/) that depend on these modules should work out of the box. For granular compatibility information, see [Runtime > Node.js APIs](https://bun.com/docs/runtime/nodejs-apis).
{% /callout %}
To start a high-performance HTTP server with a clean API, the recommended approach is [`Bun.serve`](#start-a-server-bun-serve).
@@ -149,7 +149,7 @@ Bun.serve({
}),
// Redirects
"/blog": Response.redirect("https://bun.sh/blog"),
"/blog": Response.redirect("https://bun.com/blog"),
// API responses
"/api/config": Response.json({
@@ -326,7 +326,11 @@ Bun.serve({
### HTML imports
To add a client-side single-page app, you can use an HTML import:
Bun supports importing HTML files directly into your server code, enabling full-stack applications with both server-side and client-side code. HTML imports work in two modes:
**Development (`bun --hot`):** Assets are bundled on-demand at runtime, enabling hot module replacement (HMR) for a fast, iterative development experience. When you change your frontend code, the browser automatically updates without a full page reload.
**Production (`bun build`):** When building with `bun build --target=bun`, the `import index from "./index.html"` statement resolves to a pre-built manifest object containing all bundled client assets. `Bun.serve` consumes this manifest to serve optimized assets with zero runtime bundling overhead. This is ideal for deploying to production.
```ts
import myReactSinglePageApp from "./index.html";
@@ -338,9 +342,9 @@ Bun.serve({
});
```
HTML imports don't just serve HTML. It's a full-featured frontend bundler, transpiler, and toolkit built using Bun's [bundler](https://bun.sh/docs/bundler), JavaScript transpiler and CSS parser.
HTML imports don't just serve HTML — it's a full-featured frontend bundler, transpiler, and toolkit built using Bun's [bundler](https://bun.com/docs/bundler), JavaScript transpiler and CSS parser. You can use this to build full-featured frontends with React, TypeScript, Tailwind CSS, and more.
You can use this to build a full-featured frontend with React, TypeScript, Tailwind CSS, and more. Check out [/docs/bundler/fullstack](https://bun.sh/docs/bundler/fullstack) to learn more.
For a complete guide on building full-stack applications with HTML imports, including detailed examples and best practices, see [/docs/bundler/fullstack](https://bun.com/docs/bundler/fullstack).
### Practical example: REST API
@@ -601,7 +605,7 @@ Bun.serve({
```
{% callout %}
[Learn more about debugging in Bun](https://bun.sh/docs/runtime/debugger)
[Learn more about debugging in Bun](https://bun.com/docs/runtime/debugger)
{% /callout %}
The call to `Bun.serve` returns a `Server` object. To stop the server, call the `.stop()` method.
@@ -768,7 +772,7 @@ Instead of passing the server options into `Bun.serve`, `export default` it. Thi
$ bun --hot server.ts
``` -->
<!-- It's possible to configure hot reloading while using the explicit `Bun.serve` API; for details refer to [Runtime > Hot reloading](https://bun.sh/docs/runtime/hot). -->
<!-- It's possible to configure hot reloading while using the explicit `Bun.serve` API; for details refer to [Runtime > Hot reloading](https://bun.com/docs/runtime/hot). -->
## Streaming files

View File

@@ -4,7 +4,7 @@ Production servers often read, upload, and write files to S3-compatible object s
### Bun's S3 API is fast
{% image src="https://bun.sh/bun-s3-node.gif" alt="Bun's S3 API is fast" caption="Left: Bun v1.1.44. Right: Node.js v23.6.0" /%}
{% image src="https://bun.com/bun-s3-node.gif" alt="Bun's S3 API is fast" caption="Left: Bun v1.1.44. Right: Node.js v23.6.0" /%}
{% /callout %}
@@ -160,7 +160,8 @@ const writer = s3file.writer({
partSize: 5 * 1024 * 1024,
});
for (let i = 0; i < 10; i++) {
await writer.write(bigFile);
writer.write(bigFile);
await writer.flush();
}
await writer.end();
```

View File

@@ -34,7 +34,7 @@ const proc = Bun.spawn(["cat"], {
),
});
const text = await new Response(proc.stdout).text();
const text = await proc.stdout.text();
console.log(text); // "const input = "hello world".repeat(400); ..."
```
@@ -113,14 +113,34 @@ proc.stdin.flush();
proc.stdin.end();
```
Passing a `ReadableStream` to `stdin` lets you pipe data from a JavaScript `ReadableStream` directly to the subprocess's input:
```ts
const stream = new ReadableStream({
start(controller) {
controller.enqueue("Hello from ");
controller.enqueue("ReadableStream!");
controller.close();
},
});
const proc = Bun.spawn(["cat"], {
stdin: stream,
stdout: "pipe",
});
const output = await new Response(proc.stdout).text();
console.log(output); // "Hello from ReadableStream!"
```
## Output streams
You can read results from the subprocess via the `stdout` and `stderr` properties. By default these are instances of `ReadableStream`.
```ts
const proc = Bun.spawn(["bun", "--version"]);
const text = await new Response(proc.stdout).text();
console.log(text); // => "$BUN_LATEST_VERSION"
const text = await proc.stdout.text();
console.log(text); // => "$BUN_LATEST_VERSION\n"
```
Configure the output stream by passing one of the following values to `stdout/stderr`:

View File

@@ -274,6 +274,23 @@ If no connection URL is provided, the system checks for the following individual
| `PGPASSWORD` | - | (empty) | Database password |
| `PGDATABASE` | - | username | Database name |
## Runtime Preconnection
Bun can preconnect to PostgreSQL at startup to improve performance by establishing database connections before your application code runs. This is useful for reducing connection latency on the first database query.
```bash
# Enable PostgreSQL preconnection
bun --sql-preconnect index.js
# Works with DATABASE_URL environment variable
DATABASE_URL=postgres://user:pass@localhost:5432/db bun --sql-preconnect index.js
# Can be combined with other runtime flags
bun --sql-preconnect --hot index.js
```
The `--sql-preconnect` flag will automatically establish a PostgreSQL connection using your configured environment variables at startup. If the connection fails, it won't crash your application - the error will be handled gracefully.
## Connection Options
You can configure your database connection manually by passing options to the SQL constructor:

View File

@@ -234,7 +234,7 @@ const currentFile = import.meta.url;
Bun.openInEditor(currentFile);
```
You can override this via the `debug.editor` setting in your [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig).
You can override this via the `debug.editor` setting in your [`bunfig.toml`](https://bun.com/docs/runtime/bunfig).
```toml-diff#bunfig.toml
+ [debug]
@@ -582,11 +582,11 @@ Compresses a `Uint8Array` using zlib's DEFLATE algorithm.
const buf = Buffer.from("hello".repeat(100));
const compressed = Bun.deflateSync(buf);
buf; // => Uint8Array(25)
compressed; // => Uint8Array(10)
buf; // => Buffer(500)
compressed; // => Uint8Array(12)
```
The second argument supports the same set of configuration options as [`Bun.gzipSync`](#bungzipsync).
The second argument supports the same set of configuration options as [`Bun.gzipSync`](#bun-gzipsync).
## `Bun.inflateSync()`
@@ -704,7 +704,7 @@ Bun.nanoseconds();
Bun implements a set of convenience functions for asynchronously consuming the body of a `ReadableStream` and converting it to various binary formats.
```ts
const stream = (await fetch("https://bun.sh")).body;
const stream = (await fetch("https://bun.com")).body;
stream; // => ReadableStream
await Bun.readableStreamToArrayBuffer(stream);
@@ -787,7 +787,7 @@ const buffer = Buffer.alloc(1024 * 1024);
estimateShallowMemoryUsageOf(buffer);
// => 1048624
const req = new Request("https://bun.sh");
const req = new Request("https://bun.com");
estimateShallowMemoryUsageOf(req);
// => 167

View File

@@ -126,6 +126,117 @@ The `--sourcemap` argument embeds a sourcemap compressed with zstd, so that erro
The `--bytecode` argument enables bytecode compilation. Every time you run JavaScript code in Bun, JavaScriptCore (the engine) will compile your source code into bytecode. We can move this parsing work from runtime to bundle time, saving you startup time.
## Act as the Bun CLI
{% note %}
New in Bun v1.2.16
{% /note %}
You can run a standalone executable as if it were the `bun` CLI itself by setting the `BUN_BE_BUN=1` environment variable. When this variable is set, the executable will ignore its bundled entrypoint and instead expose all the features of Bun's CLI.
For example, consider an executable compiled from a simple script:
```sh
$ cat such-bun.js
console.log("you shouldn't see this");
$ bun build --compile ./such-bun.js
[3ms] bundle 1 modules
[89ms] compile such-bun
```
Normally, running `./such-bun` with arguments would execute the script. However, with the `BUN_BE_BUN=1` environment variable, it acts just like the `bun` binary:
```sh
# Executable runs its own entrypoint by default
$ ./such-bun install
you shouldn't see this
# With the env var, the executable acts like the `bun` CLI
$ BUN_BE_BUN=1 ./such-bun install
bun install v1.2.16-canary.1 (1d1db811)
Checked 63 installs across 64 packages (no changes) [5.00ms]
```
This is useful for building CLI tools on top of Bun that may need to install packages, bundle dependencies, run different or local files and more without needing to download a separate binary or install bun.
## Full-stack executables
{% note %}
New in Bun v1.2.17
{% /note %}
Bun's `--compile` flag can create standalone executables that contain both server and client code, making it ideal for full-stack applications. When you import an HTML file in your server code, Bun automatically bundles all frontend assets (JavaScript, CSS, etc.) and embeds them into the executable. When Bun sees the HTML import on the server, it kicks off a frontend build process to bundle JavaScript, CSS, and other assets.
{% codetabs %}
```ts#server.ts
import { serve } from "bun";
import index from "./index.html";
const server = serve({
routes: {
"/": index,
"/api/hello": { GET: () => Response.json({ message: "Hello from API" }) },
},
});
console.log(`Server running at http://localhost:${server.port}`);
```
```html#index.html
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<h1>Hello World</h1>
<script src="./app.js"></script>
</body>
</html>
```
```js#app.js
console.log("Hello from the client!");
```
```css#styles.css
body {
background-color: #f0f0f0;
}
```
{% /codetabs %}
To build this into a single executable:
```sh
bun build --compile ./server.ts --outfile myapp
```
This creates a self-contained binary that includes:
- Your server code
- The Bun runtime
- All frontend assets (HTML, CSS, JavaScript)
- Any npm packages used by your server
The result is a single file that can be deployed anywhere without needing Node.js, Bun, or any dependencies installed. Just run:
```sh
./myapp
```
Bun automatically handles serving the frontend assets with proper MIME types and cache headers. The HTML import is replaced with a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets.
For more details on building full-stack applications with Bun, see the [full-stack guide](/docs/bundler/fullstack).
## Worker
To use workers in a standalone executable, add the worker's entrypoint to the CLI arguments:
@@ -174,7 +285,7 @@ $ ./hello
Standalone executables support embedding files.
To embed files into an executable with `bun build --compile`, import the file in your code
To embed files into an executable with `bun build --compile`, import the file in your code.
```ts
// this becomes an internal file path
@@ -353,5 +464,4 @@ Currently, the `--compile` flag can only accept a single entrypoint at a time an
- `--splitting`
- `--public-path`
- `--target=node` or `--target=browser`
- `--format` - always outputs a binary executable. Internally, it's almost esm.
- `--no-bundle` - we always bundle everything into the executable.

View File

@@ -1,5 +1,3 @@
Using `Bun.serve()`'s `routes` option, you can run your frontend and backend in the same app with no extra steps.
To get started, import HTML files and pass them to the `routes` option in `Bun.serve()`.
```ts
@@ -234,7 +232,92 @@ When `console: true` is set, Bun will stream console logs from the browser to th
#### Production mode
When serving your app in production, set `development: false` in `Bun.serve()`.
Hot reloading and `development: true` helps you iterate quickly, but in production, your server should be as fast as possible and have as few external dependencies as possible.
##### Ahead of time bundling (recommended)
As of Bun v1.2.17, you can use `Bun.build` or `bun build` to bundle your full-stack application ahead of time.
```sh
$ bun build --target=bun --production --outdir=dist ./src/index.ts
```
When Bun's bundler sees an HTML import from server-side code, it will bundle the referenced JavaScript/TypeScript/TSX/JSX and CSS files into a manifest object that Bun.serve() can use to serve the assets.
```ts
import { serve } from "bun";
import index from "./index.html";
serve({
routes: { "/": index },
});
```
{% details summary="Internally, the `index` variable is a manifest object that looks something like this" %}
```json
{
"index": "./index.html",
"files": [
{
"input": "index.html",
"path": "./index-f2me3qnf.js",
"loader": "js",
"isEntry": true,
"headers": {
"etag": "eet6gn75",
"content-type": "text/javascript;charset=utf-8"
}
},
{
"input": "index.html",
"path": "./index.html",
"loader": "html",
"isEntry": true,
"headers": {
"etag": "r9njjakd",
"content-type": "text/html;charset=utf-8"
}
},
{
"input": "index.html",
"path": "./index-gysa5fmk.css",
"loader": "css",
"isEntry": true,
"headers": {
"etag": "50zb7x61",
"content-type": "text/css;charset=utf-8"
}
},
{
"input": "logo.svg",
"path": "./logo-kygw735p.svg",
"loader": "file",
"isEntry": false,
"headers": {
"etag": "kygw735p",
"content-type": "application/octet-stream"
}
},
{
"input": "react.svg",
"path": "./react-ck11dneg.svg",
"loader": "file",
"isEntry": false,
"headers": {
"etag": "ck11dneg",
"content-type": "application/octet-stream"
}
}
]
}
```
{% /details %}
##### Runtime bundling
When adding a build step is too complicated, you can set `development: false` in `Bun.serve()`.
- Enable in-memory caching of bundled assets. Bun will bundle assets lazily on the first request to an `.html` file, and cache the result in memory until the server restarts.
- Enables `Cache-Control` headers and `ETag` headers
@@ -242,7 +325,7 @@ When serving your app in production, set `development: false` in `Bun.serve()`.
## Plugins
Bun's [bundler plugins](https://bun.sh/docs/bundler/plugins) are also supported when bundling static routes.
Bun's [bundler plugins](https://bun.com/docs/bundler/plugins) are also supported when bundling static routes.
To configure plugins for `Bun.serve`, add a `plugins` array in the `[serve.static]` section of your `bunfig.toml`.
@@ -282,7 +365,7 @@ Or in your CSS:
### Custom plugins
Any JS file or module which exports a [valid bundler plugin object](https://bun.sh/docs/bundler/plugins#usage) (essentially an object with a `name` and `setup` field) can be placed inside the `plugins` array:
Any JS file or module which exports a [valid bundler plugin object](https://bun.com/docs/bundler/plugins#usage) (essentially an object with a `name` and `setup` field) can be placed inside the `plugins` array:
```toml#bunfig.toml
[serve.static]
@@ -298,7 +381,6 @@ Note: this is currently in `bunfig.toml` to make it possible to know statically
Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<link>` tags in HTML files, uses them as entrypoints for [Bun's bundler](/docs/bundler), generates an optimized bundle for the JavaScript/TypeScript/TSX/JSX and CSS files, and serves the result.
1. **`<script>` processing**
- Transpiles TypeScript, JSX, and TSX in `<script>` tags
- Bundles imported dependencies
- Generates sourcemaps for debugging
@@ -309,7 +391,6 @@ Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<
```
2. **`<link>` processing**
- Processes CSS imports and `<link>` tags
- Concatenates CSS files
- Rewrites `url` and asset paths to include content-addressable hashes in URLs
@@ -319,18 +400,15 @@ Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<
```
3. **`<img>` & asset processing**
- Links to assets are rewritten to include content-addressable hashes in URLs
- Small assets in CSS files are inlined into `data:` URLs, reducing the total number of HTTP requests sent over the wire
4. **Rewrite HTML**
- Combines all `<script>` tags into a single `<script>` tag with a content-addressable hash in the URL
- Combines all `<link>` tags into a single `<link>` tag with a content-addressable hash in the URL
- Outputs a new HTML file
5. **Serve**
- All the output files from the bundler are exposed as static routes, using the same mechanism internally as when you pass a `Response` object to [`static` in `Bun.serve()`](/docs/api/http#static-routes).
This works similarly to how [`Bun.build` processes HTML files](/docs/bundler/html).

View File

@@ -26,6 +26,7 @@ The bundler is a key piece of infrastructure in the JavaScript ecosystem. As a b
- **Reducing HTTP requests.** A single package in `node_modules` may consist of hundreds of files, and large applications may have dozens of such dependencies. Loading each of these files with a separate HTTP request becomes untenable very quickly, so bundlers are used to convert our application source code into a smaller number of self-contained "bundles" that can be loaded with a single request.
- **Code transforms.** Modern apps are commonly built with languages or tools like TypeScript, JSX, and CSS modules, all of which must be converted into plain JavaScript and CSS before they can be consumed by a browser. The bundler is the natural place to configure these transformations.
- **Framework features.** Frameworks rely on bundler plugins & code transformations to implement common patterns like file-system routing, client-server code co-location (think `getServerSideProps` or Remix loaders), and server components.
- **Full-stack Applications.** Bun's bundler can handle both server and client code in a single command, enabling optimized production builds and single-file executables. With build-time HTML imports, you can bundle your entire application — frontend assets and backend server — into a single deployable unit.
Let's jump into the bundler API.
@@ -146,7 +147,7 @@ $ bun build ./index.tsx --outdir ./out --watch
## Content types
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](https://bun.sh/docs/runtime/loaders) for full documentation.
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](https://bun.com/docs/runtime/loaders) for full documentation.
{% table %}
@@ -219,11 +220,11 @@ console.log(logo);
The exact behavior of the file loader is also impacted by [`naming`](#naming) and [`publicPath`](#publicpath).
{% /callout %}
Refer to the [Bundler > Loaders](https://bun.sh/docs/bundler/loaders#file) page for more complete documentation on the file loader.
Refer to the [Bundler > Loaders](https://bun.com/docs/bundler/loaders#file) page for more complete documentation on the file loader.
### Plugins
The behavior described in this table can be overridden or extended with [plugins](https://bun.sh/docs/bundler/plugins). Refer to the [Bundler > Loaders](https://bun.sh/docs/bundler/plugins) page for complete documentation.
The behavior described in this table can be overridden or extended with [plugins](https://bun.com/docs/bundler/plugins). Refer to the [Bundler > Loaders](https://bun.com/docs/bundler/plugins) page for complete documentation.
## API
@@ -324,7 +325,7 @@ Depending on the target, Bun will apply different module resolution rules and op
---
- `bun`
- For generating bundles that are intended to be run by the Bun runtime. In many cases, it isn't necessary to bundle server-side code; you can directly execute the source code without modification. However, bundling your server code can reduce startup times and improve running performance.
- For generating bundles that are intended to be run by the Bun runtime. In many cases, it isn't necessary to bundle server-side code; you can directly execute the source code without modification. However, bundling your server code can reduce startup times and improve running performance. This is the target to use for building full-stack applications with build-time HTML imports, where both server and client code are bundled together.
All bundles generated with `target: "bun"` are marked with a special `// @bun` pragma, which indicates to the Bun runtime that there's no need to re-transpile the file before execution.
@@ -483,7 +484,7 @@ n/a
{% /codetabs %}
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](https://bun.sh/docs/bundler/plugins) for complete documentation.
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](https://bun.com/docs/bundler/plugins) for complete documentation.
<!-- ### `manifest`
@@ -1101,7 +1102,7 @@ A prefix to be appended to any import paths in bundled code.
In many cases, generated bundles will contain no `import` statements. After all, the goal of bundling is to combine all of the code into a single file. However there are a number of cases with the generated bundles will contain `import` statements.
- **Asset imports** — When importing an unrecognized file type like `*.svg`, the bundler defers to the [`file` loader](https://bun.sh/docs/bundler/loaders#file), which copies the file into `outdir` as is. The import is converted into a variable
- **Asset imports** — When importing an unrecognized file type like `*.svg`, the bundler defers to the [`file` loader](https://bun.com/docs/bundler/loaders#file), which copies the file into `outdir` as is. The import is converted into a variable
- **External modules** — Files and modules can be marked as [`external`](#external), in which case they will not be included in the bundle. Instead, the `import` statement will be left in the final bundle.
- **Chunking**. When [`splitting`](#splitting) is enabled, the bundler may generate separate "chunk" files that represent code that is shared among multiple entrypoints.
@@ -1177,7 +1178,7 @@ $ bun build ./index.tsx --outdir ./out --define 'STRING="value"' --define "neste
### `loader`
A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
A map of file extensions to [built-in loader names](https://bun.com/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
{% codetabs %}
@@ -1309,7 +1310,7 @@ Each artifact also contains the following properties:
---
- `loader`
- The loader was used to interpret the file. See [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader.
- The loader was used to interpret the file. See [Bundler > Loaders](https://bun.com/docs/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader.
---
@@ -1393,7 +1394,7 @@ $ bun build ./cli.tsx --outfile mycli --compile
$ ./mycli
```
Refer to [Bundler > Executables](https://bun.sh/docs/bundler/executables) for complete documentation.
Refer to [Bundler > Executables](https://bun.com/docs/bundler/executables) for complete documentation.
## Logs and errors

View File

@@ -2,7 +2,7 @@ The Bun bundler implements a set of default loaders out of the box. As a rule of
`.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.toml` `.json` `.txt` `.wasm` `.node` `.html`
Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](https://bun.sh/docs/bundler/plugins) that extend Bun with custom loaders.
Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](https://bun.com/docs/bundler/plugins) that extend Bun with custom loaders.
You can explicitly specify which loader to use using the 'loader' import attribute.
@@ -137,7 +137,7 @@ console.log(contents); // => "Hello, world!"
import html from "./index.html" with { type: "text" };
```
When referenced during a build, the contents are into the bundle as a string.
When referenced during a build, the contents are inlined into the bundle as a string.
```ts
var contents = `Hello, world!`;
@@ -175,7 +175,7 @@ In the bundler, `.node` files are handled using the [`file`](#file) loader.
**SQLite loader**. `with { "type": "sqlite" }` import attribute
In the runtime and bundler, SQLite databases can be directly imported. This will load the database using [`bun:sqlite`](https://bun.sh/docs/api/sqlite).
In the runtime and bundler, SQLite databases can be directly imported. This will load the database using [`bun:sqlite`](https://bun.com/docs/api/sqlite).
```ts
import db from "./my.db" with { type: "sqlite" };
@@ -192,7 +192,7 @@ You can change this behavior with the `"embed"` attribute:
import db from "./my.db" with { type: "sqlite", embed: "true" };
```
When using a [standalone executable](https://bun.sh/docs/bundler/executables), the database is embedded into the single-file executable.
When using a [standalone executable](https://bun.com/docs/bundler/executables), the database is embedded into the single-file executable.
Otherwise, the database to embed is copied into the `outdir` with a hashed filename.
@@ -262,11 +262,25 @@ Currently, the list of selectors is:
- `video[poster]`
- `video[src]`
{% callout %}
**HTML Loader Behavior in Different Contexts**
The `html` loader behaves differently depending on how it's used:
1. **Static Build:** When you run `bun build ./index.html`, Bun produces a static site with all assets bundled and hashed.
2. **Runtime:** When you run `bun run server.ts` (where `server.ts` imports an HTML file), Bun bundles assets on-the-fly during development, enabling features like hot module replacement.
3. **Full-stack Build:** When you run `bun build --target=bun server.ts` (where `server.ts` imports an HTML file), the import resolves to a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets in production.
{% /callout %}
### `sh` loader
**Bun Shell loader**. Default for `.sh` files
This loader is used to parse [Bun Shell](https://bun.sh/docs/runtime/shell) scripts. It's only supported when starting Bun itself, so it's not available in the bundler or in the runtime.
This loader is used to parse [Bun Shell](https://bun.com/docs/runtime/shell) scripts. It's only supported when starting Bun itself, so it's not available in the bundler or in the runtime.
```sh
$ bun run ./script.sh
@@ -322,7 +336,7 @@ If a value is specified for `publicPath`, the import will use value as a prefix
{% /table %}
{% callout %}
The location and file name of the copied file is determined by the value of [`naming.asset`](https://bun.sh/docs/bundler#naming).
The location and file name of the copied file is determined by the value of [`naming.asset`](https://bun.com/docs/bundler#naming).
{% /callout %}
This loader is copied into the `outdir` as-is. The name of the copied file is determined using the value of `naming.asset`.

View File

@@ -161,7 +161,7 @@ The result of `fetch` is `Promise<Response>`, so it can be directly returned.
```ts#macro.ts
export function getObject() {
return fetch("https://bun.sh")
return fetch("https://bun.com")
}
```

View File

@@ -291,7 +291,7 @@ One of the reasons why Bun's bundler is so fast is that it is written in native
However, one limitation of plugins written in JavaScript is that JavaScript itself is single-threaded.
Native plugins are written as [NAPI](https://bun.sh/docs/api/node-api) modules and can be run on multiple threads. This allows native plugins to run much faster than JavaScript plugins.
Native plugins are written as [NAPI](https://bun.com/docs/api/node-api) modules and can be run on multiple threads. This allows native plugins to run much faster than JavaScript plugins.
In addition, native plugins can skip unnecessary work such as the UTF-8 -> UTF-16 conversion needed to pass strings to JavaScript.

View File

@@ -2,7 +2,7 @@ Bun's bundler API is inspired heavily by [esbuild](https://esbuild.github.io/).
There are a few behavioral differences to note.
- **Bundling by default**. Unlike esbuild, Bun _always bundles by default_. This is why the `--bundle` flag isn't necessary in the Bun example. To transpile each file individually, use [`Bun.Transpiler`](https://bun.sh/docs/api/transpiler).
- **Bundling by default**. Unlike esbuild, Bun _always bundles by default_. This is why the `--bundle` flag isn't necessary in the Bun example. To transpile each file individually, use [`Bun.Transpiler`](https://bun.com/docs/api/transpiler).
- **It's just a bundler**. Unlike esbuild, Bun's bundler does not include a built-in development server or file watcher. It's just a bundler. The bundler is intended for use in conjunction with `Bun.serve` and other runtime APIs to achieve the same effect. As such, all options relating to HTTP/file watching are not applicable.
## Performance
@@ -65,7 +65,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `--loader:.ext=loader`
- `--loader .ext:loader`
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.com/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
The syntax for `--loader` is slightly different.
@@ -125,7 +125,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `--target`
- n/a
- No supported. Bun's bundler performs no syntactic down-leveling at this time.
- Not supported. Bun's bundler performs no syntactic down-leveling at this time.
---
@@ -474,7 +474,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `bundle`
- n/a
- Always `true`. Use [`Bun.Transpiler`](https://bun.sh/docs/api/transpiler) to transpile without bundling.
- Always `true`. Use [`Bun.Transpiler`](https://bun.com/docs/api/transpiler) to transpile without bundling.
---
@@ -635,7 +635,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `loader`
- `loader`
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.com/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
---
@@ -891,7 +891,7 @@ const myPlugin: BunPlugin = {
};
```
The `builder` object provides some methods for hooking into parts of the bundling process. Bun implements `onResolve` and `onLoad`; it does not yet implement the esbuild hooks `onStart`, `onEnd`, and `onDispose`, and `resolve` utilities. `initialOptions` is partially implemented, being read-only and only having a subset of esbuild's options; use [`config`](https://bun.sh/docs/bundler/plugins) (same thing but with Bun's `BuildConfig` format) instead.
The `builder` object provides some methods for hooking into parts of the bundling process. Bun implements `onResolve` and `onLoad`; it does not yet implement the esbuild hooks `onStart`, `onEnd`, and `onDispose`, and `resolve` utilities. `initialOptions` is partially implemented, being read-only and only having a subset of esbuild's options; use [`config`](https://bun.com/docs/bundler/plugins) (same thing but with Bun's `BuildConfig` format) instead.
```ts
import type { BunPlugin } from "bun";

View File

@@ -4,7 +4,7 @@
Template a new Bun project with `bun create`. This is a flexible command that can be used to create a new project from a React component, a `create-<template>` npm package, a GitHub repo, or a local template.
If you're looking to create a brand new empty project, use [`bun init`](https://bun.sh/docs/cli/init).
If you're looking to create a brand new empty project, use [`bun init`](https://bun.com/docs/cli/init).
## From a React component
@@ -30,11 +30,11 @@ $ bun create ./MyComponent.jsx # .tsx also supported
When you run `bun create <component>`, Bun:
1. Uses [Bun's JavaScript bundler](https://bun.sh/docs/bundler) to analyze your module graph.
1. Uses [Bun's JavaScript bundler](https://bun.com/docs/bundler) to analyze your module graph.
2. Collects all the dependencies needed to run the component.
3. Scans the exports of the entry point for a React component.
4. Generates a `package.json` file with the dependencies and scripts needed to run the component.
5. Installs any missing dependencies using [`bun install --only-missing`](https://bun.sh/docs/cli/install).
5. Installs any missing dependencies using [`bun install --only-missing`](https://bun.com/docs/cli/install).
6. Generates the following files:
- `${component}.html`
- `${component}.client.tsx` (entry point for the frontend)
@@ -308,14 +308,12 @@ IF remote template
1. GET `registry.npmjs.org/@bun-examples/${template}/latest` and parse it
2. GET `registry.npmjs.org/@bun-examples/${template}/-/${template}-${latestVersion}.tgz`
3. Decompress & extract `${template}-${latestVersion}.tgz` into `${destination}`
- If there are files that would overwrite, warn and exit unless `--force` is passed
IF GitHub repo
1. Download the tarball from GitHubs API
2. Decompress & extract into `${destination}`
- If there are files that would overwrite, warn and exit unless `--force` is passed
ELSE IF local template
@@ -333,7 +331,6 @@ ELSE IF local template
7. Run `${npmClient} install` unless `--no-install` is passed OR no dependencies are in package.json
8. Run any tasks defined in `"bun-create": { "postinstall" }` with the npm client
9. Run `git init; git add -A .; git commit -am "Initial Commit";`
- Rename `gitignore` to `.gitignore`. NPM automatically removes `.gitignore` files from appearing in packages.
- If there are dependencies, this runs in a separate thread concurrently while node_modules are being installed
- Using libgit2 if available was tested and performed 3x slower in microbenchmarks

View File

@@ -184,7 +184,7 @@ Peer dependencies are handled similarly to yarn. `bun install` will automaticall
## Lockfile
`bun.lock` is Buns lockfile format. See [our blogpost about the text lockfile](https://bun.sh/blog/bun-lock-text-lockfile).
`bun.lock` is Buns lockfile format. See [our blogpost about the text lockfile](https://bun.com/blog/bun-lock-text-lockfile).
Prior to Bun 1.2, the lockfile was binary and called `bun.lockb`. Old lockfiles can be upgraded to the new format by running `bun install --save-text-lockfile --frozen-lockfile --lockfile-only`, and then deleting `bun.lockb`.

View File

@@ -7,7 +7,7 @@ This works by checking the latest version of Bun in [bun-releases-for-updater](h
If for any reason you run into issues, you can also use the curl install script:
```bash
$ curl https://bun.sh/install | bash
$ curl https://bun.com/install | bash
```
It will still work when Bun is already installed.

View File

@@ -28,7 +28,7 @@ $ bun install --filter '!pkg-c'
$ bun install --filter './packages/*'
# Save as above, but exclude the root package.json
$ bun install --filter --filter '!./' --filter './packages/*'
$ bun install --filter '!./' --filter './packages/*'
```
Similarly, `bun outdated` will display outdated dependencies for all packages in the monorepo, and `--filter` can be used to restrict the command to a subset of the packages:
@@ -41,7 +41,7 @@ $ bun outdated --filter 'pkg-*'
$ bun outdated --filter './'
```
For more information on both these commands, see [`bun install`](https://bun.sh/docs/cli/install) and [`bun outdated`](https://bun.sh/docs/cli/outdated).
For more information on both these commands, see [`bun install`](https://bun.com/docs/cli/install) and [`bun outdated`](https://bun.com/docs/cli/outdated).
## Running scripts with `--filter`
@@ -73,7 +73,7 @@ Both commands will be run in parallel, and you will see a nice terminal UI showi
### Running scripts in workspaces
Filters respect your [workspace configuration](https://bun.sh/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
Filters respect your [workspace configuration](https://bun.com/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
`--filter` will be restricted to only these packages. Also, in a workspace you can use `--filter` to run scripts in packages that are located anywhere in the workspace:
```bash

65
docs/cli/info.md Normal file
View File

@@ -0,0 +1,65 @@
`bun info` displays package metadata from the npm registry.
## Usage
```bash
$ bun info react
```
This will display information about the `react` package, including its latest version, description, homepage, dependencies, and more.
## Viewing specific versions
To view information about a specific version:
```bash
$ bun info react@18.0.0
```
## Viewing specific properties
You can also query specific properties from the package metadata:
```bash
$ bun info react version
$ bun info react dependencies
$ bun info react repository.url
```
## JSON output
To get the output in JSON format, use the `--json` flag:
```bash
$ bun info react --json
```
## Alias
`bun pm view` is an alias for `bun info`:
```bash
$ bun pm view react # equivalent to: bun info react
```
## Examples
```bash
# View basic package information
$ bun info is-number
# View a specific version
$ bun info is-number@7.0.0
# View all available versions
$ bun info is-number versions
# View package dependencies
$ bun info express dependencies
# View package homepage
$ bun info lodash homepage
# Get JSON output
$ bun info react --json
```

View File

@@ -68,7 +68,7 @@ $ bun install --concurrent-scripts 5
## Workspaces
Bun supports `"workspaces"` in package.json. For complete documentation refer to [Package manager > Workspaces](https://bun.sh/docs/install/workspaces).
Bun supports `"workspaces"` in package.json. For complete documentation refer to [Package manager > Workspaces](https://bun.com/docs/install/workspaces).
```json#package.json
{
@@ -93,11 +93,11 @@ $ bun install --filter '!pkg-c'
$ bun install --filter './packages/pkg-a'
```
For more information on filtering with `bun install`, refer to [Package Manager > Filtering](https://bun.sh/docs/cli/filter#bun-install-and-bun-outdated)
For more information on filtering with `bun install`, refer to [Package Manager > Filtering](https://bun.com/docs/cli/filter#bun-install-and-bun-outdated)
## Overrides and resolutions
Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](https://bun.sh/docs/install/overrides) for complete documentation.
Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](https://bun.com/docs/install/overrides) for complete documentation.
```json-diff#package.json
{
@@ -142,7 +142,7 @@ For reproducible installs, use `--frozen-lockfile`. This will install the exact
$ bun install --frozen-lockfile
```
For more information on Bun's lockfile `bun.lock`, refer to [Package manager > Lockfile](https://bun.sh/docs/install/lockfile).
For more information on Bun's lockfile `bun.lock`, refer to [Package manager > Lockfile](https://bun.com/docs/install/lockfile).
## Omitting dependencies
@@ -168,7 +168,7 @@ $ bun install --dry-run
## Non-npm dependencies
Bun supports installing dependencies from Git, GitHub, and local or remotely-hosted tarballs. For complete documentation refer to [Package manager > Git, GitHub, and tarball dependencies](https://bun.sh/docs/cli/add).
Bun supports installing dependencies from Git, GitHub, and local or remotely-hosted tarballs. For complete documentation refer to [Package manager > Git, GitHub, and tarball dependencies](https://bun.com/docs/cli/add).
```json#package.json
{

View File

@@ -1,6 +1,6 @@
An alias for `bun patch --commit` to maintain compatibility with pnpm.
To get started with patch, first prepare the package for patching with [`bun patch <pkg>`](https://bun.sh/docs/install/patch).
To get started with patch, first prepare the package for patching with [`bun patch <pkg>`](https://bun.com/docs/install/patch).
### `--patches-dir`

Some files were not shown because too many files have changed in this diff Show More