Skip to content

feat(runtime): add Bun runtime compatibility#459

Merged
jackwener merged 4 commits intomainfrom
intergrate_buin
Mar 26, 2026
Merged

feat(runtime): add Bun runtime compatibility#459
jackwener merged 4 commits intomainfrom
intergrate_buin

Conversation

@ByteYue
Copy link
Copy Markdown
Collaborator

@ByteYue ByteYue commented Mar 26, 2026

Summary

Add dual-runtime support for opencli — both Node.js and Bun are now supported as JavaScript runtimes.

Changes

Phase 1: Runtime Detection Module

  • New src/runtime-detect.ts — detects whether opencli runs under Bun or Node.js via globalThis.Bun
  • Provides detectRuntime(), getRuntimeVersion(), and getRuntimeLabel() helpers
  • Unit tests that work correctly under both runtimes

Phase 2: CLI Integration

  • doctor: Shows runtime label (e.g. node v22.13.0 or bun 1.1.42) in diagnostic output
  • package.json: Added dev:bun, start:bun, test:bun convenience scripts
  • E2E helpers: Support OPENCLI_TEST_RUNTIME env var — run E2E tests under Bun with OPENCLI_TEST_RUNTIME=bun npm run test:e2e

Phase 3: CI/CD + Documentation

  • ci.yml: Added bun-test job using oven-sh/setup-bun@v2 to catch Bun compatibility regressions
  • README.md: Updated Prerequisites to mention Bun support, added "Runtime Support" section with usage examples

Testing

  • npx tsc --noEmit — typecheck clean
  • ✅ 297 unit tests pass under Node.js (npm test)
  • ✅ 297 unit tests pass under Bun (bun vitest run --project unit)
  • ✅ 12 E2E management tests pass under Bun (OPENCLI_TEST_RUNTIME=bun)
  • ✅ Build passes (npm run build)

Why Bun?

  • 4-5x faster startup — noticeable improvement for CLI tools
  • 95%+ Node.js API compatibility — near drop-in replacement
  • Native TypeScript — no tsc compilation needed for development
  • No breaking changes — Node.js remains the default, Bun is opt-in

ByteYue added 3 commits March 26, 2026 14:15
Add runtime-detect.ts module that detects whether opencli is running
under Bun or Node.js via globalThis.Bun check. Includes helper
functions for version string and label formatting.

Add corresponding unit tests that work correctly under both runtimes.
- doctor: show runtime label (e.g. 'node v22.13.0') in diagnostic output
- package.json: add dev:bun, start:bun, test:bun convenience scripts
- E2E helpers: support OPENCLI_TEST_RUNTIME env var for runtime selection
- ci.yml: add bun-test job using oven-sh/setup-bun@v2
- README.md: update Prerequisites to mention Bun, add Runtime Support
  section with usage examples for dev:bun, start:bun, test:bun
@ByteYue ByteYue requested a review from jackwener March 26, 2026 06:29
@jackwener jackwener merged commit 6d1fb6d into main Mar 26, 2026
25 checks passed
@jackwener jackwener deleted the intergrate_buin branch March 26, 2026 11:10
@jackwener jackwener mentioned this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants