1.0.10 • Published 7 months ago

dep-installer v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

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) for import and require statements.
  • Compares imported dependencies with those listed in package.json.
  • Prompts you to install any missing dependencies.
  • Supports npm and yarn 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

  1. Run the script: Navigate to your project directory and run the following command:
dep-installer
  1. 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.
  2. 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 or yarn.
  3. 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

  1. Scans Files: The script scans all .js and .ts files in your project directory (excluding node_modules) for import and require statements. It uses a regular expression to extract the names of the imported packages.
  2. Compares Dependencies: The tool compares the imported packages with those listed in your package.json under dependencies. If a package is imported but not declared, it is considered "missing."
  3. Prompts for Installation: If any missing dependencies are found, the tool prompts you to install them using your preferred package manager (npm or yarn).
  4. 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.

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago