Skip to content
Snippets Groups Projects
Unverified Commit db6b4872 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

fix(node): Use better "isStable" function (#7157)

parent c98a537f
No related branches found
No related tags found
No related merge requests found
import { api as nodever } from '.'; import { DateTime } from 'luxon';
import { isStable, api as nodever } from '.';
describe('semver.getNewValue()', () => { describe('semver.getNewValue()', () => {
let dtLocal: any;
beforeEach(() => {
dtLocal = DateTime.local;
});
afterEach(() => {
DateTime.local = dtLocal;
});
it('returns normalized toVersion', () => { it('returns normalized toVersion', () => {
expect( expect(
nodever.getNewValue({ nodever.getNewValue({
...@@ -21,4 +29,29 @@ describe('semver.getNewValue()', () => { ...@@ -21,4 +29,29 @@ describe('semver.getNewValue()', () => {
}) })
).toEqual('~8.2.0'); ).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);
});
});
}); });
import { DateTime } from 'luxon';
import { NewValueConfig, VersioningApi } from '../common'; import { NewValueConfig, VersioningApi } from '../common';
import npm, { isValid, isVersion } from '../npm'; import npm, { isValid, isVersion } from '../npm';
import { nodeSchedule } from './schedule';
export const id = 'node'; export const id = 'node';
export const displayName = 'Node.js'; export const displayName = 'Node.js';
...@@ -27,8 +29,21 @@ function getNewValue({ ...@@ -27,8 +29,21 @@ function getNewValue({
export { isValid }; 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 = { export const api: VersioningApi = {
...npm, ...npm,
isStable,
getNewValue, getNewValue,
}; };
export default api; export default api;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment