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.

268 lines
9.7 KiB

  1. npm-scripts(7) -- How npm handles the "scripts" field
  2. =====================================================
  3. ## DESCRIPTION
  4. npm supports the "scripts" property of the package.json file, for the
  5. following scripts:
  6. * prepublish:
  7. Run BEFORE the package is packed and published, as well as on local `npm
  8. install` without any arguments. (See below)
  9. * prepare:
  10. Run both BEFORE the package is packed and published, and on local `npm
  11. install` without any arguments (See below). This is run
  12. AFTER `prepublish`, but BEFORE `prepublishOnly`.
  13. * prepublishOnly:
  14. Run BEFORE the package is prepared and packed, ONLY on `npm publish`. (See
  15. below.)
  16. * prepack:
  17. run BEFORE a tarball is packed (on `npm pack`, `npm publish`, and when
  18. installing git dependencies)
  19. * postpack:
  20. Run AFTER the tarball has been generated and moved to its final destination.
  21. * publish, postpublish:
  22. Run AFTER the package is published.
  23. * preinstall:
  24. Run BEFORE the package is installed
  25. * install, postinstall:
  26. Run AFTER the package is installed.
  27. * preuninstall, uninstall:
  28. Run BEFORE the package is uninstalled.
  29. * postuninstall:
  30. Run AFTER the package is uninstalled.
  31. * preversion:
  32. Run BEFORE bumping the package version.
  33. * version:
  34. Run AFTER bumping the package version, but BEFORE commit.
  35. * postversion:
  36. Run AFTER bumping the package version, and AFTER commit.
  37. * pretest, test, posttest:
  38. Run by the `npm test` command.
  39. * prestop, stop, poststop:
  40. Run by the `npm stop` command.
  41. * prestart, start, poststart:
  42. Run by the `npm start` command.
  43. * prerestart, restart, postrestart:
  44. Run by the `npm restart` command. Note: `npm restart` will run the
  45. stop and start scripts if no `restart` script is provided.
  46. * preshrinkwrap, shrinkwrap, postshrinkwrap:
  47. Run by the `npm shrinkwrap` command.
  48. Additionally, arbitrary scripts can be executed by running `npm
  49. run-script <stage>`. *Pre* and *post* commands with matching
  50. names will be run for those as well (e.g. `premyscript`, `myscript`,
  51. `postmyscript`). Scripts from dependencies can be run with `npm explore
  52. <pkg> -- npm run <stage>`.
  53. ## PREPUBLISH AND PREPARE
  54. ### DEPRECATION NOTE
  55. Since `npm@1.1.71`, the npm CLI has run the `prepublish` script for both `npm
  56. publish` and `npm install`, because it's a convenient way to prepare a package
  57. for use (some common use cases are described in the section below). It has
  58. also turned out to be, in practice, [very
  59. confusing](https://github.com/npm/npm/issues/10074). As of `npm@4.0.0`, a new
  60. event has been introduced, `prepare`, that preserves this existing behavior. A
  61. _new_ event, `prepublishOnly` has been added as a transitional strategy to
  62. allow users to avoid the confusing behavior of existing npm versions and only
  63. run on `npm publish` (for instance, running the tests one last time to ensure
  64. they're in good shape).
  65. See <https://github.com/npm/npm/issues/10074> for a much lengthier
  66. justification, with further reading, for this change.
  67. ### USE CASES
  68. If you need to perform operations on your package before it is used, in a way
  69. that is not dependent on the operating system or architecture of the
  70. target system, use a `prepublish` script. This includes
  71. tasks such as:
  72. * Compiling CoffeeScript source code into JavaScript.
  73. * Creating minified versions of JavaScript source code.
  74. * Fetching remote resources that your package will use.
  75. The advantage of doing these things at `prepublish` time is that they can be done once, in a
  76. single place, thus reducing complexity and variability.
  77. Additionally, this means that:
  78. * You can depend on `coffee-script` as a `devDependency`, and thus
  79. your users don't need to have it installed.
  80. * You don't need to include minifiers in your package, reducing
  81. the size for your users.
  82. * You don't need to rely on your users having `curl` or `wget` or
  83. other system tools on the target machines.
  84. ## DEFAULT VALUES
  85. npm will default some script values based on package contents.
  86. * `"start": "node server.js"`:
  87. If there is a `server.js` file in the root of your package, then npm
  88. will default the `start` command to `node server.js`.
  89. * `"install": "node-gyp rebuild"`:
  90. If there is a `binding.gyp` file in the root of your package and you
  91. haven't defined your own `install` or `preinstall` scripts, npm will
  92. default the `install` command to compile using node-gyp.
  93. ## USER
  94. If npm was invoked with root privileges, then it will change the uid
  95. to the user account or uid specified by the `user` config, which
  96. defaults to `nobody`. Set the `unsafe-perm` flag to run scripts with
  97. root privileges.
  98. ## ENVIRONMENT
  99. Package scripts run in an environment where many pieces of information
  100. are made available regarding the setup of npm and the current state of
  101. the process.
  102. ### path
  103. If you depend on modules that define executable scripts, like test
  104. suites, then those executables will be added to the `PATH` for
  105. executing the scripts. So, if your package.json has this:
  106. { "name" : "foo"
  107. , "dependencies" : { "bar" : "0.1.x" }
  108. , "scripts": { "start" : "bar ./test" } }
  109. then you could run `npm start` to execute the `bar` script, which is
  110. exported into the `node_modules/.bin` directory on `npm install`.
  111. ### package.json vars
  112. The package.json fields are tacked onto the `npm_package_` prefix. So,
  113. for instance, if you had `{"name":"foo", "version":"1.2.5"}` in your
  114. package.json file, then your package scripts would have the
  115. `npm_package_name` environment variable set to "foo", and the
  116. `npm_package_version` set to "1.2.5". You can access these variables
  117. in your code with `process.env.npm_package_name` and
  118. `process.env.npm_package_version`, and so on for other fields.
  119. ### configuration
  120. Configuration parameters are put in the environment with the
  121. `npm_config_` prefix. For instance, you can view the effective `root`
  122. config by checking the `npm_config_root` environment variable.
  123. ### Special: package.json "config" object
  124. The package.json "config" keys are overwritten in the environment if
  125. there is a config param of `<name>[@<version>]:<key>`. For example,
  126. if the package.json has this:
  127. { "name" : "foo"
  128. , "config" : { "port" : "8080" }
  129. , "scripts" : { "start" : "node server.js" } }
  130. and the server.js is this:
  131. http.createServer(...).listen(process.env.npm_package_config_port)
  132. then the user could change the behavior by doing:
  133. npm config set foo:port 80
  134. ### current lifecycle event
  135. Lastly, the `npm_lifecycle_event` environment variable is set to
  136. whichever stage of the cycle is being executed. So, you could have a
  137. single script used for different parts of the process which switches
  138. based on what's currently happening.
  139. Objects are flattened following this format, so if you had
  140. `{"scripts":{"install":"foo.js"}}` in your package.json, then you'd
  141. see this in the script:
  142. process.env.npm_package_scripts_install === "foo.js"
  143. ## EXAMPLES
  144. For example, if your package.json contains this:
  145. { "scripts" :
  146. { "install" : "scripts/install.js"
  147. , "postinstall" : "scripts/install.js"
  148. , "uninstall" : "scripts/uninstall.js"
  149. }
  150. }
  151. then `scripts/install.js` will be called for the install
  152. and post-install stages of the lifecycle, and `scripts/uninstall.js`
  153. will be called when the package is uninstalled. Since
  154. `scripts/install.js` is running for two different phases, it would
  155. be wise in this case to look at the `npm_lifecycle_event` environment
  156. variable.
  157. If you want to run a make command, you can do so. This works just
  158. fine:
  159. { "scripts" :
  160. { "preinstall" : "./configure"
  161. , "install" : "make && make install"
  162. , "test" : "make test"
  163. }
  164. }
  165. ## EXITING
  166. Scripts are run by passing the line as a script argument to `sh`.
  167. If the script exits with a code other than 0, then this will abort the
  168. process.
  169. Note that these script files don't have to be nodejs or even
  170. javascript programs. They just have to be some kind of executable
  171. file.
  172. ## HOOK SCRIPTS
  173. If you want to run a specific script at a specific lifecycle event for
  174. ALL packages, then you can use a hook script.
  175. Place an executable file at `node_modules/.hooks/{eventname}`, and
  176. it'll get run for all packages when they are going through that point
  177. in the package lifecycle for any packages installed in that root.
  178. Hook scripts are run exactly the same way as package.json scripts.
  179. That is, they are in a separate child process, with the env described
  180. above.
  181. ## BEST PRACTICES
  182. * Don't exit with a non-zero error code unless you *really* mean it.
  183. Except for uninstall scripts, this will cause the npm action to
  184. fail, and potentially be rolled back. If the failure is minor or
  185. only will prevent some optional features, then it's better to just
  186. print a warning and exit successfully.
  187. * Try not to use scripts to do what npm can do for you. Read through
  188. `package.json(5)` to see all the things that you can specify and enable
  189. by simply describing your package appropriately. In general, this
  190. will lead to a more robust and consistent state.
  191. * Inspect the env to determine where to put things. For instance, if
  192. the `npm_config_binroot` environment variable is set to `/home/user/bin`, then
  193. don't try to install executables into `/usr/local/bin`. The user
  194. probably set it up that way for a reason.
  195. * Don't prefix your script commands with "sudo". If root permissions
  196. are required for some reason, then it'll fail with that error, and
  197. the user will sudo the npm command in question.
  198. * Don't use `install`. Use a `.gyp` file for compilation, and `prepublish`
  199. for anything else. You should almost never have to explicitly set a
  200. preinstall or install script. If you are doing this, please consider if
  201. there is another option. The only valid use of `install` or `preinstall`
  202. scripts is for compilation which must be done on the target architecture.
  203. ## SEE ALSO
  204. * npm-run-script(1)
  205. * package.json(5)
  206. * npm-developers(7)
  207. * npm-install(1)