npm-version.1 8.9 KB

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