| name | dependency-doctor |
| description | Diagnose and heal dependency issues in ANY package manager, ANY language. Use when facing version conflicts, security vulnerabilities, or dependency bloat. |
Dependency Doctor - Heal Your Package Problems
šÆ When to Use This Skill
Use when experiencing:
- Security vulnerabilities in dependencies
- Version conflicts ("dependency hell")
- Broken builds after updates
- Slow install times
- Large node_modules/vendor folders
- "Works on my machine" issues
- License compliance concerns
ā” Quick Health Check (30 seconds)
Universal Diagnosis Commands:
npm audit
npm outdated
npm ls --depth=0
pip check
pip list --outdated
safety check
mvn dependency:tree
mvn versions:display-dependency-updates
go mod tidy
go list -m -u all
bundle audit
bundle outdated
dotnet list package --vulnerable
dotnet list package --outdated
cargo audit
cargo outdated
š Common Dependency Diseases & Cures
1. Security Vulnerabilities šØ
WITH MCP (Security Scanner):
"Scan my dependencies for security vulnerabilities"
"Fix all high-severity security issues"
WITHOUT MCP:
Diagnosis:
npm audit --json | jq '.metadata.vulnerabilities'
pip install safety
safety check --json
gem install bundler-audit
bundle audit check
Treatment:
npm audit fix
npm audit fix --force
npm install package-name@latest
pip install --upgrade package-name
Prevention:
{
"scripts": {
"security": "npm audit --audit-level=moderate",
"preinstall": "npm audit"
}
}
2. Version Conflicts (Dependency Hell) š„
Symptoms:
- "Cannot resolve dependency tree"
- "Peer dependency not satisfied"
- Different versions required by different packages
Diagnosis:
npm ls package-name
npm explain package-name
pip check
pipdeptree -p package-name
Treatment:
rm -rf node_modules package-lock.json
npm install
{
"overrides": {
"package-name": "1.2.3"
}
}
npm install --save-dev npm-force-resolutions
python -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt
3. Bloated Dependencies š
Diagnosis - Find the Culprits:
npm install -g npm-check
npm-check
du -sh node_modules/* | sort -hr | head -20
npx webpack-bundle-analyzer stats.json
Treatment - Diet Plan:
const HEAVY_TO_LIGHT = {
moment: 'dayjs',
lodash: 'lodash-es',
request: 'node-fetch',
bluebird: 'native',
jquery: 'vanilla',
};
import _ from 'lodash';
import debounce from 'lodash/debounce';
const heavyLib = () => import('heavy-library');
Bundle Size Budget:
{
"bundlesize": [
{
"path": "./dist/app.js",
"maxSize": "100 kB"
}
]
}
4. Outdated Dependencies š
Safe Update Strategy:
npm outdated
npm update
npm install package@^1
npm install package@latest
npm test
Automated Updates with Checks:
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
open-pull-requests-limit: 10
groups:
minor-and-patch:
patterns:
- '*'
update-types:
- 'minor'
- 'patch'
5. Ghost Dependencies š»
Find Unused Dependencies:
npx depcheck
pip install pip-autoremove
pip-autoremove -l
Clean Up:
npm uninstall package-name
npx depcheck --json | jq '.dependencies[]' | xargs npm uninstall
š Dependency Management Best Practices
1. Lock Files Are Sacred
git add package-lock.json
git add yarn.lock
git add pnpm-lock.yaml
git add Pipfile.lock
git add go.sum
npm ci
2. Dependency Hygiene Routine
const weeklyMaintenance = async () => {
await exec('npm audit');
await exec('npx depcheck');
await exec('npm update');
await exec('npm outdated');
await exec('npm cache clean --force');
await exec('npm dedupe');
};
3. Version Range Strategies
{
"dependencies": {
"critical-lib": "1.2.3",
"stable-lib": "~1.2.3",
"modern-lib": "^1.2.3",
"experimental": "*"
}
}
šØ Emergency Procedures
Broken After Update:
git checkout package-lock.json
npm ci
npm ls package-name
git diff package-lock.json
npm install package-name@1.2.3 --save-exact
Cannot Install Dependencies:
rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install
node --version
nvm use 18
npm config set registry https://registry.npmjs.org/
Production Emergency:
# Reproducible builds in Docker
FROM node:18-alpine
WORKDIR /app
# Copy lock file FIRST
COPY package*.json ./
# Use ci for exact versions
RUN npm ci --only=production
# Then copy code
COPY . .
CMD ["node", "app.js"]
š Dependency Metrics
Track Your Health:
const getMetrics = async () => {
const metrics = {
total: Object.keys(require('./package.json').dependencies).length,
outdated: await getOutdatedCount(),
vulnerable: await getVulnerabilityCount(),
unused: await getUnusedCount(),
duplicates: await getDuplicateCount(),
size: await getTotalSize(),
};
metrics.health = calculateHealth(metrics);
return metrics;
};
function calculateHealth(metrics) {
let score = 100;
score -= metrics.vulnerable * 10;
score -= metrics.outdated * 2;
score -= metrics.unused * 3;
score -= metrics.duplicates;
if (metrics.total > 100) score -= 10;
if (metrics.size > 100_000_000) score -= 10;
return Math.max(0, score);
}
š”ļø Dependency Security Policy
# Security Policy
## Automated Checks
- CI runs `npm audit` on every PR
- Dependabot creates PRs for security updates
- Weekly security report via GitHub Actions
## Severity Levels
- **Critical**: Fix immediately, hotfix to production
- **High**: Fix within 24 hours
- **Moderate**: Fix within 1 week
- **Low**: Fix in next release
## Approved Sources
ā
npm official registry
ā
GitHub packages (our org)
ā Random GitHub repos
ā Unverified registries
## License Requirements
ā
MIT, Apache 2.0, BSD
ā ļø GPL (check with legal)
ā Proprietary, AGPL
š Preventive Medicine
Dependency Budget:
const BUDGET = {
maxDependencies: 50,
maxSize: 50_000_000,
maxDepth: 3,
allowedLicenses: ['MIT', 'Apache-2.0', 'BSD'],
bannedPackages: ['left-pad', 'is-odd'],
};
function checkBudget(packageName) {
const metrics = getCurrentMetrics();
if (metrics.count >= BUDGET.maxDependencies) {
throw new Error('Dependency budget exceeded');
}
if (isBanned(packageName)) {
throw new Error(`Package ${packageName} is banned`);
}
return true;
}
Dependency Documentation:
## Why This Dependency?
### Package: stripe
**Purpose**: Payment processing
**Alternatives considered**: PayPal SDK, Square
**Why chosen**: Best API, good docs
**Can we remove?**: No, core feature
**Owner**: Payment team
### Package: lodash
**Purpose**: Utility functions
**Alternatives considered**: Ramda, native
**Why chosen**: Team familiarity
**Can we remove?**: Yes, migrate to lodash-es
**Owner**: Frontend team
šÆ Quick Reference Card
alias dephealth='npm audit && npm outdated && npx depcheck'
alias depfix='rm -rf node_modules package-lock.json && npm cache clean --force && npm install'
alias depsafe='npm update && npm test && npm audit'
alias depmaint='npm audit fix && npm dedupe && npm prune && npx depcheck'
Remember: Dependencies are like medicine - necessary but can have side effects. Use wisely! š