npm-version.1 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. .TH "NPM\-VERSION" "1" "August 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 Description
  15. .P
  16. Run this in a package directory to bump the version and write the new
  17. data back to \fBpackage\.json\fP, \fBpackage\-lock\.json\fP, and, if present, \fBnpm\-shrinkwrap\.json\fP\|\.
  18. .P
  19. The \fBnewversion\fP argument should be a valid semver string, a
  20. valid second argument to semver\.inc \fIhttps://github\.com/npm/node\-semver#functions\fR (one of \fBpatch\fP, \fBminor\fP, \fBmajor\fP,
  21. \fBprepatch\fP, \fBpreminor\fP, \fBpremajor\fP, \fBprerelease\fP), or \fBfrom\-git\fP\|\. In the second case,
  22. the existing version will be incremented by 1 in the specified field\.
  23. \fBfrom\-git\fP will try to read the latest git tag, and use that as the new npm version\.
  24. .P
  25. If run in a git repo, it will also create a version commit and tag\.
  26. This behavior is controlled by \fBgit\-tag\-version\fP (see below), and can
  27. be disabled on the command line by running \fBnpm \-\-no\-git\-tag\-version version\fP\|\.
  28. It will fail if the working directory is not clean, unless the \fB\-f\fP or
  29. \fB\-\-force\fP flag is set\.
  30. .P
  31. If supplied with \fB\-m\fP or \fB\-\-message\fP config option, npm will
  32. use it as a commit message when creating a version commit\. If the
  33. \fBmessage\fP config contains \fB%s\fP then that will be replaced with the
  34. resulting version number\. For example:
  35. .P
  36. .RS 2
  37. .nf
  38. npm version patch \-m "Upgrade to %s for reasons"
  39. .fi
  40. .RE
  41. .P
  42. If the \fBsign\-git\-tag\fP config is set, then the tag will be signed using
  43. the \fB\-s\fP flag to git\. Note that you must have a default GPG key set up
  44. in your git config for this to work properly\. For example:
  45. .P
  46. .RS 2
  47. .nf
  48. $ npm config set sign\-git\-tag true
  49. $ npm version patch
  50. You need a passphrase to unlock the secret key for
  51. user: "isaacs (http://blog\.izs\.me/) <i@izs\.me>"
  52. 2048\-bit RSA key, ID 6C481CF6, created 2010\-08\-31
  53. Enter passphrase:
  54. .fi
  55. .RE
  56. .P
  57. If \fBpreversion\fP, \fBversion\fP, or \fBpostversion\fP are in the \fBscripts\fP property of
  58. the package\.json, they will be executed as part of running \fBnpm version\fP\|\.
  59. .P
  60. The exact order of execution is as follows:
  61. .RS 0
  62. .IP 1. 3
  63. Check to make sure the git working directory is clean before we get started\.
  64. Your scripts may add files to the commit in future steps\.
  65. This step is skipped if the \fB\-\-force\fP flag is set\.
  66. .IP 2. 3
  67. Run the \fBpreversion\fP script\. These scripts have access to the old \fBversion\fP in package\.json\.
  68. A typical use would be running your full test suite before deploying\.
  69. Any files you want added to the commit should be explicitly added using \fBgit add\fP\|\.
  70. .IP 3. 3
  71. Bump \fBversion\fP in \fBpackage\.json\fP as requested (\fBpatch\fP, \fBminor\fP, \fBmajor\fP, etc)\.
  72. .IP 4. 3
  73. Run the \fBversion\fP script\. These scripts have access to the new \fBversion\fP in package\.json
  74. (so they can incorporate it into file headers in generated files for example)\.
  75. Again, scripts should explicitly add generated files to the commit using \fBgit add\fP\|\.
  76. .IP 5. 3
  77. Commit and tag\.
  78. .IP 6. 3
  79. Run the \fBpostversion\fP script\. Use it to clean up the file system or automatically push
  80. the commit and/or tag\.
  81. .RE
  82. .P
  83. Take the following example:
  84. .P
  85. .RS 2
  86. .nf
  87. "scripts": {
  88. "preversion": "npm test",
  89. "version": "npm run build && git add \-A dist",
  90. "postversion": "git push && git push \-\-tags && rm \-rf build/temp"
  91. }
  92. .fi
  93. .RE
  94. .P
  95. This runs all your tests, and proceeds only if they pass\. Then runs your \fBbuild\fP script, and
  96. adds everything in the \fBdist\fP directory to the commit\. After the commit, it pushes the new commit
  97. and tag up to the server, and deletes the \fBbuild/temp\fP directory\.
  98. .SS Configuration
  99. .SS allow\-same\-version
  100. .RS 0
  101. .IP \(bu 2
  102. Default: false
  103. .IP \(bu 2
  104. Type: Boolean
  105. .RE
  106. .P
  107. Prevents throwing an error when \fBnpm version\fP is used to set the new version
  108. to the same value as the current version\.
  109. .SS git\-tag\-version
  110. .RS 0
  111. .IP \(bu 2
  112. Default: true
  113. .IP \(bu 2
  114. Type: Boolean
  115. .RE
  116. .P
  117. Commit and tag the version change\.
  118. .SS commit\-hooks
  119. .RS 0
  120. .IP \(bu 2
  121. Default: true
  122. .IP \(bu 2
  123. Type: Boolean
  124. .RE
  125. .P
  126. Run git commit hooks when committing the version change\.
  127. .SS sign\-git\-tag
  128. .RS 0
  129. .IP \(bu 2
  130. Default: false
  131. .IP \(bu 2
  132. Type: Boolean
  133. .RE
  134. .P
  135. Pass the \fB\-s\fP flag to git to sign the tag\.
  136. .P
  137. Note that you must have a default GPG key set up in your git config for this to work properly\.
  138. .SS See Also
  139. .RS 0
  140. .IP \(bu 2
  141. npm help init
  142. .IP \(bu 2
  143. npm help run\-script
  144. .IP \(bu 2
  145. npm help scripts
  146. .IP \(bu 2
  147. npm help package\.json
  148. .IP \(bu 2
  149. npm help semver
  150. .IP \(bu 2
  151. npm help config
  152. .RE