bunenv v0.2.6
bunenv
A version manager for Bun JavaScript runtime, inspired by tools like rbenv and nvm.
Features
- š Install and manage multiple Bun versions
- š Switch between versions globally or per project
- š Automatic version detection using
.bun-version
files - š ļø Shell integration for seamless version switching
- š Support for bash, zsh, and fish shells
- šŗ Homebrew installation support
Development Status
The project is now ready for initial release with all core functionality in place:
- ā Core modules: Version resolver, Path utilities, and Configuration
- ā Version manager: Installation, listing, and management of Bun versions
- ā Shim generator: Creation and management of shims for version switching
- ā CLI Commands: All commands are implemented and working
- ā Testing: Unit tests passing, direct function tests implemented, integration tests in progress
- ā Documentation: Comprehensive documentation with guides and examples
- ā Distribution: npm packaging and CI/CD workflows configured
Current focus
- Ongoing testing improvements
- Community feedback and bug fixes
- Additional features based on user needs
Documentation
- Shell Integration Guide - Detailed guide on setting up and troubleshooting shell integration
Examples
- Project-Specific Version Management - How to manage Bun versions per project
- Global Version Management - Setting up and working with global Bun versions
- Temporary Version Switching - Temporarily using different Bun versions
Installation
Prerequisites
- Node.js 16+ or Bun
- UNIX-like operating system (macOS, Linux) or Windows with WSL
Using Homebrew (macOS and Linux)
The easiest way to install bunenv on macOS or Linux is via Homebrew:
# Install bunenv via Homebrew
brew install jonathanphilippou/tap/bunenv
# Verify the installation
bunenv --version
Quick Install (Recommended)
Alternatively, you can install bunenv using our installer script:
# Using curl
curl -o- https://raw.githubusercontent.com/jonathanphilippou/bunenv/main/install.sh | bash
# Or using wget
wget -qO- https://raw.githubusercontent.com/jonathanphilippou/bunenv/main/install.sh | bash
This script will install bunenv and set up shell integration automatically.
Install via npm
npm install -g bunenv
# Then set up shell integration
bunenv init >> ~/.bashrc # or your appropriate shell config file
source ~/.bashrc
Install via Bun
bun install -g bunenv
# Then set up shell integration
bunenv init >> ~/.bashrc # or your appropriate shell config file
source ~/.bashrc
Manual installation
- Clone the repository:
git clone https://github.com/jonathanphilippou/bunenv.git
cd bunenv
- Install dependencies:
npm install
# or if you have Bun installed
bun install
- Build the project:
npm run build
# or
bun run build
- Link the binary:
npm link
# or
bun link
- Set up shell integration:
bunenv init >> ~/.bashrc
# Or for zsh
bunenv init --shell zsh >> ~/.zshrc
# Or for fish
bunenv init --shell fish >> ~/.config/fish/conf.d/bunenv.fish
- Restart your shell or source the configuration file:
source ~/.bashrc
# Or for zsh
source ~/.zshrc
Quick Start
Installing Bun versions
# Install a specific version
bunenv install 1.0.0
# List installed versions
bunenv list
Setting global version
# Set the global Bun version
bunenv global 1.0.0
# View current global version
bunenv global
Setting local version
# Set the local Bun version for the current directory
bunenv local 1.0.0
# View current local version
bunenv local
Temporary version switching
# Spawn a new shell with a specific Bun version
bunenv shell 1.0.0
Command Reference
bunenv install <version>
Install a specific version of Bun.
Options:
-f, --force
: Force reinstall if the version is already installed
bunenv list
List all installed Bun versions.
Aliases: ls
Options:
-a, --all
: Show all versions, including system installations
bunenv global [version]
Set or show the global Bun version.
bunenv local [version]
Set or show the local Bun version for the current directory.
bunenv shell <version>
Spawn a new shell using the specified Bun version.
bunenv version
Show the current active Bun version.
Options:
-v, --verbose
: Show detailed version information
bunenv rehash
Rebuild Bun shim executables.
bunenv init
Configure shell integration for bunenv.
Options:
-s, --shell <type>
: Specify shell type (bash, zsh, fish)
How it Works
bunenv works by creating a directory of shims, which map to the commands for the selected Bun version. When you run a shim, bunenv determines which Bun version to use by checking:
- The
BUNENV_VERSION
environment variable - A
.bun-version
file in the current or parent directories - The global Bun version set with
bunenv global
Version Resolution
The version resolution follows this priority order:
- The
BUNENV_VERSION
environment variable - The
.bun-version
file in the current directory - The
.bun-version
file in parent directories (searching up to root) - The global version set with
bunenv global
Directory Structure
$HOME/.bunenv/
āāā versions/ # Bun versions
ā āāā 1.0.0/
ā ā āāā bin/
ā ā āāā bun
ā āāā 1.0.1/
ā āāā bin/
ā āāā bun
āāā shims/ # Command shims
āāā version # Global version file
āāā .bun-version # Local version file (in project directories)
Development
Setup
git clone https://github.com/yourusername/bunenv.git
cd bunenv
bun install
Testing
bun test # Run all tests
bun test:unit # Run unit tests
bun test:component # Run component tests
bun test:integration # Run integration tests
Building
bun run build
Project Structure
The project is structured into several key modules:
src/core/
- Core utilities (paths, config, environment)src/resolvers/
- Version resolution logicsrc/versions/
- Version management and installationsrc/shims/
- Shim generation and managementsrc/cli/
- CLI commands and utilitiessrc/utils/
- Shared utility functions
Testing Strategy
We follow a test pyramid approach:
- Unit Tests: Test individual functions in isolation
- Component Tests: Test interactions between modules
- Integration Tests: Test end-to-end functionality
Contributing
We welcome contributions of all kinds! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
Getting Started
- Fork the repository
- Clone your fork:
git clone https://github.com/yourusername/bunenv.git
- Install dependencies:
bun install
- Create a branch for your contribution:
git checkout -b my-feature-branch
Development Workflow
- Make your changes
- Run tests:
bun test
- Format your code:
bun run format
- Commit your changes following conventional commits
- Push to your fork and submit a pull request
Homebrew Formula Development
If you're working on improving the Homebrew integration:
- Read the Homebrew documentation to understand the current implementation
- Test any changes locally with
brew install --build-from-source ./homebrew/bunenv.rb
- Update the formula using the automated script:
bun homebrew:update
Code Standards
- Follow TypeScript best practices
- Write tests for new functionality
- Document your code with JSDoc comments
- Keep commits focused and descriptive
Documentation
When adding or changing features, please update the relevant documentation:
- README.md for general usage information
- Specific documentation files in the
docs/
directory
For detailed information on specific topics, check out these resources:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by rbenv and nvm
- Built with TypeScript and Bun
- Thanks to all contributors
Using npm
npm install -g bunenv
Using bun
bun install -g bunenv
Diagram:
+---------------------------------------------+
| User |
+----------------------+----------------------+
|
| (runs command: e.g., bun --version)
v
+---------------------------------------------+
| PATH lookup |
| (~/.bunenv/shims takes precedence) |
+----------------------+----------------------+
|
| (finds shim first)
v
+---------------------------------------------+
| ~/.bunenv/shims/bun | <---- Shim Script (Bash)
| | Intercepts all 'bun' calls
+----------------------+----------------------+
|
| (looks for version)
v
+---------------------/ \---------------------+
| Version Resolution Process |
| |
| 1. Check BUNENV_VERSION env var |
| 2. Look for .bun-version file (local) |
| 3. Check package.json engines.bun |
| 4. Check ~/.bunenv/version (global) |
| |
+----------------------+----------------------+
|
| (selects version)
v
+---------------------------------------------+
| ~/.bunenv/versions/{version}/bin/bun | <---- Actual bun binary
+---------------------------------------------+
| |
v v
+-------------------+ +----------------------+
| bunenv CLI Tool | | User's Bun Commands |
| (bunenv install) | | (managed by version) |
+-------------------+ +----------------------+
+---------------------------------------------+
| Core Components |
+---------------------------------------------+
| |
| ~/.bunenv/ |
| āāā shims/ |
| ā āāā bun (shim executable) |
| āāā versions/ |
| ā āāā 1.0.0/ (installed version) |
| ā ā āāā bin/ |
| ā ā āāā bun (actual executable) |
| ā āāā 1.0.22/ (another version) |
| ā āāā bin/ |
| ā āāā bun |
| āāā version (global version file)|
| |
+---------------------------------------------+
+--------------+ +--------------------+
| bunenv CLI | <---> | Version Management |
| | | (install/list/etc) |
+--------------+ +--------------------+
|
v
+-------------------------------+
| Commands: |
| - bunenv install <version> |
| - bunenv global <version> |
| - bunenv local <version> |
| - bunenv rehash |
| - bunenv list |
| - bunenv version |
| - bunenv shell <version> |
| - bunenv init |
+-------------------------------+