Skip to content
Open
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# supported ![CI](https://github.com/stefanpenner/supported/workflows/CI/badge.svg)
# supported ![CI](https://github.com/stefanpenner/supported/workflows/CI/badge.svg)


## Usage

```sh
npx supported <path/to/node_module>
```
55 changes: 32 additions & 23 deletions bin/supported
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node
'use strict';
const ora = require('ora');
const { writeFileSync } = require('fs');
const { displayResult } = require('../lib/output/cli-output');
const { writeToCsv } = require('../lib/output/csv-output');

(async function main(cli) {
if (cli.input.length === 0) {
Expand Down Expand Up @@ -31,31 +33,38 @@ const { displayResult } = require('../lib/output/cli-output');
2,
),
);
} else if(cli.flags.csv && result) {
let fileName = `${result.projectName}-support-audit.csv`;
let filePath = `${projectPath}/${fileName}`;
writeFileSync(filePath, writeToCsv(result), 'utf-8' );
console.log(`Report created at ${filePath}`);
} else {
displayResult(result, cli.flags);
}
}
})(require('meow')(require('../lib/help'), {
flags: {
verbose: {
type: 'boolean',
alias: 'd'
})(
require('meow')(require('../lib/help'), {
flags: {
verbose: {
type: 'boolean',
alias: 'd',
},
json: {
type: 'boolean',
alias: 'j',
},
unsupported: {
type: 'boolean',
alias: 'u',
},
supported: {
type: 'boolean',
alias: 's',
},
expiring: {
type: 'boolean',
alias: 'e',
},
},
json: {
type: 'boolean',
alias: 'j'
},
unsupported: {
type: 'boolean',
alias: 'u'
},
supported: {
type: 'boolean',
alias: 's'
},
expiring: {
type: 'boolean',
alias: 'e'
},
},
}));
}),
);
1 change: 1 addition & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = chalk`
{cyan --unsupported, -u} outputs detailed report of unsupport packages only
{cyan --expiring, -e} outputs detailed report of expiring packages only
{cyan --supported, -s} outputs detailed report of support packages only
{cyan --csv} outputs csv file in the project path
{bold Examples}
{gray $} {cyan supported ./path/to/project/}
`;
12 changes: 6 additions & 6 deletions lib/lts/ember-lts.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"3.16.*": {
"versionRange": "3.16.*",
"start_date": "March 4, 2020",
"maintenance_start_date": "November 11, 2020",
"end_date": "March 17, 2021"
"start_date": "2020-03-04T00:00:00.000Z",
"maintenance_start_date": "2020-11-11T00:00:00.000Z",
"end_date": "2021-03-17T00:00:00.000Z"
},
"3.20.*": {
"versionRange": ">=3.20.*",
"start_date": "August 24, 2020",
"maintenance_start_date": "May 3, 2021",
"end_date": "September 6, 2021"
"start_date": "2020-08-24T00:00:00.000Z",
"maintenance_start_date": "2021-05-03T00:00:00.000Z",
"end_date": "2021-09-06T00:00:00.000Z"
}
}
16 changes: 11 additions & 5 deletions lib/lts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const NODE_LTS = require('./node-lts.json');
const EMBER_LTS = require('./ember-lts.json');
const { isExpiringSoon } = require('../util');
const { isExpiringSoon, dateDiff } = require('../util');

