Skip to content

Commit

Permalink
feat!: tag => prerelease and use semver (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Oct 19, 2023
1 parent dc42613 commit 2798304
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface VersionInfo {
major: number;
minor: number;
patch: number;
tag: string;
prerelease?: string[];
codename: string;
versionName: string;
start?: Date;
Expand Down
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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 }
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down

0 comments on commit 2798304

Please sign in to comment.