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.

457 lines
17 KiB

  1. npm-install(1) -- Install a package
  2. ===================================
  3. ## SYNOPSIS
  4. npm install (with no args, in package dir)
  5. npm install [<@scope>/]<name>
  6. npm install [<@scope>/]<name>@<tag>
  7. npm install [<@scope>/]<name>@<version>
  8. npm install [<@scope>/]<name>@<version range>
  9. npm install <git-host>:<git-user>/<repo-name>
  10. npm install <git repo url>
  11. npm install <tarball file>
  12. npm install <tarball url>
  13. npm install <folder>
  14. alias: npm i
  15. common options: [-P|--save-prod|-D|--save-dev|-O|--save-optional] [-E|--save-exact] [-B|--save-bundle] [--no-save] [--dry-run]
  16. ## DESCRIPTION
  17. This command installs a package, and any packages that it depends on. If the
  18. package has a package-lock or shrinkwrap file, the installation of dependencies
  19. will be driven by that, with an `npm-shrinkwrap.json` taking precedence if both
  20. files exist. See package-lock.json(5) and npm-shrinkwrap(1).
  21. A `package` is:
  22. * a) a folder containing a program described by a `package.json(5)` file
  23. * b) a gzipped tarball containing (a)
  24. * c) a url that resolves to (b)
  25. * d) a `<name>@<version>` that is published on the registry (see `npm-registry(7)`) with (c)
  26. * e) a `<name>@<tag>` (see `npm-dist-tag(1)`) that points to (d)
  27. * f) a `<name>` that has a "latest" tag satisfying (e)
  28. * g) a `<git remote url>` that resolves to (a)
  29. Even if you never publish your package, you can still get a lot of
  30. benefits of using npm if you just want to write a node program (a), and
  31. perhaps if you also want to be able to easily install it elsewhere
  32. after packing it up into a tarball (b).
  33. * `npm install` (in package directory, no arguments):
  34. Install the dependencies in the local node_modules folder.
  35. In global mode (ie, with `-g` or `--global` appended to the command),
  36. it installs the current package context (ie, the current working
  37. directory) as a global package.
  38. By default, `npm install` will install all modules listed as dependencies
  39. in `package.json(5)`.
  40. With the `--production` flag (or when the `NODE_ENV` environment variable
  41. is set to `production`), npm will not install modules listed in
  42. `devDependencies`.
  43. > NOTE: The `--production` flag has no particular meaning when adding a
  44. dependency to a project.
  45. * `npm install <folder>`:
  46. Install the package in the directory as a symlink in the current project.
  47. Its dependencies will be installed before it's linked. If `<folder>` sits
  48. inside the root of your project, its dependencies may be hoisted to the
  49. toplevel `node_modules` as they would for other types of dependencies.
  50. * `npm install <tarball file>`:
  51. Install a package that is sitting on the filesystem. Note: if you just want
  52. to link a dev directory into your npm root, you can do this more easily by
  53. using `npm link`.
  54. Tarball requirements:
  55. * The filename *must* use `.tar`, `.tar.gz`, or `.tgz` as
  56. the extension.
  57. * The package contents should reside in a subfolder inside the tarball (usually it is called `package/`). npm strips one directory layer when installing the package (an equivalent of `tar x --strip-components=1` is run).
  58. * The package must contain a `package.json` file with `name` and `version` properties.
  59. Example:
  60. npm install ./package.tgz
  61. * `npm install <tarball url>`:
  62. Fetch the tarball url, and then install it. In order to distinguish between
  63. this and other options, the argument must start with "http://" or "https://"
  64. Example:
  65. npm install https://github.com/indexzero/forever/tarball/v0.5.6
  66. * `npm install [<@scope>/]<name>`:
  67. Do a `<name>@<tag>` install, where `<tag>` is the "tag" config. (See
  68. `npm-config(7)`. The config's default value is `latest`.)
  69. In most cases, this will install the version of the modules tagged as
  70. `latest` on the npm registry.
  71. Example:
  72. npm install sax
  73. `npm install` saves any specified packages into `dependencies` by default.
  74. Additionally, you can control where and how they get saved with some
  75. additional flags:
  76. * `-P, --save-prod`: Package will appear in your `dependencies`. This is the
  77. default unless `-D` or `-O` are present.
  78. * `-D, --save-dev`: Package will appear in your `devDependencies`.
  79. * `-O, --save-optional`: Package will appear in your `optionalDependencies`.
  80. * `--no-save`: Prevents saving to `dependencies`.
  81. When using any of the above options to save dependencies to your
  82. package.json, there are two additional, optional flags:
  83. * `-E, --save-exact`: Saved dependencies will be configured with an
  84. exact version rather than using npm's default semver range
  85. operator.
  86. * `-B, --save-bundle`: Saved dependencies will also be added to your `bundleDependencies` list.
  87. Further, if you have an `npm-shrinkwrap.json` or `package-lock.json` then it
  88. will be updated as well.
  89. `<scope>` is optional. The package will be downloaded from the registry
  90. associated with the specified scope. If no registry is associated with
  91. the given scope the default registry is assumed. See `npm-scope(7)`.
  92. Note: if you do not include the @-symbol on your scope name, npm will
  93. interpret this as a GitHub repository instead, see below. Scopes names
  94. must also be followed by a slash.
  95. Examples:
  96. npm install sax
  97. npm install githubname/reponame
  98. npm install @myorg/privatepackage
  99. npm install node-tap --save-dev
  100. npm install dtrace-provider --save-optional
  101. npm install readable-stream --save-exact
  102. npm install ansi-regex --save-bundle
  103. **Note**: If there is a file or folder named `<name>` in the current
  104. working directory, then it will try to install that, and only try to
  105. fetch the package by name if it is not valid.
  106. * `npm install [<@scope>/]<name>@<tag>`:
  107. Install the version of the package that is referenced by the specified tag.
  108. If the tag does not exist in the registry data for that package, then this
  109. will fail.
  110. Example:
  111. npm install sax@latest
  112. npm install @myorg/mypackage@latest
  113. * `npm install [<@scope>/]<name>@<version>`:
  114. Install the specified version of the package. This will fail if the
  115. version has not been published to the registry.
  116. Example:
  117. npm install sax@0.1.1
  118. npm install @myorg/privatepackage@1.5.0
  119. * `npm install [<@scope>/]<name>@<version range>`:
  120. Install a version of the package matching the specified version range. This
  121. will follow the same rules for resolving dependencies described in `package.json(5)`.
  122. Note that most version ranges must be put in quotes so that your shell will
  123. treat it as a single argument.
  124. Example:
  125. npm install sax@">=0.1.0 <0.2.0"
  126. npm install @myorg/privatepackage@">=0.1.0 <0.2.0"
  127. * `npm install <git remote url>`:
  128. Installs the package from the hosted git provider, cloning it with `git`.
  129. For a full git remote url, only that URL will be attempted.
  130. <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
  131. `<protocol>` is one of `git`, `git+ssh`, `git+http`, `git+https`, or
  132. `git+file`.
  133. If `#<commit-ish>` is provided, it will be used to clone exactly that
  134. commit. If the commit-ish has the format `#semver:<semver>`, `<semver>` can
  135. be any valid semver range or exact version, and npm will look for any tags
  136. or refs matching that range in the remote repository, much as it would for a
  137. registry dependency. If neither `#<commit-ish>` or `#semver:<semver>` is
  138. specified, then `master` is used.
  139. If the repository makes use of submodules, those submodules will be cloned
  140. as well.
  141. If the package being installed contains a `prepare` script, its
  142. `dependencies` and `devDependencies` will be installed, and the prepare
  143. script will be run, before the package is packaged and installed.
  144. The following git environment variables are recognized by npm and will be
  145. added to the environment when running git:
  146. * `GIT_ASKPASS`
  147. * `GIT_EXEC_PATH`
  148. * `GIT_PROXY_COMMAND`
  149. * `GIT_SSH`
  150. * `GIT_SSH_COMMAND`
  151. * `GIT_SSL_CAINFO`
  152. * `GIT_SSL_NO_VERIFY`
  153. See the git man page for details.
  154. Examples:
  155. npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
  156. npm install git+ssh://git@github.com:npm/cli#semver:^5.0
  157. npm install git+https://isaacs@github.com/npm/cli.git
  158. npm install git://github.com/npm/cli.git#v1.0.27
  159. GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
  160. * `npm install <githubname>/<githubrepo>[#<commit-ish>]`:
  161. * `npm install github:<githubname>/<githubrepo>[#<commit-ish>]`:
  162. Install the package at `https://github.com/githubname/githubrepo` by
  163. attempting to clone it using `git`.
  164. If `#<commit-ish>` is provided, it will be used to clone exactly that
  165. commit. If the commit-ish has the format `#semver:<semver>`, `<semver>` can
  166. be any valid semver range or exact version, and npm will look for any tags
  167. or refs matching that range in the remote repository, much as it would for a
  168. registry dependency. If neither `#<commit-ish>` or `#semver:<semver>` is
  169. specified, then `master` is used.
  170. As with regular git dependencies, `dependencies` and `devDependencies` will
  171. be installed if the package has a `prepare` script, before the package is
  172. done installing.
  173. Examples:
  174. npm install mygithubuser/myproject
  175. npm install github:mygithubuser/myproject
  176. * `npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]`:
  177. Install the package at `https://gist.github.com/gistID` by attempting to
  178. clone it using `git`. The GitHub username associated with the gist is
  179. optional and will not be saved in `package.json`.
  180. As with regular git dependencies, `dependencies` and `devDependencies` will
  181. be installed if the package has a `prepare` script, before the package is
  182. done installing.
  183. Example:
  184. npm install gist:101a11beef
  185. * `npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]`:
  186. Install the package at `https://bitbucket.org/bitbucketname/bitbucketrepo`
  187. by attempting to clone it using `git`.
  188. If `#<commit-ish>` is provided, it will be used to clone exactly that
  189. commit. If the commit-ish has the format `#semver:<semver>`, `<semver>` can
  190. be any valid semver range or exact version, and npm will look for any tags
  191. or refs matching that range in the remote repository, much as it would for a
  192. registry dependency. If neither `#<commit-ish>` or `#semver:<semver>` is
  193. specified, then `master` is used.
  194. As with regular git dependencies, `dependencies` and `devDependencies` will
  195. be installed if the package has a `prepare` script, before the package is
  196. done installing.
  197. Example:
  198. npm install bitbucket:mybitbucketuser/myproject
  199. * `npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]`:
  200. Install the package at `https://gitlab.com/gitlabname/gitlabrepo`
  201. by attempting to clone it using `git`.
  202. If `#<commit-ish>` is provided, it will be used to clone exactly that
  203. commit. If the commit-ish has the format `#semver:<semver>`, `<semver>` can
  204. be any valid semver range or exact version, and npm will look for any tags
  205. or refs matching that range in the remote repository, much as it would for a
  206. registry dependency. If neither `#<commit-ish>` or `#semver:<semver>` is
  207. specified, then `master` is used.
  208. As with regular git dependencies, `dependencies` and `devDependencies` will
  209. be installed if the package has a `prepare` script, before the package is
  210. done installing.
  211. Example:
  212. npm install gitlab:mygitlabuser/myproject
  213. npm install gitlab:myusr/myproj#semver:^5.0
  214. You may combine multiple arguments, and even multiple types of arguments.
  215. For example:
  216. npm install sax@">=0.1.0 <0.2.0" bench supervisor
  217. The `--tag` argument will apply to all of the specified install targets. If a
  218. tag with the given name exists, the tagged version is preferred over newer
  219. versions.
  220. The `--dry-run` argument will report in the usual way what the install would
  221. have done without actually installing anything.
  222. The `--package-lock-only` argument will only update the `package-lock.json`,
  223. instead of checking `node_modules` and downloading dependencies.
  224. The `-f` or `--force` argument will force npm to fetch remote resources even if a
  225. local copy exists on disk.
  226. npm install sax --force
  227. The `-g` or `--global` argument will cause npm to install the package globally
  228. rather than locally. See `npm-folders(5)`.
  229. The `--global-style` argument will cause npm to install the package into
  230. your local `node_modules` folder with the same layout it uses with the
  231. global `node_modules` folder. Only your direct dependencies will show in
  232. `node_modules` and everything they depend on will be flattened in their
  233. `node_modules` folders. This obviously will eliminate some deduping.
  234. The `--ignore-scripts` argument will cause npm to not execute any
  235. scripts defined in the package.json. See `npm-scripts(7)`.
  236. The `--legacy-bundling` argument will cause npm to install the package such
  237. that versions of npm prior to 1.4, such as the one included with node 0.8,
  238. can install the package. This eliminates all automatic deduping.
  239. The `--link` argument will cause npm to link global installs into the
  240. local space in some cases.
  241. The `--no-bin-links` argument will prevent npm from creating symlinks for
  242. any binaries the package might contain.
  243. The `--no-optional` argument will prevent optional dependencies from
  244. being installed.
  245. The `--no-shrinkwrap` argument, which will ignore an available
  246. package lock or shrinkwrap file and use the package.json instead.
  247. The `--no-package-lock` argument will prevent npm from creating a
  248. `package-lock.json` file. When running with package-lock's disabled npm
  249. will not automatically prune your node modules when installing.
  250. The `--nodedir=/path/to/node/source` argument will allow npm to find the
  251. node source code so that npm can compile native modules.
  252. The `--only={prod[uction]|dev[elopment]}` argument will cause either only
  253. `devDependencies` or only non-`devDependencies` to be installed regardless of the `NODE_ENV`.
  254. The `--no-audit` argument can be used to disable sending of audit reports to
  255. the configured registries. See `npm-audit(1)` for details on what is sent.
  256. See `npm-config(7)`. Many of the configuration params have some
  257. effect on installation, since that's most of what npm does.
  258. ## ALGORITHM
  259. To install a package, npm uses the following algorithm:
  260. load the existing node_modules tree from disk
  261. clone the tree
  262. fetch the package.json and assorted metadata and add it to the clone
  263. walk the clone and add any missing dependencies
  264. dependencies will be added as close to the top as is possible
  265. without breaking any other modules
  266. compare the original tree with the cloned tree and make a list of
  267. actions to take to convert one to the other
  268. execute all of the actions, deepest first
  269. kinds of actions are install, update, remove and move
  270. For this `package{dep}` structure: `A{B,C}, B{C}, C{D}`,
  271. this algorithm produces:
  272. A
  273. +-- B
  274. +-- C
  275. +-- D
  276. That is, the dependency from B to C is satisfied by the fact that A
  277. already caused C to be installed at a higher level. D is still installed
  278. at the top level because nothing conflicts with it.
  279. For `A{B,C}, B{C,D@1}, C{D@2}`, this algorithm produces:
  280. A
  281. +-- B
  282. +-- C
  283. `-- D@2
  284. +-- D@1
  285. Because B's D@1 will be installed in the top level, C now has to install D@2
  286. privately for itself. This algorithm is deterministic, but different trees may
  287. be produced if two dependencies are requested for installation in a different
  288. order.
  289. See npm-folders(5) for a more detailed description of the specific
  290. folder structures that npm creates.
  291. ### Limitations of npm's Install Algorithm
  292. npm will refuse to install any package with an identical name to the
  293. current package. This can be overridden with the `--force` flag, but in
  294. most cases can simply be addressed by changing the local package name.
  295. There are some very rare and pathological edge-cases where a cycle can
  296. cause npm to try to install a never-ending tree of packages. Here is
  297. the simplest case:
  298. A -> B -> A' -> B' -> A -> B -> A' -> B' -> A -> ...
  299. where `A` is some version of a package, and `A'` is a different version
  300. of the same package. Because `B` depends on a different version of `A`
  301. than the one that is already in the tree, it must install a separate
  302. copy. The same is true of `A'`, which must install `B'`. Because `B'`
  303. depends on the original version of `A`, which has been overridden, the
  304. cycle falls into infinite regress.
  305. To avoid this situation, npm flat-out refuses to install any
  306. `name@version` that is already present anywhere in the tree of package
  307. folder ancestors. A more correct, but more complex, solution would be
  308. to symlink the existing version into the new location. If this ever
  309. affects a real use-case, it will be investigated.
  310. ## SEE ALSO
  311. * npm-folders(5)
  312. * npm-update(1)
  313. * npm-audit(1)
  314. * npm-link(1)
  315. * npm-rebuild(1)
  316. * npm-scripts(7)
  317. * npm-build(1)
  318. * npm-config(1)
  319. * npm-config(7)
  320. * npmrc(5)
  321. * npm-registry(7)
  322. * npm-dist-tag(1)
  323. * npm-uninstall(1)
  324. * npm-shrinkwrap(1)
  325. * package.json(5)