BetterPack - A Universal Node.js Package Manager CLI
BetterPack (bpack) is a command-line interface (CLI) tool designed to simplify package management across different Node.js ecosystems. It automatically detects the package manager used in your project (npm, yarn, or pnpm) and translates universal commands into the appropriate commands for that manager.
Installation
You can install BetterPack globally using your favorite package manager:
npm
npm install -g betterpack
yarn
yarn global add betterpack
pnpm
pnpm add -g betterpack
bun
bun add -g betterpack
Supported Package Managers
- npm (Node.js Package Manager)
- yarn
- pnpm
- bun
Universal Commands
BetterPack provides a consistent set of commands:
install: Install dependencies.add: Add a new package/dependency.remove: Remove an existing package/dependency.update: Update dependencies.run>: Run a script defined in the project'spackage.json.test: Run tests.build: Build the project.outdated: Check for outdated dependencies.list: List installed packages.doctor: Run a health check on the project.
Betterpack Commands
bpack gemini
Starts an interactive chat session with Google's Gemini AI.
bpack host
Starts a local web server in the current directory.
- Default Port:
4020 - Default Host:
0.0.0.0
bpack listversions
Lists the installed versions of all supported package managers.
bpack manage
A suite of commands for managing global packages and the tool itself.
bpack manage: Manage global packages for a specific package manager.[args] bpack manage selfupdate: Automatically updatesbetterpackto the latest version.bpack manage about: Opens the project's GitHub repository or npm page in your browser.bpack manage support: Opens the "Buy Me a Coffee" page to support the project.bpack manage git autocommit: Enable or disable autocommit.
bpack node
Executes a JavaScript file using Node.js.
bpack watch
Watches a file for changes and automatically restarts the process.
bpack repair
Attempts to repair a broken betterpack installation by reinstalling it and clearing package manager caches.
bpack noinstall
Runs a command without installing the package globally, using pnpm dlx or yarn dlx.
bpack create-shortcut
Creates a shortcut for a bpack command. For example, bpack create-shortcut bl bpack list will allow you to run bpack list by simply typing bl.
bpack git
A wrapper for common git commands.
bpack git init: Initialize a new git repository.bpack git clone: Clone a repository.bpack git pull: Pull changes from the remote repository.bpack git push: Push changes to the remote repository.bpack git commit: Commit changes. If autocommit is enabled, Gemini will generate a commit message.
Usage
Once installed, you can use `bpack` from any Node.js project directory. BetterPack will automatically detect the package manager from the lock file (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`) and use it to run the commands.
Examples
Install dependencies:
bpack install
Add a new dependency:
bpack add express
Run a script from your `package.json`:
bpack run dev
Configuration
BetterPack works out of the box with no configuration required. However, you can customize its behavior using a .bpackrc file in your project's root directory. The configuration file should be in JSON format.
Example .bpackrc
{
"defaultPackageManager": "pnpm",
"autoCommit": true
}
Options
- defaultPackageManager: Set a default package manager to use if no lock file is found. Can be `npm`, `yarn`, or `pnpm`.
- autoCommit: Enable or disable autocommit for git commands. Can be `true` or `false`.
How it Works
- Detection: BetterPack checks for the presence of
package-lock.json(for npm),yarn.lock(for yarn), orpnpm-lock.yaml(for pnpm) in the current directory to identify the active package manager. - Translation: Based on the detected package manager, it translates the universal command (e.g.,
install) into the manager-specific command (e.g.,npm install,yarn install,pnpm install). - Execution: The translated command is then executed using Node.js's
child_process.spawn.