Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm-update with npm-shrinkwrap.json

Tags:

node.js

npm

What does running:

npm update

do if a npm-shrinkwrap.json file exists? Does it

  1. Update the dependencies to match the shrinkwrap.json file
  2. Update the dependencies to obey package.json (thereby disregarding the shrinkwrap.json file)
  3. Not do anything

Thanks in advance

like image 386
pQuestions123 Avatar asked Dec 08 '16 19:12

pQuestions123


1 Answers

When you run

npm update

It will update the dependencies to obey package.json and will not care what is stored in npm-shrinkwrap.json even when node_modules folder is empty which means update command will install using package.json while install command will use npm-shrinkwrap.json.

It does not make any sense to obey the shrinkwrap file[ in most cases.]

Reason

  • It is supposed to be a snapshot of package at some stable point and this thing makes it perfect for production code.

  • There are no ^,~,latest etc. in shrinkwrap file.

  • And we also know that shrinkwrap file is not supposed to be tampered manually using editor
  • So all we can do is go back to some previous state of dependencies using this command and this thing can be achieved using npm install

However when you run

npm install 

It follows shrinkwrap file.

But when you run

npm install newPkg --save

It will change both package.json and npm-shrinkwrap.json file as well

But when you run

npm update pkg --save

It will change only npm-shrinkwrap.json file and as I wrote before it will use package.json file to update according to semver

like image 178
bugwheels94 Avatar answered Sep 27 '22 20:09

bugwheels94