From 1b64909c79ee15aa5cf8d5de6f4561010114f61e Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Thu, 19 Oct 2023 08:56:06 -0500 Subject: [PATCH] feat!: tag => prerelease and use semver (#20) --- index.js | 10 ++-------- test/index.js | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 453ffdf..3667816 100644 --- a/index.js +++ b/index.js @@ -81,10 +81,9 @@ async function getLatestVersionsByCodename (now, cache, mirror) { const lts = {} const aliases = versions.reduce((obj, ver) => { - const { major, minor, patch, tag } = splitVersion(ver.version) + const { version, major, minor, patch, prerelease } = semver.parse(ver.version) const versionName = major !== '0' ? `v${major}` : `v${major}.${minor}` const codename = ver.lts ? ver.lts.toLowerCase() : versionName - const version = tag !== '' ? `${major}.${minor}.${patch}-${tag}` : `${major}.${minor}.${patch}` const s = schedule[versionName] // Version Object @@ -93,7 +92,7 @@ async function getLatestVersionsByCodename (now, cache, mirror) { major, minor, patch, - tag, + prerelease, codename, versionName, start: s && s.start && new Date(s.start), @@ -186,8 +185,3 @@ async function getLatestVersionsByCodename (now, cache, mirror) { return aliases } - -function splitVersion (ver) { - const [, major, minor, patch, tag] = /^v([0-9]*)\.([0-9]*)\.([0-9]*)(?:-([0-9A-Za-z-_]+))?/.exec(ver).map((n, i) => i < 4 ? parseInt(n, 10) : n || '') - return { major, minor, patch, tag } -} diff --git a/test/index.js b/test/index.js index cba2ab0..edb5410 100644 --- a/test/index.js +++ b/test/index.js @@ -162,7 +162,7 @@ suite('nv', () => { assert.strictEqual(versions[0].major, 13) assert.strictEqual(versions[0].minor, 0) assert.strictEqual(versions[0].patch, 0) - assert.strictEqual(versions[0].tag, 'v8-canary20191022e5d3472f57') + assert.deepStrictEqual(versions[0].prerelease, ['v8-canary20191022e5d3472f57']) assert.strictEqual(versions[0].versionName, 'v13') })