npm-diff.html 15 KB

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