From 1f594b1e641badab28993d8a8c60706b058fd079 Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Thu, 3 Feb 2022 22:34:24 +0000 Subject: [PATCH] Tidy up --- src/tags.js | 20 ++++++-------------- test/tags.js | 9 +++------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/tags.js b/src/tags.js index 4a5d8d9e..0678e6ed 100644 --- a/src/tags.js +++ b/src/tags.js @@ -46,23 +46,15 @@ const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate, tagP return 1 } if (startingVersion) { - // check for literal match first, this allows matching non-semver tags - let index = tags.findIndex(({ tag }) => tag === startingVersion) + const semverStartingVersion = inferSemver(startingVersion.replace(tagPrefix, '')) + const index = tags.findIndex(({ tag }) => { + return tag === startingVersion || tag === semverStartingVersion + }) if (index !== -1) { return index + 1 - } else { - // infer semver from startingVersion & compare with other tag's inferred versions - startingVersion = inferSemver(startingVersion.replace(tagPrefix, '')) - index = tags.findIndex(({ version }) => version === startingVersion) - // check for literal match first - if (index !== -1) { - return index + 1 - // find nearest version that is lower than startingVersion - } else { - index = tags.findIndex(({ version }) => semver.gt(startingVersion, version)) - return index - } } + // Fall back to nearest version lower than startingVersion + return tags.findIndex(({ version }) => semver.lt(version, semverStartingVersion)) } if (startingDate) { return tags.filter(t => t.isoDate >= startingDate).length diff --git a/test/tags.js b/test/tags.js index 2771bc8d..29eb00d0 100644 --- a/test/tags.js +++ b/test/tags.js @@ -105,12 +105,9 @@ describe('fetchTags', () => { it('supports --starting-version', async () => { expect(await fetchTags({ ...options, startingVersion: 'v0.3' })).to.have.lengthOf(2) - // abreviated tag inferred via semver - expect(await fetchTags({ ...options, startingVersion: 'v1' })).to.have.lengthOf(1) - // inexistant tag in the past - expect(await fetchTags({ ...options, startingVersion: 'v0.2.8' })).to.have.lengthOf(2) - // inexistant tag in the future - expect(await fetchTags({ ...options, startingVersion: 'v2.0.0' })).to.have.lengthOf(0) + expect(await fetchTags({ ...options, startingVersion: 'v1' })).to.have.lengthOf(1) // Inferred semver + expect(await fetchTags({ ...options, startingVersion: 'v0.2.8' })).to.have.lengthOf(2) // Non-existent tag from the past + expect(await fetchTags({ ...options, startingVersion: 'v2.0.0' })).to.have.lengthOf(0) // Non-existent tag from the future }) it('supports --ending-version', async () => {