Skip to content

Commit

Permalink
fix(node): Use better "isStable" function (#7157)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Dec 11, 2020
1 parent c98a537 commit db6b487
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
35 changes: 34 additions & 1 deletion lib/versioning/node/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
});
});
});
15 changes: 15 additions & 0 deletions lib/versioning/node/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

0 comments on commit db6b487

Please sign in to comment.