Auto-Dep-Install is a Node.js CLI tool designed to streamline dependency management, making it easier for developers to focus on coding without being interrupted by the need to manually run npm install package or npm update package. This tool automatically installs missing packages, updates outdated ones, and removes unused dependencies—without any manual intervention required.
By monitoring your project’s codebase for import (ES6) and require (commonJS) statements, Auto-Dep-Install ensures that only the packages actively used in your code are installed. When you add an import, it automatically installs the required package. When you remove an import, it will uninstall the package if it's no longer being used elsewhere in your project. It also handles peer dependency errors, ensuring that your project environment stays in sync with compatible package versions.
This tool works seamlessly in Node.js, React, and React Native projects.
- Real-Time File Monitoring:
Continuously watches your project files for any additions, modifications, or deletions, utilizing chokidar to automatically trigger dependency updates when changes are detected. - Automated Dependency Management:
Seamlessly handles the installation and uninstallation of dependencies by scanning your code forimportandrequirestatements. It automatically installs missing packages and removes unused ones, eliminating the need for manual dependency management throughnpm install packageornpm uninstall package. - Support for Modern JavaScript, JSX, and TypeScript:
Leverages @babel/parser to effectively parse and analyze modern JavaScript, JSX, and TypeScript files, ensuring full compatibility across various project setups. - Framework Agnostic Compatibility:
Designed to work flawlessly with Node.js, React, and React Native projects, making it a versatile tool for a wide range of applications. - Intelligent Peer Dependency Resolution:
Automatically handles peer dependency conflicts by resolving and installing the most compatible versions, ensuring that all dependencies work harmoniously within your project environment without the need for manual conflict resolution. - Automatic Dependency Updates:
Keeps your dependencies up to date by automatically updating them to the latest compatible versions, based on your project's requirements. This ensures your project stays current without the need for manual version management. - Automatic Cleanup of Unused Packages:
If a package is no longer referenced in your code, Auto-Dep-Install will automatically uninstall it from yournode_modulesand remove it from yourpackage.json, helping to maintain a lean and clean project environment.
Since this package is now published, install it globally via npm:
npm install -g auto-dep-installOr install it as a dev dependency in your project:
npm install --save-dev auto-dep-installTo verify the installation, run:
npx auto-install --helpStart monitoring your project with:
npx auto-installThe tool will watch for changes in your project files (e.g., .js, .jsx, .ts, .tsx) and update dependencies automatically.
To perform a full scan (install missing dependencies and uninstall unused ones) without entering watch mode, run:
npx auto-install --installFor available options and usage details, run:
npx auto-install --helpThe following simple Node.js code demonstrates the core functionality:
In this version, example.js imports lodash. When you save this file, Auto-Dep-Install detects the require('lodash') call and runs npm install lodash if it isn’t installed.
// example.js (Version 1)
const _ = require('lodash');
console.log('Lodash is available:', _.isEmpty({}));If lodash is removed, Auto-Dep-Install scans your project and, if no file references lodash, it runs npm uninstall lodash to remove it.
// example.js (Version 2)
console.log('No external dependencies are required.');If you encounter issues, enable debug mode:
DEBUG=auto-dep-install:* npx auto-installContributions are welcome! If you have improvements or bug fixes, please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or issues, please open an issue in the repository.