Should I commit yarn.lock and package-lock.json files?

后端 未结 7 890
野趣味
野趣味 2020-12-12 12:15

We\'re using yarn for all our deterministic pkg installations but don\'t prevent the user from using npm - I\'m guessing having both these files will cause issues however. S

7条回答
  •  醉梦人生
    2020-12-12 12:45

    You should commit 1 dependency tree lock file, but you shouldn't commit both. This also requires standardizing on either yarn or npm (not both) to build + develop a project with.

    Here's the yarn article on why yarn.lock should be committed, if you standardize on yarn.

    If you commit both the yarn.lock file, AND the package-lock.json files there are a lot of ways that the 2 files can provide different dependency trees (even if yarn's and npm's tree resolution algorithms are identical), and it's non-trivial to ensure that they provide exactly the same answer. Since it's non-trivial, it's unlikely that the same dependency tree will be maintained in both files, and you don't want different behavior depending on whether the build was done using yarn or npm.

    If and when yarn switches from using yarn.lock to package-lock.json (issue here), then the choice of lock file to commit becomes easy, and we no longer have to worry about yarn and npm resulting in different builds. Based on this blog post, this is a change we shouldn't expect soon (the blog post also describes the differences between yarn.lock and package-lock.json.

提交回复
热议问题