batch-upgrade-npm-packages
v1.1.0
Published
A CLI tool to upgrade npm packages across multiple repositories with automatic PR creation
Maintainers
Readme
Batch Upgrade NPM Packages
A command-line tool to upgrade npm packages across multiple repositories with automatic PR creation.
Features
- Update npm packages across multiple repositories in one go
- Create unique branches for changes in each repository
- Create pull requests automatically for code review
- Verify package installation with both force and regular installs
- Skip packages already at or above the requested version
- Command-line and interactive modes
- Colorful terminal output for better visibility
Requirements
- Node.js 14 or higher
- Git
- GitHub CLI (gh) - Must be authenticated before running
- npm
Installation
Global Installation (Recommended)
npm install -g batch-upgrade-npm-packagesProject Installation
npm install batch-upgrade-npm-packagesAuthentication Setup
Before using this tool, you need to authenticate with GitHub CLI:
gh auth loginFollow the prompts to complete the authentication process.
Usage
Interactive Mode
The easiest way to use this tool is in interactive mode:
batch-upgrade-npm -iThis will guide you through the process with prompts for:
- Packages to update (space-separated)
- Version ranges (space-separated, matching package order)
- Repository paths (space-separated, relative to current directory)
Command Line Mode
You can also provide all parameters on the command line:
batch-upgrade-npm -p package1 package2 -v "^1.0.0" "^2.0.0" -r repo1 repo2Where:
-p, --packages: Space-separated list of packages to update-v, --versions: Space-separated list of version ranges (must match packages in order)-r, --repos: Space-separated list of repository paths relative to current directory
Examples
Update multiple packages in multiple repositories:
batch-upgrade-npm -p @company/pkg1 @company/pkg2 -v "^1.0.0" "^2.2.1" -r repo1 repo2Update a single package in a single repository:
batch-upgrade-npm -p react -v "^18.0.0" -r my-appHow It Works
For each repository, the tool will:
- Check out the main branch and pull latest changes
- Create a new branch for package updates
- Update the specified packages to their target versions
- Skip packages not found in the repository
- Skip packages already at or above the requested version
- Verify installations using:
- Remove node_modules directory for a clean environment
- First attempt with 'npm install --force'
- Remove node_modules again
- Second verification with regular 'npm install'
- Commit changes if any updates were made
- Push the branch to origin
- Create a pull request with details of the updates (only if changes were made)
Safety Features
- Will not commit directly to main branch
- Discards any uncommitted changes in repositories
- Validates GitHub CLI authentication before proceeding
- Creates descriptive pull requests for review before merging
- Cleans up branches if no changes were made
- Double verification of package installations
- Clean node_modules removal before installations
- Skips updating packages that are already up-to-date
- Skips creating PRs when no changes were made
License
MIT
