Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
12 KiB

  1. <!doctype html>
  2. <html>
  3. <title>npm-folders</title>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" type="text/css" href="../../static/style.css">
  6. <link rel="canonical" href="https://www.npmjs.org/doc/files/npm-folders.html">
  7. <script async=true src="../../static/toc.js"></script>
  8. <body>
  9. <div id="wrapper">
  10. <h1><a href="../files/npm-folders.html">npm-folders</a></h1> <p>Folder Structures Used by npm</p>
  11. <h2 id="description">DESCRIPTION</h2>
  12. <p>npm puts various things on your computer. That&#39;s its job.</p>
  13. <p>This document will tell you what it puts where.</p>
  14. <h3 id="tl-dr">tl;dr</h3>
  15. <ul>
  16. <li>Local install (default): puts stuff in <code>./node_modules</code> of the current
  17. package root.</li>
  18. <li>Global install (with <code>-g</code>): puts stuff in /usr/local or wherever node
  19. is installed.</li>
  20. <li>Install it <strong>locally</strong> if you&#39;re going to <code>require()</code> it.</li>
  21. <li>Install it <strong>globally</strong> if you&#39;re going to run it on the command line.</li>
  22. <li>If you need both, then install it in both places, or use <code>npm link</code>.</li>
  23. </ul>
  24. <h3 id="prefix-configuration">prefix Configuration</h3>
  25. <p>The <code>prefix</code> config defaults to the location where node is installed.
  26. On most systems, this is <code>/usr/local</code>. On Windows, it&#39;s <code>%AppData%\npm</code>.
  27. On Unix systems, it&#39;s one level up, since node is typically installed at
  28. <code>{prefix}/bin/node</code> rather than <code>{prefix}/node.exe</code>.</p>
  29. <p>When the <code>global</code> flag is set, npm installs things into this prefix.
  30. When it is not set, it uses the root of the current package, or the
  31. current working directory if not in a package already.</p>
  32. <h3 id="node-modules">Node Modules</h3>
  33. <p>Packages are dropped into the <code>node_modules</code> folder under the <code>prefix</code>.
  34. When installing locally, this means that you can
  35. <code>require(&quot;packagename&quot;)</code> to load its main module, or
  36. <code>require(&quot;packagename/lib/path/to/sub/module&quot;)</code> to load other modules.</p>
  37. <p>Global installs on Unix systems go to <code>{prefix}/lib/node_modules</code>.
  38. Global installs on Windows go to <code>{prefix}/node_modules</code> (that is, no
  39. <code>lib</code> folder.)</p>
  40. <p>Scoped packages are installed the same way, except they are grouped together
  41. in a sub-folder of the relevant <code>node_modules</code> folder with the name of that
  42. scope prefix by the @ symbol, e.g. <code>npm install @myorg/package</code> would place
  43. the package in <code>{prefix}/node_modules/@myorg/package</code>. See <code><a href="../misc/scope.html">scope(7)</a></code> for
  44. more details.</p>
  45. <p>If you wish to <code>require()</code> a package, then install it locally.</p>
  46. <h3 id="executables">Executables</h3>
  47. <p>When in global mode, executables are linked into <code>{prefix}/bin</code> on Unix,
  48. or directly into <code>{prefix}</code> on Windows.</p>
  49. <p>When in local mode, executables are linked into
  50. <code>./node_modules/.bin</code> so that they can be made available to scripts run
  51. through npm. (For example, so that a test runner will be in the path
  52. when you run <code>npm test</code>.)</p>
  53. <h3 id="man-pages">Man Pages</h3>
  54. <p>When in global mode, man pages are linked into <code>{prefix}/share/man</code>.</p>
  55. <p>When in local mode, man pages are not installed.</p>
  56. <p>Man pages are not installed on Windows systems.</p>
  57. <h3 id="cache">Cache</h3>
  58. <p>See <code><a href="../cli/npm-cache.html">npm-cache(1)</a></code>. Cache files are stored in <code>~/.npm</code> on Posix, or
  59. <code>%AppData%/npm-cache</code> on Windows.</p>
  60. <p>This is controlled by the <code>cache</code> configuration param.</p>
  61. <h3 id="temp-files">Temp Files</h3>
  62. <p>Temporary files are stored by default in the folder specified by the
  63. <code>tmp</code> config, which defaults to the TMPDIR, TMP, or TEMP environment
  64. variables, or <code>/tmp</code> on Unix and <code>c:\windows\temp</code> on Windows.</p>
  65. <p>Temp files are given a unique folder under this root for each run of the
  66. program, and are deleted upon successful exit.</p>
  67. <h2 id="more-information">More Information</h2>
  68. <p>When installing locally, npm first tries to find an appropriate
  69. <code>prefix</code> folder. This is so that <code>npm install foo@1.2.3</code> will install
  70. to the sensible root of your package, even if you happen to have <code>cd</code>ed
  71. into some other folder.</p>
  72. <p>Starting at the $PWD, npm will walk up the folder tree checking for a
  73. folder that contains either a <code>package.json</code> file, or a <code>node_modules</code>
  74. folder. If such a thing is found, then that is treated as the effective
  75. &quot;current directory&quot; for the purpose of running npm commands. (This
  76. behavior is inspired by and similar to git&#39;s .git-folder seeking
  77. logic when running git commands in a working dir.)</p>
  78. <p>If no package root is found, then the current folder is used.</p>
  79. <p>When you run <code>npm install foo@1.2.3</code>, then the package is loaded into
  80. the cache, and then unpacked into <code>./node_modules/foo</code>. Then, any of
  81. foo&#39;s dependencies are similarly unpacked into
  82. <code>./node_modules/foo/node_modules/...</code>.</p>
  83. <p>Any bin files are symlinked to <code>./node_modules/.bin/</code>, so that they may
  84. be found by npm scripts when necessary.</p>
  85. <h3 id="global-installation">Global Installation</h3>
  86. <p>If the <code>global</code> configuration is set to true, then npm will
  87. install packages &quot;globally&quot;.</p>
  88. <p>For global installation, packages are installed roughly the same way,
  89. but using the folders described above.</p>
  90. <h3 id="cycles-conflicts-and-folder-parsimony">Cycles, Conflicts, and Folder Parsimony</h3>
  91. <p>Cycles are handled using the property of node&#39;s module system that it
  92. walks up the directories looking for <code>node_modules</code> folders. So, at every
  93. stage, if a package is already installed in an ancestor <code>node_modules</code>
  94. folder, then it is not installed at the current location.</p>
  95. <p>Consider the case above, where <code>foo -&gt; bar -&gt; baz</code>. Imagine if, in
  96. addition to that, baz depended on bar, so you&#39;d have:
  97. <code>foo -&gt; bar -&gt; baz -&gt; bar -&gt; baz ...</code>. However, since the folder
  98. structure is: <code>foo/node_modules/bar/node_modules/baz</code>, there&#39;s no need to
  99. put another copy of bar into <code>.../baz/node_modules</code>, since when it calls
  100. require(&quot;bar&quot;), it will get the copy that is installed in
  101. <code>foo/node_modules/bar</code>.</p>
  102. <p>This shortcut is only used if the exact same
  103. version would be installed in multiple nested <code>node_modules</code> folders. It
  104. is still possible to have <code>a/node_modules/b/node_modules/a</code> if the two
  105. &quot;a&quot; packages are different versions. However, without repeating the
  106. exact same package multiple times, an infinite regress will always be
  107. prevented.</p>
  108. <p>Another optimization can be made by installing dependencies at the
  109. highest level possible, below the localized &quot;target&quot; folder.</p>
  110. <h4 id="example">Example</h4>
  111. <p>Consider this dependency graph:</p>
  112. <pre><code>foo
  113. +-- blerg@1.2.5
  114. +-- bar@1.2.3
  115. | +-- blerg@1.x (latest=1.3.7)
  116. | +-- baz@2.x
  117. | | `-- quux@3.x
  118. | | `-- bar@1.2.3 (cycle)
  119. | `-- asdf@*
  120. `-- baz@1.2.3
  121. `-- quux@3.x
  122. `-- bar</code></pre><p>In this case, we might expect a folder structure like this:</p>
  123. <pre><code>foo
  124. +-- node_modules
  125. +-- blerg (1.2.5) &lt;---[A]
  126. +-- bar (1.2.3) &lt;---[B]
  127. | `-- node_modules
  128. | +-- baz (2.0.2) &lt;---[C]
  129. | | `-- node_modules
  130. | | `-- quux (3.2.0)
  131. | `-- asdf (2.3.4)
  132. `-- baz (1.2.3) &lt;---[D]
  133. `-- node_modules
  134. `-- quux (3.2.0) &lt;---[E]</code></pre><p>Since foo depends directly on <a href="mailto:%60bar@1.2.3">`bar@1.2.3</a><code>and</code><a href="mailto:baz@1.2.3">baz@1.2.3</a><code>, those are
  135. installed in foo&#39;s</code>node_modules` folder.</p>
  136. <p>Even though the latest copy of blerg is 1.3.7, foo has a specific
  137. dependency on version 1.2.5. So, that gets installed at [A]. Since the
  138. parent installation of blerg satisfies bar&#39;s dependency on <a href="mailto:%60blerg@1.x">`blerg@1.x</a>`,
  139. it does not install another copy under [B].</p>
  140. <p>Bar [B] also has dependencies on baz and asdf, so those are installed in
  141. bar&#39;s <code>node_modules</code> folder. Because it depends on <a href="mailto:%60baz@2.x">`baz@2.x</a><code>, it cannot
  142. re-use the</code><a href="mailto:baz@1.2.3">baz@1.2.3</a><code>installed in the parent</code>node_modules` folder [D],
  143. and must install its own copy [C].</p>
  144. <p>Underneath bar, the <code>baz -&gt; quux -&gt; bar</code> dependency creates a cycle.
  145. However, because bar is already in quux&#39;s ancestry [B], it does not
  146. unpack another copy of bar into that folder.</p>
  147. <p>Underneath <code>foo -&gt; baz</code> [D], quux&#39;s [E] folder tree is empty, because its
  148. dependency on bar is satisfied by the parent folder copy installed at [B].</p>
  149. <p>For a graphical breakdown of what is installed where, use <code>npm ls</code>.</p>
  150. <h3 id="publishing">Publishing</h3>
  151. <p>Upon publishing, npm will look in the <code>node_modules</code> folder. If any of
  152. the items there are not in the <code>bundledDependencies</code> array, then they will
  153. not be included in the package tarball.</p>
  154. <p>This allows a package maintainer to install all of their dependencies
  155. (and dev dependencies) locally, but only re-publish those items that
  156. cannot be found elsewhere. See <code><a href="../files/package.json.html">package.json(5)</a></code> for more information.</p>
  157. <h2 id="see-also">SEE ALSO</h2>
  158. <ul>
  159. <li><a href="../files/package.json.html">package.json(5)</a></li>
  160. <li><a href="../cli/npm-install.html">npm-install(1)</a></li>
  161. <li><a href="../cli/npm-pack.html">npm-pack(1)</a></li>
  162. <li><a href="../cli/npm-cache.html">npm-cache(1)</a></li>
  163. <li><a href="../cli/npm-config.html">npm-config(1)</a></li>
  164. <li><a href="../files/npmrc.html">npmrc(5)</a></li>
  165. <li><a href="../misc/npm-config.html">npm-config(7)</a></li>
  166. <li><a href="../cli/npm-publish.html">npm-publish(1)</a></li>
  167. </ul>
  168. </div>
  169. <table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
  170. <tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
  171. <tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td colspan=6 style="width:60px;height:10px;background:#fff">&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td></tr>
  172. <tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2>&nbsp;</td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td></tr>
  173. <tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
  174. <tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
  175. <tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6>&nbsp;</td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td></tr>
  176. <tr><td colspan=5 style="width:50px;height:10px;background:#fff">&nbsp;</td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4>&nbsp;</td><td style="width:90px;height:10px;background:#fff" colspan=9>&nbsp;</td></tr>
  177. </table>
  178. <p id="footer">npm-folders &mdash; npm@6.4.1</p>