当前位置 : 主页 > 网页制作 > Nodejs >

node.js – 清除* NPM缓存中的一个*包

来源:互联网 收集:自由互联 发布时间:2021-06-16
问题: 有时我跑 npm install x@latest 但它实际上并没有拉出最新版本的软件包(这是蹩脚的). 但是,如果我这样做: npm cache clean --force npm install x@latest 它会拉最新的 但我实际上宁愿避免删除
问题:

有时我跑

npm install x@latest

但它实际上并没有拉出最新版本的软件包(这是蹩脚的).

但是,如果我这样做:

npm cache clean --force && npm install x@latest

它会拉最新的

但我实际上宁愿避免删除整个缓存,只删除单个包的缓存,例如:

npm cache clean x --force

但似乎不允许这样做.有人知道一个好的解决方法吗?

也许只是:

rm -rf $HOME/.npm/x

这似乎很烦人,但不是100%肯定.这应该是您只删除一个名为“XXX”的包的缓存.

cache_location="$(npm config get cache)";

if [[ -z "$cache_location" ]]; then
   # if for whatever reason the cache location is empty/undefined, default to this
  cache_location="$HOME/.npm"
fi

rm -r "$cache_location/XXX" || {
  echo "no XXX package in npm cache dir.";
}

你可以通过检查它是否适合你而感谢我,如果确实如此,请回答这个问题.如果它不起作用,请批评答案.

网友评论