function sortByMinor(a, b) {
return a.minor - b.minor;
Expand Down Expand Up @@ -146,6 +146,7 @@ function isLtsOrLatest(info, resolvedVersion, currentDate /* this used for testi
let packageName = 'node';
let message = '';
let duration = 0;

const today = currentDate || new Date();
if (info.type == 'node') {
// Check when there is no node version could be found in package.json.
Expand All @@ -162,7 +163,7 @@ function isLtsOrLatest(info, resolvedVersion, currentDate /* this used for testi
const isMaintenanceLts = new Date(data.maintenance_start_date) <= today;
if (isMaintenanceLts) {
message = 'Using maintenance LTS. Update to latest LTS';
duration = new Date(data.end_date) - today;
duration = dateDiff(new Date(data.end_date), today);
}
return true;
}
Expand All @@ -178,32 +179,36 @@ function isLtsOrLatest(info, resolvedVersion, currentDate /* this used for testi
// if maintenance version is in the list of ember LTS then do not match semver.gtr.
// We discourage people from using 3.18 when 3.20 is active LTS and 3.16 is maintenance.
const isMaintenanceLts = new Date(data.maintenance_start_date) <= today;

if (
semver.satisfies(resolvedVersion, versionRange) ||
(!isMaintenanceLts && semver.gtr(resolvedVersion, versionRange))
) {
if (isMaintenanceLts) {
message = 'Using maintenance LTS. Update to latest LTS';
duration = new Date(data.end_date) - today;
duration = dateDiff(new Date(data.end_date), today);
}
return true;
}
});
}

if (isSupported) {
let returnVal = {
const returnVal = {
isSupported: true,
resolvedVersion,
latestVersion: getCurrentLts(ltsList, packageName, currentDate),
};

if (isExpiringSoon(duration)) {
returnVal['duration'] = duration;
returnVal['message'] = message;
}

if (!duration && message) {
returnVal['message'] = message;
}

return returnVal;
} else {
let version = '';
Expand All @@ -215,10 +220,11 @@ function isLtsOrLatest(info, resolvedVersion, currentDate /* this used for testi
today <= new Date(data.maintenance_start_date)
) {
version = key;
duration = today - new Date(data.start_date);
duration = dateDiff(today, new Date(data.start_date));
return true;
}
});

return {
isSupported: false,
message: `${packageName} needs to be on v${version} or above LTS version`,
Expand Down
24 changes: 12 additions & 12 deletions lib/lts/node-lts.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"10.*": {
"versionRange": "10.*",
"start_date": "Oct 30 2018",
"maintenance_start_date": "May 19 2020",
"end_date": "Apr 30 2021"
"start_date": "2018-10-30T00:00:00.000Z",
"maintenance_start_date": "2020-05-19T00:00:00.000Z",
"end_date": "2021-04-30T00:00:00.000Z"
},
"12.*": {
"versionRange": "12.*",
"start_date": "Oct 21 2019",
"maintenance_start_date": "Nov 30 2020",
"end_date": "Apr 30 2022"
"start_date": "2019-10-21T00:00:00.000Z",
"maintenance_start_date": "2020-11-30T00:00:00.000Z",
"end_date": "2022-04-30T00:00:00.000Z"
},
"14.*": {
"versionRange": ">=14.*",
"start_date": "Oct 27 2020",
"maintenance_start_date": "Oct 19 2021",
"end_date": "Apr 30 2023"
"start_date": "2020-10-27T00:00:00.000Z",
"maintenance_start_date": "2021-10-19T00:00:00.000Z",
"end_date": "2023-04-30T00:00:00.000Z"
},
"16.*": {
"versionRange": ">=16.*",
"start_date": "2021-10-26",
"maintenance_start_date": "2022-10-18",
"end_date": "2024-04-30"
"start_date": "2021-10-26T00:00:00.000Z",
"maintenance_start_date": "2022-10-18T00:00:00.000Z",
"end_date": "2024-04-30T00:00:00.000Z"
}
}
1 change: 1 addition & 0 deletions lib/npm/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const execa = require('execa');
const camelcaseKeys = require('camelcase-keys');

module.exports = async function (cwd) {
const child = execa.sync('npm', ['config', 'list', '--json'], {
cwd,
Expand Down
69 changes: 29 additions & 40 deletions lib/output/cli-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function getBodyContent(results, flags) {
supportedTable.push([
chalk` {dim ${name}}`,
chalk`{dim ${resolvedVersion}}`,
chalk`{dim ${latestVersion}}`
chalk`{dim ${latestVersion}}`,
]);
}
}
Expand Down Expand Up @@ -160,7 +160,12 @@ function getLtsViolation(packageInfo) {
* @param {boolean | undefined} isWarning: is it only warning not violation
* @returns {string} formatted package semver violation title string
*/
function getPackageViolationTitle(violatingPackages, totalSemVerViolation, totalPackages, isWarning) {
function getPackageViolationTitle(
violatingPackages,
totalSemVerViolation,
totalPackages,
isWarning,
) {
if (violatingPackages.length) {
return LOG_SEMVER_TITLE(totalSemVerViolation, totalPackages, isWarning);
}
Expand Down Expand Up @@ -286,24 +291,23 @@ function getHead(

/**
*
* @param {object} reportContent : processed details from the displayContent
* @returns {string} formatted output for the support check run
* @param {object} supportResult : support check result
*
*/
function makeConsoleReport(reportContent) {
const {
body,
isInSupportWindow,
currentPolicy,
function makeConsoleReport(supportResult, flags, supportMessage) {
const isInSupportWindow = supportResult.isInSupportWindow;
const currentPolicy = supportMessage ? supportMessage : DEFAULT_SUPPORT_MESSAGE();
let {
expiresSoon,
unsupportedPackages,
supportedPackages,
nodePackage,
emberPackage,
} = reportContent;
supportedPackages,
} = getCategorisedList(supportResult.supportChecks);

let title = getTitle(isInSupportWindow, expiresSoon, nodePackage, emberPackage);
const title = getTitle(isInSupportWindow, expiresSoon, nodePackage, emberPackage);

let head = getHead(
const head = getHead(
isInSupportWindow,
unsupportedPackages,
supportedPackages,
Expand All @@ -313,9 +317,13 @@ function makeConsoleReport(reportContent) {
currentPolicy,
);

return `${title}${head}
${body}
`;
const body = getBodyContent(supportResult.supportChecks, flags);

return {
title,
head,
body,
};
}

/**
Expand Down Expand Up @@ -408,36 +416,17 @@ function getCategorisedList(pkgList) {
*
*/
function displayResult(supportResult, flags, supportMessage) {
const title = supportResult.projectName;
const isInSupportWindow = supportResult.isInSupportWindow;
const currentPolicy = supportMessage ? supportMessage : DEFAULT_SUPPORT_MESSAGE();
let {
expiresSoon,
unsupportedPackages,
nodePackage,
emberPackage,
supportedPackages,
} = getCategorisedList(supportResult.supportChecks);
const { title, head, body } = makeConsoleReport(supportResult, flags, supportMessage);

console.log(
makeConsoleReport({
title,
isInSupportWindow,
body: getBodyContent(supportResult.supportChecks, flags),
currentPolicy,
expiresSoon,
unsupportedPackages,
supportedPackages,
nodePackage,
emberPackage,
}),
);
console.log(`${title}${head}
${body}`);
}

module.exports = {
displayResult,
getBodyContent,
getCategorisedList,
getBodyContent,
getHead,
getTitle,
makeConsoleReport,
};
Loading