npm-dependency-verifier
v1.2.0
Published
A command line tool that verifies all dependencies and devDependencies in your package.json file against the npm registry.
Readme
NPM Dependency Verifier
A command line tool that verifies all dependencies and devDependencies in your package.json file against the npm registry.
Features
- Verifies package existence on npm registry
- Checks if specified versions are available
- Suggests closest available version when version is not found
- Recommends similar package names when package does not exist
- Automatically fixes issues with various modes
- Color coded output for easy reading
Installation
npm install -g npm-dependency-verifierUsage
Navigate to your project directory (where package.json is located) and run:
Verify Only
verify-depsThis will scan all dependencies and report any issues without making changes.
Fix All Issues
verify-deps --fix-allFixes both package name errors and version mismatches by updating package.json with the closest available versions and most similar package names.
Fix Version Issues Only
verify-deps --fix-versionOnly updates version numbers to the closest available version. Package names remain unchanged.
Fix Package Name Issues Only
verify-deps --fix-nameOnly updates incorrect package names with suggested alternatives. Version numbers remain unchanged.
Output
Examples
Valid Dependency
✔ [email protected]Version Not Found
✘ [email protected]
▍ Version 18.5.0 does not exist for react
▍ Closest version available: 18.2.0Package Not Found
✘ [email protected]
▍ This package does not exist
▍ Did you mean: expressHow It Works
- Reads package.json from the current directory
- Fetches package metadata from npm registry (https://registry.npmjs.org)
- Verifies each package exists
- Checks if the specified version is available
- Calculates closest available version using semantic versioning
- Searches for similar package names using npm search
- Reports findings with detailed suggestions
- Optionally updates package.json with fixes
Requirements
- Node.js 12.0.0 or higher
- npm (for package search functionality)
- Internet connection (to access npm registry)
Error Handling
The tool handles various error scenarios:
- Missing package.json file
- Network connectivity issues
- Invalid package.json format
- npm registry timeouts
- Malformed version strings
Version Matching
The tool preserves version prefixes when suggesting replacements:
^1.2.3becomes^1.2.5(if 1.2.3 does not exist)~2.0.1becomes~2.0.2(if 2.0.1 does not exist)1.0.0becomes1.0.1(exact version replacement)
Package Name Suggestions
When a package is not found, the tool uses npm search to find similar packages based on:
- String similarity algorithms
- Search relevance from npm registry
- Download popularity
Contributing
Contributions are welcome. Please ensure:
- Code follows existing style
- All features are tested
- Documentation is updated
- Commit messages are clear
License
MIT
