1NPM-VERSION(1) NPM-VERSION(1)
2
3
4
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() be‐
49 fore 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
116 the root project, unless one or more workspaces are specified in
117 the 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, npm-
149 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 -f
162 or --force flag is set.
163
164 If supplied with -m or --message config ⟨/using-npm/config#message⟩ op‐
165 tion, npm will use it as a commit message when creating a version com‐
166 mit. If the message config contains %s then that will be replaced with
167 the resulting version number. For example:
168
169 npm version patch -m "Upgrade to %s for reasons"
170
171 If the sign-git-tag config ⟨/using-npm/config#sign-git-tag⟩ is set,
172 then the tag will be signed using the -s flag to git. Note that you
173 must have a default GPG key set up in your git config for this to work
174 properly. For example:
175
176 $ npm config set sign-git-tag true
177 $ npm version patch
178
179 You need a passphrase to unlock the secret key for
180 user: "isaacs (http://blog.izs.me/) <i@izs.me>"
181 2048-bit RSA key, ID 6C481CF6, created 2010-08-31
182
183 Enter passphrase:
184
185 If preversion, version, or postversion are in the scripts property of
186 the package.json, they will be executed as part of running npm version.
187
188 The exact order of execution is as follows:
189
190 1. Check to make sure the git working directory is clean before we get
191 started. Your scripts may add files to the commit in future steps.
192 This step is skipped if the --force flag is set.
193
194 2. Run the preversion script. These scripts have access to the old
195 version in package.json. A typical use would be running your full
196 test suite before deploying. Any files you want added to the commit
197 should be explicitly added using git add.
198
199 3. Bump version in package.json as requested (patch, minor, major,
200 etc).
201
202 4. Run the version script. These scripts have access to the new ver‐
203 sion in package.json (so they can incorporate it into file headers
204 in generated files for example). Again, scripts should explicitly
205 add generated files to the commit using git add.
206
207 5. Commit and tag.
208
209 6. Run the postversion script. Use it to clean up the file system or
210 automatically push the commit and/or tag.
211
212
213 Take the following example:
214
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
223 This runs all your tests and proceeds only if they pass. Then runs your
224 build script, and adds everything in the dist directory to the commit.
225 After the commit, it pushes the new commit and tag up to the server,
226 and deletes the build/temp directory.
227
228 See Also
229 • npm help init
230
231 • npm help run-script
232
233 • npm help scripts
234
235 • package.json ⟨/configuring-npm/package-json⟩
236
237 • npm help config
238
239
240
241 November 2023 NPM-VERSION(1)