npm - how to show the latest version of a package

前端 未结 6 1429
太阳男子
太阳男子 2020-12-04 05:46

How do I use npm to show the latest version of a module? I am expecting something like npm --latest express to print out v3.0.0.

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 06:21

    The npm view version prints the last version by release date. That might very well be an hotfix release for a older stable branch at times.

    The solution is to list all versions and fetch the last one by version number

    $ npm view  versions --json | jq -r '.[-1]'
    

    Or with awk instead of jq:

    $ npm view  --json  | awk '/"$/{print gensub("[ \"]", "", "G")}'
    

提交回复
热议问题