NPM view most recent *stable* version of a package

2019-08-12 10:04发布

Instead of installing the latest version of an NPM package using

npm install x@latest

is there a way to view the latest stable version? something like this:

npm view x@stable version

I am looking for a programmatic/command line solution.

https://docs.npmjs.com/cli/view

标签: node.js npm
1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-12 10:39

Utilizing the following syntax returns the semver/value of the latest stable version only:

npm view <name> dist-tags.latest

You'll need to replace the <name> part with the actual package name.

Example:

npm view babel-cli dist-tags.latest

Running the command above currently prints 6.26.0 to the console, whilst the latest non-stable version available is the npm registry is currently 7.0.0-beta.3


Notes:

The command above will report the same version which would get installed when running:

npm install <name>@latest

Caveat: For either of the two commands to get the truly stable latest version they are reliant on the author/owner of the package having correctly managed their dist-tags. An excerpt from the docs (at the link provided) reads:

Publishing a package sets the latest tag to the published version unless the --tag option is used. For example, npm publish --tag=beta.

查看更多
登录 后发表回答