dependency-detective 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/worktrees/amazing-bartik-b7ca06/.claude/settings.local.json +19 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/LICENSE +21 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/README.md +151 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/docs/superpowers/specs/2026-05-09-correctness-fixes-design.md +118 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/index.js +19 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/package-lock.json +915 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/package.json +36 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/src/alternative-suggester.js +64 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/src/analyzer.js +141 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/src/security-checker.js +62 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/src/unused-detector.js +71 -0
- package/README.md +33 -11
- package/index.js +10 -3
- package/package.json +2 -1
- package/src/analyzer.js +8 -29
- package/src/ast-parser.js +79 -0
- package/src/config-scanner.js +65 -0
- package/src/security-checker.js +6 -10
- package/src/unused-detector.js +49 -71
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Read(//c/Users/Marvin Kudjo/dependency-detective/**)",
|
|
5
|
+
"Bash(node index.js --no-suggestions)",
|
|
6
|
+
"Bash(node index.js --help)",
|
|
7
|
+
"Bash(node index.js --ignore axios,chalk --no-suggestions)",
|
|
8
|
+
"Bash(node index.js --ignore axios,chalk --no-suggestions --verbose)",
|
|
9
|
+
"Bash(node index.js --no-suggestions --verbose)",
|
|
10
|
+
"Bash(npm install *)",
|
|
11
|
+
"Bash(node -e \"import\\('@babel/parser'\\).then\\(m => console.log\\('ok:', typeof m.parse\\)\\)\")",
|
|
12
|
+
"Bash(node --input-type=module)",
|
|
13
|
+
"Bash(node index.js --no-suggestions --directory .)",
|
|
14
|
+
"Bash(node -e ' *)",
|
|
15
|
+
"Bash(node -e \"const r = require\\('./package.json'\\); console.log\\(r.version\\)\")",
|
|
16
|
+
"Bash(npm version *)"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Marvin Ackerman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# dependency-detective 🕵️♂️
|
|
2
|
+
|
|
3
|
+
A powerful Node.js tool that analyzes your project's dependencies, identifies unused packages, forecasts potential security risks, and suggests better alternatives based on community engagement and update frequency.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## 🔍 Overview
|
|
7
|
+
|
|
8
|
+
**dependency-detective** addresses a common pain point that virtually every Node.js developer faces - dependency management gets messy as projects grow, and it's hard to know which packages are actually being used, which ones pose security risks, and which ones could be replaced with better alternatives.
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- **Unused Dependencies Detection**: Identifies truly unused packages that can be safely removed
|
|
13
|
+
- **Security Vulnerabilities Check**: Highlights packages with known security issues
|
|
14
|
+
- **Alternative Package Suggestions**: Recommends better alternatives based on community adoption, performance metrics, and update frequency
|
|
15
|
+
- **Detailed Reporting**: Get comprehensive information about your dependency health in an easy-to-read format
|
|
16
|
+
|
|
17
|
+
## 📋 Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Install globally
|
|
21
|
+
npm install -g dependency-detective
|
|
22
|
+
|
|
23
|
+
# Or use with npx
|
|
24
|
+
npx dependency-detective
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Run in your project directory
|
|
31
|
+
dependency-detective
|
|
32
|
+
|
|
33
|
+
# Or specify a different project directory
|
|
34
|
+
dependency-detective --directory /path/to/your/project
|
|
35
|
+
|
|
36
|
+
# Show more detailed information
|
|
37
|
+
dependency-detective --verbose
|
|
38
|
+
|
|
39
|
+
# Skip alternative package suggestions
|
|
40
|
+
dependency-detective --no-suggestions
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 📊 Example Output
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
📦 DEPENDENCY DETECTIVE REPORT
|
|
47
|
+
|
|
48
|
+
🗑️ Unused Dependencies:
|
|
49
|
+
jquery v3.6.0
|
|
50
|
+
moment v2.29.4
|
|
51
|
+
|
|
52
|
+
Removing these could save approximately ~10MB of disk space
|
|
53
|
+
|
|
54
|
+
🔒 Security Vulnerabilities:
|
|
55
|
+
lodash (1 issues)
|
|
56
|
+
|
|
57
|
+
💡 Recommended Alternatives:
|
|
58
|
+
moment → date-fns
|
|
59
|
+
jquery → No dependency needed
|
|
60
|
+
express → fastify
|
|
61
|
+
|
|
62
|
+
📋 Next Steps:
|
|
63
|
+
1. Run with --verbose flag for more detailed information
|
|
64
|
+
2. Consider removing unused dependencies with: npm uninstall [package-names]
|
|
65
|
+
3. Address security vulnerabilities by updating affected packages
|
|
66
|
+
4. Evaluate suggested alternatives for potential improvements
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 🔧 Options
|
|
70
|
+
|
|
71
|
+
| Option | Description |
|
|
72
|
+
|--------|-------------|
|
|
73
|
+
| `-d, --directory <path>` | Project directory to analyze (default: current directory) |
|
|
74
|
+
| `-v, --verbose` | Show detailed output including reasons and statistics |
|
|
75
|
+
| `--no-suggestions` | Skip suggesting alternative packages |
|
|
76
|
+
| `--help` | Display help information |
|
|
77
|
+
| `--version` | Display version number |
|
|
78
|
+
|
|
79
|
+
## 🧩 How It Works
|
|
80
|
+
|
|
81
|
+
1. **Scanning Source Code**: The tool scans your project files looking for import/require statements
|
|
82
|
+
2. **Dependency Analysis**: It cross-references found imports with your package.json
|
|
83
|
+
3. **Security Checking**: It queries security databases for known vulnerabilities
|
|
84
|
+
4. **Alternative Analysis**: It evaluates potential alternative packages based on multiple metrics
|
|
85
|
+
5. **Report Generation**: It presents findings in a clear, actionable format
|
|
86
|
+
|
|
87
|
+
## 🛠️ For Developers
|
|
88
|
+
|
|
89
|
+
### Project Structure
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
dependency-detective/
|
|
93
|
+
├── index.js # CLI entry point
|
|
94
|
+
├── package.json
|
|
95
|
+
└── src/
|
|
96
|
+
├── analyzer.js # Main analysis logic
|
|
97
|
+
├── unused-detector.js # Detects unused dependencies
|
|
98
|
+
├── security-checker.js # Checks for vulnerabilities
|
|
99
|
+
└── alternative-suggester.js # Suggests better alternatives
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Local Development
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Clone the repository
|
|
106
|
+
git clone https://github.com/yourusername/dependency-detective.git
|
|
107
|
+
cd dependency-detective
|
|
108
|
+
|
|
109
|
+
# Install dependencies
|
|
110
|
+
npm install
|
|
111
|
+
|
|
112
|
+
# Link for local testing
|
|
113
|
+
npm link
|
|
114
|
+
|
|
115
|
+
# Run tests
|
|
116
|
+
npm test
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## ⚠️ Limitations
|
|
120
|
+
|
|
121
|
+
- The tool may not detect dependencies used in dynamically generated requires or imports
|
|
122
|
+
- Security vulnerability detection relies on external databases which may not be 100% complete
|
|
123
|
+
- Alternative suggestions are based on general community metrics and might not be ideal for every specific use case
|
|
124
|
+
|
|
125
|
+
## 📝 Roadmap
|
|
126
|
+
|
|
127
|
+
- [ ] Improve detection accuracy with AST parsing
|
|
128
|
+
- [ ] Add support for monorepos and workspaces
|
|
129
|
+
- [ ] Visual reporting with charts and graphs
|
|
130
|
+
- [ ] Interactive mode for bulk actions on dependencies
|
|
131
|
+
- [ ] Customizable rules and thresholds
|
|
132
|
+
- [ ] GitHub Actions integration
|
|
133
|
+
|
|
134
|
+
## 📄 License
|
|
135
|
+
|
|
136
|
+
MIT
|
|
137
|
+
|
|
138
|
+
## 👥 Contributing
|
|
139
|
+
|
|
140
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
141
|
+
|
|
142
|
+
1. Fork the repository
|
|
143
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
144
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
145
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
146
|
+
5. Open a Pull Request
|
|
147
|
+
|
|
148
|
+
## 🙏 Acknowledgements
|
|
149
|
+
|
|
150
|
+
- Thanks to all the open-source package maintainers
|
|
151
|
+
- Inspired by similar tools like depcheck and npm-check
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Design: Correctness Fixes for dependency-detective
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-05-09
|
|
4
|
+
**Status:** Approved
|
|
5
|
+
**Scope:** Fix three correctness bugs that prevent the tool from working reliably across all project types
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Problem Summary
|
|
10
|
+
|
|
11
|
+
The tool has three bugs that affect correctness:
|
|
12
|
+
|
|
13
|
+
1. **Broken version import (`index.js`)** — the `package.json` import is commented out but `packageJson.version` is still referenced on line 10, causing a `ReferenceError` on startup.
|
|
14
|
+
2. **Hardcoded Snyk API token (`security-checker.js`)** — a real API token is committed in source code; it should come from the environment.
|
|
15
|
+
3. **React/Next.js assumption (`analyzer.js`)** — `REQUIRED_DEPENDENCIES` is a hardcoded set of React/Next.js packages excluded from the unused check, producing false negatives on any other project type.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Fix 1: Restore Version in `index.js`
|
|
20
|
+
|
|
21
|
+
**Problem:** `packageJson` is referenced but not imported, causing a crash before any analysis runs.
|
|
22
|
+
|
|
23
|
+
**Fix:** Read the version directly from `package.json` using a static JSON import with the `assert { type: 'json' }` syntax (Node 18+), or inline the version string as a fallback if import assertions cause issues. The simplest and most compatible approach is to use `createRequire` from the `module` built-in to load JSON synchronously — this works reliably across Node 16+.
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { createRequire } from 'module';
|
|
27
|
+
const require = createRequire(import.meta.url);
|
|
28
|
+
const { version } = require('./package.json');
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This replaces the commented-out import and the reference to `packageJson.version` with `version` directly.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Fix 2: Snyk Token via Environment Variable (`security-checker.js`)
|
|
36
|
+
|
|
37
|
+
**Problem:** Token is hardcoded — a security risk and breaks for any user who doesn't have that exact token.
|
|
38
|
+
|
|
39
|
+
**Fix:**
|
|
40
|
+
- Remove the hardcoded token.
|
|
41
|
+
- Read from `process.env.SNYK_API_TOKEN`.
|
|
42
|
+
- If the env var is not set, skip the vulnerability check entirely and print a clear, actionable warning:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
⚠ SNYK_API_TOKEN not set — skipping vulnerability check.
|
|
46
|
+
To enable: add SNYK_API_TOKEN=<your-token> to a .env file or your shell profile.
|
|
47
|
+
Get a free token at https://snyk.io
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- The tool continues and still reports unused dependencies and alternatives.
|
|
51
|
+
- The project already uses `dotenv`, so `.env` loading is already wired up in `index.js`.
|
|
52
|
+
|
|
53
|
+
**What changes:**
|
|
54
|
+
- `security-checker.js`: remove constant, read from `process.env`, add early-return guard.
|
|
55
|
+
- `analyzer.js`: handle the case where `checkVulnerabilities` returns `null` (skipped) vs `{}` (no vulns found). When `null`, `displayResults` omits the vulnerability section entirely and prints the skip warning instead.
|
|
56
|
+
- `README.md`: add a section documenting the `SNYK_API_TOKEN` setup.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Fix 3: Remove Hardcoded `REQUIRED_DEPENDENCIES` + Add `--ignore` Flag (`analyzer.js`, `index.js`)
|
|
61
|
+
|
|
62
|
+
**Problem:** The hardcoded exemption list silently skips packages like `react`, `next`, and `tailwindcss` regardless of whether the target project uses them, hiding real unused dependencies in non-React projects.
|
|
63
|
+
|
|
64
|
+
**Fix:**
|
|
65
|
+
- Delete the `REQUIRED_DEPENDENCIES` Set from `analyzer.js`.
|
|
66
|
+
- Add an `--ignore <packages>` CLI option to `index.js` that accepts a comma-separated list of package names to exempt:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
dependency-detective --ignore react,next,tailwindcss
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- Pass the parsed ignore list into `analyzeProject()` and filter it out before running the unused check.
|
|
73
|
+
- Default: no packages are ignored (full scan).
|
|
74
|
+
|
|
75
|
+
**What changes:**
|
|
76
|
+
- `index.js`: add `--ignore <packages>` option, parse as comma-separated array, pass to `analyzeProject`.
|
|
77
|
+
- `analyzer.js`: remove `REQUIRED_DEPENDENCIES`, accept `ignore` array in options, filter dependencies before passing to `findUnusedDependencies`.
|
|
78
|
+
- `README.md`: document the `--ignore` flag with examples.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Architecture Impact
|
|
83
|
+
|
|
84
|
+
No new files are created. All changes are confined to existing files:
|
|
85
|
+
|
|
86
|
+
| File | Change |
|
|
87
|
+
|------|--------|
|
|
88
|
+
| `index.js` | Fix version import; add `--ignore` flag |
|
|
89
|
+
| `src/analyzer.js` | Remove `REQUIRED_DEPENDENCIES`; accept `ignore` option; handle skipped vuln check |
|
|
90
|
+
| `src/security-checker.js` | Remove hardcoded token; read from env; return `null` when skipped |
|
|
91
|
+
| `README.md` | Document `SNYK_API_TOKEN` setup and `--ignore` flag |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Error Handling
|
|
96
|
+
|
|
97
|
+
- Missing `SNYK_API_TOKEN`: warn and skip, do not crash.
|
|
98
|
+
- Empty `--ignore` value (e.g., `--ignore ""`): treat as no ignores.
|
|
99
|
+
- Invalid package names in `--ignore`: silently skip (they won't match any dependency anyway).
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Testing Approach
|
|
104
|
+
|
|
105
|
+
Manual verification steps after implementation:
|
|
106
|
+
1. Run `node index.js` — confirm no ReferenceError on startup, version prints correctly.
|
|
107
|
+
2. Run without `SNYK_API_TOKEN` set — confirm warning prints and tool continues.
|
|
108
|
+
3. Run with `SNYK_API_TOKEN` set — confirm vulnerability check runs.
|
|
109
|
+
4. Run against a non-React project — confirm previously hardcoded packages are now flagged if unused.
|
|
110
|
+
5. Run with `--ignore react,next` against a React project — confirm those packages are excluded.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Out of Scope
|
|
115
|
+
|
|
116
|
+
- AST-based import detection (detection accuracy improvement, separate effort)
|
|
117
|
+
- `npm audit` integration (separate effort)
|
|
118
|
+
- Automated test suite (separate effort)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
//import packageJson from './package.json' assert { type: 'json' };
|
|
5
|
+
import { analyzeProject } from "./src/analyzer.js"
|
|
6
|
+
import 'dotenv/config';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.version(packageJson.version)
|
|
11
|
+
.description('Analyzes your project dependencies to identify unused packages, security risks, and suggest alternatives')
|
|
12
|
+
.option('-d, --directory <path>', 'project directory to analyze', process.cwd())
|
|
13
|
+
.option('-v, --verbose', 'show detailed output')
|
|
14
|
+
.option('--no-suggestions', 'skip suggesting alternative packages')
|
|
15
|
+
.action(async (options) => {
|
|
16
|
+
await analyzeProject(options);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
program.parse(process.argv);
|