ius ius - 3 months ago 13
JSON Question

npm install -SE with minor versions notation

Don't know whether this is a missing feature or I'm doing something wrong but I have the following "problem".

Lets say I want to install the foo@3.2.x package and save it automatically in my package.json

npm install foo@3.2.x -S


This would write in my package.json the version ^3.2.0

npm install foo@3.2.x -SE


This would write in my package.json the version 3.2.0

What if I want to profit of the patch versions notation and I want to have the 3.2.x in my package.json?
The only option is adding it manually?

Thanks!

Answer

The semver shorthand ~ can be used to install only patch version updates of packages but not minor or major version updates (See https://docs.npmjs.com/misc/semver#tilde-ranges-123-12-1). To make this the default in npm use npm config command

npm config set save-prefix=~

Now the tilde will be used for every package installed with

npm install foo -S

And only patch level updates are installed when using npm i.

Comments