npm-version.1 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. .TH "NPM\-VERSION" "1" "October 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-version\fR \- Bump a package version
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [\-\-preid=<prerelease\-id>] | from\-git]
  9. \|'npm [\-v | \-\-version]' to print npm version
  10. \|'npm view <pkg> version' to view a package's published version
  11. \|'npm ls' to inspect current package/dependency versions
  12. .fi
  13. .RE
  14. .SS Configuration
  15. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS START \-\->
  16. <!\-\- automatically generated, do not edit manually \-\->
  17. <!\-\- see lib/utils/config/definitions\.js \-\->
  18. .SS \fBallow\-same\-version\fP
  19. .RS 0
  20. .IP \(bu 2
  21. Default: false
  22. .IP \(bu 2
  23. Type: Boolean
  24. .RE
  25. .P
  26. Prevents throwing an error when \fBnpm version\fP is used to set the new version
  27. to the same value as the current version\.
  28. <!\-\- automatically generated, do not edit manually \-\->
  29. <!\-\- see lib/utils/config/definitions\.js \-\->
  30. .SS \fBcommit\-hooks\fP
  31. .RS 0
  32. .IP \(bu 2
  33. Default: true
  34. .IP \(bu 2
  35. Type: Boolean
  36. .RE
  37. .P
  38. Run git commit hooks when using the \fBnpm version\fP command\.
  39. <!\-\- automatically generated, do not edit manually \-\->
  40. <!\-\- see lib/utils/config/definitions\.js \-\->
  41. .SS \fBgit\-tag\-version\fP
  42. .RS 0
  43. .IP \(bu 2
  44. Default: true
  45. .IP \(bu 2
  46. Type: Boolean
  47. .RE
  48. .P
  49. Tag the commit when using the \fBnpm version\fP command\.
  50. <!\-\- automatically generated, do not edit manually \-\->
  51. <!\-\- see lib/utils/config/definitions\.js \-\->
  52. .SS \fBjson\fP
  53. .RS 0
  54. .IP \(bu 2
  55. Default: false
  56. .IP \(bu 2
  57. Type: Boolean
  58. .RE
  59. .P
  60. Whether or not to output JSON data, rather than the normal output\.
  61. .RS 0
  62. .IP \(bu 2
  63. In \fBnpm pkg set\fP it enables parsing set values with JSON\.parse() before
  64. saving them to your \fBpackage\.json\fP\|\.
  65. .RE
  66. .P
  67. Not supported by all npm commands\.
  68. <!\-\- automatically generated, do not edit manually \-\->
  69. <!\-\- see lib/utils/config/definitions\.js \-\->
  70. .SS \fBpreid\fP
  71. .RS 0
  72. .IP \(bu 2
  73. Default: ""
  74. .IP \(bu 2
  75. Type: String
  76. .RE
  77. .P
  78. The "prerelease identifier" to use as a prefix for the "prerelease" part of
  79. a semver\. Like the \fBrc\fP in \fB1\.2\.0\-rc\.8\fP\|\.
  80. <!\-\- automatically generated, do not edit manually \-\->
  81. <!\-\- see lib/utils/config/definitions\.js \-\->
  82. .SS \fBsign\-git\-tag\fP
  83. .RS 0
  84. .IP \(bu 2
  85. Default: false
  86. .IP \(bu 2
  87. Type: Boolean
  88. .RE
  89. .P
  90. If set to true, then the \fBnpm version\fP command will tag the version using
  91. \fB\-s\fP to add a signature\.
  92. .P
  93. Note that git requires you to have set up GPG keys in your git configs for
  94. this to work properly\.
  95. <!\-\- automatically generated, do not edit manually \-\->
  96. <!\-\- see lib/utils/config/definitions\.js \-\->
  97. .SS \fBworkspace\fP
  98. .RS 0
  99. .IP \(bu 2
  100. Default:
  101. .IP \(bu 2
  102. Type: String (can be set multiple times)
  103. .RE
  104. .P
  105. Enable running a command in the context of the configured workspaces of the
  106. current project while filtering by running only the workspaces defined by
  107. this configuration option\.
  108. .P
  109. Valid values for the \fBworkspace\fP config are either:
  110. .RS 0
  111. .IP \(bu 2
  112. Workspace names
  113. .IP \(bu 2
  114. Path to a workspace directory
  115. .IP \(bu 2
  116. Path to a parent workspace directory (will result in selecting all
  117. workspaces within that folder)
  118. .RE
  119. .P
  120. When set for the \fBnpm init\fP command, this may be set to the folder of a
  121. workspace which does not yet exist, to create the folder and set it up as a
  122. brand new workspace within the project\.
  123. .P
  124. This value is not exported to the environment for child processes\.
  125. <!\-\- automatically generated, do not edit manually \-\->
  126. <!\-\- see lib/utils/config/definitions\.js \-\->
  127. .SS \fBworkspaces\fP
  128. .RS 0
  129. .IP \(bu 2
  130. Default: null
  131. .IP \(bu 2
  132. Type: null or Boolean
  133. .RE
  134. .P
  135. Set to true to run the command in the context of \fBall\fR configured
  136. workspaces\.
  137. .P
  138. Explicitly setting this to false will cause commands like \fBinstall\fP to
  139. ignore workspaces altogether\. When not set explicitly:
  140. .RS 0
  141. .IP \(bu 2
  142. Commands that operate on the \fBnode_modules\fP tree (install, update, etc\.)
  143. will link workspaces into the \fBnode_modules\fP folder\. \- Commands that do
  144. other things (test, exec, publish, etc\.) will operate on the root project,
  145. \fIunless\fR one or more workspaces are specified in the \fBworkspace\fP config\.
  146. .RE
  147. .P
  148. This value is not exported to the environment for child processes\.
  149. <!\-\- automatically generated, do not edit manually \-\->
  150. <!\-\- see lib/utils/config/definitions\.js \-\->
  151. .SS \fBinclude\-workspace\-root\fP
  152. .RS 0
  153. .IP \(bu 2
  154. Default: false
  155. .IP \(bu 2
  156. Type: Boolean
  157. .RE
  158. .P
  159. Include the workspace root when workspaces are enabled for a command\.
  160. .P
  161. When false, specifying individual workspaces via the \fBworkspace\fP config, or
  162. all workspaces via the \fBworkspaces\fP flag, will cause npm to operate only on
  163. the specified workspaces, and not on the root project\.
  164. <!\-\- automatically generated, do not edit manually \-\->
  165. <!\-\- see lib/utils/config/definitions\.js \-\->
  166. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS END \-\->
  167. .SS Description
  168. .P
  169. Run this in a package directory to bump the version and write the new data
  170. back to \fBpackage\.json\fP, \fBpackage\-lock\.json\fP, and, if present,
  171. \fBnpm\-shrinkwrap\.json\fP\|\.
  172. .P
  173. The \fBnewversion\fP argument should be a valid semver string, a valid second
  174. argument to semver\.inc \fIhttps://github\.com/npm/node\-semver#functions\fR (one
  175. of \fBpatch\fP, \fBminor\fP, \fBmajor\fP, \fBprepatch\fP, \fBpreminor\fP, \fBpremajor\fP,
  176. \fBprerelease\fP), or \fBfrom\-git\fP\|\. In the second case, the existing version will
  177. be incremented by 1 in the specified field\. \fBfrom\-git\fP will try to read
  178. the latest git tag, and use that as the new npm version\.
  179. .P
  180. If run in a git repo, it will also create a version commit and tag\. This
  181. behavior is controlled by \fBgit\-tag\-version\fP (see below), and can be
  182. disabled on the command line by running \fBnpm \-\-no\-git\-tag\-version version\fP\|\.
  183. It will fail if the working directory is not clean, unless the \fB\-f\fP or
  184. \fB\-\-force\fP flag is set\.
  185. .P
  186. If supplied with \fB\-m\fP or \fB\-\-message\fP config option, npm will use it as a
  187. commit message when creating a version commit\. If the \fBmessage\fP config
  188. contains \fB%s\fP then that will be replaced with the resulting version number\.
  189. For example:
  190. .P
  191. .RS 2
  192. .nf
  193. npm version patch \-m "Upgrade to %s for reasons"
  194. .fi
  195. .RE
  196. .P
  197. If the \fBsign\-git\-tag\fP config is set, then the tag will be signed using the
  198. \fB\-s\fP flag to git\. Note that you must have a default GPG key set up in your
  199. git config for this to work properly\. For example:
  200. .P
  201. .RS 2
  202. .nf
  203. $ npm config set sign\-git\-tag true
  204. $ npm version patch
  205. You need a passphrase to unlock the secret key for
  206. user: "isaacs (http://blog\.izs\.me/) <i@izs\.me>"
  207. 2048\-bit RSA key, ID 6C481CF6, created 2010\-08\-31
  208. Enter passphrase:
  209. .fi
  210. .RE
  211. .P
  212. If \fBpreversion\fP, \fBversion\fP, or \fBpostversion\fP are in the \fBscripts\fP property
  213. of the package\.json, they will be executed as part of running \fBnpm
  214. version\fP\|\.
  215. .P
  216. The exact order of execution is as follows:
  217. .RS 0
  218. .IP 1. 3
  219. Check to make sure the git working directory is clean before we get
  220. started\. Your scripts may add files to the commit in future steps\.
  221. This step is skipped if the \fB\-\-force\fP flag is set\.
  222. .IP 2. 3
  223. Run the \fBpreversion\fP script\. These scripts have access to the old
  224. \fBversion\fP in package\.json\. A typical use would be running your full
  225. test suite before deploying\. Any files you want added to the commit
  226. should be explicitly added using \fBgit add\fP\|\.
  227. .IP 3. 3
  228. Bump \fBversion\fP in \fBpackage\.json\fP as requested (\fBpatch\fP, \fBminor\fP,
  229. \fBmajor\fP, etc)\.
  230. .IP 4. 3
  231. Run the \fBversion\fP script\. These scripts have access to the new \fBversion\fP
  232. in package\.json (so they can incorporate it into file headers in
  233. generated files for example)\. Again, scripts should explicitly add
  234. generated files to the commit using \fBgit add\fP\|\.
  235. .IP 5. 3
  236. Commit and tag\.
  237. .IP 6. 3
  238. Run the \fBpostversion\fP script\. Use it to clean up the file system or
  239. automatically push the commit and/or tag\.
  240. .RE
  241. .P
  242. Take the following example:
  243. .P
  244. .RS 2
  245. .nf
  246. {
  247. "scripts": {
  248. "preversion": "npm test",
  249. "version": "npm run build && git add \-A dist",
  250. "postversion": "git push && git push \-\-tags && rm \-rf build/temp"
  251. }
  252. }
  253. .fi
  254. .RE
  255. .P
  256. This runs all your tests and proceeds only if they pass\. Then runs your
  257. \fBbuild\fP script, and adds everything in the \fBdist\fP directory to the commit\.
  258. After the commit, it pushes the new commit and tag up to the server, and
  259. deletes the \fBbuild/temp\fP directory\.
  260. .SS See Also
  261. .RS 0
  262. .IP \(bu 2
  263. npm help init
  264. .IP \(bu 2
  265. npm help run\-script
  266. .IP \(bu 2
  267. npm help scripts
  268. .IP \(bu 2
  269. npm help package\.json
  270. .IP \(bu 2
  271. npm help config
  272. .RE