-
Notifications
You must be signed in to change notification settings - Fork 245
/
constants.ts
177 lines (157 loc) · 5.36 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import * as process from 'process';
import { Range, SemVer } from 'semver';
const ONE_DAY_IN_MILLISECONDS = 86_400_000;
/**
* The support information for a given node release range.
*
* @see https://nodejs.org/en/about/releases/
*/
export class NodeRelease {
/**
* How long before enf-of-life do we start warning customers? Expressed in
* milliseconds to make it easier to deal with JS dates.
*/
private static readonly DEPRECATION_WINDOW_MS = 30 * ONE_DAY_IN_MILLISECONDS;
/**
* All registered node releases.
*/
public static readonly ALL_RELEASES: readonly NodeRelease[] = [
// Historical releases (not relevant at time of writing this as they're all EOL now...)
...([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const).map(
(majorVersion) => new NodeRelease(majorVersion, { endOfLife: true }),
),
// Past end-of-life releases
new NodeRelease(12, {
endOfLife: new Date('2022-04-30'),
supportedRange: '^12.7.0',
}),
new NodeRelease(13, { endOfLife: new Date('2020-06-01'), untested: true }),
new NodeRelease(14, {
endOfLife: new Date('2023-04-30'),
supportedRange: '^14.17.0',
}),
new NodeRelease(15, { endOfLife: new Date('2021-06-01'), untested: true }),
new NodeRelease(16, {
endOfLife: new Date('2023-09-11'),
supportedRange: '^16.3.0',
}),
new NodeRelease(17, {
endOfLife: new Date('2022-06-01'),
supportedRange: '^17.3.0',
untested: true,
}),
new NodeRelease(19, { endOfLife: new Date('2023-06-01'), untested: true }),
new NodeRelease(21, { endOfLife: new Date('2024-06-01'), untested: true }),
// Currently active releases (as of last edit to this file...)
new NodeRelease(18, { endOfLife: new Date('2025-04-30') }),
new NodeRelease(20, { endOfLife: new Date('2026-04-30') }),
new NodeRelease(22, { endOfLife: new Date('2027-04-30') }),
// Future (planned releases)
];
/**
* @returns the `NodeRelease` corresponding to the version of the node runtime
* executing this code (as provided by `process.version`), and a
* boolean indicating whether this version is known to be broken. If
* the runtime does not correspond to a known node major, this
* returns an `undefined` release object.
*/
public static forThisRuntime(): {
nodeRelease: NodeRelease | undefined;
knownBroken: boolean;
} {
const semver = new SemVer(process.version);
const majorVersion = semver.major;
for (const nodeRelease of this.ALL_RELEASES) {
if (nodeRelease.majorVersion === majorVersion) {
return {
nodeRelease,
knownBroken: !nodeRelease.supportedRange.test(semver),
};
}
}
return { nodeRelease: undefined, knownBroken: false };
}
/**
* The major version of this node release.
*/
public readonly majorVersion: number;
/**
* The date on which this release range starts to be considered end-of-life.
* May be `undefined` for "ancient" releases (before Node 12).
*/
public readonly endOfLifeDate: Date | undefined;
/**
* Determines whether this release is currently considered end-of-life.
*/
public readonly endOfLife: boolean;
/**
* Determines whether this release is within the deprecation window ahead of
* it's end-of-life date.
*/
public readonly deprecated: boolean;
/**
* If `true` denotes that this version of node has not been added to the test
* matrix yet. This is used when adding not-yet-released versions of node that
* are already planned (typically one or two years out).
*
* @default false
*/
public readonly untested: boolean;
/**
* The range of versions from this release line that are supported (early
* releases in a new line often lack essential features, and some have known
* bugs).
*/
public readonly supportedRange: Range;
/**
* Determines whether this major version line is currently "in support",
* meaning it is not end-of-life nor pending.
*/
public readonly supported: boolean;
/** @internal visible for testing */
public constructor(
majorVersion: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11,
opts: { endOfLife: true },
);
/** @internal visible for testing */
public constructor(
majorVersion: number,
opts: {
endOfLife: Date;
untested?: boolean;
supportedRange?: string;
},
);
/** @internal visible for testing */
public constructor(
majorVersion: number,
opts: {
endOfLife: Date | true;
untested?: boolean;
supportedRange?: string;
},
) {
this.majorVersion = majorVersion;
this.endOfLifeDate = opts.endOfLife === true ? undefined : opts.endOfLife;
this.untested = opts.untested ?? false;
this.supportedRange = new Range(
opts.supportedRange ?? `^${majorVersion}.0.0`,
);
this.endOfLife =
opts.endOfLife === true || opts.endOfLife.getTime() <= Date.now();
this.deprecated =
!this.endOfLife &&
opts.endOfLife !== true &&
opts.endOfLife.getTime() - NodeRelease.DEPRECATION_WINDOW_MS <=
Date.now();
this.supported = !this.untested && !this.endOfLife;
}
public toString(): string {
const eolInfo = this.endOfLifeDate
? ` (Planned end-of-life: ${this.endOfLifeDate
.toISOString()
.slice(0, 10)})`
: '';
return `${this.supportedRange.raw}${eolInfo}`;
}
}