{"id":1139,"date":"2021-05-04T16:56:37","date_gmt":"2021-05-04T14:56:37","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1139"},"modified":"2022-06-08T17:55:34","modified_gmt":"2022-06-08T15:55:34","slug":"the-difference-between-tilde-and-caret-in-package-json","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2021\/05\/04\/the-difference-between-tilde-and-caret-in-package-json\/","title":{"rendered":"The difference between tilde(~) and caret(^) in package.json"},"content":{"rendered":"\n<h3 id=\"dependencies\">Dependencies &amp; Versions <\/h3>\n\n\n\n<p>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. <em><span class=\"has-inline-color has-vivid-red-color\">Dependencies can also be identified with a tarball or git URL.<\/span><\/em><\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul><li><code>~version<\/code>&nbsp;<strong>\u201cApproximately equivalent to version\u201d<\/strong>, will update you to all future patch versions, without incrementing the minor version.&nbsp;<code>~1.2.3<\/code>&nbsp;will use releases from 1.2.3 to &lt;1.3.0.<\/li><\/ul>\n\n\n\n<ul><li><code>^version<\/code>&nbsp;<strong>\u201cCompatible with version\u201d<\/strong>, will update you to all future minor\/patch versions, without incrementing the major version.&nbsp;<code>^2.3.4<\/code>&nbsp;will use releases from 2.3.4 to &lt;3.0.0.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>There a re many others options  how to set\/define\/customize your dependencies. Other version specifiers include GitHub urls and GitHub user repo&#8217;s, local paths and packages with specific npm tags. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Here, a not exhaustive list : <\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>value<\/th><th>desc<\/th><\/tr><\/thead><tbody><tr><td><code>~version<\/code><\/td><td>&#8220;Approximately equivalent to version&#8221;<br>See&nbsp;<a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/using-npm\/semver#tilde-ranges-123-12-1\">npm semver &#8211; Tilde Ranges<\/a><\/td><\/tr><tr><td><code>^version<\/code><\/td><td>&#8220;Compatible with version&#8221;<br>See&nbsp;<a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/using-npm\/semver#caret-ranges-123-025-004\">npm semver &#8211; Caret Ranges<\/a><\/td><\/tr><tr><td><\/td><td><\/td><\/tr><tr><td><code>version<\/code><\/td><td>Must match version exactly<\/td><\/tr><tr><td><code>&gt;version<\/code><\/td><td>Must be greater than version<\/td><\/tr><tr><td><code>&gt;=version<\/code><\/td><td>etc<\/td><\/tr><tr><td><code>&lt;version<\/code><\/td><td><\/td><\/tr><tr><td><code>&lt;=version<\/code><\/td><td><\/td><\/tr><tr><td><code>1.2.x<\/code><\/td><td>1.2.0, 1.2.1, etc., but not 1.3.0<\/td><\/tr><tr><td><code>*<\/code><\/td><td>Matches any version<\/td><\/tr><tr><td><code>latest<\/code><\/td><td>Obtains latest release<\/td><\/tr><tr><td>version1 &#8211; version2<\/td><td>Same as&nbsp;<code>&gt;=version1 &lt;=version2<\/code><\/td><\/tr><tr><td>range1 || range2<\/td><td>Passes if either range1 or range2 are satisfied.<\/td><\/tr><tr><td>git&#8230;<\/td><td>See &#8216;Git URLs as Dependencies&#8217; below<\/td><\/tr><tr><td>user\/repo<\/td><td>See &#8216;GitHub URLs&#8217; below<\/td><\/tr><tr><td>tag<\/td><td>A specific version tagged and published as&nbsp;<code>tag<\/code>&nbsp;See&nbsp;<a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/commands\/npm-dist-tag\"><code>npm dist-tag<\/code><\/a><\/td><\/tr><tr><td>path\/path\/path<\/td><td>See&nbsp;<a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/configuring-npm\/package-json#local-paths\">Local Paths<\/a>&nbsp;below<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>example: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"dependencies\": {\n    \"foo\": \"1.0.0 - 2.9999.9999\",\n    \"bar\": \"&gt;=1.0.2 &lt;2.1.2\",\n    \"baz\": \"&gt;1.0.2 &lt;=2.3.4\",\n    \"boo\": \"2.0.1\",\n    \"qux\": \"&lt;1.0.0 || &gt;=2.3.1 &lt;2.4.5 || &gt;=2.5.2 &lt;3.0.0\",\n    \"asd\": \"http:\/\/asdf.com\/asdf.tar.gz\",\n    \"til\": \"~1.2\",\n    \"elf\": \"~1.2.3\",\n    \"two\": \"2.x\",\n    \"thr\": \"3.3.x\",\n    \"lat\": \"latest\",\n    \"dyl\": \"file:..\/dyl\"\n  }\n}<\/code><\/pre>\n\n\n\n<h5 id=\"urls-as-dependencies\">URLs as Dependencies<\/h5>\n\n\n\n<p>You may specify a tarball URL in place of a version range.<\/p>\n\n\n\n<p>This tarball will be downloaded and installed locally to your package at install time.<\/p>\n\n\n\n<h5 id=\"git-urls-as-dependencies\"><a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/configuring-npm\/package-json#git-urls-as-dependencies\"><\/a>Git URLs as Dependencies<\/h5>\n\n\n\n<p>Git urls are of the form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;protocol&gt;:\/\/&#91;&lt;user&gt;&#91;:&lt;password&gt;]@]&lt;hostname&gt;&#91;:&lt;port&gt;]&#91;:]&#91;\/]&lt;path&gt;&#91;#&lt;commit-ish&gt; | #semver:&lt;semver&gt;]<\/code><\/pre>\n\n\n\n<p><code>&lt;protocol&gt;<\/code>&nbsp;is one of&nbsp;<code>git<\/code>,&nbsp;<code>git+ssh<\/code>,&nbsp;<code>git+http<\/code>,&nbsp;<code>git+https<\/code>, or&nbsp;<code>git+file<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git+ssh:\/\/git@github.com:npm\/cli.git#v1.0.27\ngit+ssh:\/\/git@github.com:npm\/cli#semver:^5.0\ngit+https:\/\/isaacs@github.com\/npm\/cli.git\ngit:\/\/github.com\/npm\/cli.git#v1.0.27<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5>Reference : <\/h5>\n\n\n\n<p><a href=\"https:\/\/docs.npmjs.com\/\">https:\/\/docs.npmjs.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dependencies &amp; 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&nbsp;\u201cApproximately equivalent to version\u201d, will update you to all future patch versions, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1965,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37],"tags":[307,102,103,273,101,308],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1139"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1139"}],"version-history":[{"count":3,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1139\/revisions"}],"predecessor-version":[{"id":1970,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1139\/revisions\/1970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1965"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}