UNPKG

eol-check

Version:

CLI tool to check End-of-Life (EOL) status of Node.js, package managers, operating systems, dependencies, and databases. Supports HTML reports and GitHub Actions.

76 lines (75 loc) 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Status = void 0; exports.evaluateVersion = evaluateVersion; var Status; (function (Status) { Status["OK"] = "OK"; Status["WARN"] = "WARN"; Status["ERR"] = "ERR"; })(Status || (exports.Status = Status = {})); function evaluateVersion(component, rawVersion, eolData) { const version = rawVersion.replace(/^v/, ''); // Debug log // console.log(`Evaluating ${component} version ${version}`); // 1. Try exact match let cycle = eolData.find((c) => c.cycle === version); // 2. Try matching major.minor (e.g. "4.2.0" -> "4.2") if (!cycle) { const parts = version.split('.'); if (parts.length >= 2) { const majorMinor = `${parts[0]}.${parts[1]}`; cycle = eolData.find((c) => c.cycle === majorMinor); } } // 3. Try matching major version (e.g. "18.14.0" -> "18") if (!cycle) { const major = version.split('.')[0]; cycle = eolData.find((c) => c.cycle === major); } if (!cycle) { return { component, version, status: Status.WARN, message: `Could not find EOL data for version ${version}`, }; } const now = new Date(); const eolDate = typeof cycle.eol === 'string' ? new Date(cycle.eol) : null; const isEolBoolean = typeof cycle.eol === 'boolean' && cycle.eol === true; if (isEolBoolean) { return { component, version, status: Status.ERR, message: `Version ${cycle.cycle} is EOL`, }; } if (eolDate && now > eolDate) { return { component, version, status: Status.ERR, message: `Version ${cycle.cycle} is EOL (ended ${cycle.eol})`, }; } if (eolDate) { const monthsUntilEol = (eolDate.getFullYear() - now.getFullYear()) * 12 + (eolDate.getMonth() - now.getMonth()); if (monthsUntilEol <= 6) { return { component, version, status: Status.WARN, message: `Version ${cycle.cycle} is approaching EOL (ends ${cycle.eol})`, }; } } return { component, version, status: Status.OK, message: `Version ${cycle.cycle} is supported (ends ${cycle.eol || 'unknown'})`, }; }