dwyl / learn-node-js-by-example

:cloud: Practical node.js examples.
http://nelsonic.gitbooks.io/node-js-by-example/
Other
48 stars 11 forks source link

package-lock.json ? Necessary or Noise? #36

Open nelsonic opened 5 years ago

nelsonic commented 5 years ago

The purpose of the package-lock.json file is to "lock" the list of dependencies for a Node.js project beyond simply listing the dependencies in a package.json file.

Here is an example of a package-lock.json being added to a project: image

GitHub (obviously) does not show the full 10k lines of JSON because it's a massive file.

When we attempt to expand on this list we see an ocean of dependencies and versions: image What does this information tell us? It tells us the precise versions of all the dependencies that are being used in the project at this point in its' history. That is a good thing right...? Well, on the surface, yes, it is a good thing to have a precise control of the dependencies, that's incontestable.

The question is: will having a package-lock.json file save you from a "bad" dependency update? or is the file simply creating clutter and noise in your project?

As much as I hate the noise of a package-lock.json file having hundreds of lines updated each time a dependency is updated, on balance I feel it's a necessary evil for some projects that don't have complete end-to-end testing. When an app does not have good testing and continuous integration, package-lock.json can be a good "fallback".

There is no substitute for having full test coverage when upgrading versions of a dependency.