dep-installer v1.0.10
dep-installer
dep-installer
is a simple command-line tool that helps you identify and install missing dependencies in your project. It checks for imported packages in your project files and compares them with the declared dependencies in package.json
. If any packages are missing, the tool offers to install them using your preferred package manager (npm, yarn, etc.).
Features
- Scans your project files (
.js
and.ts
by default) forimport
andrequire
statements. - Compares imported dependencies with those listed in
package.json
. - Prompts you to install any missing dependencies.
- Supports
npm
andyarn
package managers (more can be added). - Handles both default and scoped package names.
Installation
To use dep-installer
, you need to have Node.js installed. Then, you can install the package globally or as a dev dependency in your project.
Install globally:
npm install -g dep-installer
Install as a dev dependency:
npm install --save-dev dep-installer
Usage
- Run the script: Navigate to your project directory and run the following command:
dep-installer
- Scan for missing dependencies: The tool will scan your project files for imported packages and compare them with the dependencies declared in your
package.json
. - Install missing dependencies: If any missing dependencies are found, the tool will list them and ask if you want to install them. You can choose to install them using
npm
oryarn
. - Installation process: The script will attempt to install the missing dependencies and show progress. If any installation fails, it will display a list of failed packages.
Example Output
Dependencies not declared in package.json:
- lodash
- axios
Do you want to install these dependencies now? (y/n) y
Which package manager would you like to use?
npm
yarn
Installing dependencies... 3/3
Dependencies install done (3/3)
How It Works
- Scans Files: The script scans all
.js
and.ts
files in your project directory (excludingnode_modules
) forimport
andrequire
statements. It uses a regular expression to extract the names of the imported packages. - Compares Dependencies: The tool compares the imported packages with those listed in your
package.json
underdependencies
. If a package is imported but not declared, it is considered "missing." - Prompts for Installation: If any missing dependencies are found, the tool prompts you to install them using your preferred package manager (
npm
oryarn
). - Installs Missing Packages: If you choose to install the missing dependencies, the tool will attempt to install them and show progress in the terminal.
Configuration
By default, dep-installer
looks for .js
and .ts
files. You can modify the file extensions or add additional options by modifying the script directly.
Customizing File Extensions
To scan additional file types (e.g., .jsx
, .tsx
), you can modify the getImportsFromFiles
function in the script:
} else if (file.endsWith('.js') || file.endsWith('.ts') || file.endsWith('.jsx') || file.endsWith('.tsx')) {
Changing Package Manager
The script currently supports npm
and yarn
. If you'd like to add support for other package managers, you can modify the prompt choices in the main()
function.
Contributing
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.