npm-check-updates
$ ncu 社区开源 低风险npm-check-updates(ncu)默认只读地向 npm 仓库检查 package.json 依赖更新,不改动 node_modules。通过 --jsonUpgraded 可输出干净的 JSON 差异,而 --doctor 会循环运行测试并自动回滚导致破坏性失败的升级。
npm install -g npm-check-updates ncu 直接读取本地 package.json、继承 .npmrc 私有源并可配合 --doctor 执行本地测试套件,这类工作流不适合通过 MCP 替代。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
默认只读,支持输出纯净的 --jsonUpgraded 与 --jsonAll、支持 --no-color,且除非传入 -i 否则绝不进入交互提示。
ncu --jsonUpgradedreturns pure JSON key-value upgrade map- Default invocation performs zero file writes unless
-uis explicitly passed
默认行为只读安全;-u 仅修改 package.json,且 --doctor 可借助项目测试脚本自动回滚破坏性更新。
- Read-only unless
-u(--upgrade) is specified --doctorbisects and reverts failing dependency upgrades
在任意安装了 Node.js 的机器上均可通过 npm 全局安装或 npx npm-check-updates 零安装运行。
- Run directly via
npx npm-check-updatesacross macOS, Linux, and Windows
借助 --target minor 与 --filter 等选项一次完成批量依赖审计与定向升级,远胜手动查询仓库。
- Supports workspace (
--workspaces) and semver-target filtering in one pass
长期稳定维护的社区项目(raineorshine/npm-check-updates),采用 Apache-2.0 协议。
- Established
raineorshine/npm-check-updatesrepository
README 参数说明详尽,--help 输出清晰。
- Complete CLI flags documented in README and
--help
安全边界、鉴权与放权指南
查询公共仓库无需认证;私有仓库会直接继承 .npmrc 中的凭据配置。
Apache-2.0 开源 CLI;可免费配合公共或私有 npm 仓库使用。
# npm-check-updates (ncu) Agent Rules - Always run `ncu --jsonUpgraded` (read-only) before passing `-u`. - Prefer `--target minor` or `--doctor -u` when upgrading dependencies autonomously.
Agent 高频安全命令配方
只读查询(安全推荐)
ncu --jsonUpgraded
只读检查并返回可升级包名到目标版本的 JSON 映射。
ncu --target minor --jsonUpgraded
过滤掉主版本破坏性升级,仅以 JSON 输出安全的次版本与补丁版本候选。
受控写入与预演
ncu -u --target minor --jsonUpgraded
只把 minor/patch 版本更新写入 package.json,不自动执行 npm install。
核心优势
- + 默认只读并支持
--jsonUpgraded,便于 Agent 直接解析 JSON。 - +
--doctor可自动执行“升级-测试-二分回滚”,隔离破坏构建的依赖。 - +
--target minor/--target patch与--filter可有效控制升级影响面。
注意事项与踩坑点
- ! 依赖 Node.js 运行时且需联网访问配置的 npm 仓库。
- ! 使用
-u更新package.json后仍需额外执行npm/pnpm/yarn安装以更新 lockfile。