Skip to content

Commit cbca3e5

Browse files
committed
fix: prerelease identifier
1 parent 2677f2a commit cbca3e5

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

internal/re.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
7676

7777
// ## Pre-release Version Identifier
7878
// A numeric identifier, or a non-numeric identifier.
79+
// Non-numberic identifiers include numberic identifiers but can be longer.
80+
// Therefore non-numberic identifiers must go first.
7981

80-
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
81-
}|${src[t.NONNUMERICIDENTIFIER]})`)
82+
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
83+
}|${src[t.NUMERICIDENTIFIER]})`)
8284

83-
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
84-
}|${src[t.NONNUMERICIDENTIFIER]})`)
85+
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
86+
}|${src[t.NUMERICIDENTIFIERLOOSE]})`)
8587

8688
// ## Pre-release Version
8789
// Hyphen, followed by one or more dot-separated pre-release version

test/classes/semver.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@ const SemVer = require('../../classes/semver')
33
const increments = require('../fixtures/increments.js')
44
const comparisons = require('../fixtures/comparisons.js')
55
const equality = require('../fixtures/equality.js')
6-
const invalidVersions = require('../fixtures/invalid-versions')
6+
const invalidVersions = require('../fixtures/invalid-versions.js')
7+
const validVersions = require('../fixtures/valid-versions.js')
8+
9+
test('valid versions', t => {
10+
t.plan(validVersions.length)
11+
validVersions.forEach(([v, major, minor, patch, prerelease, build]) => t.test(v, t => {
12+
const s = new SemVer(v)
13+
t.strictSame(s.major, major)
14+
t.strictSame(s.minor, minor)
15+
t.strictSame(s.patch, patch)
16+
t.strictSame(s.prerelease, prerelease)
17+
t.strictSame(s.build, build)
18+
t.strictSame(s.raw, v)
19+
t.end()
20+
}))
21+
})
722

823
test('comparisons', t => {
924
t.plan(comparisons.length)

test/fixtures/valid-versions.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// [version, major, minor, patch, prerelease[], build[]]
2+
module.exports = [
3+
['1.0.0', 1, 0, 0, [], []],
4+
['2.1.0', 2, 1, 0, [], []],
5+
['3.2.1', 3, 2, 1, [], []],
6+
['v1.2.3', 1, 2, 3, [], []],
7+
8+
// prerelease
9+
['1.2.3-0', 1, 2, 3, [0], []],
10+
['1.2.3-123', 1, 2, 3, [123], []],
11+
['1.2.3-1.2.3', 1, 2, 3, [1, 2, 3], []],
12+
['1.2.3-1a', 1, 2, 3, ['1a'], []],
13+
['1.2.3-a1', 1, 2, 3, ['a1'], []],
14+
['1.2.3-alpha', 1, 2, 3, ['alpha'], []],
15+
['1.2.3-alpha.1', 1, 2, 3, ['alpha', 1], []],
16+
['1.2.3-alpha-1', 1, 2, 3, ['alpha-1'], []],
17+
['1.2.3-alpha-.-beta', 1, 2, 3, ['alpha-', '-beta'], []],
18+
19+
// build
20+
['1.2.3+456', 1, 2, 3, [], ['456']],
21+
['1.2.3+build', 1, 2, 3, [], ['build']],
22+
['1.2.3+new-build', 1, 2, 3, [], ['new-build']],
23+
['1.2.3+build.1', 1, 2, 3, [], ['build', '1']],
24+
['1.2.3+build.1a', 1, 2, 3, [], ['build', '1a']],
25+
['1.2.3+build.a1', 1, 2, 3, [], ['build', 'a1']],
26+
['1.2.3+build.alpha', 1, 2, 3, [], ['build', 'alpha']],
27+
['1.2.3+build.alpha.beta', 1, 2, 3, [], ['build', 'alpha', 'beta']],
28+
29+
// mixed
30+
['1.2.3-alpha+build', 1, 2, 3, ['alpha'], ['build']],
31+
]

test/functions/coerce.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ test('coerce tests', (t) => {
118118
['1.2.3.4-rc.5', '1.2.3', { includePrerelease: true }],
119119
['1.2.3.4+rev.6', '1.2.3', { includePrerelease: true }],
120120

121+
['1.0.0-1a', '1.0.0-1a', { includePrerelease: true }],
122+
['1.0.0-alpha.12ab', '1.0.0-alpha.12ab', { includePrerelease: true }],
123+
['1.0.0-alpha.1234.23cd', '1.0.0-alpha.1234.23cd', { includePrerelease: true }],
124+
['1.0.0-nightly.abc123', '1.0.0-nightly.abc123', { includePrerelease: true }],
125+
['1.0.0-nightly.abcdef', '1.0.0-nightly.abcdef', { includePrerelease: true }],
126+
['1.0.0-nightly.123456', '1.0.0-nightly.123456', { includePrerelease: true }],
127+
121128
['1+rev.6', '1.0.0+rev.6', { includePrerelease: true }],
122129
['1.2+rev.6', '1.2.0+rev.6', { includePrerelease: true }],
123130
['1.2.3+rev.6', '1.2.3+rev.6', { includePrerelease: true }],

0 commit comments

Comments
 (0)