正在观看 nice YouTube video提到使用 NPM 包管理器的安全问题,我认为禁止包在安装时执行代码是有意义的。此 NPM 配置将执行以下操作:
npm config set ignore-scripts true
但随后在
package.json
中定义的脚本不要跑。包括npm start
.这很烦人。有没有一种方法可以阻止包执行代码(如果我没记错的话,我认为这是安装后脚本)并且仍然允许在
package.json
中定义的脚本运行?澄清一下:我做 想执行我自己的脚本。我不要想在
npm install
期间执行第 3 方脚本.
最佳答案
在 npm-install文件指出:
The
--ignore-scripts
argument will cause npm to not execute any scripts defined in the package.json.
所以,基本上当你安装一个包时,你需要附加
--ignore-scripts
防止第三方包执行脚本的参数,例如 postinstall
.例如:
npm install <pkg_name> --ignore-scripts
备注:
I think it makes sense to disallow packages to execute code as they are installed.
这取决于,当使用
--ignore-scripts
忽略脚本时您不能总是保证您安装的软件包功能齐全 - 这取决于 postinstall
中执行的任务例如脚本。 --ignore-scripts
指定要忽略哪些脚本。争论。 关于npm - 如何在不禁用 package.json 中定义的脚本的情况下禁止 npm 包执行安装后脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59028570/