Skip to content

Commit

Permalink
feat: removed Disable Prerelease Identifier Base, now using false in …
Browse files Browse the repository at this point in the history
…Prerelease Identifier Base parameter
  • Loading branch information
lsvalina committed Apr 13, 2023
1 parent 0c69881 commit fda7e36
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 91 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,32 +239,29 @@ $ semver 1.2.4-beta.0 -i prerelease

The method `.inc` takes an optional parameter 'identifierBase' string
that will let you let your prerelease number as zero-based or one-based.
If you provide false zero will be omitted.
If you do not specify this parameter, it will default to zero-based.

```javascript
semver.inc('1.2.3', 'prerelease', 'beta', '1')
// '1.2.4-beta.1'
```

```javascript
semver.inc('1.2.3', 'prerelease', 'beta', false)
// '1.2.4-beta'
```

command-line example:

```bash
$ semver 1.2.3 -i prerelease --preid beta -n 1
1.2.4-beta.1
```

#### Disable Prerelease Identifier Base
when this flag is set to true initial prerelease identifier base is disabled.

```javascript
semver.inc('1.2.3', 'prerelease', { disableIdentifierBase: true } , 'beta')
// '1.2.4-beta'
```
command-line example:
```bash
$ semver 1.2.3 -i prerelease --preid beta -noidbase
# 1.2.4-beta
$ semver 1.2.3 -i prerelease --preid beta -n false
1.2.4-beta
```


Expand Down
17 changes: 3 additions & 14 deletions bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ let identifier

let identifierBase

let disableIdentifierBase

const semver = require('../')
const parseOptions = require('../internal/parse-options')

Expand Down Expand Up @@ -79,9 +77,6 @@ const main = () => {
case '-n':
identifierBase = argv.shift()
break
case '--noidbase':
disableIdentifierBase = true
break
case '-c': case '--coerce':
coerce = true
break
Expand All @@ -99,7 +94,7 @@ const main = () => {
}
}

options = parseOptions({ loose, includePrerelease, rtl, disableIdentifierBase })
options = parseOptions({ loose, includePrerelease, rtl })

versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
Expand Down Expand Up @@ -186,15 +181,9 @@ Options:
-n <base>
Prerelease Identifier Base
that will let you let your prerelease number as
zero-based or one-based.If you do not specify
zero-based or one-based. If you provide false
zero will be omitted. If you do not specify
this parameter, it will default to zero-based.
--noidbase
Disable Identifier Base
when this flag is set to true initial prerelease
identifier base is disabled, if another version
is created with same identifier then the prerelease
number is used based on Prerelease Identifier Base
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down
22 changes: 10 additions & 12 deletions classes/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ class SemVer {
// This probably shouldn't be used publicly.
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
case 'pre': {
const base = Number(identifierBase) ? 1 : 0
const base = identifierBase === false ||
identifierBase === 'false' ||
Number(identifierBase) ? 1 : 0

if (this.prerelease.length === 0) {
this.prerelease = [base]
} else {
Expand All @@ -266,21 +269,16 @@ class SemVer {
if (identifier) {
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
let prerelease = [identifier, base]
if (identifierBase === false || identifierBase === 'false') {
prerelease = [identifier]
}
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
if (isNaN(this.prerelease[1])) {
if (this.options.disableIdentifierBase) {
this.prerelease = [identifier]
} else {
this.prerelease = [identifier, base]
}
this.prerelease = prerelease
}
} else {
this.prerelease = [identifier, base]
if (this.options.disableIdentifierBase) {
this.prerelease = [identifier]
} else {
this.prerelease = [identifier, base]
}
this.prerelease = prerelease
}
}
break
Expand Down
42 changes: 9 additions & 33 deletions tap-snapshots/test/bin/semver.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,9 @@ Object {
-n <base>
Prerelease Identifier Base
that will let you let your prerelease number as
zero-based or one-based.If you do not specify
zero-based or one-based. If you provide false
zero will be omitted. If you do not specify
this parameter, it will default to zero-based.
--noidbase
Disable Identifier Base
when this flag is set to true initial prerelease
identifier base is disabled, if another version
is created with same identifier then the prerelease
number is used based on Prerelease Identifier Base
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down Expand Up @@ -165,15 +159,9 @@ Object {
-n <base>
Prerelease Identifier Base
that will let you let your prerelease number as
zero-based or one-based.If you do not specify
zero-based or one-based. If you provide false
zero will be omitted. If you do not specify
this parameter, it will default to zero-based.
--noidbase
Disable Identifier Base
when this flag is set to true initial prerelease
identifier base is disabled, if another version
is created with same identifier then the prerelease
number is used based on Prerelease Identifier Base
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down Expand Up @@ -234,15 +222,9 @@ Object {
-n <base>
Prerelease Identifier Base
that will let you let your prerelease number as
zero-based or one-based.If you do not specify
zero-based or one-based. If you provide false
zero will be omitted. If you do not specify
this parameter, it will default to zero-based.
--noidbase
Disable Identifier Base
when this flag is set to true initial prerelease
identifier base is disabled, if another version
is created with same identifier then the prerelease
number is used based on Prerelease Identifier Base
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down Expand Up @@ -303,15 +285,9 @@ Object {
-n <base>
Prerelease Identifier Base
that will let you let your prerelease number as
zero-based or one-based.If you do not specify
zero-based or one-based. If you provide false
zero will be omitted. If you do not specify
this parameter, it will default to zero-based.
--noidbase
Disable Identifier Base
when this flag is set to true initial prerelease
identifier base is disabled, if another version
is created with same identifier then the prerelease
number is used based on Prerelease Identifier Base
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down Expand Up @@ -362,7 +338,7 @@ Object {
}
`

exports[`test/bin/semver.js TAP inc tests > -i premajor 1.0.0 --preid=beta --noidbase 1`] = `
exports[`test/bin/semver.js TAP inc tests > -i premajor 1.0.0 --preid=beta -n false 1`] = `
Object {
"code": 0,
"err": "",
Expand Down
2 changes: 1 addition & 1 deletion test/bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ t.test('inc tests', t => Promise.all([
['-i', 'major', '1.0.0'],
['-i', 'major', '1.0.0', '1.0.1'],
['-i', 'premajor', '1.0.0', '--preid=beta', '-n', '1'],
['-i', 'premajor', '1.0.0', '--preid=beta', '--noidbase'],
['-i', 'premajor', '1.0.0', '--preid=beta', '-n', 'false'],
['-i', '1.2.3'],
].map(args => t.resolveMatchSnapshot(run(args), args.join(' ')))))

Expand Down
30 changes: 14 additions & 16 deletions test/fixtures/increments.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,18 @@ module.exports = [
['1.2.0', 'preminor', '1.3.0-dev.1', false, 'dev', '1'],
['1.2.3-1', 'preminor', '1.3.0-dev.0', false, 'dev'],

// disableIdentifierBase
['1.2.0-1', 'prerelease', '1.2.0-alpha', { disableIdentifierBase: true }, 'alpha', '0'],
['1.2.1', 'prerelease', '1.2.2-alpha', { disableIdentifierBase: true }, 'alpha', '0'],
['1.2.2', 'prerelease', '1.2.3-alpha', { disableIdentifierBase: true }, 'alpha', '1'],
['1.2.0', 'prepatch', '1.2.1-dev', { disableIdentifierBase: true }, 'dev', '1'],
['1.2.0-1', 'prepatch', '1.2.1-dev', { disableIdentifierBase: true }, 'dev', '1'],
['1.2.0', 'premajor', '2.0.0-dev', { disableIdentifierBase: true }, 'dev', '0'],
['1.2.3-1', 'premajor', '2.0.0-dev', { disableIdentifierBase: true }, 'dev', '0'],
['1.2.3-dev.bar', 'prerelease', '1.2.3-dev', { disableIdentifierBase: true }, 'dev', '0'],
['1.2.0', 'preminor', '1.3.0-dev', { disableIdentifierBase: true }, 'dev', '1'],
['1.2.3-1', 'preminor', '1.3.0-dev', { disableIdentifierBase: true }, 'dev'],
['1.2.3-dev', 'prerelease', '1.2.3-dev.0', { disableIdentifierBase: true }, 'dev', '0'],
['1.2.3-dev', 'prerelease', '1.2.3-dev.1', { disableIdentifierBase: true }, 'dev', '1'],
['1.2.0-dev', 'premajor', '2.0.0-dev', { disableIdentifierBase: true }, 'dev', '0'],
['1.2.0-dev', 'preminor', '1.3.0-beta', { disableIdentifierBase: true }, 'beta', '1'],
['1.2.0-dev', 'prepatch', '1.2.1-dev', { disableIdentifierBase: true }, 'dev', '1'],
['1.2.0-1', 'prerelease', '1.2.0-alpha', false, 'alpha', false],
['1.2.1', 'prerelease', '1.2.2-alpha', false, 'alpha', false],
['1.2.2', 'prerelease', '1.2.3-alpha', false, 'alpha', false],
['1.2.0', 'prepatch', '1.2.1-dev', false, 'dev', false],
['1.2.0-1', 'prepatch', '1.2.1-dev', false, 'dev', false],
['1.2.0', 'premajor', '2.0.0-dev', false, 'dev', false],
['1.2.3-1', 'premajor', '2.0.0-dev', false, 'dev', false],
['1.2.3-dev.bar', 'prerelease', '1.2.3-dev', false, 'dev', false],
['1.2.0', 'preminor', '1.3.0-dev', false, 'dev', false],
['1.2.3-1', 'preminor', '1.3.0-dev', false, 'dev', false],
['1.2.3-dev', 'prerelease', '1.2.3-dev.1', false, 'dev', false],
['1.2.0-dev', 'premajor', '2.0.0-dev', false, 'dev', false],
['1.2.0-dev', 'preminor', '1.3.0-beta', false, 'beta', false],
['1.2.0-dev', 'prepatch', '1.2.1-dev', false, 'dev', false],
]
8 changes: 4 additions & 4 deletions test/internal/parse-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ t.test('any object passed is returned', t => {
loose: true,
includePrerelease: true,
})
t.strictSame(parseOptions({ disableIdentifierBase: true }), {
disableIdentifierBase: true,
t.strictSame(parseOptions({ initialIdentifierBase: true }), {
initialIdentifierBase: true,
})
t.strictSame(parseOptions({ rtl: true, includePrerelease: true, disableIdentifierBase: true }), {
t.strictSame(parseOptions({ rtl: true, includePrerelease: true, initialIdentifierBase: true }), {
rtl: true,
includePrerelease: true,
disableIdentifierBase: true,
initialIdentifierBase: true,
})
t.end()
})

0 comments on commit fda7e36

Please sign in to comment.