npm-ls.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <html><head>
  2. <title>npm-ls</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-ls">npm-ls</h1>
  125. <span class="description">List installed packages</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="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#note-design-changes-pending">Note: Design Changes Pending</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#all"><code>all</code></a></li><li><a href="#json"><code>json</code></a></li><li><a href="#long"><code>long</code></a></li><li><a href="#parseable"><code>parseable</code></a></li><li><a href="#global"><code>global</code></a></li><li><a href="#depth"><code>depth</code></a></li><li><a href="#omit"><code>omit</code></a></li><li><a href="#link"><code>link</code></a></li><li><a href="#package-lock-only"><code>package-lock-only</code></a></li><li><a href="#unicode"><code>unicode</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li></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 ls [[&lt;@scope&gt;/]&lt;pkg&gt; ...]
  133. aliases: list, la, ll
  134. </code></pre>
  135. <h3 id="description">Description</h3>
  136. <p>This command will print to stdout all the versions of packages that are
  137. installed, as well as their dependencies when <code>--all</code> is specified, in a
  138. tree structure.</p>
  139. <p>Note: to get a “bottoms up” view of why a given package is included in the
  140. tree at all, use <a href="../commands/npm-explain.html"><code>npm explain</code></a>.</p>
  141. <p>Positional arguments are <code>name@version-range</code> identifiers, which will limit
  142. the results to only the paths to the packages named. Note that nested
  143. packages will <em>also</em> show the paths to the specified packages. For
  144. example, running <code>npm ls promzard</code> in npm’s source tree will show:</p>
  145. <pre lang="bash"><code>npm@8.1.2 /path/to/npm
  146. └─┬ init-package-json@0.0.4
  147. └── promzard@0.1.5
  148. </code></pre>
  149. <p>It will print out extraneous, missing, and invalid packages.</p>
  150. <p>If a project specifies git urls for dependencies these are shown
  151. in parentheses after the name@version to make it easier for users to
  152. recognize potential forks of a project.</p>
  153. <p>The tree shown is the logical dependency tree, based on package
  154. dependencies, not the physical layout of your <code>node_modules</code> folder.</p>
  155. <p>When run as <code>ll</code> or <code>la</code>, it shows extended information by default.</p>
  156. <h3 id="note-design-changes-pending">Note: Design Changes Pending</h3>
  157. <p>The <code>npm ls</code> command’s output and behavior made a <em>ton</em> of sense when npm
  158. created a <code>node_modules</code> folder that naively nested every dependency. In
  159. such a case, the logical dependency graph and physical tree of packages on
  160. disk would be roughly identical.</p>
  161. <p>With the advent of automatic install-time deduplication of dependencies in
  162. npm v3, the <code>ls</code> output was modified to display the logical dependency
  163. graph as a tree structure, since this was more useful to most users.
  164. However, without using <code>npm ls -l</code>, it became impossible show <em>where</em> a
  165. package was actually installed much of the time!</p>
  166. <p>With the advent of automatic installation of <code>peerDependencies</code> in npm v7,
  167. this gets even more curious, as <code>peerDependencies</code> are logically
  168. “underneath” their dependents in the dependency graph, but are always
  169. physically at or above their location on disk.</p>
  170. <p>Also, in the years since npm got an <code>ls</code> command (in version 0.0.2!),
  171. dependency graphs have gotten much larger as a general rule. Therefore, in
  172. order to avoid dumping an excessive amount of content to the terminal, <code>npm ls</code> now only shows the <em>top</em> level dependencies, unless <code>--all</code> is
  173. provided.</p>
  174. <p>A thorough re-examination of the use cases, intention, behavior, and output
  175. of this command, is currently underway. Expect significant changes to at
  176. least the default human-readable <code>npm ls</code> output in npm v8.</p>
  177. <h3 id="configuration">Configuration</h3>
  178. <!-- raw HTML omitted -->
  179. <!-- raw HTML omitted -->
  180. <!-- raw HTML omitted -->
  181. <h4 id="all"><code>all</code></h4>
  182. <ul>
  183. <li>Default: false</li>
  184. <li>Type: Boolean</li>
  185. </ul>
  186. <p>When running <code>npm outdated</code> and <code>npm ls</code>, setting <code>--all</code> will show all
  187. outdated or installed packages, rather than only those directly depended
  188. upon by the current project.</p>
  189. <!-- raw HTML omitted -->
  190. <!-- raw HTML omitted -->
  191. <h4 id="json"><code>json</code></h4>
  192. <ul>
  193. <li>Default: false</li>
  194. <li>Type: Boolean</li>
  195. </ul>
  196. <p>Whether or not to output JSON data, rather than the normal output.</p>
  197. <ul>
  198. <li>In <code>npm pkg set</code> it enables parsing set values with JSON.parse() before
  199. saving them to your <code>package.json</code>.</li>
  200. </ul>
  201. <p>Not supported by all npm commands.</p>
  202. <!-- raw HTML omitted -->
  203. <!-- raw HTML omitted -->
  204. <h4 id="long"><code>long</code></h4>
  205. <ul>
  206. <li>Default: false</li>
  207. <li>Type: Boolean</li>
  208. </ul>
  209. <p>Show extended information in <code>ls</code>, <code>search</code>, and <code>help-search</code>.</p>
  210. <!-- raw HTML omitted -->
  211. <!-- raw HTML omitted -->
  212. <h4 id="parseable"><code>parseable</code></h4>
  213. <ul>
  214. <li>Default: false</li>
  215. <li>Type: Boolean</li>
  216. </ul>
  217. <p>Output parseable results from commands that write to standard output. For
  218. <code>npm search</code>, this will be tab-separated table format.</p>
  219. <!-- raw HTML omitted -->
  220. <!-- raw HTML omitted -->
  221. <h4 id="global"><code>global</code></h4>
  222. <ul>
  223. <li>Default: false</li>
  224. <li>Type: Boolean</li>
  225. </ul>
  226. <p>Operates in “global” mode, so that packages are installed into the <code>prefix</code>
  227. folder instead of the current working directory. See
  228. <a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
  229. <ul>
  230. <li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
  231. of the current working directory.</li>
  232. <li>bin files are linked to <code>{prefix}/bin</code></li>
  233. <li>man pages are linked to <code>{prefix}/share/man</code></li>
  234. </ul>
  235. <!-- raw HTML omitted -->
  236. <!-- raw HTML omitted -->
  237. <h4 id="depth"><code>depth</code></h4>
  238. <ul>
  239. <li>Default: <code>Infinity</code> if <code>--all</code> is set, otherwise <code>1</code></li>
  240. <li>Type: null or Number</li>
  241. </ul>
  242. <p>The depth to go when recursing packages for <code>npm ls</code>.</p>
  243. <p>If not set, <code>npm ls</code> will show only the immediate dependencies of the root
  244. project. If <code>--all</code> is set, then npm will show all dependencies by default.</p>
  245. <!-- raw HTML omitted -->
  246. <!-- raw HTML omitted -->
  247. <h4 id="omit"><code>omit</code></h4>
  248. <ul>
  249. <li>Default: ‘dev’ if the <code>NODE_ENV</code> environment variable is set to
  250. ‘production’, otherwise empty.</li>
  251. <li>Type: “dev”, “optional”, or “peer” (can be set multiple times)</li>
  252. </ul>
  253. <p>Dependency types to omit from the installation tree on disk.</p>
  254. <p>Note that these dependencies <em>are</em> still resolved and added to the
  255. <code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
  256. physically installed on disk.</p>
  257. <p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
  258. it will be included.</p>
  259. <p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
  260. variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
  261. <!-- raw HTML omitted -->
  262. <!-- raw HTML omitted -->
  263. <h4 id="link"><code>link</code></h4>
  264. <ul>
  265. <li>Default: false</li>
  266. <li>Type: Boolean</li>
  267. </ul>
  268. <p>Used with <code>npm ls</code>, limiting output to only those packages that are linked.</p>
  269. <!-- raw HTML omitted -->
  270. <!-- raw HTML omitted -->
  271. <h4 id="package-lock-only"><code>package-lock-only</code></h4>
  272. <ul>
  273. <li>Default: false</li>
  274. <li>Type: Boolean</li>
  275. </ul>
  276. <p>If set to true, the current operation will only use the <code>package-lock.json</code>,
  277. ignoring <code>node_modules</code>.</p>
  278. <p>For <code>update</code> this means only the <code>package-lock.json</code> will be updated,
  279. instead of checking <code>node_modules</code> and downloading dependencies.</p>
  280. <p>For <code>list</code> this means the output will be based on the tree described by the
  281. <code>package-lock.json</code>, rather than the contents of <code>node_modules</code>.</p>
  282. <!-- raw HTML omitted -->
  283. <!-- raw HTML omitted -->
  284. <h4 id="unicode"><code>unicode</code></h4>
  285. <ul>
  286. <li>Default: false on windows, true on mac/unix systems with a unicode locale,
  287. as defined by the <code>LC_ALL</code>, <code>LC_CTYPE</code>, or <code>LANG</code> environment variables.</li>
  288. <li>Type: Boolean</li>
  289. </ul>
  290. <p>When set to true, npm uses unicode characters in the tree output. When
  291. false, it uses ascii characters instead of unicode glyphs.</p>
  292. <!-- raw HTML omitted -->
  293. <!-- raw HTML omitted -->
  294. <h4 id="workspace"><code>workspace</code></h4>
  295. <ul>
  296. <li>Default:</li>
  297. <li>Type: String (can be set multiple times)</li>
  298. </ul>
  299. <p>Enable running a command in the context of the configured workspaces of the
  300. current project while filtering by running only the workspaces defined by
  301. this configuration option.</p>
  302. <p>Valid values for the <code>workspace</code> config are either:</p>
  303. <ul>
  304. <li>Workspace names</li>
  305. <li>Path to a workspace directory</li>
  306. <li>Path to a parent workspace directory (will result in selecting all
  307. workspaces within that folder)</li>
  308. </ul>
  309. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  310. workspace which does not yet exist, to create the folder and set it up as a
  311. brand new workspace within the project.</p>
  312. <p>This value is not exported to the environment for child processes.</p>
  313. <!-- raw HTML omitted -->
  314. <!-- raw HTML omitted -->
  315. <h4 id="workspaces"><code>workspaces</code></h4>
  316. <ul>
  317. <li>Default: null</li>
  318. <li>Type: null or Boolean</li>
  319. </ul>
  320. <p>Set to true to run the command in the context of <strong>all</strong> configured
  321. workspaces.</p>
  322. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  323. ignore workspaces altogether. When not set explicitly:</p>
  324. <ul>
  325. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  326. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  327. other things (test, exec, publish, etc.) will operate on the root project,
  328. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  329. </ul>
  330. <p>This value is not exported to the environment for child processes.</p>
  331. <!-- raw HTML omitted -->
  332. <!-- raw HTML omitted -->
  333. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  334. <ul>
  335. <li>Default: false</li>
  336. <li>Type: Boolean</li>
  337. </ul>
  338. <p>Include the workspace root when workspaces are enabled for a command.</p>
  339. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  340. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  341. the specified workspaces, and not on the root project.</p>
  342. <!-- raw HTML omitted -->
  343. <!-- raw HTML omitted -->
  344. <!-- raw HTML omitted -->
  345. <h3 id="see-also">See Also</h3>
  346. <ul>
  347. <li><a href="../commands/npm-explain.html">npm explain</a></li>
  348. <li><a href="../commands/npm-config.html">npm config</a></li>
  349. <li><a href="../configuring-npm/npmrc.html">npmrc</a></li>
  350. <li><a href="../configuring-npm/folders.html">npm folders</a></li>
  351. <li><a href="../commands/npm-explain.html">npm explain</a></li>
  352. <li><a href="../commands/npm-install.html">npm install</a></li>
  353. <li><a href="../commands/npm-link.html">npm link</a></li>
  354. <li><a href="../commands/npm-prune.html">npm prune</a></li>
  355. <li><a href="../commands/npm-outdated.html">npm outdated</a></li>
  356. <li><a href="../commands/npm-update.html">npm update</a></li>
  357. </ul>
  358. </div>
  359. <footer id="edit">
  360. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-ls.md">
  361. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  362. <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>
  363. </svg>
  364. Edit this page on GitHub
  365. </a>
  366. </footer>
  367. </section>
  368. </body></html>