Skip to content

Commit

Permalink
Treat pre-release as minor to their unsuffixed version (#22)
Browse files Browse the repository at this point in the history
* fix: don't bump semantic level 2 tag for a 3-level increment with a modifier tag

* fix: don't bump semantic level 2 tag for a 2-level increment with a modifier tag

* chore: test 'rc' is a modifier tag type

* chore: add tests for pre-release level 3 modifiers with semver level 2 tags fixes

* Add 'prepare' script to package.json

* Update package-lock.json

* chore: add build outputs
  • Loading branch information
imgrant authored May 16, 2024
1 parent 564b8f9 commit 9877f8d
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 18 deletions.
8 changes: 6 additions & 2 deletions dist/node/cjs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/cjs/index.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions dist/node/es/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/es/index.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions dist/node/lts/cjs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/lts/cjs/index.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions dist/node/lts/es/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/lts/es/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"type": "module",
"scripts": {
"test": "for i in tests/*.js; do node \"$i\"; done",
"build": "rollup --config rollup.config.js"
"build": "rollup --config rollup.config.js",
"prepare": "npm run build"
},
"exports": {
".": {
Expand Down
8 changes: 6 additions & 2 deletions src/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default class Version {
}
else if (SemanticVersion.tags.indexOf(l2) !== -1) {
if (this.isCalendarLeading && this.datever.hasChanged) this.semanticver.reset()
else this.semanticver.inc(l2)
else {
if (!this.versionStringHasModifier) this.semanticver.inc(l2)
}
}
else {
throw new Error(`The second tag of the level should be either modifier or semantic tag. You specified "${l2}" as the second tag and "${l}" as the first tag.`)
Expand All @@ -74,7 +76,9 @@ export default class Version {

if (SemanticVersion.tags.indexOf(l2) !== -1) {
if (this.isCalendarLeading && this.datever.hasChanged) this.semanticver.reset()
else this.semanticver.inc(l2)
else {
if (!this.versionStringHasModifier) this.semanticver.inc(l2)
}
}

if (ModifierVersion.tags.includes(l3) && !ModifierVersion.tags.includes(l2) && !ModifierVersion.tags.includes(l)) {
Expand Down
11 changes: 10 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ assert.strictEqual(calver.getTagType('major'), 'semantic')
assert.strictEqual(calver.getTagType('patch'), 'semantic')
assert.strictEqual(calver.getTagType('dev'), 'modifier')
assert.strictEqual(calver.getTagType('alpha'), 'modifier')
assert.strictEqual(calver.getTagType('rc'), 'modifier')

assert.strictEqual(calver.inc('major.minor.patch', '', 'major'), '1.0.0')
assert.strictEqual(calver.inc('yyyy.mm', '', 'calendar'), '2021.1')
Expand Down Expand Up @@ -77,4 +78,12 @@ calver.useLocalTime = true
assert.strictEqual(calver.inc('yyyy.mm.dd.minor.patch', '', 'calendar'), '2021.1.20.0.0')

assert.strictEqual(calver.inc('yyyy.mm.minor', '2020.12.2', 'calendar.minor.rc'), '2021.1.0-rc.0')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2020.12.2', 'calendar.rc'), '2021.1.0-rc.0')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2020.12.2', 'calendar.rc'), '2021.1.0-rc.0')

assert.strictEqual(calver.inc('yyyy.mm.minor', '2021.1.0', 'calendar.minor.rc'), '2021.1.1-rc.0')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2021.1.1-rc.0', 'calendar.minor.rc'), '2021.1.1-rc.1')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2021.1.1-rc.1', 'calendar.minor.rc'), '2021.1.1-rc.2')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2021.1.1-rc.2', 'calendar.minor'), '2021.1.1')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2021.1.1-rc.2', 'calendar.minor.dev'), '2021.1.1-dev.0')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2020.12.5', 'calendar.minor.rc'), '2021.1.0-rc.0')
assert.strictEqual(calver.inc('yyyy.mm.minor', '2020.12.5-rc.6', 'calendar.minor.rc'), '2021.1.0-rc.7')

0 comments on commit 9877f8d

Please sign in to comment.