Skip to content

Commit

Permalink
Adds display of days allowed to report and CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ominestre committed Apr 13, 2022
1 parent 5d4ae55 commit 675b29a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/bin/rotten-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ yargs
let exitCode: ExitCode = 0;

const table = new Table({
head: ['name', 'current version', 'latest version', 'days outdated', 'is outdated'],
head: ['name', 'current version', 'latest version', 'days allowed', 'days outdated', 'is outdated'],
});

x.data.forEach(({
Expand All @@ -91,12 +91,13 @@ yargs
isOutdated,
isIgnored,
isStale,
daysAllowed,
}) => {
// if the exit code is already 1 for error we don't want to downgrade to warn
if (!isIgnored && exitCode !== 1 && isStale) exitCode = 2;
if (!isIgnored && isOutdated) exitCode = 1;
const outdated = isIgnored ? 'ignored' : isOutdated;
table.push([name, current, latest, daysOutdated, outdated]);
table.push([name, current, latest, daysAllowed, daysOutdated, outdated]);
});

resolve({
Expand Down
22 changes: 19 additions & 3 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ReportData {
isOutdated: boolean,
isIgnored: boolean,
isStale: boolean,
daysAllowed: number | 'inf',
}

interface Report {
Expand Down Expand Up @@ -137,17 +138,31 @@ export const generateReport = async (c: Config, r?: Reporter): Promise<ReportRes
let isOutdated = false;
let isIgnored = false;
let isStale = false;
let daysAllowed: number | 'inf' = 0;

const rule = rules.filter(x => x.dependencyName === details.name).shift();

if (!rule) isOutdated = true;
if (!rule && config.defaultExpiration && config.defaultExpiration > daysOutdated) isOutdated = false;
if (rule && rule.daysUntilExpiration && rule.daysUntilExpiration <= daysOutdated) isOutdated = true;
if (rule && rule.daysUntilExpiration && rule.daysUntilExpiration > daysOutdated) isStale = true;

if (!rule && config.defaultExpiration && config.defaultExpiration > daysOutdated) {
isOutdated = false;
daysAllowed = config.defaultExpiration;
}

if (rule && rule.daysUntilExpiration && rule.daysUntilExpiration <= daysOutdated) {
isOutdated = true;
daysAllowed = rule.daysUntilExpiration;
}

if (rule && rule.daysUntilExpiration && rule.daysUntilExpiration > daysOutdated) {
isStale = true;
daysAllowed = rule.daysUntilExpiration;
}

if (rule && rule.ignore) {
isIgnored = true;
isOutdated = false;
daysAllowed = 'inf';
}

const data = {
Expand All @@ -158,6 +173,7 @@ export const generateReport = async (c: Config, r?: Reporter): Promise<ReportRes
isOutdated,
isIgnored,
isStale,
daysAllowed,
};

r?.report(data);
Expand Down
14 changes: 14 additions & 0 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ describe('API integrations', () => {
assert.equal(maybeReport.kind, 'warning', 'The report type should be a report with warnings');
}).timeout(20000);

it('Displays days allowed and correctly determines if outdated', async () => {
sampleAppDir();
const config = getTestConfig('rules-only-config');
const maybeReport = await generateReport(config);

if (maybeReport instanceof Error) assert.fail();

maybeReport.data.forEach(report => {
assert.exists(report.daysAllowed);
assert.isFalse(report.daysAllowed > report.daysOutdated && report.isOutdated);
assert.isFalse(report.daysAllowed < report.daysOutdated && !report.isOutdated);
});
}).timeout(20000);

/* TODO Sitting on this one because you should just be using npm or yarn outdated.
Not sure I want to support this scenario */
xit('generate a report without config');
Expand Down

0 comments on commit 675b29a

Please sign in to comment.