CLI tool to audit & auto-update Node.js dependencies via GitHub PRs
Project description
DepGuardian
DepGuardian is a Python CLI tool that helps you monitor and update your project dependencies. It currently focuses on Node.js (NPM) dependencies, checking if your direct dependencies are up-to-date and if any installed packages (direct or transitive) have known vulnerabilities. It can even automate the process of updating a single dependency by opening a GitHub Pull Request.
Features
-
Outdated Dependency Check: Scans your
package.jsonandpackage-lock.json(v1, v2, v3 supported) to find direct dependencies that are out of date compared to the NPM registry's 'latest' tag. Reports the installed version, latest available version, and whether the installed version satisfies the range specified inpackage.json. -
Vulnerability Audit: Queries the Open Source Vulnerabilities (OSV) database (osv.dev) for any known vulnerabilities affecting your project’s installed package versions (from
package-lock.json). -
Automated Update PR (Experimental): Optionally, for the first outdated direct dependency found, DepGuardian can:
- Create a new git branch (e.g.,
depguardian/update-express-4.18.2). - Run
npm install <package>@<latest_version>. - Commit the
package.jsonandpackage-lock.jsonchanges. - Push the branch to your
originremote. - Open a Pull Request on GitHub targeting your repository's default branch.
- Prerequisites for PR creation:
- A clean Git working directory (no uncommitted changes or untracked files).
- The
gitcommand available in your PATH. - The
nodeandnpmcommands available in your PATH. - A GitHub Personal Access Token (Classic or Fine-Grained) with
reposcope (or specific write permissions for PRs/code) provided via the--github-tokenoption orGITHUB_TOKENenvironment variable. - The target GitHub repository specified via
--github-repoor theGITHUB_REPOSITORYenvironment variable (inowner/repoformat).
- Create a new git branch (e.g.,
Installation
# From PyPI (Recommended)
pip install dep-guardian
# From source (for development)
git clone [https://github.com/AbhayBhandarkar/DepGuardian.git](https://github.com/AbhayBhandarkar/DepGuardian.git)
cd DepGuardian
pip install -r requirements_dev.txt # Install dev dependencies
pip install -e . # Install in editable mode
npm install # Install Node.js 'semver' package needed by the helper script
Usage
Checking Dependencies
Navigate to your Node.js project directory (containing package.json and package-lock.json) and run:
depg check
Example Output:
Scanning project at: /path/to/your/project
Found 2 direct dependencies in package.json.
Found 158 installed packages in package-lock.json.
--------------------
Checking Direct Dependencies against NPM Registry:
- Checking express (^4.17.1)... Installed=4.17.1 | Latest=4.18.2 | satisfies range | Update available: 4.18.2
- Checking jest (^27.0.0)... Installed=27.5.1 | Latest=29.5.0 | DOES NOT satisfy range | Update available: 29.5.0
--------------------
Checking for Known Vulnerabilities (OSV API):
Querying OSV for 158 package versions...
OSV query complete. Found 0 vulnerabilities affecting 0 package versions.
No known vulnerabilities found in installed packages.
--------------------
Summary:
2 direct dependencies are outdated.
No vulnerabilities found.
Options:
--path /path/to/project: Specify the project directory if not the current one.--verboseor-v: Show more detailed debug logging.
Creating an Automated Pull Request
To automatically create a PR for the first outdated dependency found:
# Ensure GITHUB_TOKEN is set in your environment
export GITHUB_TOKEN="ghp_YourTokenHere..."
# Run the check with the --create-pr flag and specify the repo
depg check --create-pr --github-repo YourGitHubUsername/YourRepoName
Output for PR Creation:
... [previous check output] ...
Summary:
2 direct dependencies are outdated.
No vulnerabilities found.
Attempting to auto-update express from 4.17.1 -> 4.18.2
Found Git repository at: /path/to/your/project
Creating new branch 'depguardian/update-express-4.18.2' from 'main'
Running: npm install express@4.18.2 in /path/to/your/project
Staging files: ['package.json', 'package-lock.json']
Committing with message: Update express from 4.17.1 to 4.18.2
Automated by DepGuardian.
Pushing branch 'depguardian/update-express-4.18.2' to remote 'origin'...
Branch 'depguardian/update-express-4.18.2' pushed successfully.
Creating Pull Request on 'YourGitHubUsername/YourRepoName' from 'depguardian/update-express-4.18.2' to 'main'...
Pull Request created: [https://github.com/YourGitHubUsername/YourRepoName/pull/123](https://github.com/YourGitHubUsername/YourRepoName/pull/123)
Check complete.
Exit Codes:
0: Check completed successfully, no outdated dependencies or vulnerabilities found (or PR created successfully if requested).1: Check completed, but outdated dependencies or vulnerabilities were found, OR an error occurred during processing (e.g., network issue, PR creation failure). Check logs for details.2: Usage error (e.g., invalid command-line arguments).
Development
- Clone the repository.
- Create a virtual environment:
python -m venv .venv && source .venv/bin/activate - Install dependencies:
pip install -r requirements_dev.txt && pip install -e . - Install Node helper dependency:
npm install - Run linters:
flake8 .andblack --check . - Run tests:
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dep_guardian-0.1.1.tar.gz.
File metadata
- Download URL: dep_guardian-0.1.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
840ed549f61c3778f50fd093863982c17adeb258c47e415f38b7007c6e0e56fd
|
|
| MD5 |
50700f78ca9ad95c348efab28f46659c
|
|
| BLAKE2b-256 |
8b846a800f376719abfd9fc12dac8a1974e4be0ea1c464f2ca663c88ca2d7c15
|
File details
Details for the file dep_guardian-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dep_guardian-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e44bd0420dffc2d81c9f84375979371cf717a7ff9093bda98c1f77138a1484b
|
|
| MD5 |
90a5f64ecf2d72c92afe81f1b8e7e4e4
|
|
| BLAKE2b-256 |
11249c03edc303664edcdf7e50d4352946956449284ee897f2b3769fa0e30c63
|