codekingpro/portable-devtools
115k
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
116header.title .version {
117 font-size: 0.8em;
118 color: #666666;
119}
120
121footer#edit {
122 border-top: solid 1px #e1e4e8;
123 margin: 3em 0 4em 0;
124 padding-top: 2em;
125}
126
127table {
128 width: 100%;
129 margin: 1em 0;
130 border-radius: 6px;
131 border: 1px solid #e1e4e8;
132 overflow: hidden;
133 border-collapse: separate;
134 border-spacing: 0;
135}
136
137table thead {
138 background-color: #f6f8fa;
139}
140
141table tbody {
142 background-color: #ffffff;
143}
144
145table th,
146table td {
147 padding: 0.75em;
148 text-align: left;
149 border-right: 1px solid #e1e4e8;
150 border-bottom: 1px solid #e1e4e8;
151}
152
153table th:last-child,
154table td:last-child {
155 border-right: none;
156}
157
158table tbody tr:last-child td {
159 border-bottom: none;
160}
161
162table th {
163 font-weight: 600;
164 background-color: #f6f8fa;
165}
166
167table code {
168 white-space: nowrap;
169}
170
171</style>
172</head>
173<body>
174<div id="banner">
175<div id="rainbar"></div>
176<div id="logobar">
177<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
178<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
179<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
180</svg>
181<div class="title">
182npm command-line interface
183</div>
184</div>
185</div>
186
187<section id="content">
188<header class="title">
189<h1 id="----npm-diff----11130">
190 <span>npm-diff</span>
191 <span class="version">@11.13.0</span>
192</h1>
193<span class="description">The registry diff command</span>
194</header>
195
196<section id="table_of_contents">
197<h2 id="table-of-contents">Table of contents</h2>
198<div id="_table_of_contents"><ul><li><a href="#see-also">See Also</a></li></ul></div>
199</section>
200
201<div id="_content"><h3 id="synopsis">Synopsis</h3>
202<pre><code class="language-bash">npm diff [...<paths>]
203</code></pre>
204<h3 id="description">Description</h3>
205<p>Similar to its <code>git diff</code> counterpart, this command will print diff patches of files for packages published to the npm registry.</p>
206<ul>
207<li>
208<p><code>npm diff --diff=<spec-a> --diff=<spec-b></code></p>
209<p>Compares two package versions using their registry specifiers, e.g: <code>npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0</code>.
210It's also possible to compare across forks of any package, e.g: <code>npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0</code>.</p>
211<p>Any valid spec can be used, so that it's also possible to compare directories or git repositories, e.g: <code>npm diff --diff=pkg@latest --diff=./packages/pkg</code></p>
212<p>Here's an example comparing two different versions of a package named <code>abbrev</code> from the registry:</p>
213<pre><code class="language-bash">npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1
214</code></pre>
215<p>On success, output looks like:</p>
216<pre><code class="language-bash">diff --git a/package.json b/package.json
217index v1.1.0..v1.1.1 100644
218--- a/package.json
219+++ b/package.json
220@@ -1,6 +1,6 @@
221 {
222 "name": "abbrev",
223- "version": "1.1.0",
224+ "version": "1.1.1",
225 "description": "Like ruby's abbrev module, but in js",
226 "author": "Isaac Z. Schlueter <i@izs.me>",
227 "main": "abbrev.js",
228</code></pre>
229<p>Given the flexible nature of npm specs, you can also target local directories or git repos just like when using <code>npm install</code>:</p>
230<pre><code class="language-bash">npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path
231</code></pre>
232<p>In the example above we can compare the contents from the package installed from the git repo at <code>github.com/npm/libnpmdiff</code> with the contents of the <code>./local-path</code> that contains a valid package, such as a modified copy of the original.</p>
233</li>
234<li>
235<p><code>npm diff</code> (in a package directory, no arguments):</p>
236<p>If the package is published to the registry, <code>npm diff</code> will fetch the tarball version tagged as <code>latest</code> (this value can be configured using the <code>tag</code> option) and proceed to compare the contents of files present in that tarball, with the current files in your local file system.</p>
237<p>This workflow provides a handy way for package authors to see what package-tracked files have been changed in comparison with the latest published version of that package.</p>
238</li>
239<li>
240<p><code>npm diff --diff=<pkg-name></code> (in a package directory):</p>
241<p>When using a single package name (with no version or tag specifier) as an argument, <code>npm diff</code> will work in a similar way to <a href="npm-outdated"><code>npm-outdated</code></a> and reach for the registry to figure out what current published version of the package named <code><pkg-name></code> will satisfy its dependent declared semver-range.
242Once that specific version is known <code>npm diff</code> will print diff patches comparing the current version of <code><pkg-name></code> found in the local file system with that specific version returned by the registry.</p>
243<p>Given a package named <code>abbrev</code> that is currently installed:</p>
244<pre><code class="language-bash">npm diff --diff=abbrev
245</code></pre>
246<p>That will request from the registry its most up to date version and will print a diff output comparing the currently installed version to this newer one if the version numbers are not the same.</p>
247</li>
248<li>
249<p><code>npm diff --diff=<spec-a></code> (in a package directory):</p>
250<p>Similar to using only a single package name, it's also possible to declare a full registry specifier version if you wish to compare the local version of an installed package with the specific version/tag/semver-range provided in <code><spec-a></code>.</p>
251<p>An example: assuming <code>pkg@1.0.0</code> is installed in the current <code>node_modules</code> folder, running:</p>
252<pre><code class="language-bash">npm diff --diff=pkg@2.0.0
253</code></pre>
254<p>It will effectively be an alias to
255<code>npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0</code>.</p>
256</li>
257<li>
258<p><code>npm diff --diff=<semver-a> [--diff=<semver-b>]</code> (in a package directory):</p>
259<p>Using <code>npm diff</code> along with semver-valid version numbers is a shorthand to compare different versions of the current package.</p>
260<p>It needs to be run from a package directory, such that for a package named <code>pkg</code> running <code>npm diff --diff=1.0.0 --diff=1.0.1</code> is the same as running <code>npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1</code>.</p>
261<p>If only a single argument <code><version-a></code> is provided, then the current local file system is going to be compared against that version.</p>
262<p>Here's an example comparing two specific versions (published to the configured registry) of the current project directory:</p>
263<pre><code class="language-bash">npm diff --diff=1.0.0 --diff=1.1.0
264</code></pre>
265</li>
266</ul>
267<p>Note that tag names are not valid <code>--diff</code> argument values, if you wish to compare to a published tag, you must use the <code>pkg@tagname</code> syntax.</p>
268<h4 id="filtering-files">Filtering files</h4>
269<p>It's possible to also specify positional arguments using file names or globs pattern matching in order to limit the result of diff patches to only a subset of files for a given package, e.g:</p>
270<pre><code class="language-bash">npm diff --diff=pkg@2 ./lib/ CHANGELOG.md
271</code></pre>
272<p>In the example above the diff output is only going to print contents of files located within the folder <code>./lib/</code> and changed lines of code within the <code>CHANGELOG.md</code> file.</p>
273<h3 id="configuration">Configuration</h3>
274<h4 id="diff"><code>diff</code></h4>
275<ul>
276<li>Default:</li>
277<li>Type: String (can be set multiple times)</li>
278</ul>
279<p>Define arguments to compare in <code>npm diff</code>.</p>
280<h4 id="diff-name-only"><code>diff-name-only</code></h4>
281<ul>
282<li>Default: false</li>
283<li>Type: Boolean</li>
284</ul>
285<p>Prints only filenames when using <code>npm diff</code>.</p>
286<h4 id="diff-unified"><code>diff-unified</code></h4>
287<ul>
288<li>Default: 3</li>
289<li>Type: Number</li>
290</ul>
291<p>The number of lines of context to print in <code>npm diff</code>.</p>
292<h4 id="diff-ignore-all-space"><code>diff-ignore-all-space</code></h4>
293<ul>
294<li>Default: false</li>
295<li>Type: Boolean</li>
296</ul>
297<p>Ignore whitespace when comparing lines in <code>npm diff</code>.</p>
298<h4 id="diff-no-prefix"><code>diff-no-prefix</code></h4>
299<ul>
300<li>Default: false</li>
301<li>Type: Boolean</li>
302</ul>
303<p>Do not show any source or destination prefix in <code>npm diff</code> output.</p>
304<p>Note: this causes <code>npm diff</code> to ignore the <code>--diff-src-prefix</code> and
305<code>--diff-dst-prefix</code> configs.</p>
306<h4 id="diff-src-prefix"><code>diff-src-prefix</code></h4>
307<ul>
308<li>Default: "a/"</li>
309<li>Type: String</li>
310</ul>
311<p>Source prefix to be used in <code>npm diff</code> output.</p>
312<h4 id="diff-dst-prefix"><code>diff-dst-prefix</code></h4>
313<ul>
314<li>Default: "b/"</li>
315<li>Type: String</li>
316</ul>
317<p>Destination prefix to be used in <code>npm diff</code> output.</p>
318<h4 id="diff-text"><code>diff-text</code></h4>
319<ul>
320<li>Default: false</li>
321<li>Type: Boolean</li>
322</ul>
323<p>Treat all files as text in <code>npm diff</code>.</p>
324<h4 id="global"><code>global</code></h4>
325<ul>
326<li>Default: false</li>
327<li>Type: Boolean</li>
328</ul>
329<p>Operates in "global" mode, so that packages are installed into the <code>prefix</code>
330folder instead of the current working directory. See
331<a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
332<ul>
333<li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
334of the current working directory.</li>
335<li>bin files are linked to <code>{prefix}/bin</code></li>
336<li>man pages are linked to <code>{prefix}/share/man</code></li>
337</ul>
338<h4 id="tag"><code>tag</code></h4>
339<ul>
340<li>Default: "latest"</li>
341<li>Type: String</li>
342</ul>
343<p>If you ask npm to install a package and don't tell it a specific version,
344then it will install the specified tag.</p>
345<p>It is the tag added to the package@version specified in the <code>npm dist-tag add</code> command, if no explicit tag is given.</p>
346<p>When used by the <code>npm diff</code> command, this is the tag used to fetch the
347tarball that will be compared with the local files by default.</p>
348<p>If used in the <code>npm publish</code> command, this is the tag that will be added to
349the package submitted to the registry.</p>
350<h4 id="workspace"><code>workspace</code></h4>
351<ul>
352<li>Default:</li>
353<li>Type: String (can be set multiple times)</li>
354</ul>
355<p>Enable running a command in the context of the configured workspaces of the
356current project while filtering by running only the workspaces defined by
357this configuration option.</p>
358<p>Valid values for the <code>workspace</code> config are either:</p>
359<ul>
360<li>Workspace names</li>
361<li>Path to a workspace directory</li>
362<li>Path to a parent workspace directory (will result in selecting all
363workspaces within that folder)</li>
364</ul>
365<p>When set for the <code>npm init</code> command, this may be set to the folder of a
366workspace which does not yet exist, to create the folder and set it up as a
367brand new workspace within the project.</p>
368<p>This value is not exported to the environment for child processes.</p>
369<h4 id="workspaces"><code>workspaces</code></h4>
370<ul>
371<li>Default: null</li>
372<li>Type: null or Boolean</li>
373</ul>
374<p>Set to true to run the command in the context of <strong>all</strong> configured
375workspaces.</p>
376<p>Explicitly setting this to false will cause commands like <code>install</code> to
377ignore workspaces altogether. When not set explicitly:</p>
378<ul>
379<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
380will link workspaces into the <code>node_modules</code> folder. - Commands that do
381other things (test, exec, publish, etc.) will operate on the root project,
382<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
383</ul>
384<p>This value is not exported to the environment for child processes.</p>
385<h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
386<ul>
387<li>Default: false</li>
388<li>Type: Boolean</li>
389</ul>
390<p>Include the workspace root when workspaces are enabled for a command.</p>
391<p>When false, specifying individual workspaces via the <code>workspace</code> config, or
392all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
393the specified workspaces, and not on the root project.</p>
394<p>This value is not exported to the environment for child processes.</p>
395<h2 id="see-also">See Also</h2>
396<ul>
397<li><a href="../commands/npm-outdated.html">npm outdated</a></li>
398<li><a href="../commands/npm-install.html">npm install</a></li>
399<li><a href="../commands/npm-config.html">npm config</a></li>
400<li><a href="../using-npm/registry.html">npm registry</a></li>
401</ul></div>
402
403<footer id="edit">
404<a href="https://github.com/npm/cli/edit/latest/docs/lib/content/commands/npm-diff.md">
405<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
406<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>
407</svg>
408Edit this page on GitHub
409</a>
410</footer>
411</section>
412
413
414
415</body></html>