[英]How to upgrade all global NPM packages to their latest non-breaking version?
I try to update all global packages (including NPM itself) to their latest version of their current major version (so current_major.xx
).我尝试将所有全局包(包括 NPM 本身)更新到其当前主要版本的最新版本(因此current_major.xx
)。
npm upgrade -g --force
will forcefully upgrade all global packages, including major versions, but this will break things for sure. npm upgrade -g --force
将强制升级所有全局包,包括主要版本,但这肯定会破坏。
Is there a way?有办法吗? I know that I can upgrade all individual packages knowing their current major version, but I'd like to automate the process.我知道我可以升级所有知道它们当前主要版本的单个包,但我想自动化这个过程。
This will do it for me, although, it will re-install existing packages, even when there was no version change.这将为我做这件事,尽管它会重新安装现有的软件包,即使没有版本更改。
npm_global_packages=($(npm list -g --depth 0 | awk '/ /{print $2}'))
for val in "${npm_global_packages[@]}"; do
npm i -g --force $(echo $val | tr "." "\n" | head -1)
done
The --force
option is to avoid symlink issues. --force
选项是为了避免符号链接问题。 Leaving it away will not solve unnecessary re-installs.离开它不会解决不必要的重新安装。 I wonder if there is a smarter way, but that's what I will go for as of now.我想知道是否有更聪明的方法,但这就是我现在要做的 go 。
npm_global_packages
will be an array such as npm@6.14.12 npx@10.2.2 pm2@5.2.0 rimraf@3.0.2
. npm_global_packages
将是一个数组,例如npm@6.14.12 npx@10.2.2 pm2@5.2.0 rimraf@3.0.2
。tr "." "\n" | head -1
tr "." "\n" | head -1
will split each value by .
tr "." "\n" | head -1
将每个值拆分为.
and return only the first segment, so the script essentially would run npm i -g --force npm@6
, npm i -g --force npx@10
, ...并且只返回第一段,所以脚本基本上会运行npm i -g --force npm@6
, npm i -g --force npx@10
,...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.