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.

226 lines
8.2 KiB

  1. .TH "NPM\-FOLDERS" "5" "August 2018" "" ""
  2. .SH "NAME"
  3. \fBnpm-folders\fR \- Folder Structures Used by npm
  4. .SH DESCRIPTION
  5. .P
  6. npm puts various things on your computer\. That's its job\.
  7. .P
  8. This document will tell you what it puts where\.
  9. .SS tl;dr
  10. .RS 0
  11. .IP \(bu 2
  12. Local install (default): puts stuff in \fB\|\./node_modules\fP of the current
  13. package root\.
  14. .IP \(bu 2
  15. Global install (with \fB\-g\fP): puts stuff in /usr/local or wherever node
  16. is installed\.
  17. .IP \(bu 2
  18. Install it \fBlocally\fR if you're going to \fBrequire()\fP it\.
  19. .IP \(bu 2
  20. Install it \fBglobally\fR if you're going to run it on the command line\.
  21. .IP \(bu 2
  22. If you need both, then install it in both places, or use \fBnpm link\fP\|\.
  23. .RE
  24. .SS prefix Configuration
  25. .P
  26. The \fBprefix\fP config defaults to the location where node is installed\.
  27. On most systems, this is \fB/usr/local\fP\|\. On Windows, it's \fB%AppData%\\npm\fP\|\.
  28. On Unix systems, it's one level up, since node is typically installed at
  29. \fB{prefix}/bin/node\fP rather than \fB{prefix}/node\.exe\fP\|\.
  30. .P
  31. When the \fBglobal\fP flag is set, npm installs things into this prefix\.
  32. When it is not set, it uses the root of the current package, or the
  33. current working directory if not in a package already\.
  34. .SS Node Modules
  35. .P
  36. Packages are dropped into the \fBnode_modules\fP folder under the \fBprefix\fP\|\.
  37. When installing locally, this means that you can
  38. \fBrequire("packagename")\fP to load its main module, or
  39. \fBrequire("packagename/lib/path/to/sub/module")\fP to load other modules\.
  40. .P
  41. Global installs on Unix systems go to \fB{prefix}/lib/node_modules\fP\|\.
  42. Global installs on Windows go to \fB{prefix}/node_modules\fP (that is, no
  43. \fBlib\fP folder\.)
  44. .P
  45. Scoped packages are installed the same way, except they are grouped together
  46. in a sub\-folder of the relevant \fBnode_modules\fP folder with the name of that
  47. scope prefix by the @ symbol, e\.g\. \fBnpm install @myorg/package\fP would place
  48. the package in \fB{prefix}/node_modules/@myorg/package\fP\|\. See npm help 7 \fBscope\fP for
  49. more details\.
  50. .P
  51. If you wish to \fBrequire()\fP a package, then install it locally\.
  52. .SS Executables
  53. .P
  54. When in global mode, executables are linked into \fB{prefix}/bin\fP on Unix,
  55. or directly into \fB{prefix}\fP on Windows\.
  56. .P
  57. When in local mode, executables are linked into
  58. \fB\|\./node_modules/\.bin\fP so that they can be made available to scripts run
  59. through npm\. (For example, so that a test runner will be in the path
  60. when you run \fBnpm test\fP\|\.)
  61. .SS Man Pages
  62. .P
  63. When in global mode, man pages are linked into \fB{prefix}/share/man\fP\|\.
  64. .P
  65. When in local mode, man pages are not installed\.
  66. .P
  67. Man pages are not installed on Windows systems\.
  68. .SS Cache
  69. .P
  70. See npm help \fBnpm\-cache\fP\|\. Cache files are stored in \fB~/\.npm\fP on Posix, or
  71. \fB%AppData%/npm\-cache\fP on Windows\.
  72. .P
  73. This is controlled by the \fBcache\fP configuration param\.
  74. .SS Temp Files
  75. .P
  76. Temporary files are stored by default in the folder specified by the
  77. \fBtmp\fP config, which defaults to the TMPDIR, TMP, or TEMP environment
  78. variables, or \fB/tmp\fP on Unix and \fBc:\\windows\\temp\fP on Windows\.
  79. .P
  80. Temp files are given a unique folder under this root for each run of the
  81. program, and are deleted upon successful exit\.
  82. .SH More Information
  83. .P
  84. When installing locally, npm first tries to find an appropriate
  85. \fBprefix\fP folder\. This is so that \fBnpm install foo@1\.2\.3\fP will install
  86. to the sensible root of your package, even if you happen to have \fBcd\fPed
  87. into some other folder\.
  88. .P
  89. Starting at the $PWD, npm will walk up the folder tree checking for a
  90. folder that contains either a \fBpackage\.json\fP file, or a \fBnode_modules\fP
  91. folder\. If such a thing is found, then that is treated as the effective
  92. "current directory" for the purpose of running npm commands\. (This
  93. behavior is inspired by and similar to git's \.git\-folder seeking
  94. logic when running git commands in a working dir\.)
  95. .P
  96. If no package root is found, then the current folder is used\.
  97. .P
  98. When you run \fBnpm install foo@1\.2\.3\fP, then the package is loaded into
  99. the cache, and then unpacked into \fB\|\./node_modules/foo\fP\|\. Then, any of
  100. foo's dependencies are similarly unpacked into
  101. \fB\|\./node_modules/foo/node_modules/\.\.\.\fP\|\.
  102. .P
  103. Any bin files are symlinked to \fB\|\./node_modules/\.bin/\fP, so that they may
  104. be found by npm scripts when necessary\.
  105. .SS Global Installation
  106. .P
  107. If the \fBglobal\fP configuration is set to true, then npm will
  108. install packages "globally"\.
  109. .P
  110. For global installation, packages are installed roughly the same way,
  111. but using the folders described above\.
  112. .SS Cycles, Conflicts, and Folder Parsimony
  113. .P
  114. Cycles are handled using the property of node's module system that it
  115. walks up the directories looking for \fBnode_modules\fP folders\. So, at every
  116. stage, if a package is already installed in an ancestor \fBnode_modules\fP
  117. folder, then it is not installed at the current location\.
  118. .P
  119. Consider the case above, where \fBfoo \-> bar \-> baz\fP\|\. Imagine if, in
  120. addition to that, baz depended on bar, so you'd have:
  121. \fBfoo \-> bar \-> baz \-> bar \-> baz \.\.\.\fP\|\. However, since the folder
  122. structure is: \fBfoo/node_modules/bar/node_modules/baz\fP, there's no need to
  123. put another copy of bar into \fB\|\.\.\./baz/node_modules\fP, since when it calls
  124. require("bar"), it will get the copy that is installed in
  125. \fBfoo/node_modules/bar\fP\|\.
  126. .P
  127. This shortcut is only used if the exact same
  128. version would be installed in multiple nested \fBnode_modules\fP folders\. It
  129. is still possible to have \fBa/node_modules/b/node_modules/a\fP if the two
  130. "a" packages are different versions\. However, without repeating the
  131. exact same package multiple times, an infinite regress will always be
  132. prevented\.
  133. .P
  134. Another optimization can be made by installing dependencies at the
  135. highest level possible, below the localized "target" folder\.
  136. .SS Example
  137. .P
  138. Consider this dependency graph:
  139. .P
  140. .RS 2
  141. .nf
  142. foo
  143. +\-\- blerg@1\.2\.5
  144. +\-\- bar@1\.2\.3
  145. | +\-\- blerg@1\.x (latest=1\.3\.7)
  146. | +\-\- baz@2\.x
  147. | | `\-\- quux@3\.x
  148. | | `\-\- bar@1\.2\.3 (cycle)
  149. | `\-\- asdf@*
  150. `\-\- baz@1\.2\.3
  151. `\-\- quux@3\.x
  152. `\-\- bar
  153. .fi
  154. .RE
  155. .P
  156. In this case, we might expect a folder structure like this:
  157. .P
  158. .RS 2
  159. .nf
  160. foo
  161. +\-\- node_modules
  162. +\-\- blerg (1\.2\.5) <\-\-\-[A]
  163. +\-\- bar (1\.2\.3) <\-\-\-[B]
  164. | `\-\- node_modules
  165. | +\-\- baz (2\.0\.2) <\-\-\-[C]
  166. | | `\-\- node_modules
  167. | | `\-\- quux (3\.2\.0)
  168. | `\-\- asdf (2\.3\.4)
  169. `\-\- baz (1\.2\.3) <\-\-\-[D]
  170. `\-\- node_modules
  171. `\-\- quux (3\.2\.0) <\-\-\-[E]
  172. .fi
  173. .RE
  174. .P
  175. Since foo depends directly on \fBand\fP\fB, those are
  176. installed in foo's\fPnode_modules` folder\.
  177. .P
  178. Even though the latest copy of blerg is 1\.3\.7, foo has a specific
  179. dependency on version 1\.2\.5\. So, that gets installed at [A]\. Since the
  180. parent installation of blerg satisfies bar's dependency on `,
  181. it does not install another copy under [B]\.
  182. .P
  183. Bar [B] also has dependencies on baz and asdf, so those are installed in
  184. bar's \fBnode_modules\fP folder\. Because it depends on \fB, it cannot
  185. re\-use the\fP\fBinstalled in the parent\fPnode_modules` folder [D],
  186. and must install its own copy [C]\.
  187. .P
  188. Underneath bar, the \fBbaz \-> quux \-> bar\fP dependency creates a cycle\.
  189. However, because bar is already in quux's ancestry [B], it does not
  190. unpack another copy of bar into that folder\.
  191. .P
  192. Underneath \fBfoo \-> baz\fP [D], quux's [E] folder tree is empty, because its
  193. dependency on bar is satisfied by the parent folder copy installed at [B]\.
  194. .P
  195. For a graphical breakdown of what is installed where, use \fBnpm ls\fP\|\.
  196. .SS Publishing
  197. .P
  198. Upon publishing, npm will look in the \fBnode_modules\fP folder\. If any of
  199. the items there are not in the \fBbundledDependencies\fP array, then they will
  200. not be included in the package tarball\.
  201. .P
  202. This allows a package maintainer to install all of their dependencies
  203. (and dev dependencies) locally, but only re\-publish those items that
  204. cannot be found elsewhere\. See npm help 5 \fBpackage\.json\fP for more information\.
  205. .SH SEE ALSO
  206. .RS 0
  207. .IP \(bu 2
  208. npm help 5 package\.json
  209. .IP \(bu 2
  210. npm help install
  211. .IP \(bu 2
  212. npm help pack
  213. .IP \(bu 2
  214. npm help cache
  215. .IP \(bu 2
  216. npm help config
  217. .IP \(bu 2
  218. npm help 5 npmrc
  219. .IP \(bu 2
  220. npm help 7 config
  221. .IP \(bu 2
  222. npm help publish
  223. .RE