关于 deps
deps 是用于审计、分析和管理项目依赖的技能,面向使用 npm、yarn 或 pnpm 的开发者。它涵盖安全审计、过期与未使用依赖检查、升级和依赖树查看。
主要功能
- 01使用 npm、yarn、pnpm 审计安全问题
- 02检查过期的软件包
- 03升级全部或指定依赖
- 04分析依赖来源及未使用包
- 05查看依赖树与软件包信息
适用场景
- 01定期检查项目依赖的安全风险
- 02定位过期依赖并规划升级
- 03清理未使用的软件包
- 04调查某个软件包的引入来源
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ johnlindquist/ claude --skill deps安装后在 Claude Code 中输入/deps确认已加载。
详细介绍
依赖管理器
审计、分析并管理项目依赖。
前置要求
至少一个包管理器:
# npm (comes with Node.js)
node --version
# yarn
npm install -g yarn
# pnpm
npm install -g pnpm
用于依赖分析:
npm install -g depcheck
命令行参考
安全审计
npm
# Run security audit
npm audit
# JSON output
npm audit --json
# Only production deps
npm audit --omit=dev
# Fix automatically
npm audit fix
# Fix with breaking changes (careful!)
npm audit fix --force
yarn
yarn audit
yarn audit --json
pnpm
pnpm audit
pnpm audit --json
检查过时的包
npm
# List outdated
npm outdated
# JSON output
npm outdated --json
# Long format with details
npm outdated --long
yarn
yarn outdated
pnpm
pnpm outdated
pnpm outdated --json
升级包
npm
# Update to latest within semver range
npm update
# Update specific package
npm update lodash
# Install latest (ignoring semver)
npm install lodash@latest
# Interactive upgrade (with npm-check)
npx npm-check -u
yarn
yarn upgrade
yarn upgrade lodash
yarn upgrade lodash@latest
yarn upgrade-interactive
pnpm
pnpm update
pnpm update lodash
pnpm update lodash --latest
pnpm update --interactive
依赖分析
为什么安装了这个包?
# npm
npm explain lodash
npm ls lodash
# yarn
yarn why lodash
# pnpm
pnpm why lodash
查找未使用的依赖
npx depcheck
# JSON output
npx depcheck --json
# Ignore patterns
npx depcheck --ignores="@types/*,eslint-*"
查看包信息
# View package details
npm view lodash
# Specific fields
npm view lodash version
npm view lodash versions
npm view lodash dependencies
npm view lodash repository.url
# JSON output
npm view lodash --json
依赖树
# Full tree
npm ls
# Specific depth
npm ls --depth=2
# Production only
npm ls --omit=dev
# Specific package
npm ls lodash
# JSON
npm ls --json
工作流模式
安全审计工作流
# 1. Run audit
npm audit --json > audit-report.json
# 2. Review high/critical
npm audit --audit-level=high
# 3. Auto-fix what's safe
npm audit fix
# 4. Manually review remaining
npm audit
升级工作流
# 1. Check what's outdated
npm outdated --json
# 2. Test current state
npm test
# 3. Update patch/minor versions (safer)
npm update
# 4. Test again
npm test
# 5. Update major versions one at a time
npm install package@latest
npm test
依赖清理
# 1. Find unused deps
npx depcheck
# 2. Review and remove
npm uninstall unused-package
# 3. Verify
npm test && npm run build
调查某个包
# Package info
npm view express
# Current version in project
npm ls express
# Who depends on it
npm explain express
# Security vulnerabilities
npm audit | grep express
常见问题
对等依赖警告
# See peer deps
npm ls --json | grep peer
# Install missing peer deps
npm install missing-peer-dep
版本冲突
# See duplicate packages
npm ls --all | grep "deduped"
# Force dedupe
npm dedupe
锁文件问题
# Regenerate lock file
rm package-lock.json
npm install
# Or for yarn
rm yarn.lock
yarn install
最佳实践
- 定期审计 - 每周或在 CI 中运行
npm audit - 增量更新 - 一次更新一个主版本
- 更新后测试 - 更新后始终运行测试
- 修复前先审查 -
npm audit fix --force可能会破坏项目 - 清理未使用的依赖 - 定期运行
depcheck - 锁定版本 - 将锁文件提交到 git
- 添加前先检查 - 安装前审查包的健康状况
评论
支持 Markdown