如何识别最新的 npm 包版本

你可以使用

npm_info_cmd.sh
npm info [package name] version | head -n1

只打印最新的包版本,例如:

npm_info_example.sh
npm info @angular/cli version | head -n1

head -n1 部分是必要的,用于抑制不需要的 npm info 消息。只运行不带 head -n1 的命令:

npm_info_full.sh
npm info @angular/cli version

打印以下输出:

npm_info_output.txt
12.2.6
npm notice
npm notice New minor version of npm available! 7.21.1 -> 7.24.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.24.0
npm notice Run npm install -g npm@7.24.0 to update!
npm notice

我通常使用 node:latest docker 容器而不是本地 npm 来查找 npm 包的最新版本:

docker_npm_command.sh
docker run -it --rm node:latest npm info meshcommander version | head -n1

撰写本文时,该命令打印

npm_version_output.txt
0.9.0-d

Check out similar posts by category: NodeJS