diff --git a/lib/versioning/node/index.spec.ts b/lib/versioning/node/index.spec.ts index aa071196a9c6c71ce88850f4b3cdf90e1393c48e..91e1fc3c0e2e38d9da085166078f6421a32cbcc5 100644 --- a/lib/versioning/node/index.spec.ts +++ b/lib/versioning/node/index.spec.ts @@ -1,6 +1,14 @@ -import { api as nodever } from '.'; +import { DateTime } from 'luxon'; +import { isStable, api as nodever } from '.'; describe('semver.getNewValue()', () => { + let dtLocal: any; + beforeEach(() => { + dtLocal = DateTime.local; + }); + afterEach(() => { + DateTime.local = dtLocal; + }); it('returns normalized toVersion', () => { expect( nodever.getNewValue({ @@ -21,4 +29,29 @@ describe('semver.getNewValue()', () => { }) ).toEqual('~8.2.0'); }); + it('isStable', () => { + const t1 = DateTime.fromISO('2020-09-01'); + const t2 = DateTime.fromISO('2021-06-01'); + [ + ['16.0.0', t1, false], + ['15.0.0', t1, false], + ['14.9.0', t1, false], + ['14.0.0', t2, true], + ['12.0.3', t1, true], + ['v12.0.3', t1, true], + ['12.0.3a', t1, false], + ['11.0.0', t1, false], + + ['10.0.0', t1, true], + ['10.0.999', t1, true], + ['10.1.0', t1, true], + + ['10.0.0a', t1, false], + ['9.0.0', t1, false], + ].forEach(([version, time, result]) => { + DateTime.local = (...args) => + args.length ? dtLocal.apply(DateTime, args) : time; + expect(isStable(version as string)).toBe(result); + }); + }); }); diff --git a/lib/versioning/node/index.ts b/lib/versioning/node/index.ts index 2d88961d6532b0da2d2069121eb583692d2c9707..8662b9dfe382a18c639393e6282cb1b2b320be5c 100644 --- a/lib/versioning/node/index.ts +++ b/lib/versioning/node/index.ts @@ -1,5 +1,7 @@ +import { DateTime } from 'luxon'; import { NewValueConfig, VersioningApi } from '../common'; import npm, { isValid, isVersion } from '../npm'; +import { nodeSchedule } from './schedule'; export const id = 'node'; export const displayName = 'Node.js'; @@ -27,8 +29,21 @@ function getNewValue({ export { isValid }; +export function isStable(version: string): boolean { + if (npm.isStable(version)) { + const major = npm.getMajor(version); + const schedule = nodeSchedule[`v${major}`]; + if (schedule?.lts) { + // TODO: use the exact release that started LTS + return DateTime.local() > DateTime.fromISO(schedule.lts); + } + } + return false; +} + export const api: VersioningApi = { ...npm, + isStable, getNewValue, }; export default api;