diff --git a/index.d.ts b/index.d.ts index 4ebaaff..55a7c83 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,7 +10,7 @@ interface VersionInfo { major: number; minor: number; patch: number; - tag: string; + prerelease?: string[]; codename: string; versionName: string; start?: Date; diff --git a/index.js b/index.js index 8d17990..c5672bf 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() : null - 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/index.test-d.ts b/index.test-d.ts index f6d2b39..fd3662a 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -7,7 +7,7 @@ import assert from 'node:assert' assert(versions[0].major) assert(versions[0].minor) assert(versions[0].patch) - assert(versions[0].tag) + assert(!versions[0].prerelease) assert(versions[0].codename) assert(versions[0].versionName) assert(versions[0].start) diff --git a/test/index.js b/test/index.js index fc12fd2..208374a 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') })