消除 npm“更新可用”消息

问题描述 投票:0回答:6

看起来更新版本的 npm 现在产生:

enter image description here

我依靠 Linux (Ubuntu) 包管理器来决定何时更新 Node 和 npm。有没有办法关闭这个检查?

npm config ls -l
似乎与此无关,并且在我的主目录中的
.npm
中似乎没有首选项文件。

npm environment-variables
6个回答
74
投票

要禁用通知程序,只需运行:

npm config set update-notifier false

正如 Dem Pilafian 提到的 - 它将把

update-notifier=false
添加到
~/.npmrc

要查看当前值,您需要此行

npm config get update-notifier

在此处阅读有关 npm 配置的更多信息 https://docs.npmjs.com/cli/config


26
投票

这也让我很烦恼,但在任何地方都没有关于它的信息。

查看代码,我发现 npm 使用的 update-notifier-module 实际上有几种方法可以将其关闭。

最好的可能是位于

~/.config/configstore/update-notifier-npm.json
的特殊配置文件(只需搜索
update-notifier-npm.json
)。在其中,只需将“optOut”设置为 true 即可。

禁用它的其他方法是设置一个名为“NO_UPDATE_NOTIFIER”的环境变量或使用参数“--no-update-notifier”


16
投票

更新通知=假

.npmrc
文件中似乎自 NPM v6.2.0-next.0 (2018-06-28).

就可以解决问题

9
投票

对于较新的(v7+)npm,您可以使用

export NPM_CONFIG_UPDATE_NOTIFIER=false
通过环境禁用

https://github.com/npm/cli/pull/1632


1
投票

如果要解析 npm 命令输出,一种选择是格式化输出,例如“--json true”、“npm list --json true”,npm 将遵循该参数并隐藏升级消息。


-1
投票

我创建了一个 ansible 任务,将

optOut
设置为
true
并将
lastUpdateCheck
设置为当前日期。

tasks/main.yml

---

- name: copy update-notifier-npm template file to disable checking for npm updates
  template: src=update-notifier-npm.j2 dest=~/.config/configstore/update-notifier-npm.json

templates/update-notifier-npm.j2

{
    "optOut": true,
    "lastUpdateCheck": {{ ansible_date_time.epoch }}000
}

update-notifier
包中创建这个文件的逻辑在这里:

https://github.com/yeoman/update-notifier/blob/3fdb21876aa391f9bc7dc35b7d81151677fb533d/index.js#L53

© www.soinside.com 2019 - 2024. All rights reserved.