Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ interface Options {
now?: Date;
cache?: Map<any, any>;
mirror?: string;
latestOfMajorOnly?: Boolean
latestOfMajorOnly?: Boolean;
ignoreFutureReleases?: Boolean;
}

interface VersionInfo {
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ module.exports = async function (alias = 'lts_active', opts = {}) {
const cache = opts.cache || _cache
const mirror = opts.mirror || 'https://nodejs.org/dist/'
const latestOfMajorOnly = opts.latestOfMajorOnly || false
const ignoreFutureReleases = opts.ignoreFutureReleases || false

const a = Array.isArray(alias) ? alias : [alias]
const versions = await getLatestVersionsByCodename({
now,
cache,
mirror
mirror,
ignoreFutureReleases
})

// Reduce to an object
Expand Down Expand Up @@ -74,7 +76,7 @@ function getVersions (cache, mirror) {
}).json()
}

async function getLatestVersionsByCodename ({ now, cache, mirror }) {
async function getLatestVersionsByCodename ({ now, cache, mirror, ignoreFutureReleases }) {
const schedule = await getSchedule(cache)
const versions = await getVersions(cache, mirror)

Expand Down Expand Up @@ -120,6 +122,11 @@ async function getLatestVersionsByCodename ({ now, cache, mirror }) {
}
}

// This version is from future; completely ignore it (i.e. we may have specified a `now` from the past)
if (ignoreFutureReleases && now < v.releaseDate) {
return obj
}

// Is in any supported period
if (now > v.start && now < v.end) {
v.isSupported = true
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,20 @@ suite('nv', () => {
assert.strictEqual(versions[0].major, 0)
assert.strictEqual(versions[0].isLts, false)
})

test('ignoreFutureReleases=false', async () => {
const versions = await nv('v8', { now, ignoreFutureReleases: false })
assert.strictEqual(versions.length, 1)
assert.strictEqual(versions[0].major, 8)
assert.strictEqual(versions[0].minor, 17)
assert.strictEqual(versions[0].patch, 0)
})

test('ignoreFutureReleases=true', async () => {
const versions = await nv('v8', { now, ignoreFutureReleases: true })
assert.strictEqual(versions.length, 1)
assert.strictEqual(versions[0].major, 8)
assert.strictEqual(versions[0].minor, 16)
assert.strictEqual(versions[0].patch, 1)
})
})