g3k0 / dependencies-hoover

cleans unused dependencies from node.js projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependencies Hoover

A superfast Node.js projects dependencies cleaner.

Overview

Dependencies Hoover scans a Node.js project (both js and ts), searches recursively for package.json files and if a dependency (included devDependencies) is not imported in a source file or is not present inside the node_modules/.bin folder, removes the dependency from the package.json.
A final report file is produced after the scan.
The application can run in cleaning mode or analysis_only mode, in this case only the report is produced and the dependencies are not removed.

Dependencies Hoover is entirely written in Rust, it reads at runtime from a configuration file, so it is possible to change the configuration with no need to compile the source code again.

Configuration

The configuration is contained in the config.toml file, it has 4 parameters:

  • project_to_scan_path: is the path (full of relative) of the Node.js project to scan;
  • analysis_only: is a boolean flag that permits to perform only the code analysis without the dependencies being removed;
  • ignore_dirs: is the list of directories that Dependencies Hoover will ignore;
  • dependencies_whitelist: is a list of dependencies that are ignored by Depencies Hoover, wrote as regex strings;

Build

In order to build the application, rust and cargo must be installed on the local machine. Once installed, go to the root directory of this project and run the command:

cargo build

if you want to build a release version run:

cargo build --release

The release version of the executble is optimized, but it will take longer to compile.
The executable will be produced under the target folder.

How to run

Before to run the application edit the config.toml file depending on your needs.

If you want to run the application in development mode, it is possible to install the dependencies, build and run the application at the same time with the following command:

cargo run

If you want to run the executable, be sure that the config.toml file is present and the executable has the needed rights (read, write and execution), then just run from a shell:

./dependencies_hoover

If the execution is correct, a report is written in a reports folder.

Test

In order to run tests type the following command:

cargo test

Code Coverage Report

It is possible to generate a code coverage report if the following prerequisites are satisfied:

Then, follow these steps:

  1. build the application with the cargo build command;
  2. execute the tests with the cargo test command;
  3. generate the report with the following command:
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/

The HTML report is generated under the following path:

target/debug/coverage

At the time of writing, the application has about the 75% of code coverage.

Notes

This application is developed and tested with the stable release of Rust:

rustc 1.65.0 (897e37553 2022-11-02)

About

cleans unused dependencies from node.js projects


Languages

Language:Rust 99.6%Language:JavaScript 0.4%