Projects

April 2026

Deptrace

A CLI that tells you where a JS/TS dependency is used before you delete it. Live on npm.

Visit source
Deptrace preview hero image

Every JavaScript project eventually has that one dependency you stare at and wonder, "where the hell is this being used?"

Package managers can tell you why something is installed, and lockfiles can tell you how it got resolved, but finding where your own code uses it is still manual. You search for the package name, miss a subpath import, forget about scripts and config files, skip the type-only imports, remove the thing, and break the build.

I got tired of doing that, so I wrote a CLI that shows me all of those places first and published it on npm.

What it does

deptrace is a Node CLI that shows where a JavaScript or TypeScript project uses a dependency. You run:

npx @mxdhavgautam/deptrace <package-name> --cwd /path/to/project

The report covers:

  • which package.json section declares the package
  • installed package metadata from node_modules
  • source imports, requires, re-exports, dynamic string imports and type-only imports
  • script usage, including the package's binary names
  • config file matches, each with a confidence level
  • runtime hints, such as browser or client usage
  • a cautious verdict, one of KEEP, REMOVE_CANDIDATE, MOVE_TO_DEV_CANDIDATE, REPLACE_OR_SHRINK or INSPECT

There's also a --json flag, so other tools can read the report too.

deptrace.webp

No overconfidence

The thing I was most careful about is that deptrace never pretends to know more than it does.

An overconfident cleanup tool breaks builds, so this one is conservative on purpose. It doesn't claim to find every unused dependency in your project. It explains one dependency, in one JS/TS package root, from local evidence, and suggests a cautious next step. It will never tell you to delete something. It shows you the evidence and leaves the call to you.

The scanner

deptrace is written in TypeScript, with Commander, Babel Parser, fast-glob, YAML, Vitest and tsup.

The scanner normalizes package subpaths, handles scoped packages, and classifies each file as source, test, config or declaration. It parses import forms from the AST, scans scripts without dumb substring matching, checks config files, and reads installed package metadata, and all of that feeds the verdict.

The tests cover the annoying cases that usually make this kind of tool lie:

  • scoped package subpaths
  • type-only imports
  • declaration files
  • config imports
  • script binary usage
  • lockfile-only packages
  • hoisted workspace installs
  • duplicate declarations
  • peer and optional dependencies
  • dynamic or computed imports, which get a diagnostic instead of false certainty

When deptrace can't tell, it says so in the report.

It's a small tool, and it shows how I like to build. I picked a narrow problem, solved it properly, and made the tool show its evidence for every answer.

The package is on npm and the source is on GitHub.

Projects

April 2026

Deptrace

A CLI that tells you where a JS/TS dependency is used before you delete it. Live on npm.

Visit source
Deptrace preview hero image

Every JavaScript project eventually has that one dependency you stare at and wonder, "where the hell is this being used?"

Package managers can tell you why something is installed, and lockfiles can tell you how it got resolved, but finding where your own code uses it is still manual. You search for the package name, miss a subpath import, forget about scripts and config files, skip the type-only imports, remove the thing, and break the build.

I got tired of doing that, so I wrote a CLI that shows me all of those places first and published it on npm.

What it does

deptrace is a Node CLI that shows where a JavaScript or TypeScript project uses a dependency. You run:

npx @mxdhavgautam/deptrace <package-name> --cwd /path/to/project

The report covers:

  • which package.json section declares the package
  • installed package metadata from node_modules
  • source imports, requires, re-exports, dynamic string imports and type-only imports
  • script usage, including the package's binary names
  • config file matches, each with a confidence level
  • runtime hints, such as browser or client usage
  • a cautious verdict, one of KEEP, REMOVE_CANDIDATE, MOVE_TO_DEV_CANDIDATE, REPLACE_OR_SHRINK or INSPECT

There's also a --json flag, so other tools can read the report too.

deptrace.webp

No overconfidence

The thing I was most careful about is that deptrace never pretends to know more than it does.

An overconfident cleanup tool breaks builds, so this one is conservative on purpose. It doesn't claim to find every unused dependency in your project. It explains one dependency, in one JS/TS package root, from local evidence, and suggests a cautious next step. It will never tell you to delete something. It shows you the evidence and leaves the call to you.

The scanner

deptrace is written in TypeScript, with Commander, Babel Parser, fast-glob, YAML, Vitest and tsup.

The scanner normalizes package subpaths, handles scoped packages, and classifies each file as source, test, config or declaration. It parses import forms from the AST, scans scripts without dumb substring matching, checks config files, and reads installed package metadata, and all of that feeds the verdict.

The tests cover the annoying cases that usually make this kind of tool lie:

  • scoped package subpaths
  • type-only imports
  • declaration files
  • config imports
  • script binary usage
  • lockfile-only packages
  • hoisted workspace installs
  • duplicate declarations
  • peer and optional dependencies
  • dynamic or computed imports, which get a diagnostic instead of false certainty

When deptrace can't tell, it says so in the report.

It's a small tool, and it shows how I like to build. I picked a narrow problem, solved it properly, and made the tool show its evidence for every answer.

The package is on npm and the source is on GitHub.