1NPM-VERSION(1)                                                  NPM-VERSION(1)
2
3
4

NAME

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