Dependencies & Versions

Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.

  • ~version “Approximately equivalent to version”, will update you to all future patch versions, without incrementing the minor version. ~1.2.3 will use releases from 1.2.3 to <1.3.0.
  • ^version “Compatible with version”, will update you to all future minor/patch versions, without incrementing the major version. ^2.3.4 will use releases from 2.3.4 to <3.0.0.

There a re many others options how to set/define/customize your dependencies. Other version specifiers include GitHub urls and GitHub user repo’s, local paths and packages with specific npm tags.

Here, a not exhaustive list :

valuedesc
~version“Approximately equivalent to version”
See npm semver – Tilde Ranges
^version“Compatible with version”
See npm semver – Caret Ranges
versionMust match version exactly
>versionMust be greater than version
>=versionetc
<version
<=version
1.2.x1.2.0, 1.2.1, etc., but not 1.3.0
*Matches any version
latestObtains latest release
version1 – version2Same as >=version1 <=version2
range1 || range2Passes if either range1 or range2 are satisfied.
git…See ‘Git URLs as Dependencies’ below
user/repoSee ‘GitHub URLs’ below
tagA specific version tagged and published as tag See npm dist-tag
path/path/pathSee Local Paths below

example:

{
  "dependencies": {
    "foo": "1.0.0 - 2.9999.9999",
    "bar": ">=1.0.2 <2.1.2",
    "baz": ">1.0.2 <=2.3.4",
    "boo": "2.0.1",
    "qux": "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0",
    "asd": "http://asdf.com/asdf.tar.gz",
    "til": "~1.2",
    "elf": "~1.2.3",
    "two": "2.x",
    "thr": "3.3.x",
    "lat": "latest",
    "dyl": "file:../dyl"
  }
}
URLs as Dependencies

You may specify a tarball URL in place of a version range.

This tarball will be downloaded and installed locally to your package at install time.

Git URLs as Dependencies

Git urls are of the form:

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

<protocol> is one of gitgit+sshgit+httpgit+https, or git+file.

git+ssh://git@github.com:npm/cli.git#v1.0.27
git+ssh://git@github.com:npm/cli#semver:^5.0
git+https://isaacs@github.com/npm/cli.git
git://github.com/npm/cli.git#v1.0.27
Reference :

https://docs.npmjs.com/

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *