npm-diff.html 15 KB

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