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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2021-7-26

### Breaking
- End of support dates are now always rounded to the end of the quarter

## [0.5.0] - 2021-7-22

### Added
Expand Down
44 changes: 24 additions & 20 deletions lib/time/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { isExpiringSoon, dateDiff, getLatest, DEFAULT_PRIMARY_POLICY } = require(
const moment = require('moment');
module.exports.supportedRanges = supportedRanges;

const EOQ = ['31 March', '30 June', '30 Sept', '31 Dec'];
const MONTHS_IN_QTR = 3;

// TODO: Should check if we should remove this function as we are using deprecationDates function for the calculation
Expand Down Expand Up @@ -40,29 +39,34 @@ function supportedRanges(_origin, upgradeBudget = DEFAULT_PRIMARY_POLICY.upgrade
];
}

function roundToEndOfQuarter(date) {
return moment(date)
.endOf('quarter')
.add({
minutes: moment().utcOffset(),
})
.toDate();
}

module.exports.deprecationDates = deprecationDates;
/**
* calculates the major, minor and patch version deprecation dates for the given release date
* if release occurred at the end of quarter, add a padding of one quarter.
* @param {Date} _release : release date of next version
* @param {Object} upgradeBudget : The budget object
* @param {Integer} eoqPaddingInWeeks : Padding in number of weeks before expiration date is rolled
* over to the next quarter.
*/
function deprecationDates(_release, upgradeBudget = DEFAULT_PRIMARY_POLICY.upgradeBudget) {
function deprecationDates(
_release,
upgradeBudget = DEFAULT_PRIMARY_POLICY.upgradeBudget,
eoqPaddingInWeeks = 0,
) {
const release = new Date(_release);
const major = new Date(release);
const minor = new Date(release);
const patch = new Date(release);
const releaseYear = release.getFullYear();
let padding = 0;
const isEOQ = EOQ.some(halfDate => {
let endOfQuarter = moment(new Date(`${halfDate} ${releaseYear}`));
let twoWeeksBefore = moment(new Date(`${halfDate} ${releaseYear}`)).subtract(14, 'd');
let releaseDate = moment(release);
return releaseDate.isBefore(endOfQuarter) && releaseDate.isAfter(twoWeeksBefore);
});
// if new version is released at the end of quarter do not count next quarter.
if (isEOQ) {
padding = 3;
}
const padding = eoqPaddingInWeeks;
major.setMonth(release.getMonth() + upgradeBudget.major * MONTHS_IN_QTR);
if (padding) {
major.setMonth(major.getMonth() + padding);
Expand All @@ -71,12 +75,12 @@ function deprecationDates(_release, upgradeBudget = DEFAULT_PRIMARY_POLICY.upgra
patch.setMonth(release.getMonth() + upgradeBudget.patch * MONTHS_IN_QTR + padding);

return {
major,
minor,
patch,
prerelease: major,
preminor: minor,
prepatch: patch,
major: roundToEndOfQuarter(major),
minor: roundToEndOfQuarter(minor),
patch: roundToEndOfQuarter(patch),
prerelease: roundToEndOfQuarter(major),
preminor: roundToEndOfQuarter(minor),
prepatch: roundToEndOfQuarter(patch),
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supported",
"version": "0.5.0",
"version": "0.6.0",
"main": "index.js",
"repository": "git@github.com:supportedjs/supported",
"homepage": "https://github.com/supportedjs/supported",
Expand Down
47 changes: 42 additions & 5 deletions tests/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,28 @@ describe('CLI', function () {
it('works against a version expires soon project', async function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/version-expire-soon`,
'--current-date="March 31, 2021"',
'--current-date="April 10, 2021"',
]);

expect(child).to.exitGracefully();
expect(child.stderr).to.includes('⚠ SemVer Policy');
expect(child.stdout).to.includes('⚠ Warning!');
expect(child.stdout).to.includes(
'⚠ node LTS Policy\n ⚠ version/version-range 10.0.0 will be deprecated within 1 qtr',
'⚠ SemVer Policy (1 in 4 dependencies will expire soon) \n ⚠ major [1 dependency will expire within',
);
});

it('works against a project with node version expiring soon', async function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/node-expire-soon`,
'--current-date="April 1, 2021"',
]);

expect(child).to.exitGracefully();
expect(child.stderr).to.includes('⚠ node LTS Policy');
expect(child.stdout).to.includes('⚠ Warning!');
expect(child.stdout).to.includes(
'⚠ SemVer Policy (1 in 4 dependencies will expire soon) \n ⚠ major [1 dependency will expire within',
'⚠ node LTS Policy\n ⚠ version/version-range 10.0.0 will be deprecated within 1 qtr',
);
});

Expand Down Expand Up @@ -167,7 +178,7 @@ describe('CLI', function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/version-expire-soon`,
'--verbose',
'--current-date="March 31, 2021"',
'--current-date="April 10, 2021"',
]);

expect(child).to.exitGracefully();
Expand All @@ -176,6 +187,18 @@ describe('CLI', function () {
expect(child.stdout).to.includes(
`@stefanpenner/b 1.0.3 2.0.0 major`,
);
});

it('works against a project with node expiring soon', async function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/node-expire-soon`,
'--verbose',
'--current-date="March 31, 2021"',
]);

expect(child).to.exitGracefully();
expect(child.stderr).to.includes('⚠ node LTS Policy');
expect(child.stdout).to.includes('⚠ Warning!');
expect(child.stdout).to.includes(`node 10.0.0 >=14.* LTS`);
});
});
Expand Down Expand Up @@ -247,7 +270,21 @@ describe('CLI', function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/version-expire-soon`,
'--expiring',
'--current-date="March 31, 2021"',
'--current-date="April 2, 2021"',
]);

expect(child).to.exitGracefully();
expect(child.stderr).to.includes('- working');
expect(child.stdout).to.includes('⚠ Warning!');
expect(child.stdout).to.includes('@stefanpenner/b 1.0.3 2.0.0 major');
});

// TODO https://github.com/supportedjs/supported/issues/53
xit('first day of quarter - works against a unsupported project with --expiring option', async function () {
const child = await runSupportedCmd([
`${__dirname}/fixtures/version-expire-soon`,
'--expiring',
'--current-date="April 1, 2021"',
]);

expect(child).to.exitGracefully();
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/node-expire-soon/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=http://0.0.0.0:3000
@stefanpenner:registry=http://0.0.0.0:3001
15 changes: 15 additions & 0 deletions tests/fixtures/node-expire-soon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "version-expiring-soon",
"dependencies": {
"@eslint-ast/eslint-plugin-graphql": "^1.0.4",
"@stefanpenner/b": "^1.0.3",
"rsvp": "^4.8.0"
},
"devDependencies": {
"es6-promise": "^4.2.0"
},
"volta": {
"node": "10.0.0",
"yarn": "1.22.10"
}
}
Loading