node-lifecycle 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -4
- package/dist/index.js +10 -2
- package/dist/utils.js +18 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -61,12 +61,12 @@ async function main() {
|
|
|
61
61
|
const current = findCurrent(schedule); // e.g., 24
|
|
62
62
|
// Only recommend LTS if it's newer than the user's major
|
|
63
63
|
if (Number.isFinite(topLts) && topLts > result.major) {
|
|
64
|
-
const name = codenameFor(topLts);
|
|
64
|
+
const name = codenameFor(topLts, schedule);
|
|
65
65
|
rec.push(`LTS v${topLts}${name ? ` (“${name}”)` : ""}`);
|
|
66
66
|
}
|
|
67
67
|
// Always recommend Current unless they're already on it
|
|
68
68
|
if (current && current !== result.major) {
|
|
69
|
-
const name = codenameFor(current);
|
|
69
|
+
const name = codenameFor(current, schedule);
|
|
70
70
|
rec.push(`Current v${current}${name ? ` (“${name}”)` : ""}`);
|
|
71
71
|
}
|
|
72
72
|
return rec;
|
|
@@ -82,7 +82,7 @@ async function main() {
|
|
|
82
82
|
}
|
|
83
83
|
// Unknown line → warn (non-fatal)
|
|
84
84
|
if (result.status === "unknown") {
|
|
85
|
-
console.warn(`⚠️ Node ${runtime} → unknown
|
|
85
|
+
console.warn(`⚠️ Node ${runtime} → unknown or unreleased line (check version and schedule data).`);
|
|
86
86
|
process.exit(1);
|
|
87
87
|
}
|
|
88
88
|
// Near-EOL window
|
|
@@ -96,7 +96,7 @@ async function main() {
|
|
|
96
96
|
}
|
|
97
97
|
// Supported OK
|
|
98
98
|
const eolPretty = formatFriendlyDate(result.eol);
|
|
99
|
-
const code = codenameFor(result.major);
|
|
99
|
+
const code = codenameFor(result.major, schedule);
|
|
100
100
|
const suffix = code ? ` (“${code}”)` : "";
|
|
101
101
|
console.log(`✅ Node ${runtime} (major ${result.major})${suffix} → ${result.status}. EOL ${result.eol} (${eolPretty}) in ${result.daysToEol} days.`);
|
|
102
102
|
process.exit(0);
|
package/dist/index.js
CHANGED
|
@@ -42,13 +42,17 @@ async function fetchJson(url) {
|
|
|
42
42
|
throw new Error(`${url} -> ${r.status}`);
|
|
43
43
|
return r.json();
|
|
44
44
|
}
|
|
45
|
+
// Strip the upstream prefix without collapsing historical lines such as v0.10.
|
|
46
|
+
function normalizeScheduleKeys(schedule) {
|
|
47
|
+
return Object.fromEntries(Object.entries(schedule).map(([version, release]) => [version.replace(/^v/, ""), release]));
|
|
48
|
+
}
|
|
45
49
|
async function fetchWG(ttlMs) {
|
|
46
50
|
const url = "https://raw.githubusercontent.com/nodejs/Release/HEAD/schedule.json";
|
|
47
51
|
const cacheName = "schedule.wg.json";
|
|
48
52
|
const cached = await readCache(cacheName, ttlMs);
|
|
49
53
|
if (cached)
|
|
50
|
-
return cached;
|
|
51
|
-
const data = (await fetchJson(url));
|
|
54
|
+
return normalizeScheduleKeys(cached);
|
|
55
|
+
const data = normalizeScheduleKeys((await fetchJson(url)));
|
|
52
56
|
await writeCache(cacheName, data);
|
|
53
57
|
return data;
|
|
54
58
|
}
|
|
@@ -117,6 +121,10 @@ export function classify(nodeVersion, schedule) {
|
|
|
117
121
|
if (!rel)
|
|
118
122
|
return { major, status: "unknown" };
|
|
119
123
|
const now = new Date();
|
|
124
|
+
// A scheduled release is not supported before its initial release date.
|
|
125
|
+
if (rel.start && new Date(rel.start) > now) {
|
|
126
|
+
return { major, status: "unknown" };
|
|
127
|
+
}
|
|
120
128
|
// If no end date or invalid date → unknown
|
|
121
129
|
if (!rel.end || Number.isNaN(new Date(rel.end).getTime())) {
|
|
122
130
|
return { major, status: "unknown" };
|
package/dist/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ export const CODENAMES = {
|
|
|
3
3
|
20: "Iron",
|
|
4
4
|
22: "Jod",
|
|
5
5
|
24: "Krypton",
|
|
6
|
+
26: "Lithium",
|
|
6
7
|
};
|
|
7
8
|
const toValidDate = (iso) => {
|
|
8
9
|
if (!iso)
|
|
@@ -10,6 +11,15 @@ const toValidDate = (iso) => {
|
|
|
10
11
|
const d = new Date(iso);
|
|
11
12
|
return Number.isNaN(d.getTime()) ? null : d;
|
|
12
13
|
};
|
|
14
|
+
function releasedMajors(schedule, now) {
|
|
15
|
+
return Object.keys(schedule).map(Number).filter((major) => {
|
|
16
|
+
if (!Number.isFinite(major))
|
|
17
|
+
return false;
|
|
18
|
+
const start = toValidDate(schedule[String(major)]?.start);
|
|
19
|
+
// Sources without a start date retain the existing fallback behavior.
|
|
20
|
+
return !start || start <= now;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
13
23
|
// ISO → friendly date without TZ drift
|
|
14
24
|
export function formatFriendlyDate(isoDate) {
|
|
15
25
|
if (!isoDate)
|
|
@@ -27,6 +37,7 @@ export function formatFriendlyDate(isoDate) {
|
|
|
27
37
|
}
|
|
28
38
|
/**
|
|
29
39
|
* Return ALL active LTS majors.
|
|
40
|
+
* Only consider releases whose known start date has arrived.
|
|
30
41
|
* Normal path: require ltsStart <= now && eol > now.
|
|
31
42
|
* Fallback path (when no majors have an `lts` field at all, e.g. endoflife.date only):
|
|
32
43
|
* infer LTS = even majors with eol > now, EXCLUDING the highest supported major (assumed Current).
|
|
@@ -35,7 +46,7 @@ export function findActiveLTS(schedule, now = new Date()) {
|
|
|
35
46
|
const keys = Object.keys(schedule);
|
|
36
47
|
if (keys.length === 0)
|
|
37
48
|
return [];
|
|
38
|
-
const majors =
|
|
49
|
+
const majors = releasedMajors(schedule, now);
|
|
39
50
|
const anyLtsInfo = majors.some((m) => !!schedule[String(m)]?.lts);
|
|
40
51
|
if (anyLtsInfo) {
|
|
41
52
|
return majors
|
|
@@ -62,14 +73,14 @@ export function findActiveLTS(schedule, now = new Date()) {
|
|
|
62
73
|
.sort((a, b) => b - a);
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
65
|
-
* Latest Current (supported & not yet LTS).
|
|
76
|
+
* Latest Current (released, supported & not yet LTS).
|
|
66
77
|
* Fallback (no `lts` fields): the highest supported major.
|
|
67
78
|
*/
|
|
68
79
|
export function findCurrent(schedule, now = new Date()) {
|
|
69
80
|
const keys = Object.keys(schedule);
|
|
70
81
|
if (keys.length === 0)
|
|
71
82
|
return null;
|
|
72
|
-
const majors =
|
|
83
|
+
const majors = releasedMajors(schedule, now);
|
|
73
84
|
const anyLtsInfo = majors.some((m) => !!schedule[String(m)]?.lts);
|
|
74
85
|
if (anyLtsInfo) {
|
|
75
86
|
const candidates = majors.filter((m) => {
|
|
@@ -91,8 +102,11 @@ export function findCurrent(schedule, now = new Date()) {
|
|
|
91
102
|
});
|
|
92
103
|
return supported.length ? Math.max(...supported) : null;
|
|
93
104
|
}
|
|
94
|
-
export function codenameFor(major) {
|
|
105
|
+
export function codenameFor(major, schedule) {
|
|
95
106
|
if (!Number.isFinite(major))
|
|
96
107
|
return "";
|
|
108
|
+
const release = schedule?.[String(major)];
|
|
109
|
+
if (release?.codename?.trim())
|
|
110
|
+
return release.codename.trim();
|
|
97
111
|
return CODENAMES[major] || "";
|
|
98
112
|
}
|