npm package: @hitorisensei/check-unused-deps
Description: Another tool to analyze the JS/TS codebase for unused dependencies
Author: Piotr "Hitori" Bosak
Latest version: 0.9.0

# @hitorisensei/check-unused-deps

Finds unused dependencies in your package.json. That's it.

## What it does

Scans your code with ts-morph (the TypeScript AST thing) and checks what you're actually importing. Works with TypeScript and JavaScript files - all the extensions, doesn't matter.

Picks up:
- Regular imports
- Dynamic imports
- require() calls
- Re-exports

Also checks:
- npm scripts (for stuff like jest, eslint)
- ESLint config files (handles plugin shorthand and all that)
- tsconfig.json and other configs
- @types packages (only marks them used if you use the actual package, except @types/node which is always kept)
- Peer dependencies

## Install

```bash
npm install -g @hitorisensei/check-unused-deps
```

Or just:

```bash
npx @hitorisensei/check-unused-deps
```

## How to use

```bash
check-unused-deps                              # Run it
check-unused-deps /some/path                   # Or point it somewhere
check-unused-deps --report                     # Get a detailed text file
check-unused-deps /some/path --report          # Both
```

## Output looks like

```
📦 Reading package.json...
Found 50 dependencies to check

🔍 Scanning codebase for imports...
Found 234 source files to scan

✅ Finished scanning 234 files

... (does its thing checking scripts, configs, etc)

════════════════════════════════════════════════════════════
RESULTS
════════════════════════════════════════════════════════════

⚠️  Found 3 potentially unused dependencies:

📦 Unused in dependencies:
   - unused-package-1

🔧 Unused in devDependencies:
   - unused-dev-package-1
   - unused-dev-package-2

════════════════════════════════════════════════════════════
Total dependencies: 50
Used dependencies: 47
Potentially unused: 3
════════════════════════════════════════════════════════════
```

With `--report` you get a text file with details on where everything is used.

## Heads up

This thing isn't perfect. Might flag stuff that's actually needed if you're doing weird dynamic imports with variables or using some obscure config files I didn't think of.

Also don't blindly delete everything it suggests. Check first. I'm not responsible for your broken builds.

It's pretty good at catching the common stuff though - build tools, eslint plugins, @types packages, etc.

## Requirements

- Node 18.12+
- A package.json

## Dev stuff

```bash
npm install
npm run build
npm test
```

Code's split into modules if you want to poke around:
- `types.ts` - interfaces
- `package-analyzer.ts` - reads package.json
- `import-scanner.ts` - scans code with ts-morph
- `config-scanner/` - checks different config files
- `dependency-detector.ts` - handles special cases
- `report-generator.ts` - makes the report
- `index.ts` - ties it all together

If you want to add support for more config files or whatever, the code should be straightforward enough to figure out where it goes.

## License

MIT

---

Made because I got tired of manually checking this stuff and other libraries were very slow on large projects.