From 985a584a7ff57a5d56f66545a79feb168df0aa5e Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 14 Jun 2023 23:03:06 -0700 Subject: [PATCH] fix: preserve build in raw after inc Fixes: #562 --- classes/semver.js | 6 ++++-- test/classes/semver.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/semver.js b/classes/semver.js index 99dbe82d..c811e3f6 100644 --- a/classes/semver.js +++ b/classes/semver.js @@ -291,8 +291,10 @@ class SemVer { default: throw new Error(`invalid increment argument: ${release}`) } - this.format() - this.raw = this.version + this.raw = this.format() + if (this.build.length) { + this.raw += `+${this.build.join('.')}` + } return this } } diff --git a/test/classes/semver.js b/test/classes/semver.js index 6be0ac8f..7c644d0e 100644 --- a/test/classes/semver.js +++ b/test/classes/semver.js @@ -81,7 +81,7 @@ test('invalid version numbers', (t) => { }) test('incrementing', t => { - t.plan(increments.length) + t.plan(increments.length + 1) increments.forEach(([ version, inc, @@ -97,6 +97,18 @@ test('incrementing', t => { t.equal(new SemVer(version, options).inc(inc, id, base).version, expect) } })) + t.test('preserve build in raw', t => { + // https://github.com/npm/node-semver/issues/562 + t.plan(2) + t.equal( + new SemVer('1.0.0-rc.1+build.4').inc('prerelease', 'rc').raw, + '1.0.0-rc.2+build.4' + ) + t.equal( + new SemVer('1.0.0-rc.1').inc('prerelease', 'rc').raw, + '1.0.0-rc.2' + ) + }) }) test('compare main vs pre', (t) => {