|
| 1 | +# 🧄 Bun Integration Guide |
| 2 | + |
| 3 | +This document covers the new Bun runtime and package manager integration in Syncable CLI. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Syncable CLI now fully supports Bun, the all-in-one JavaScript runtime & toolkit. The integration includes: |
| 8 | + |
| 9 | +- **Runtime Detection**: Automatically detects Bun projects via lock files, package.json configuration, and Bun-specific files |
| 10 | +- **Vulnerability Scanning**: Uses `bun audit` to check for vulnerabilities in Bun projects |
| 11 | +- **Tool Installation**: Auto-installs Bun when needed across all platforms |
| 12 | +- **Multi-Runtime Support**: Prioritizes Bun when multiple package managers are present |
| 13 | + |
| 14 | +## How Bun Projects Are Detected |
| 15 | + |
| 16 | +Syncable CLI uses a priority-based detection system: |
| 17 | + |
| 18 | +### 1. Lock File Detection (Highest Priority) |
| 19 | +```bash |
| 20 | +# If bun.lockb exists, project is detected as Bun |
| 21 | +bun.lockb |
| 22 | +``` |
| 23 | + |
| 24 | +### 2. Package.json Configuration |
| 25 | +```json |
| 26 | +{ |
| 27 | + "name": "my-app", |
| 28 | + "packageManager": "bun@1.0.0", |
| 29 | + "engines": { |
| 30 | + "bun": ">=1.0.0" |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +### 3. Bun Configuration Files |
| 36 | +```bash |
| 37 | +bunfig.toml # Bun configuration file |
| 38 | +.bunfig.toml # Alternative config name |
| 39 | +``` |
| 40 | + |
| 41 | +### 4. Bun Scripts in package.json |
| 42 | +```json |
| 43 | +{ |
| 44 | + "scripts": { |
| 45 | + "start": "bun run index.js", |
| 46 | + "dev": "bun --watch server.ts" |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Priority Order |
| 52 | + |
| 53 | +When multiple package managers are detected, Syncable CLI uses this priority: |
| 54 | + |
| 55 | +1. **Bun** (bun.lockb, packageManager: "bun@*") |
| 56 | +2. **pnpm** (pnpm-lock.yaml, packageManager: "pnpm@*") |
| 57 | +3. **Yarn** (yarn.lock, packageManager: "yarn@*") |
| 58 | +4. **npm** (package-lock.json, packageManager: "npm@*") |
| 59 | + |
| 60 | +## Vulnerability Scanning |
| 61 | + |
| 62 | +### Automatic Runtime Detection |
| 63 | +```bash |
| 64 | +# Automatically detects Bun and uses 'bun audit' |
| 65 | +sync-ctl vulnerabilities /path/to/bun-project |
| 66 | + |
| 67 | +# Shows runtime detection in output |
| 68 | +Runtime: Bun |
| 69 | +Package Manager: bun |
| 70 | +Audit Command: bun audit |
| 71 | +``` |
| 72 | + |
| 73 | +### Example Output |
| 74 | +```bash |
| 75 | +$ sync-ctl vulnerabilities ./my-bun-app |
| 76 | + |
| 77 | +🔍 Vulnerability Analysis Report |
| 78 | +═══════════════════════════════════════════════════════════════════════ |
| 79 | + |
| 80 | +┌─ Project Information ────────────────────────────────────────────────┐ |
| 81 | +│ Runtime: Bun │ |
| 82 | +│ Package Manager: bun │ |
| 83 | +│ Dependencies: 42 total (38 production, 4 development) │ |
| 84 | +│ Lock File: bun.lockb │ |
| 85 | +└──────────────────────────────────────────────────────────────────────┘ |
| 86 | + |
| 87 | +┌─ Vulnerability Summary ──────────────────────────────────────────────┐ |
| 88 | +│ Total Vulnerabilities: 3 │ |
| 89 | +│ Critical: 1 | High: 1 | Medium: 1 | Low: 0 │ |
| 90 | +│ Checked at: 2024-01-15 14:30:22 UTC │ |
| 91 | +└──────────────────────────────────────────────────────────────────────┘ |
| 92 | +``` |
| 93 | + |
| 94 | +## Installation Integration |
| 95 | + |
| 96 | +### Automatic Installation |
| 97 | +If Bun is not installed but detected as the project's package manager: |
| 98 | + |
| 99 | +```bash |
| 100 | +$ sync-ctl vulnerabilities ./bun-project |
| 101 | + |
| 102 | +⚙️ Bun not found but required for this project |
| 103 | +🔧 Installing Bun automatically... |
| 104 | + |
| 105 | +# On Windows |
| 106 | +> powershell -c "irm bun.sh/install.ps1 | iex" |
| 107 | + |
| 108 | +# On Unix/Linux/macOS |
| 109 | +> curl -fsSL https://bun.sh/install | bash |
| 110 | + |
| 111 | +✅ Bun v1.0.3 installed successfully |
| 112 | +🔍 Running vulnerability scan with bun audit... |
| 113 | +``` |
| 114 | + |
| 115 | +### Manual Installation |
| 116 | +```bash |
| 117 | +# Check tool status |
| 118 | +sync-ctl tools status |
| 119 | + |
| 120 | +# Install all missing tools (including Bun if needed) |
| 121 | +sync-ctl tools install |
| 122 | + |
| 123 | +# Get installation guide |
| 124 | +sync-ctl tools guide --bun |
| 125 | +``` |
| 126 | + |
| 127 | +## Cross-Platform Support |
| 128 | + |
| 129 | +### Windows Installation |
| 130 | +```powershell |
| 131 | +# PowerShell (Administrator recommended) |
| 132 | +irm bun.sh/install.ps1 | iex |
| 133 | +
|
| 134 | +# Or via Scoop |
| 135 | +scoop install bun |
| 136 | +``` |
| 137 | + |
| 138 | +### Unix/Linux/macOS Installation |
| 139 | +```bash |
| 140 | +# Official installer |
| 141 | +curl -fsSL https://bun.sh/install | bash |
| 142 | + |
| 143 | +# Homebrew (macOS) |
| 144 | +brew install bun |
| 145 | + |
| 146 | +# Manual download |
| 147 | +wget https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip |
| 148 | +``` |
| 149 | + |
| 150 | +## Multi-Runtime Projects |
| 151 | + |
| 152 | +For projects with multiple package managers, Bun takes priority: |
| 153 | + |
| 154 | +```bash |
| 155 | +# Project structure |
| 156 | +my-project/ |
| 157 | +├── package.json # Shared dependencies |
| 158 | +├── bun.lockb # Bun lock file (highest priority) |
| 159 | +├── yarn.lock # Yarn lock file |
| 160 | +├── package-lock.json # npm lock file |
| 161 | +└── pnpm-lock.yaml # pnpm lock file |
| 162 | + |
| 163 | +# Result: Detected as Bun project |
| 164 | +Runtime: Bun |
| 165 | +Package Manager: bun |
| 166 | +Confidence: High |
| 167 | +``` |
| 168 | + |
| 169 | +## Configuration Options |
| 170 | + |
| 171 | +### .syncable.toml Configuration |
| 172 | +```toml |
| 173 | +[javascript] |
| 174 | +# Force specific package manager |
| 175 | +preferred_package_manager = "bun" |
| 176 | + |
| 177 | +# Skip auto-installation |
| 178 | +auto_install_tools = false |
| 179 | + |
| 180 | +[vulnerability] |
| 181 | +# Custom audit commands |
| 182 | +bun_audit_command = "bun audit --json" |
| 183 | +``` |
| 184 | + |
| 185 | +### Command Line Options |
| 186 | +```bash |
| 187 | +# Force specific package manager for vulnerability scanning |
| 188 | +sync-ctl vulnerabilities . --package-manager bun |
| 189 | + |
| 190 | +# Skip missing tool installation |
| 191 | +sync-ctl vulnerabilities . --no-install |
| 192 | +``` |
| 193 | + |
| 194 | +## Troubleshooting |
| 195 | + |
| 196 | +### Common Issues |
| 197 | + |
| 198 | +1. **Bun not found in PATH** |
| 199 | + ```bash |
| 200 | + # Add Bun to PATH (Unix/Linux/macOS) |
| 201 | + echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc |
| 202 | + source ~/.bashrc |
| 203 | + |
| 204 | + # Windows: Add %USERPROFILE%\.bun\bin to PATH |
| 205 | + ``` |
| 206 | + |
| 207 | +2. **Permission issues during installation** |
| 208 | + ```bash |
| 209 | + # Run with elevated permissions or use package manager |
| 210 | + sudo curl -fsSL https://bun.sh/install | bash |
| 211 | + ``` |
| 212 | + |
| 213 | +3. **Lock file conflicts** |
| 214 | + ```bash |
| 215 | + # Clean conflicting lock files |
| 216 | + rm package-lock.json yarn.lock pnpm-lock.yaml |
| 217 | + bun install # Recreate bun.lockb |
| 218 | + ``` |
| 219 | + |
| 220 | +### Debug Information |
| 221 | +```bash |
| 222 | +# Enable debug logging |
| 223 | +RUST_LOG=debug sync-ctl vulnerabilities . |
| 224 | + |
| 225 | +# View runtime detection details |
| 226 | +sync-ctl analyze . --display detailed |
| 227 | +``` |
| 228 | + |
| 229 | +## Best Practices |
| 230 | + |
| 231 | +1. **Use explicit packageManager field** in package.json for clarity |
| 232 | +2. **Remove conflicting lock files** when switching to Bun |
| 233 | +3. **Keep bunfig.toml** for project-specific Bun configuration |
| 234 | +4. **Use bun scripts** in package.json for consistency |
| 235 | + |
| 236 | +## Migration from Other Package Managers |
| 237 | + |
| 238 | +### From npm |
| 239 | +```bash |
| 240 | +# Remove npm artifacts |
| 241 | +rm package-lock.json node_modules/ -rf |
| 242 | + |
| 243 | +# Install with Bun |
| 244 | +bun install |
| 245 | + |
| 246 | +# Update package.json |
| 247 | +{ |
| 248 | + "packageManager": "bun@1.0.0" |
| 249 | +} |
| 250 | +``` |
| 251 | + |
| 252 | +### From Yarn |
| 253 | +```bash |
| 254 | +# Remove Yarn artifacts |
| 255 | +rm yarn.lock node_modules/ -rf |
| 256 | + |
| 257 | +# Install with Bun |
| 258 | +bun install |
| 259 | + |
| 260 | +# Update scripts if needed |
| 261 | +{ |
| 262 | + "scripts": { |
| 263 | + "start": "bun run index.js" |
| 264 | + } |
| 265 | +} |
| 266 | +``` |
| 267 | + |
| 268 | +## Examples |
| 269 | + |
| 270 | +See `examples/` directory for sample Bun projects and usage patterns. |
| 271 | + |
| 272 | +--- |
| 273 | + |
| 274 | +For more information, see the [main documentation](../README.md) or [file an issue](https://github.com/syncable-dev/syncable-cli/issues). |
0 commit comments