| name | npm-deps |
| description | Manage npm dependencies: audit, update, dedupe, outdated, lockfile, workspaces, and package tree analysis. Trigger: when managing npm packages, npm outdated, npm update, npm audit, npm install, package.json dependencies, node_modules, npm ci, npm dedupe |
| version | 1 |
| argument-hint | [outdated|update|audit|dedupe|ci|ls <package>] |
| allowed-tools | ["bash","read","write","grep","glob"] |
NPM Dependency Management
You are now operating in npm dependency management mode.
Installation Check
node --version
npm --version
cat package.json
Listing and Auditing
npm outdated --json
npm outdated
npm ls --depth=0
npm ls lodash
npm ls --all --depth=0 2>/dev/null | grep -v UNMET
npm audit
npm audit --json
npm audit fix
npm audit fix --force
Installing Dependencies
npm install
npm ci
npm install <package>
npm install --save-dev <package>
npm install <package>@1.2.3
npm install <package>@latest
npm install -g <package>
npm install --ignore-scripts
Updating Dependencies
npm update
npm update <package>
npm install <package>@latest
npx npm-check-updates -u && npm install
npx npm-check-updates
Conservative vs Aggressive Update Strategy
Conservative (within declared semver ranges — lowest risk)
npm update
npm audit fix
npm test
Moderate (latest within major version)
npx npm-check-updates --target minor
npm install
npm test
Aggressive (includes major version bumps)
npx npm-check-updates -u
npm install
npm test
Cleaning Up
npm dedupe
npm prune
npm prune --production
rm -rf node_modules package-lock.json
npm install
Lockfile Management
npm install
npm ci --dry-run 2>&1 | head -5
cat package-lock.json | head -5
git diff package-lock.json | head -50
npm ci
Workspace Management (npm 7+)
npm ls --workspaces --depth=0
npm install --workspaces
npm run build --workspace=packages/ui
npm run test --workspaces
npm install lodash --workspace=packages/api
npm run build -ws --if-present
Dependency Analysis
npm ls <package> --all
du -sh node_modules/*/ 2>/dev/null | sort -h | tail -20
npm audit --json | jq '.vulnerabilities | keys[]'
npm audit --json | jq '.vulnerabilities | to_entries[] | select(.value.severity == "high" or .value.severity == "critical") | .key'
npm ls --all --parseable 2>/dev/null | wc -l
Publishing and Pack
npm pack --dry-run
npm pack
npm install ./mypackage-1.0.0.tgz
package.json Scripts Reference
{
"scripts": {
"prepare": "npm run build",
"pretest": "npm run lint",
"test": "jest",
"posttest": "npm run coverage",
"build": "tsc",
"clean": "rm -rf dist node_modules"
}
}
npm run build
npm test -- --watch
npm run prebuild
Common CI Workflow
npm ci
npm run build
npm test
npm audit --audit-level=high
Best Practices
- Always commit
package-lock.json to version control for reproducible builds.
- Use
npm ci in CI environments — it never modifies package-lock.json.
- Run
npm audit in CI and fail builds on high or critical vulnerabilities.
- Pin exact versions in production with
--save-exact for critical dependencies.
- Use
--save-dev for tools that are not needed at runtime (linters, test runners, TypeScript).
- Prefer
npm dedupe after major updates to reduce bundle size.
- Run
npm prune to remove packages left over from removed dependencies.
- Review
npm outdated weekly; apply patch updates promptly; schedule major updates.