node.js - 我是否提交由 npm 5 创建的 package-lock.json 文件?

标签 node.js git npm version-control lockfile

npm 5 was released today其中一项新功能包括通过创建 package-lock.json 文件进行确定性安装。

这个文件应该保存在源代码管理中吗?

我假设它类似于 yarn.lockcomposer.lock ,两者都应该保存在源代码管理中。

最佳答案

是的,package-lock.json 旨在检查到源代码控制中。如果您使用的是 npm 5+,您可能会在命令行上看到此通知:created a lockfile as package-lock.json。你应该提交这个文件。 根据 npm help package-lock.json :

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.

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.

One key detail about package-lock.json is that it cannot be published, and it will be ignored if found in any place other than the toplevel package. It shares a format with npm-shrinkwrap.json, which is essentially the same file, but allows publication. This is not recommended unless deploying a CLI tool or otherwise using the publication process for producing production packages.

If both package-lock.json and npm-shrinkwrap.json are present in the root of a package, package-lock.json will be completely ignored.

关于node.js - 我是否提交由 npm 5 创建的 package-lock.json 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44206782/

相关文章:

java - 如何在接口(interface)中定义构造函数签名?

git - 意外删除 heroku 上的应用程序后无法推送到 heroku

node.js - 无法在 Linux 中安装 node-expat

javascript - NPM 安装错误

javascript - grunt-newer 不使用 grunt-sass

node.js - 等待关键部分在 Node.js 正常关闭中完成

javascript - 在 Sequelize 中使用实例方法

git - 总是撤消 git config --global branch.autosetuprebase 的设置更改

git - Hg 相当于 git post-receive hook

javascript - 由于 url 可能不正确,npm install 挂起