Skip to content

Commit 0864b3c

Browse files
authored
feat: add "release" inc type (#753)
Here's the `release` options for `inc`. Includes update to docs and a few tests. Closes #740
1 parent 67e5478 commit 0864b3c

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Options:
100100
-i --increment [<level>]
101101
Increment a version by the specified level. Level can
102102
be one of: major, minor, patch, premajor, preminor,
103-
prepatch, or prerelease. Default level is 'patch'.
103+
prepatch, prerelease, or release. Default level is 'patch'.
104104
Only one version may be specified.
105105
106106
--preid <identifier>
@@ -239,6 +239,13 @@ $ semver 1.2.4-beta.0 -i prerelease
239239
1.2.4-beta.1
240240
```
241241

242+
To get out of the prerelease phase, use the `release` option:
243+
244+
```bash
245+
$ semver 1.2.4-beta.1 -i release
246+
1.2.4
247+
```
248+
242249
#### Prerelease Identifier Base
243250

244251
The method `.inc` takes an optional parameter 'identifierBase' string
@@ -417,17 +424,18 @@ Strict-mode Comparators and Ranges will be strict about the SemVer
417424
strings that they parse.
418425

419426
* `valid(v)`: Return the parsed version, or null if it's not valid.
420-
* `inc(v, release, options, identifier, identifierBase)`:
427+
* `inc(v, releaseType, options, identifier, identifierBase)`:
421428
Return the version incremented by the release
422429
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
423-
`prepatch`, or `prerelease`), or null if it's not valid
430+
`prepatch`, `prerelease`, or `release`), or null if it's not valid
424431
* `premajor` in one call will bump the version up to the next major
425432
version and down to a prerelease of that major version.
426433
`preminor`, and `prepatch` work the same way.
427434
* If called from a non-prerelease version, `prerelease` will work the
428435
same as `prepatch`. It increments the patch version and then makes a
429436
prerelease. If the input version is already a prerelease it simply
430437
increments it.
438+
* `release` will remove any prerelease part of the version.
431439
* `identifier` can be used to prefix `premajor`, `preminor`,
432440
`prepatch`, or `prerelease` version increments. `identifierBase`
433441
is the base to be used for the `prerelease` identifier.

bin/semver.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const main = () => {
6161
switch (argv[0]) {
6262
case 'major': case 'minor': case 'patch': case 'prerelease':
6363
case 'premajor': case 'preminor': case 'prepatch':
64+
case 'release':
6465
inc = argv.shift()
6566
break
6667
default:
@@ -149,7 +150,7 @@ Options:
149150
-i --increment [<level>]
150151
Increment a version by the specified level. Level can
151152
be one of: major, minor, patch, premajor, preminor,
152-
prepatch, or prerelease. Default level is 'patch'.
153+
prepatch, prerelease, or release. Default level is 'patch'.
153154
Only one version may be specified.
154155
155156
--preid <identifier>

classes/semver.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SemVer {
1010

1111
if (version instanceof SemVer) {
1212
if (version.loose === !!options.loose &&
13-
version.includePrerelease === !!options.includePrerelease) {
13+
version.includePrerelease === !!options.includePrerelease) {
1414
return version
1515
} else {
1616
version = version.version
@@ -206,6 +206,12 @@ class SemVer {
206206
}
207207
this.inc('pre', identifier, identifierBase)
208208
break
209+
case 'release':
210+
if (this.prerelease.length === 0) {
211+
throw new Error(`version ${this.raw} is not a prerelease`)
212+
}
213+
this.prerelease.length = 0
214+
break
209215

210216
case 'major':
211217
// If this is a pre-major version, bump up to the same major version.

tap-snapshots/test/bin/semver.js.test.cjs

+13-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Object {
7070
-i --increment [<level>]
7171
Increment a version by the specified level. Level can
7272
be one of: major, minor, patch, premajor, preminor,
73-
prepatch, or prerelease. Default level is 'patch'.
73+
prepatch, prerelease, or release. Default level is 'patch'.
7474
Only one version may be specified.
7575
7676
--preid <identifier>
@@ -131,7 +131,7 @@ Object {
131131
-i --increment [<level>]
132132
Increment a version by the specified level. Level can
133133
be one of: major, minor, patch, premajor, preminor,
134-
prepatch, or prerelease. Default level is 'patch'.
134+
prepatch, prerelease, or release. Default level is 'patch'.
135135
Only one version may be specified.
136136
137137
--preid <identifier>
@@ -192,7 +192,7 @@ Object {
192192
-i --increment [<level>]
193193
Increment a version by the specified level. Level can
194194
be one of: major, minor, patch, premajor, preminor,
195-
prepatch, or prerelease. Default level is 'patch'.
195+
prepatch, prerelease, or release. Default level is 'patch'.
196196
Only one version may be specified.
197197
198198
--preid <identifier>
@@ -253,7 +253,7 @@ Object {
253253
-i --increment [<level>]
254254
Increment a version by the specified level. Level can
255255
be one of: major, minor, patch, premajor, preminor,
256-
prepatch, or prerelease. Default level is 'patch'.
256+
prepatch, prerelease, or release. Default level is 'patch'.
257257
Only one version may be specified.
258258
259259
--preid <identifier>
@@ -348,6 +348,15 @@ Object {
348348
}
349349
`
350350

351+
exports[`test/bin/semver.js TAP inc tests > -i release 1.0.0-pre`] = `
352+
Object {
353+
"code": 0,
354+
"err": "",
355+
"out": "1.0.0\\n",
356+
"signal": null,
357+
}
358+
`
359+
351360
exports[`test/bin/semver.js TAP sorting and filtering > 1.2.3 -v 3.2.1 --version 2.3.4 -rv 1`] = `
352361
Object {
353362
"code": 0,

test/fixtures/increments.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ module.exports = [
4040
['1.2.3-1', 'premajor', '2.0.0-0'],
4141
['1.2.0-1', 'minor', '1.2.0'],
4242
['1.0.0-1', 'major', '1.0.0'],
43+
['1.0.0-1', 'release', '1.0.0'],
44+
['1.2.0-1', 'release', '1.2.0'],
45+
['1.2.3-1', 'release', '1.2.3'],
46+
['1.2.3', 'release', null],
4347

48+
// [version, inc, result, identifierIndex, loose, identifier]
4449
['1.2.3', 'major', '2.0.0', false, 'dev'],
4550
['1.2.3', 'minor', '1.3.0', false, 'dev'],
4651
['1.2.3', 'patch', '1.2.4', false, 'dev'],
@@ -88,7 +93,7 @@ module.exports = [
8893
['1.2.3-1.1', 'prerelease', '1.2.3-1.2', false, '1'],
8994
['1.2.3-1.1', 'prerelease', '1.2.3-2.0', false, '2'],
9095

91-
// [version, inc, result, identifierIndex, loose, identifier]
96+
// [version, inc, result, identifierIndex, loose, identifier, identifierBase]
9297
['1.2.0-1', 'prerelease', '1.2.0-alpha.0', false, 'alpha', '0'],
9398
['1.2.1', 'prerelease', '1.2.2-alpha.0', false, 'alpha', '0'],
9499
['0.2.0', 'prerelease', '0.2.1-alpha.0', false, 'alpha', '0'],

0 commit comments

Comments
 (0)