看起来更新版本的 npm 现在产生:
我依靠 Linux (Ubuntu) 包管理器来决定何时更新 Node 和 npm。有没有办法关闭这个检查?
npm config ls -l
似乎与此无关,并且在我的主目录中的.npm
中似乎没有首选项文件。
要禁用通知程序,只需运行:
npm config set update-notifier false
正如 Dem Pilafian 提到的 - 它将把
update-notifier=false
添加到 ~/.npmrc
要查看当前值,您需要此行
npm config get update-notifier
在此处阅读有关 npm 配置的更多信息 https://docs.npmjs.com/cli/config
这也让我很烦恼,但在任何地方都没有关于它的信息。
查看代码,我发现 npm 使用的 update-notifier-module 实际上有几种方法可以将其关闭。
最好的可能是位于
~/.config/configstore/update-notifier-npm.json
的特殊配置文件(只需搜索 update-notifier-npm.json
)。在其中,只需将“optOut”设置为 true 即可。
禁用它的其他方法是设置一个名为“NO_UPDATE_NOTIFIER”的环境变量或使用参数“--no-update-notifier”
对于较新的(v7+)npm,您可以使用
export NPM_CONFIG_UPDATE_NOTIFIER=false
通过环境禁用
如果要解析 npm 命令输出,一种选择是格式化输出,例如“--json true”、“npm list --json true”,npm 将遵循该参数并隐藏升级消息。
我创建了一个 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