npm install with ^ dependency instead of exact mat

2019-08-26 18:19发布

问题:

I am developing an npm package and realized that it is added with the exact version to the package.json when adding it with

npm i -S packagename

How can I tell it to use ^0.0.1 instead of 0.0.1 ? Can I define this as the default from within the package itself?

回答1:

That happens because ^0.0.1 is considered to be equivalent to 0.0.1.

When the version of a package starts with 0 it's considered to be in development, and the semantic versioning rules are different. An increase in either of the numbers can be expected to have breaking changes when the version is 0.0.X. You can see the rules here.

Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4

Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.

You'll probably see the caret when you increment the minor version, but it will also have the special rules that are mentioned over. "Normal" rules start applying when you increment the major version.