Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^ in package.json dependency version

Tags:

What does the ^ symbol mean in the version of a dependency in package.json?

I couldn't find it in the docs.

For example:

"dependencies": {     "grunt": "^0.4.4",     ... } 
like image 904
gberger Avatar asked Mar 21 '14 17:03

gberger


People also ask

How do I get the latest version of dependency in package json?

For updating a new and major version of the packages, you must install the npm-check-updates package globally. It will display the new dependencies in the current directory whereas running this command will list all the global packages which have new releases.

What is in package json dependency?

The dependencies property of a module's package. json is where dependencies - the other modules that this module uses - are defined. The dependencies property takes an object that has the name and version at which each dependency should be used.

What is package json version?

The package. json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.

Is version required in package json?

Required name and version fieldsA package. json file must contain "name" and "version" fields. The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores.


1 Answers

I found an answer here:

The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0. npm’s semantic versioning parser clarifies the distinction:

~1.2.3 := >=1.2.3-0 <1.3.0-0 "Reasonably close to 1.2.3". ^1.2.3 := >=1.2.3-0 <2.0.0-0 "Compatible with 1.2.3". 

― isaacs/node-semver (emphasis added)

The relevant points from isaacs/node-semver are:

  • ^1.2.3 := >=1.2.3-0 <2.0.0-0 Compatible with 1.2.3.
    When using caret operators, anything from the specified version (including prerelease) will be supported up to, but not including, the next major version (or its prereleases). 1.5.1 will satisfy ^1.2.3, while 1.2.2 and 2.0.0-beta will not.

  • ^0.1.3 := >=0.1.3-0 <0.2.0-0 Compatible with 0.1.3.
    0.x.x versions are special: the first non-zero component indicates potentially breaking changes, meaning the caret operator matches any version with the same first non-zero component starting at the specified version.

  • ^0.0.2 := =0.0.2 Only the version 0.0.2 is considered compatible

like image 182
rossipedia Avatar answered Oct 21 '22 10:10

rossipedia