Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

tophat/ghost-imports-buster

Repository files navigation

This project was an idea we had that we weren't able to dedicate the resources to see it through. For this reason, we've archived this repository for now. If there's interest, we may unarchive it.

Ghost Imports Buster

All Contributors

codecov Build

👻 I ain't afraid of no ghost

A tale of well-defined dependencies

Because of how NodeJS import resolution works, it is possible for packages that are not part of your project's package.json to be resolved by import and require statements in your code. This creates a "works on machine" scenario where your code depends on packages installed outside of their respective projects, causing failures for whoever consumes your packages and does not have the same global installs.

With the ghost-imports-buster dependency validator, you can monitor dependencies declared in your package.json files and compare them against what is actually imported in your code. It then becomes easy to find and eliminate extraneous dependencies (which are declared, but not used anywhere) and fix ghost dependencies (which are not declared, but imported in code).

Installation

yarn add ghost-imports-buster -D

Usage

yarn ghost-imports-buster [--cwd <cwd>] [--include <inclusion glob>]

Configuration

You can pass in parameters to the ghost import call to customize the analysis:

Parameter Type Description
cdw string Directory root to execute the validation from, defaults to .
include string Glob to filter files to include when looking for imports, can be used multiple times to define multiple globs. Defaults to **/*
exclude string Glob to filter files to exclude when looking for imports. Same usage as include
fix boolean When set, unused dependencies are removed and undeclared ones, added. This adds latest if available.

Autofixing

By default, ghost-imports-buster will attempt to resolve undeclared packages the (loosely) same way node's require will: by crawling from the current working directory and checking in every node_modules in its path to the file system root. If a package cannot be resolved, the latest from the registry will be used instead.

Contributing

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Marc Cataford

🤔 💻 ⚠️ 📖 🚇

Shouvik DCosta

🚇

Noah

💻

This project follows the all-contributors specification. Contributions of any kind welcome!