gpt4 book ai didi

javascript - 值得麻烦地提交 package-lock.json 吗?

转载 作者:行者123 更新时间:2023-12-02 22:46:01 25 4
gpt4 key购买 nike

我在 GitHub 上发布了一个 NodeJS 项目,它使用了一些 NPM 模块,如我的 package.json 中指定的那样。 。我有我的package-lock.json提交到存储库中。

最近,我在我的存储库中收到有关我的依赖项之一最近发现的安全漏洞的通知。经过进一步检查,发现存在漏洞的不是我的直接依赖项之一,而是我的依赖项之一所依赖的模块。因为所有模块都出现在我的 package-lock.json 中,通知出现告诉我将该依赖项更新到最新版本。

- myproject
- someDependency
- anotherDependency
- aSubDependency
- anotherOne <--- this one has a security issue

所以现在我不得不问:是否值得提交 package-lock.json ?如果我没有package-lock.json,我的项目中就不会有任何安全漏洞。现在,我被迫更新我的项目并重新发布,只是为了更新 package-lock.json 。如果该文件根本不存在,问题就会自行解决,因为任何执行 install 操作的人都会自行解决。或update我的项目仅使用 package.json会自动从上游获取更新的依赖项。

这样想吧。鲍勃创建 moduleA 。然后其他人创建moduleB这取决于 moduleA 。然后,世界上 1000 名开发人员创建了直接依赖于 moduleB 的各种项目。 。如果 Bob 在 moduleA 中发现安全漏洞,现在 1000 人必须更新他们的 1000 个项目才能解决这一切,因为他们正在提交他们的 package-lock.json .

那么值得吗?做的优势package-lock.json超过本主题的缺点?

最佳答案

是的,值得

This file is intended to be committed into source repositories, and serves various purposes:

  • Describe a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.

  • Provide a facility for users to “time-travel” to previous states of node_modules without having to commit the directory itself.

  • To facilitate greater visibility of tree changes through readable source control diffs.

  • And optimize the installation process by allowing npm to skip repeated metadata resolutions for previously-installed packages.

See npm documentation

See GitHub - "Viewing and updating vulnerable dependencies in your repository"

关于javascript - 值得麻烦地提交 package-lock.json 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58401378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com