如果 npm 安装显示高严重性漏洞,我想让我的应用程序的打包脚本失败。
例子:
added 137 packages from 151 contributors and audited 4041 packages in 8.689s
found 1 high severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
我现在拥有的 我正在用 grep 来做这件事,但这听起来不是一个好的解决方案,因为审计的微小输出调整可能会破坏它而不会立即发现它。
function npm-prod-install-audit() {
if npm install --no-optional --only=prod | grep "high severity";then
echo "Audit failed! 🖐 Please update your packages."
exit 1
else
echo "Audit passed ✅";
fi
}
有什么好的解决办法吗?
最佳答案
你可以使用npm audit
https://docs.npmjs.com/cli/audit .如果发现漏洞,它将以非零返回码退出。您可以使用 --audit-level=(low|moderate|high|critical)
控制您希望失败的级别。
关于bash - 如果存在高严重性漏洞,npm install 的 shell 脚本将失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56609112/