When to use shrinkwrap, npm-lockdown, or npm-seal
Asked Answered
G

3

7

I'm coming from a background much more familiar with composer. I'm getting gulp (etc) going for the build processes and learning node and how to use npm as I go.

It's very odd (again, coming from a composer background) that a composer.lock-like manifest is not included by default. Having said that, I've been reading documentation on [shrinkwrap], [npm-lockdown], and [npm-seal]. ...and the more documentation I read, the more confused I become as to which I should be choosing (everyone thinks their way is the best way). One of the issues I notice is that npm-seal hasn't changed in 4 years and npm-lockdown in 8 months -- this all leads me to wonder if this because it's not needed with the newest version of npm...

  1. What are the benefits / drawbacks of each?
  2. In what cases would I use one over another in Project A, but use a different one in Project B?
  3. How will each impact our development workflow?

PS: Brownie points if you include the most basic implementation example for each. ;)

Gandhi answered 10/1, 2016 at 3:56 Comment(2)
And then there's this too... github.com/uber/npm-shrinkwrap hahGandhi
+ github.com/JamieMason/shrinkpackFishgig
M
8

npm shrinkwrap is the most standard way how to lock your dependencies. And yes, npm install does not create it by default which is a pity and it is something that npm creators definitely should change.

npm-lockdown is trying to do the same things as npm shrinkwrap, there are two minor points in which npm-lockdown is better: it handles optional dependencies better and it validates checksums of the package:

https://www.npmjs.com/package/lockdown#related-tools

Both these features seem not so relevant for me; I'm quite happy with npm shrinkwrap: For example, npmjs guarantees that once you upload certain package at certain version, it stays immutable - so checking sha checksums is not so hot (I've never encountered an error caused by this).

seal is meant to be used together with npm shrinkwrap. It adds the 'checksum checking' aspect. It looks abandoned and quite raw.

Maynard answered 10/1, 2016 at 11:32 Comment(0)
K
3

Good question - I'm going to skip everything but shrinkwrap because it is the de-facto way to do this, per NPM's docs.

Long story short the npm-shrinkwrap.json file is akin to your lock files you are used to in every other package manager, though NPM allows different versions of the same package to play nice together by isolation - literally scoping and copying different entire versions to node_modules at different levels of the tree. If two projects that are parent-child to each other use the exact same version, NPM will copy the version to only the parent and the child will traverse up the tree to find the package.

Best practice is simply to update package.json for your direct dependencies, run npm install, verify that things are working while developing, then run npm shrinkwrap when you are just about to commit and push. NOTE: make sure to rm npm-shrinkwrap.json before running npm install during active development - if your direct dependencies have changed, you want package.json to be used, and not the lock! Also include node_modules in your .gitignore or equivalent in your source control system. Then, when you are deploying and getting to run the project, run npm install like normal. If npm finds an npm-shrinkwrap.json file, it will use that to recursively pull all locked modules, and it will ignore package.json in both your project and all dependent projects.

Kanaka answered 10/1, 2016 at 4:7 Comment(0)
F
2

You might find shrinkpack useful – it checks in the tarballs which npm install downloads and bundles them into your repository, before finally rewriting npm-shrinkwrap.json to point at that local bundle instead.

This way, your project is totally locked down, completely available offline, and much quicker to install.

Fishgig answered 15/7, 2016 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.