npm-version.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <html><head>
  2. <title>npm-version</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="npm-version">npm-version</h1>
  125. <span class="description">Bump a package version</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#allow-same-version"><code>allow-same-version</code></a></li><li><a href="#commit-hooks"><code>commit-hooks</code></a></li><li><a href="#git-tag-version"><code>git-tag-version</code></a></li><li><a href="#json"><code>json</code></a></li><li><a href="#preid"><code>preid</code></a></li><li><a href="#sign-git-tag"><code>sign-git-tag</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li></ul><li><a href="#description">Description</a></li><li><a href="#see-also">See Also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="synopsis">Synopsis</h3>
  132. <pre lang="bash"><code>npm version [&lt;newversion&gt; | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=&lt;prerelease-id&gt;] | from-git]
  133. 'npm [-v | --version]' to print npm version
  134. 'npm view &lt;pkg&gt; version' to view a package's published version
  135. 'npm ls' to inspect current package/dependency versions
  136. </code></pre>
  137. <h3 id="configuration">Configuration</h3>
  138. <!-- raw HTML omitted -->
  139. <!-- raw HTML omitted -->
  140. <!-- raw HTML omitted -->
  141. <h4 id="allow-same-version"><code>allow-same-version</code></h4>
  142. <ul>
  143. <li>Default: false</li>
  144. <li>Type: Boolean</li>
  145. </ul>
  146. <p>Prevents throwing an error when <code>npm version</code> is used to set the new version
  147. to the same value as the current version.</p>
  148. <!-- raw HTML omitted -->
  149. <!-- raw HTML omitted -->
  150. <h4 id="commit-hooks"><code>commit-hooks</code></h4>
  151. <ul>
  152. <li>Default: true</li>
  153. <li>Type: Boolean</li>
  154. </ul>
  155. <p>Run git commit hooks when using the <code>npm version</code> command.</p>
  156. <!-- raw HTML omitted -->
  157. <!-- raw HTML omitted -->
  158. <h4 id="git-tag-version"><code>git-tag-version</code></h4>
  159. <ul>
  160. <li>Default: true</li>
  161. <li>Type: Boolean</li>
  162. </ul>
  163. <p>Tag the commit when using the <code>npm version</code> command.</p>
  164. <!-- raw HTML omitted -->
  165. <!-- raw HTML omitted -->
  166. <h4 id="json"><code>json</code></h4>
  167. <ul>
  168. <li>Default: false</li>
  169. <li>Type: Boolean</li>
  170. </ul>
  171. <p>Whether or not to output JSON data, rather than the normal output.</p>
  172. <ul>
  173. <li>In <code>npm pkg set</code> it enables parsing set values with JSON.parse() before
  174. saving them to your <code>package.json</code>.</li>
  175. </ul>
  176. <p>Not supported by all npm commands.</p>
  177. <!-- raw HTML omitted -->
  178. <!-- raw HTML omitted -->
  179. <h4 id="preid"><code>preid</code></h4>
  180. <ul>
  181. <li>Default: “”</li>
  182. <li>Type: String</li>
  183. </ul>
  184. <p>The “prerelease identifier” to use as a prefix for the “prerelease” part of
  185. a semver. Like the <code>rc</code> in <code>1.2.0-rc.8</code>.</p>
  186. <!-- raw HTML omitted -->
  187. <!-- raw HTML omitted -->
  188. <h4 id="sign-git-tag"><code>sign-git-tag</code></h4>
  189. <ul>
  190. <li>Default: false</li>
  191. <li>Type: Boolean</li>
  192. </ul>
  193. <p>If set to true, then the <code>npm version</code> command will tag the version using
  194. <code>-s</code> to add a signature.</p>
  195. <p>Note that git requires you to have set up GPG keys in your git configs for
  196. this to work properly.</p>
  197. <!-- raw HTML omitted -->
  198. <!-- raw HTML omitted -->
  199. <h4 id="workspace"><code>workspace</code></h4>
  200. <ul>
  201. <li>Default:</li>
  202. <li>Type: String (can be set multiple times)</li>
  203. </ul>
  204. <p>Enable running a command in the context of the configured workspaces of the
  205. current project while filtering by running only the workspaces defined by
  206. this configuration option.</p>
  207. <p>Valid values for the <code>workspace</code> config are either:</p>
  208. <ul>
  209. <li>Workspace names</li>
  210. <li>Path to a workspace directory</li>
  211. <li>Path to a parent workspace directory (will result in selecting all
  212. workspaces within that folder)</li>
  213. </ul>
  214. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  215. workspace which does not yet exist, to create the folder and set it up as a
  216. brand new workspace within the project.</p>
  217. <p>This value is not exported to the environment for child processes.</p>
  218. <!-- raw HTML omitted -->
  219. <!-- raw HTML omitted -->
  220. <h4 id="workspaces"><code>workspaces</code></h4>
  221. <ul>
  222. <li>Default: null</li>
  223. <li>Type: null or Boolean</li>
  224. </ul>
  225. <p>Set to true to run the command in the context of <strong>all</strong> configured
  226. workspaces.</p>
  227. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  228. ignore workspaces altogether. When not set explicitly:</p>
  229. <ul>
  230. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  231. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  232. other things (test, exec, publish, etc.) will operate on the root project,
  233. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  234. </ul>
  235. <p>This value is not exported to the environment for child processes.</p>
  236. <!-- raw HTML omitted -->
  237. <!-- raw HTML omitted -->
  238. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  239. <ul>
  240. <li>Default: false</li>
  241. <li>Type: Boolean</li>
  242. </ul>
  243. <p>Include the workspace root when workspaces are enabled for a command.</p>
  244. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  245. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  246. the specified workspaces, and not on the root project.</p>
  247. <!-- raw HTML omitted -->
  248. <!-- raw HTML omitted -->
  249. <!-- raw HTML omitted -->
  250. <h3 id="description">Description</h3>
  251. <p>Run this in a package directory to bump the version and write the new data
  252. back to <code>package.json</code>, <code>package-lock.json</code>, and, if present,
  253. <code>npm-shrinkwrap.json</code>.</p>
  254. <p>The <code>newversion</code> argument should be a valid semver string, a valid second
  255. argument to <a href="https://github.com/npm/node-semver#functions">semver.inc</a> (one
  256. of <code>patch</code>, <code>minor</code>, <code>major</code>, <code>prepatch</code>, <code>preminor</code>, <code>premajor</code>,
  257. <code>prerelease</code>), or <code>from-git</code>. In the second case, the existing version will
  258. be incremented by 1 in the specified field. <code>from-git</code> will try to read
  259. the latest git tag, and use that as the new npm version.</p>
  260. <p>If run in a git repo, it will also create a version commit and tag. This
  261. behavior is controlled by <code>git-tag-version</code> (see below), and can be
  262. disabled on the command line by running <code>npm --no-git-tag-version version</code>.
  263. It will fail if the working directory is not clean, unless the <code>-f</code> or
  264. <code>--force</code> flag is set.</p>
  265. <p>If supplied with <code>-m</code> or <code>--message</code> config option, npm will use it as a
  266. commit message when creating a version commit. If the <code>message</code> config
  267. contains <code>%s</code> then that will be replaced with the resulting version number.
  268. For example:</p>
  269. <pre lang="bash"><code>npm version patch -m "Upgrade to %s for reasons"
  270. </code></pre>
  271. <p>If the <code>sign-git-tag</code> config is set, then the tag will be signed using the
  272. <code>-s</code> flag to git. Note that you must have a default GPG key set up in your
  273. git config for this to work properly. For example:</p>
  274. <pre lang="bash"><code>$ npm config set sign-git-tag true
  275. $ npm version patch
  276. You need a passphrase to unlock the secret key for
  277. user: "isaacs (http://blog.izs.me/) &lt;i@izs.me&gt;"
  278. 2048-bit RSA key, ID 6C481CF6, created 2010-08-31
  279. Enter passphrase:
  280. </code></pre>
  281. <p>If <code>preversion</code>, <code>version</code>, or <code>postversion</code> are in the <code>scripts</code> property
  282. of the package.json, they will be executed as part of running <code>npm version</code>.</p>
  283. <p>The exact order of execution is as follows:</p>
  284. <ol>
  285. <li>Check to make sure the git working directory is clean before we get
  286. started. Your scripts may add files to the commit in future steps.
  287. This step is skipped if the <code>--force</code> flag is set.</li>
  288. <li>Run the <code>preversion</code> script. These scripts have access to the old
  289. <code>version</code> in package.json. A typical use would be running your full
  290. test suite before deploying. Any files you want added to the commit
  291. should be explicitly added using <code>git add</code>.</li>
  292. <li>Bump <code>version</code> in <code>package.json</code> as requested (<code>patch</code>, <code>minor</code>,
  293. <code>major</code>, etc).</li>
  294. <li>Run the <code>version</code> script. These scripts have access to the new <code>version</code>
  295. in package.json (so they can incorporate it into file headers in
  296. generated files for example). Again, scripts should explicitly add
  297. generated files to the commit using <code>git add</code>.</li>
  298. <li>Commit and tag.</li>
  299. <li>Run the <code>postversion</code> script. Use it to clean up the file system or
  300. automatically push the commit and/or tag.</li>
  301. </ol>
  302. <p>Take the following example:</p>
  303. <pre lang="json"><code>{
  304. "scripts": {
  305. "preversion": "npm test",
  306. "version": "npm run build &amp;&amp; git add -A dist",
  307. "postversion": "git push &amp;&amp; git push --tags &amp;&amp; rm -rf build/temp"
  308. }
  309. }
  310. </code></pre>
  311. <p>This runs all your tests and proceeds only if they pass. Then runs your
  312. <code>build</code> script, and adds everything in the <code>dist</code> directory to the commit.
  313. After the commit, it pushes the new commit and tag up to the server, and
  314. deletes the <code>build/temp</code> directory.</p>
  315. <h3 id="see-also">See Also</h3>
  316. <ul>
  317. <li><a href="../commands/npm-init.html">npm init</a></li>
  318. <li><a href="../commands/npm-run-script.html">npm run-script</a></li>
  319. <li><a href="../using-npm/scripts.html">npm scripts</a></li>
  320. <li><a href="../configuring-npm/package-json.html">package.json</a></li>
  321. <li><a href="../using-npm/config.html">config</a></li>
  322. </ul>
  323. </div>
  324. <footer id="edit">
  325. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-version.md">
  326. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  327. <path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
  328. </svg>
  329. Edit this page on GitHub
  330. </a>
  331. </footer>
  332. </section>
  333. </body></html>