1<!DOCTYPE html><html><head> 2<meta charset="utf-8"> 3<title>npm-diff</title> 4<style> 5body { 6 background-color: #ffffff; 7 color: #24292e; 8 9 margin: 0; 10 11 line-height: 1.5; 12 13 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; 14} 15#rainbar { 16 height: 10px; 17 background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff); 18} 19 20a { 21 text-decoration: none; 22 color: #0366d6; 23} 24a:hover { 25 text-decoration: underline; 26} 27 28pre { 29 margin: 1em 0px; 30 padding: 1em; 31 border: solid 1px #e1e4e8; 32 border-radius: 6px; 33 34 display: block; 35 overflow: auto; 36 37 white-space: pre; 38 39 background-color: #f6f8fa; 40 color: #393a34; 41} 42code { 43 font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; 44 font-size: 85%; 45 padding: 0.2em 0.4em; 46 background-color: #f6f8fa; 47 color: #393a34; 48} 49pre > code { 50 padding: 0; 51 background-color: inherit; 52 color: inherit; 53} 54h1, h2, h3 { 55 font-weight: 600; 56} 57 58#logobar { 59 background-color: #333333; 60 margin: 0 auto; 61 padding: 1em 4em; 62} 63#logobar .logo { 64 float: left; 65} 66#logobar .title { 67 font-weight: 600; 68 color: #dddddd; 69 float: left; 70 margin: 5px 0 0 1em; 71} 72#logobar:after { 73 content: ""; 74 display: block; 75 clear: both; 76} 77 78#content { 79 margin: 0 auto; 80 padding: 0 4em; 81} 82 83#table_of_contents > h2 { 84 font-size: 1.17em; 85} 86#table_of_contents ul:first-child { 87 border: solid 1px #e1e4e8; 88 border-radius: 6px; 89 padding: 1em; 90 background-color: #f6f8fa; 91 color: #393a34; 92} 93#table_of_contents ul { 94 list-style-type: none; 95 padding-left: 1.5em; 96} 97#table_of_contents li { 98 font-size: 0.9em; 99} 100#table_of_contents li a { 101 color: #000000; 102} 103 104header.title { 105 border-bottom: solid 1px #e1e4e8; 106} 107header.title > h1 { 108 margin-bottom: 0.25em; 109} 110header.title > .description { 111 display: block; 112 margin-bottom: 0.5em; 113 line-height: 1; 114} 115 116footer#edit { 117 border-top: solid 1px #e1e4e8; 118 margin: 3em 0 4em 0; 119 padding-top: 2em; 120} 121</style> 122</head> 123<body> 124<div id="banner"> 125<div id="rainbar"></div> 126<div id="logobar"> 127<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700"> 128<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon> 129<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon> 130</svg> 131<div class="title"> 132npm command-line interface 133</div> 134</div> 135</div> 136 137<section id="content"> 138<header class="title"> 139<h1 id="npm-diff">npm-diff</h1> 140<span class="description">The registry diff command</span> 141</header> 142 143<section id="table_of_contents"> 144<h2 id="table-of-contents">Table of contents</h2> 145<div id="_table_of_contents"><ul><li><a href="#see-also">See Also</a></li></ul></div> 146</section> 147 148<div id="_content"><h3 id="synopsis">Synopsis</h3> 149<pre><code class="language-bash">npm diff [...<paths>] 150</code></pre> 151<h3 id="description">Description</h3> 152<p>Similar to its <code>git diff</code> counterpart, this command will print diff patches 153of files for packages published to the npm registry.</p> 154<ul> 155<li> 156<p><code>npm diff --diff=<spec-a> --diff=<spec-b></code></p> 157<p>Compares two package versions using their registry specifiers, e.g: 158<code>npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0</code>. It's also possible to 159compare across forks of any package, 160e.g: <code>npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0</code>.</p> 161<p>Any valid spec can be used, so that it's also possible to compare 162directories or git repositories, 163e.g: <code>npm diff --diff=pkg@latest --diff=./packages/pkg</code></p> 164<p>Here's an example comparing two different versions of a package named 165<code>abbrev</code> from the registry:</p> 166<pre><code class="language-bash">npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1 167</code></pre> 168<p>On success, output looks like:</p> 169<pre><code class="language-bash">diff --git a/package.json b/package.json 170index v1.1.0..v1.1.1 100644 171--- a/package.json 172+++ b/package.json 173@@ -1,6 +1,6 @@ 174 { 175 "name": "abbrev", 176- "version": "1.1.0", 177+ "version": "1.1.1", 178 "description": "Like ruby's abbrev module, but in js", 179 "author": "Isaac Z. Schlueter <i@izs.me>", 180 "main": "abbrev.js", 181</code></pre> 182<p>Given the flexible nature of npm specs, you can also target local 183directories or git repos just like when using <code>npm install</code>:</p> 184<pre><code class="language-bash">npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path 185</code></pre> 186<p>In the example above we can compare the contents from the package installed 187from the git repo at <code>github.com/npm/libnpmdiff</code> with the contents of the 188<code>./local-path</code> that contains a valid package, such as a modified copy of 189the original.</p> 190</li> 191<li> 192<p><code>npm diff</code> (in a package directory, no arguments):</p> 193<p>If the package is published to the registry, <code>npm diff</code> will fetch the 194tarball version tagged as <code>latest</code> (this value can be configured using the 195<code>tag</code> option) and proceed to compare the contents of files present in that 196tarball, with the current files in your local file system.</p> 197<p>This workflow provides a handy way for package authors to see what 198package-tracked files have been changed in comparison with the latest 199published version of that package.</p> 200</li> 201<li> 202<p><code>npm diff --diff=<pkg-name></code> (in a package directory):</p> 203<p>When using a single package name (with no version or tag specifier) as an 204argument, <code>npm diff</code> will work in a similar way to 205<a href="npm-outdated"><code>npm-outdated</code></a> and reach for the registry to figure out 206what current published version of the package named <code><pkg-name></code> 207will satisfy its dependent declared semver-range. Once that specific 208version is known <code>npm diff</code> will print diff patches comparing the 209current version of <code><pkg-name></code> found in the local file system with 210that specific version returned by the registry.</p> 211<p>Given a package named <code>abbrev</code> that is currently installed:</p> 212<pre><code class="language-bash">npm diff --diff=abbrev 213</code></pre> 214<p>That will request from the registry its most up to date version and 215will print a diff output comparing the currently installed version to this 216newer one if the version numbers are not the same.</p> 217</li> 218<li> 219<p><code>npm diff --diff=<spec-a></code> (in a package directory):</p> 220<p>Similar to using only a single package name, it's also possible to declare 221a full registry specifier version if you wish to compare the local version 222of an installed package with the specific version/tag/semver-range provided 223in <code><spec-a></code>.</p> 224<p>An example: assuming <code>pkg@1.0.0</code> is installed in the current <code>node_modules</code> 225folder, running:</p> 226<pre><code class="language-bash">npm diff --diff=pkg@2.0.0 227</code></pre> 228<p>It will effectively be an alias to 229<code>npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0</code>.</p> 230</li> 231<li> 232<p><code>npm diff --diff=<semver-a> [--diff=<semver-b>]</code> (in a package directory):</p> 233<p>Using <code>npm diff</code> along with semver-valid version numbers is a shorthand 234to compare different versions of the current package.</p> 235<p>It needs to be run from a package directory, such that for a package named 236<code>pkg</code> running <code>npm diff --diff=1.0.0 --diff=1.0.1</code> is the same as running 237<code>npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1</code>.</p> 238<p>If only a single argument <code><version-a></code> is provided, then the current local 239file system is going to be compared against that version.</p> 240<p>Here's an example comparing two specific versions (published to the 241configured registry) of the current project directory:</p> 242<pre><code class="language-bash">npm diff --diff=1.0.0 --diff=1.1.0 243</code></pre> 244</li> 245</ul> 246<p>Note that tag names are not valid <code>--diff</code> argument values, if you wish to 247compare to a published tag, you must use the <code>pkg@tagname</code> syntax.</p> 248<h4 id="filtering-files">Filtering files</h4> 249<p>It's possible to also specify positional arguments using file names or globs 250pattern matching in order to limit the result of diff patches to only a subset 251of files for a given package, e.g:</p> 252<pre><code class="language-bash">npm diff --diff=pkg@2 ./lib/ CHANGELOG.md 253</code></pre> 254<p>In the example above the diff output is only going to print contents of files 255located within the folder <code>./lib/</code> and changed lines of code within the 256<code>CHANGELOG.md</code> file.</p> 257<h3 id="configuration">Configuration</h3> 258<h4 id="diff"><code>diff</code></h4> 259<ul> 260<li>Default:</li> 261<li>Type: String (can be set multiple times)</li> 262</ul> 263<p>Define arguments to compare in <code>npm diff</code>.</p> 264<h4 id="diff-name-only"><code>diff-name-only</code></h4> 265<ul> 266<li>Default: false</li> 267<li>Type: Boolean</li> 268</ul> 269<p>Prints only filenames when using <code>npm diff</code>.</p> 270<h4 id="diff-unified"><code>diff-unified</code></h4> 271<ul> 272<li>Default: 3</li> 273<li>Type: Number</li> 274</ul> 275<p>The number of lines of context to print in <code>npm diff</code>.</p> 276<h4 id="diff-ignore-all-space"><code>diff-ignore-all-space</code></h4> 277<ul> 278<li>Default: false</li> 279<li>Type: Boolean</li> 280</ul> 281<p>Ignore whitespace when comparing lines in <code>npm diff</code>.</p> 282<h4 id="diff-no-prefix"><code>diff-no-prefix</code></h4> 283<ul> 284<li>Default: false</li> 285<li>Type: Boolean</li> 286</ul> 287<p>Do not show any source or destination prefix in <code>npm diff</code> output.</p> 288<p>Note: this causes <code>npm diff</code> to ignore the <code>--diff-src-prefix</code> and 289<code>--diff-dst-prefix</code> configs.</p> 290<h4 id="diff-src-prefix"><code>diff-src-prefix</code></h4> 291<ul> 292<li>Default: "a/"</li> 293<li>Type: String</li> 294</ul> 295<p>Source prefix to be used in <code>npm diff</code> output.</p> 296<h4 id="diff-dst-prefix"><code>diff-dst-prefix</code></h4> 297<ul> 298<li>Default: "b/"</li> 299<li>Type: String</li> 300</ul> 301<p>Destination prefix to be used in <code>npm diff</code> output.</p> 302<h4 id="diff-text"><code>diff-text</code></h4> 303<ul> 304<li>Default: false</li> 305<li>Type: Boolean</li> 306</ul> 307<p>Treat all files as text in <code>npm diff</code>.</p> 308<h4 id="global"><code>global</code></h4> 309<ul> 310<li>Default: false</li> 311<li>Type: Boolean</li> 312</ul> 313<p>Operates in "global" mode, so that packages are installed into the <code>prefix</code> 314folder instead of the current working directory. See 315<a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p> 316<ul> 317<li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead 318of the current working directory.</li> 319<li>bin files are linked to <code>{prefix}/bin</code></li> 320<li>man pages are linked to <code>{prefix}/share/man</code></li> 321</ul> 322<h4 id="tag"><code>tag</code></h4> 323<ul> 324<li>Default: "latest"</li> 325<li>Type: String</li> 326</ul> 327<p>If you ask npm to install a package and don't tell it a specific version, 328then it will install the specified tag.</p> 329<p>Also the tag that is added to the package@version specified by the <code>npm tag</code> 330command, if no explicit tag is given.</p> 331<p>When used by the <code>npm diff</code> command, this is the tag used to fetch the 332tarball that will be compared with the local files by default.</p> 333<h4 id="workspace"><code>workspace</code></h4> 334<ul> 335<li>Default:</li> 336<li>Type: String (can be set multiple times)</li> 337</ul> 338<p>Enable running a command in the context of the configured workspaces of the 339current project while filtering by running only the workspaces defined by 340this configuration option.</p> 341<p>Valid values for the <code>workspace</code> config are either:</p> 342<ul> 343<li>Workspace names</li> 344<li>Path to a workspace directory</li> 345<li>Path to a parent workspace directory (will result in selecting all 346workspaces within that folder)</li> 347</ul> 348<p>When set for the <code>npm init</code> command, this may be set to the folder of a 349workspace which does not yet exist, to create the folder and set it up as a 350brand new workspace within the project.</p> 351<p>This value is not exported to the environment for child processes.</p> 352<h4 id="workspaces"><code>workspaces</code></h4> 353<ul> 354<li>Default: null</li> 355<li>Type: null or Boolean</li> 356</ul> 357<p>Set to true to run the command in the context of <strong>all</strong> configured 358workspaces.</p> 359<p>Explicitly setting this to false will cause commands like <code>install</code> to 360ignore workspaces altogether. When not set explicitly:</p> 361<ul> 362<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.) 363will link workspaces into the <code>node_modules</code> folder. - Commands that do 364other things (test, exec, publish, etc.) will operate on the root project, 365<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li> 366</ul> 367<p>This value is not exported to the environment for child processes.</p> 368<h4 id="include-workspace-root"><code>include-workspace-root</code></h4> 369<ul> 370<li>Default: false</li> 371<li>Type: Boolean</li> 372</ul> 373<p>Include the workspace root when workspaces are enabled for a command.</p> 374<p>When false, specifying individual workspaces via the <code>workspace</code> config, or 375all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on 376the specified workspaces, and not on the root project.</p> 377<p>This value is not exported to the environment for child processes.</p> 378<h2 id="see-also">See Also</h2> 379<ul> 380<li><a href="../commands/npm-outdated.html">npm outdated</a></li> 381<li><a href="../commands/npm-install.html">npm install</a></li> 382<li><a href="../commands/npm-config.html">npm config</a></li> 383<li><a href="../using-npm/registry.html">npm registry</a></li> 384</ul></div> 385 386<footer id="edit"> 387<a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-diff.md"> 388<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;"> 389<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path> 390</svg> 391Edit this page on GitHub 392</a> 393</footer> 394</section> 395 396 397 398</body></html>