@simbo/platform-check 0.0.0-stage → 1.0.1
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/CHANGELOG.md +38 -0
- package/LICENSE.md +20 -0
- package/README.md +157 -2
- package/dist/compare-targets.d.ts +11 -0
- package/dist/compare-targets.js +66 -0
- package/dist/compare-targets.js.map +1 -0
- package/dist/compat-data.d.ts +19 -0
- package/dist/compat-data.js +109 -0
- package/dist/compat-data.js.map +1 -0
- package/dist/data-packages.d.ts +50 -0
- package/dist/data-packages.js +214 -0
- package/dist/data-packages.js.map +1 -0
- package/dist/es-mapping.d.ts +26 -0
- package/dist/es-mapping.js +143 -0
- package/dist/es-mapping.js.map +1 -0
- package/dist/expected-targets.d.ts +48 -0
- package/dist/expected-targets.js +93 -0
- package/dist/expected-targets.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.types.d.ts +54 -0
- package/dist/internal.types.js +2 -0
- package/dist/internal.types.js.map +1 -0
- package/dist/node-checks.d.ts +34 -0
- package/dist/node-checks.js +96 -0
- package/dist/node-checks.js.map +1 -0
- package/dist/node-schedule.d.ts +39 -0
- package/dist/node-schedule.js +61 -0
- package/dist/node-schedule.js.map +1 -0
- package/dist/options-schema.d.ts +63 -0
- package/dist/options-schema.js +55 -0
- package/dist/options-schema.js.map +1 -0
- package/dist/platform-check.d.ts +25 -0
- package/dist/platform-check.js +334 -0
- package/dist/platform-check.js.map +1 -0
- package/dist/platform-check.types.d.ts +419 -0
- package/dist/platform-check.types.js +2 -0
- package/dist/platform-check.types.js.map +1 -0
- package/dist/typescript-libs.d.ts +50 -0
- package/dist/typescript-libs.js +186 -0
- package/dist/typescript-libs.js.map +1 -0
- package/package.json +78 -3
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An environment that code runs in.
|
|
3
|
+
*
|
|
4
|
+
* - `node`: Node.js only
|
|
5
|
+
* - `browser`: browsers only
|
|
6
|
+
* - `universal`: Node.js and browsers alike
|
|
7
|
+
*/
|
|
8
|
+
export type Platform = 'node' | 'browser' | 'universal';
|
|
9
|
+
/**
|
|
10
|
+
* The TypeScript settings that follow from the supported environments.
|
|
11
|
+
*/
|
|
12
|
+
export interface PlatformTargets {
|
|
13
|
+
/**
|
|
14
|
+
* The ECMAScript sub-libs of TypeScript, in lowercase and sorted, such as
|
|
15
|
+
* `es2024.promise`.
|
|
16
|
+
*/
|
|
17
|
+
libs: string[];
|
|
18
|
+
/**
|
|
19
|
+
* The ECMAScript version of `target` as a year, such as `2024`.
|
|
20
|
+
* `ESNext` is `Infinity`.
|
|
21
|
+
*/
|
|
22
|
+
target: number;
|
|
23
|
+
/**
|
|
24
|
+
* Whether `resolveJsonModule` is enabled.
|
|
25
|
+
*/
|
|
26
|
+
resolveJsonModule: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether features are available in the supported environments.
|
|
30
|
+
*/
|
|
31
|
+
export interface CompatData {
|
|
32
|
+
/**
|
|
33
|
+
* Whether web-features has a Baseline status and browser-compat-data has
|
|
34
|
+
* Node.js support data for a feature.
|
|
35
|
+
*
|
|
36
|
+
* @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.
|
|
37
|
+
* @returns `true` if both know the feature.
|
|
38
|
+
*/
|
|
39
|
+
isKnown: (key: string) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a feature is Baseline Widely Available on the date of the check:
|
|
42
|
+
* 30 months after it became Baseline Newly Available. Unknown features are
|
|
43
|
+
* not.
|
|
44
|
+
*
|
|
45
|
+
* @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.
|
|
46
|
+
* @returns `true` if the feature is widely available.
|
|
47
|
+
*/
|
|
48
|
+
isWidelyAvailable: (key: string) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a Node.js version supports a feature without flags.
|
|
51
|
+
*
|
|
52
|
+
* @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.
|
|
53
|
+
* @param version - The Node.js version, such as `24.15.0`.
|
|
54
|
+
* @returns `true` if the version supports the feature; `false` for unknown features.
|
|
55
|
+
*/
|
|
56
|
+
isSupportedByNode: (key: string, version: string) => boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `features` of `web-features`, reduced to what the checks read.
|
|
60
|
+
*/
|
|
61
|
+
export type WebFeatures = Record<string, {
|
|
62
|
+
kind: string;
|
|
63
|
+
status?: {
|
|
64
|
+
by_compat_key?: Record<string, BaselineStatus>;
|
|
65
|
+
};
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* The Baseline status of a feature in web-features. Dates are `YYYY-MM-DD`,
|
|
69
|
+
* possibly prefixed with `≤` for ranges.
|
|
70
|
+
*/
|
|
71
|
+
export interface BaselineStatus {
|
|
72
|
+
/**
|
|
73
|
+
* The Baseline status at the release of the data.
|
|
74
|
+
*/
|
|
75
|
+
baseline: boolean | string;
|
|
76
|
+
/**
|
|
77
|
+
* When the feature became Baseline Newly Available.
|
|
78
|
+
*/
|
|
79
|
+
baseline_low_date?: string;
|
|
80
|
+
/**
|
|
81
|
+
* When the feature became Baseline Widely Available.
|
|
82
|
+
*/
|
|
83
|
+
baseline_high_date?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The release schedule of Node.js, as published in `schedule.json` of the
|
|
87
|
+
* `nodejs/Release` repository, keyed by release line such as `v24`.
|
|
88
|
+
*/
|
|
89
|
+
export type NodeSchedule = Record<string, NodeScheduleEntry>;
|
|
90
|
+
/**
|
|
91
|
+
* The dates of a Node.js release line, as `YYYY-MM-DD`.
|
|
92
|
+
*/
|
|
93
|
+
export interface NodeScheduleEntry {
|
|
94
|
+
/**
|
|
95
|
+
* The first release.
|
|
96
|
+
*/
|
|
97
|
+
start: string;
|
|
98
|
+
/**
|
|
99
|
+
* The start of the Active LTS phase, if the line becomes LTS.
|
|
100
|
+
*/
|
|
101
|
+
lts?: string;
|
|
102
|
+
/**
|
|
103
|
+
* The start of the Maintenance phase.
|
|
104
|
+
*/
|
|
105
|
+
maintenance?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The end of life.
|
|
108
|
+
*/
|
|
109
|
+
end: string;
|
|
110
|
+
/**
|
|
111
|
+
* The LTS codename.
|
|
112
|
+
*/
|
|
113
|
+
codename?: string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The Node.js release lines that Node.js maintains on a date.
|
|
117
|
+
*/
|
|
118
|
+
export interface NodeSupport {
|
|
119
|
+
/**
|
|
120
|
+
* The major versions of the maintained release lines, ascending.
|
|
121
|
+
*/
|
|
122
|
+
maintained: number[];
|
|
123
|
+
/**
|
|
124
|
+
* The major version of the Active LTS release line, if there is one.
|
|
125
|
+
*/
|
|
126
|
+
activeLts: number | undefined;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The kind of a finding.
|
|
130
|
+
*/
|
|
131
|
+
export type FindingCheck = 'engines' | 'types-node' | 'nvmrc' | 'lib' | 'target' | 'resolve-json-module' | 'mapping' | 'config' | 'data';
|
|
132
|
+
/**
|
|
133
|
+
* The change that resolves a finding.
|
|
134
|
+
*
|
|
135
|
+
* - `raise`: a setting can be raised, usually a minor change
|
|
136
|
+
* - `lower`: a setting must be lowered, usually a breaking change
|
|
137
|
+
* - `add`: a Node.js release line must be added to `engines`
|
|
138
|
+
* - `remove`: a Node.js release line must be removed from `engines`, a breaking change
|
|
139
|
+
* - `update`: a value or a dependency must be updated
|
|
140
|
+
*/
|
|
141
|
+
export type FindingChange = 'raise' | 'lower' | 'add' | 'remove' | 'update';
|
|
142
|
+
/**
|
|
143
|
+
* Options for comparing TypeScript settings.
|
|
144
|
+
*/
|
|
145
|
+
export interface CompareTargetsOptions {
|
|
146
|
+
/**
|
|
147
|
+
* Whether to report settings that could be raised, not only settings that
|
|
148
|
+
* must be lowered.
|
|
149
|
+
*/
|
|
150
|
+
reportBehind: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Sub-libs that may be provided beyond the expected ones, in lowercase.
|
|
153
|
+
*/
|
|
154
|
+
allowedLibs?: string[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A setting that does not match the supported environments.
|
|
158
|
+
*/
|
|
159
|
+
export interface Finding {
|
|
160
|
+
/**
|
|
161
|
+
* The kind of the finding.
|
|
162
|
+
*/
|
|
163
|
+
check: FindingCheck;
|
|
164
|
+
/**
|
|
165
|
+
* What the finding is about, such as a file path relative to the
|
|
166
|
+
* repository root, a preset or a package name.
|
|
167
|
+
*/
|
|
168
|
+
subject: string;
|
|
169
|
+
/**
|
|
170
|
+
* A description of the finding.
|
|
171
|
+
*/
|
|
172
|
+
message: string;
|
|
173
|
+
/**
|
|
174
|
+
* The change that resolves the finding.
|
|
175
|
+
*/
|
|
176
|
+
change: FindingChange;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* An installed data package and the range that its dependent requires.
|
|
180
|
+
*/
|
|
181
|
+
export interface InstalledPackage {
|
|
182
|
+
/**
|
|
183
|
+
* The package name.
|
|
184
|
+
*/
|
|
185
|
+
name: string;
|
|
186
|
+
/**
|
|
187
|
+
* The installed version.
|
|
188
|
+
*/
|
|
189
|
+
version: string;
|
|
190
|
+
/**
|
|
191
|
+
* The range that the dependent requires.
|
|
192
|
+
*/
|
|
193
|
+
range: string;
|
|
194
|
+
/**
|
|
195
|
+
* The package that depends on it, such as `@simbo/platform-check` or
|
|
196
|
+
* `browserslist`.
|
|
197
|
+
*/
|
|
198
|
+
dependent: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The registry data of a package that the checks read.
|
|
202
|
+
*/
|
|
203
|
+
export interface RegistryPackage {
|
|
204
|
+
/**
|
|
205
|
+
* The published versions.
|
|
206
|
+
*/
|
|
207
|
+
versions: string[];
|
|
208
|
+
/**
|
|
209
|
+
* The publish dates by version, as ISO date strings.
|
|
210
|
+
*/
|
|
211
|
+
time: Partial<Record<string, string>>;
|
|
212
|
+
/**
|
|
213
|
+
* The version of the `latest` dist-tag.
|
|
214
|
+
*/
|
|
215
|
+
latest: string | undefined;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The version information of an installed data package.
|
|
219
|
+
*/
|
|
220
|
+
export interface DataPackage {
|
|
221
|
+
/**
|
|
222
|
+
* The package name.
|
|
223
|
+
*/
|
|
224
|
+
name: string;
|
|
225
|
+
/**
|
|
226
|
+
* The package that depends on it.
|
|
227
|
+
*/
|
|
228
|
+
dependent: string;
|
|
229
|
+
/**
|
|
230
|
+
* The range that the dependent requires.
|
|
231
|
+
*/
|
|
232
|
+
range: string;
|
|
233
|
+
/**
|
|
234
|
+
* The installed version.
|
|
235
|
+
*/
|
|
236
|
+
installed: string;
|
|
237
|
+
/**
|
|
238
|
+
* When the installed version was published, as an ISO date string; empty
|
|
239
|
+
* if unknown.
|
|
240
|
+
*/
|
|
241
|
+
published: string;
|
|
242
|
+
/**
|
|
243
|
+
* The newest version within the range.
|
|
244
|
+
*/
|
|
245
|
+
latestInRange: string;
|
|
246
|
+
/**
|
|
247
|
+
* The latest version on the npm registry.
|
|
248
|
+
*/
|
|
249
|
+
latest: string;
|
|
250
|
+
/**
|
|
251
|
+
* When the latest version was published, as an ISO date string; empty if
|
|
252
|
+
* unknown.
|
|
253
|
+
*/
|
|
254
|
+
latestPublished: string;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The result of a platform check.
|
|
258
|
+
*/
|
|
259
|
+
export interface PlatformCheckResult {
|
|
260
|
+
/**
|
|
261
|
+
* The date of the check, as `YYYY-MM-DD`.
|
|
262
|
+
*/
|
|
263
|
+
date: string;
|
|
264
|
+
/**
|
|
265
|
+
* The Node.js release lines and the lowest Node.js version that the
|
|
266
|
+
* repository supports.
|
|
267
|
+
*/
|
|
268
|
+
node: NodeSupport & {
|
|
269
|
+
/**
|
|
270
|
+
* The maintained release lines that the repository deliberately does not
|
|
271
|
+
* support, from `droppedNodeLines`.
|
|
272
|
+
*/
|
|
273
|
+
dropped: number[];
|
|
274
|
+
/**
|
|
275
|
+
* The lowest minimum version of all `engines.node` ranges.
|
|
276
|
+
*/
|
|
277
|
+
lowestVersion: string | undefined;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* The installed TypeScript that the settings were read with.
|
|
281
|
+
*/
|
|
282
|
+
typescript: {
|
|
283
|
+
/**
|
|
284
|
+
* The TypeScript version.
|
|
285
|
+
*/
|
|
286
|
+
version: string;
|
|
287
|
+
/**
|
|
288
|
+
* The ECMAScript sub-libs that it knows, in lowercase and sorted.
|
|
289
|
+
*/
|
|
290
|
+
esLibs: string[];
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* The expected TypeScript settings per environment, for the lowest supported
|
|
294
|
+
* Node.js version.
|
|
295
|
+
*/
|
|
296
|
+
expected: Partial<Record<Platform, PlatformTargets>>;
|
|
297
|
+
/**
|
|
298
|
+
* The data packages that the check used.
|
|
299
|
+
*/
|
|
300
|
+
data: DataPackage[];
|
|
301
|
+
/**
|
|
302
|
+
* The findings, empty if everything is current.
|
|
303
|
+
*/
|
|
304
|
+
findings: Finding[];
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* A shared TypeScript configuration to check.
|
|
308
|
+
*/
|
|
309
|
+
export interface PresetOption {
|
|
310
|
+
/**
|
|
311
|
+
* A path relative to the repository root or a package specifier, as in
|
|
312
|
+
* `extends`, such as `@simbo/tsconfig/node`.
|
|
313
|
+
*/
|
|
314
|
+
config: string;
|
|
315
|
+
/**
|
|
316
|
+
* The environment that the configuration is for.
|
|
317
|
+
*/
|
|
318
|
+
platform: Platform;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Libs that a workspace may provide beyond its environment, such as for
|
|
322
|
+
* polyfills.
|
|
323
|
+
*/
|
|
324
|
+
export interface LibException {
|
|
325
|
+
/**
|
|
326
|
+
* The workspace path relative to the repository root, such as `sites/app`.
|
|
327
|
+
*/
|
|
328
|
+
workspace: string;
|
|
329
|
+
/**
|
|
330
|
+
* The TypeScript sub-libs, such as `ES2025.Collection`.
|
|
331
|
+
*/
|
|
332
|
+
libs: string[];
|
|
333
|
+
/**
|
|
334
|
+
* Why the workspace may provide the libs.
|
|
335
|
+
*/
|
|
336
|
+
reason: string;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* A maintained Node.js release line that a repository deliberately no longer
|
|
340
|
+
* supports, such as shortly before its end of life.
|
|
341
|
+
*/
|
|
342
|
+
export interface DroppedNodeLine {
|
|
343
|
+
/**
|
|
344
|
+
* The major version, such as `22`.
|
|
345
|
+
*/
|
|
346
|
+
major: number;
|
|
347
|
+
/**
|
|
348
|
+
* Why the release line is not supported.
|
|
349
|
+
*/
|
|
350
|
+
reason: string;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* A function that fetches a URL, compatible with the global `fetch`.
|
|
354
|
+
*/
|
|
355
|
+
export type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
|
|
356
|
+
/**
|
|
357
|
+
* Options for the platform check.
|
|
358
|
+
*/
|
|
359
|
+
export interface Options {
|
|
360
|
+
/**
|
|
361
|
+
* A directory inside the repository. The check runs from the monorepo root
|
|
362
|
+
* if there is one, else from this directory.
|
|
363
|
+
*
|
|
364
|
+
* @default process.cwd()
|
|
365
|
+
*/
|
|
366
|
+
workingDir?: string;
|
|
367
|
+
/**
|
|
368
|
+
* The date to check against.
|
|
369
|
+
*
|
|
370
|
+
* @default new Date()
|
|
371
|
+
*/
|
|
372
|
+
date?: Date;
|
|
373
|
+
/**
|
|
374
|
+
* The path of the `.nvmrc` file relative to the repository root, or `false`
|
|
375
|
+
* to skip the check.
|
|
376
|
+
*
|
|
377
|
+
* @default ".nvmrc"
|
|
378
|
+
*/
|
|
379
|
+
nvmrc?: string | false;
|
|
380
|
+
/**
|
|
381
|
+
* Maintained Node.js release lines that the repository deliberately no
|
|
382
|
+
* longer supports. They are neither expected in `engines` nor followed by
|
|
383
|
+
* `@types/node`.
|
|
384
|
+
*
|
|
385
|
+
* @default []
|
|
386
|
+
*/
|
|
387
|
+
droppedNodeLines?: DroppedNodeLine[];
|
|
388
|
+
/**
|
|
389
|
+
* The shared TypeScript configurations to check.
|
|
390
|
+
*
|
|
391
|
+
* @default the `node`, `browser` and `universal` presets of `@simbo/tsconfig`
|
|
392
|
+
*/
|
|
393
|
+
presets?: PresetOption[];
|
|
394
|
+
/**
|
|
395
|
+
* Whether to check the TypeScript configurations of all workspaces against
|
|
396
|
+
* the environment that their `package.json` declares.
|
|
397
|
+
*
|
|
398
|
+
* @default true
|
|
399
|
+
*/
|
|
400
|
+
workspaces?: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Libs that workspaces may provide beyond their environment.
|
|
403
|
+
*
|
|
404
|
+
* @default []
|
|
405
|
+
*/
|
|
406
|
+
libExceptions?: LibException[];
|
|
407
|
+
/**
|
|
408
|
+
* The number of days after which an outdated data package is a finding.
|
|
409
|
+
*
|
|
410
|
+
* @default 60
|
|
411
|
+
*/
|
|
412
|
+
maxDataAge?: number;
|
|
413
|
+
/**
|
|
414
|
+
* The function to fetch the Node.js release schedule and npm registry data.
|
|
415
|
+
*
|
|
416
|
+
* @default globalThis.fetch
|
|
417
|
+
*/
|
|
418
|
+
fetch?: FetchFn;
|
|
419
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-check.types.js","sourceRoot":"","sources":["../src/platform-check.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * An environment that code runs in.\n *\n * - `node`: Node.js only\n * - `browser`: browsers only\n * - `universal`: Node.js and browsers alike\n */\nexport type Platform = 'node' | 'browser' | 'universal';\n\n/**\n * The TypeScript settings that follow from the supported environments.\n */\nexport interface PlatformTargets {\n /**\n * The ECMAScript sub-libs of TypeScript, in lowercase and sorted, such as\n * `es2024.promise`.\n */\n libs: string[];\n\n /**\n * The ECMAScript version of `target` as a year, such as `2024`.\n * `ESNext` is `Infinity`.\n */\n target: number;\n\n /**\n * Whether `resolveJsonModule` is enabled.\n */\n resolveJsonModule: boolean;\n}\n\n/**\n * Checks whether features are available in the supported environments.\n */\nexport interface CompatData {\n /**\n * Whether web-features has a Baseline status and browser-compat-data has\n * Node.js support data for a feature.\n *\n * @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.\n * @returns `true` if both know the feature.\n */\n isKnown: (key: string) => boolean;\n\n /**\n * Whether a feature is Baseline Widely Available on the date of the check:\n * 30 months after it became Baseline Newly Available. Unknown features are\n * not.\n *\n * @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.\n * @returns `true` if the feature is widely available.\n */\n isWidelyAvailable: (key: string) => boolean;\n\n /**\n * Whether a Node.js version supports a feature without flags.\n *\n * @param key - The browser-compat-data key, such as `javascript.builtins.Array.at`.\n * @param version - The Node.js version, such as `24.15.0`.\n * @returns `true` if the version supports the feature; `false` for unknown features.\n */\n isSupportedByNode: (key: string, version: string) => boolean;\n}\n\n/**\n * The `features` of `web-features`, reduced to what the checks read.\n */\nexport type WebFeatures = Record<string, { kind: string; status?: { by_compat_key?: Record<string, BaselineStatus> } }>;\n\n/**\n * The Baseline status of a feature in web-features. Dates are `YYYY-MM-DD`,\n * possibly prefixed with `≤` for ranges.\n */\nexport interface BaselineStatus {\n /**\n * The Baseline status at the release of the data.\n */\n baseline: boolean | string;\n\n /**\n * When the feature became Baseline Newly Available.\n */\n baseline_low_date?: string;\n\n /**\n * When the feature became Baseline Widely Available.\n */\n baseline_high_date?: string;\n}\n\n/**\n * The release schedule of Node.js, as published in `schedule.json` of the\n * `nodejs/Release` repository, keyed by release line such as `v24`.\n */\nexport type NodeSchedule = Record<string, NodeScheduleEntry>;\n\n/**\n * The dates of a Node.js release line, as `YYYY-MM-DD`.\n */\nexport interface NodeScheduleEntry {\n /**\n * The first release.\n */\n start: string;\n\n /**\n * The start of the Active LTS phase, if the line becomes LTS.\n */\n lts?: string;\n\n /**\n * The start of the Maintenance phase.\n */\n maintenance?: string;\n\n /**\n * The end of life.\n */\n end: string;\n\n /**\n * The LTS codename.\n */\n codename?: string;\n}\n\n/**\n * The Node.js release lines that Node.js maintains on a date.\n */\nexport interface NodeSupport {\n /**\n * The major versions of the maintained release lines, ascending.\n */\n maintained: number[];\n\n /**\n * The major version of the Active LTS release line, if there is one.\n */\n activeLts: number | undefined;\n}\n\n/**\n * The kind of a finding.\n */\nexport type FindingCheck =\n 'engines' | 'types-node' | 'nvmrc' | 'lib' | 'target' | 'resolve-json-module' | 'mapping' | 'config' | 'data';\n\n/**\n * The change that resolves a finding.\n *\n * - `raise`: a setting can be raised, usually a minor change\n * - `lower`: a setting must be lowered, usually a breaking change\n * - `add`: a Node.js release line must be added to `engines`\n * - `remove`: a Node.js release line must be removed from `engines`, a breaking change\n * - `update`: a value or a dependency must be updated\n */\nexport type FindingChange = 'raise' | 'lower' | 'add' | 'remove' | 'update';\n\n/**\n * Options for comparing TypeScript settings.\n */\nexport interface CompareTargetsOptions {\n /**\n * Whether to report settings that could be raised, not only settings that\n * must be lowered.\n */\n reportBehind: boolean;\n\n /**\n * Sub-libs that may be provided beyond the expected ones, in lowercase.\n */\n allowedLibs?: string[];\n}\n\n/**\n * A setting that does not match the supported environments.\n */\nexport interface Finding {\n /**\n * The kind of the finding.\n */\n check: FindingCheck;\n\n /**\n * What the finding is about, such as a file path relative to the\n * repository root, a preset or a package name.\n */\n subject: string;\n\n /**\n * A description of the finding.\n */\n message: string;\n\n /**\n * The change that resolves the finding.\n */\n change: FindingChange;\n}\n\n/**\n * An installed data package and the range that its dependent requires.\n */\nexport interface InstalledPackage {\n /**\n * The package name.\n */\n name: string;\n\n /**\n * The installed version.\n */\n version: string;\n\n /**\n * The range that the dependent requires.\n */\n range: string;\n\n /**\n * The package that depends on it, such as `@simbo/platform-check` or\n * `browserslist`.\n */\n dependent: string;\n}\n\n/**\n * The registry data of a package that the checks read.\n */\nexport interface RegistryPackage {\n /**\n * The published versions.\n */\n versions: string[];\n\n /**\n * The publish dates by version, as ISO date strings.\n */\n time: Partial<Record<string, string>>;\n\n /**\n * The version of the `latest` dist-tag.\n */\n latest: string | undefined;\n}\n\n/**\n * The version information of an installed data package.\n */\nexport interface DataPackage {\n /**\n * The package name.\n */\n name: string;\n\n /**\n * The package that depends on it.\n */\n dependent: string;\n\n /**\n * The range that the dependent requires.\n */\n range: string;\n\n /**\n * The installed version.\n */\n installed: string;\n\n /**\n * When the installed version was published, as an ISO date string; empty\n * if unknown.\n */\n published: string;\n\n /**\n * The newest version within the range.\n */\n latestInRange: string;\n\n /**\n * The latest version on the npm registry.\n */\n latest: string;\n\n /**\n * When the latest version was published, as an ISO date string; empty if\n * unknown.\n */\n latestPublished: string;\n}\n\n/**\n * The result of a platform check.\n */\nexport interface PlatformCheckResult {\n /**\n * The date of the check, as `YYYY-MM-DD`.\n */\n date: string;\n\n /**\n * The Node.js release lines and the lowest Node.js version that the\n * repository supports.\n */\n node: NodeSupport & {\n /**\n * The maintained release lines that the repository deliberately does not\n * support, from `droppedNodeLines`.\n */\n dropped: number[];\n\n /**\n * The lowest minimum version of all `engines.node` ranges.\n */\n lowestVersion: string | undefined;\n };\n\n /**\n * The installed TypeScript that the settings were read with.\n */\n typescript: {\n /**\n * The TypeScript version.\n */\n version: string;\n\n /**\n * The ECMAScript sub-libs that it knows, in lowercase and sorted.\n */\n esLibs: string[];\n };\n\n /**\n * The expected TypeScript settings per environment, for the lowest supported\n * Node.js version.\n */\n expected: Partial<Record<Platform, PlatformTargets>>;\n\n /**\n * The data packages that the check used.\n */\n data: DataPackage[];\n\n /**\n * The findings, empty if everything is current.\n */\n findings: Finding[];\n}\n\n/**\n * A shared TypeScript configuration to check.\n */\nexport interface PresetOption {\n /**\n * A path relative to the repository root or a package specifier, as in\n * `extends`, such as `@simbo/tsconfig/node`.\n */\n config: string;\n\n /**\n * The environment that the configuration is for.\n */\n platform: Platform;\n}\n\n/**\n * Libs that a workspace may provide beyond its environment, such as for\n * polyfills.\n */\nexport interface LibException {\n /**\n * The workspace path relative to the repository root, such as `sites/app`.\n */\n workspace: string;\n\n /**\n * The TypeScript sub-libs, such as `ES2025.Collection`.\n */\n libs: string[];\n\n /**\n * Why the workspace may provide the libs.\n */\n reason: string;\n}\n\n/**\n * A maintained Node.js release line that a repository deliberately no longer\n * supports, such as shortly before its end of life.\n */\nexport interface DroppedNodeLine {\n /**\n * The major version, such as `22`.\n */\n major: number;\n\n /**\n * Why the release line is not supported.\n */\n reason: string;\n}\n\n/**\n * A function that fetches a URL, compatible with the global `fetch`.\n */\nexport type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;\n\n/**\n * Options for the platform check.\n */\nexport interface Options {\n /**\n * A directory inside the repository. The check runs from the monorepo root\n * if there is one, else from this directory.\n *\n * @default process.cwd()\n */\n workingDir?: string;\n\n /**\n * The date to check against.\n *\n * @default new Date()\n */\n date?: Date;\n\n /**\n * The path of the `.nvmrc` file relative to the repository root, or `false`\n * to skip the check.\n *\n * @default \".nvmrc\"\n */\n nvmrc?: string | false;\n\n /**\n * Maintained Node.js release lines that the repository deliberately no\n * longer supports. They are neither expected in `engines` nor followed by\n * `@types/node`.\n *\n * @default []\n */\n droppedNodeLines?: DroppedNodeLine[];\n\n /**\n * The shared TypeScript configurations to check.\n *\n * @default the `node`, `browser` and `universal` presets of `@simbo/tsconfig`\n */\n presets?: PresetOption[];\n\n /**\n * Whether to check the TypeScript configurations of all workspaces against\n * the environment that their `package.json` declares.\n *\n * @default true\n */\n workspaces?: boolean;\n\n /**\n * Libs that workspaces may provide beyond their environment.\n *\n * @default []\n */\n libExceptions?: LibException[];\n\n /**\n * The number of days after which an outdated data package is a finding.\n *\n * @default 60\n */\n maxDataAge?: number;\n\n /**\n * The function to fetch the Node.js release schedule and npm registry data.\n *\n * @default globalThis.fetch\n */\n fetch?: FetchFn;\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { TsconfigFile } from './internal.types.js';
|
|
2
|
+
import type { PlatformTargets } from './platform-check.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Expands libs into the ECMAScript sub-libs they contain.
|
|
5
|
+
*
|
|
6
|
+
* @param names - Lib names, such as `es2025` or `es2024.promise`, in any case.
|
|
7
|
+
* @returns The ECMAScript sub-libs, in lowercase and sorted.
|
|
8
|
+
*/
|
|
9
|
+
export declare function expandEsLibs(names: string[]): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Lists the ECMAScript sub-libs that the installed TypeScript knows, without
|
|
12
|
+
* `esnext`.
|
|
13
|
+
*
|
|
14
|
+
* @returns The sub-libs, in lowercase and sorted.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTypeScriptEsLibs(): Promise<string[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Lists the ECMAScript versions that the installed TypeScript accepts as
|
|
19
|
+
* `target`, from ES2015 on.
|
|
20
|
+
*
|
|
21
|
+
* @returns The versions as years, ascending.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTypeScriptTargets(): number[];
|
|
24
|
+
/**
|
|
25
|
+
* Formats a year of an ECMAScript version for messages.
|
|
26
|
+
*
|
|
27
|
+
* @param year - The year, as returned for `target`.
|
|
28
|
+
* @returns The version, such as `ES2024`, `ES5` or `ESNext`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatTarget(year: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the effective `lib`, `target` and `resolveJsonModule` of a TypeScript
|
|
33
|
+
* configuration, following `extends`.
|
|
34
|
+
*
|
|
35
|
+
* @param config - A configuration file path or a package specifier, as in `extends`.
|
|
36
|
+
* @param basePath - The directory to resolve `config` from.
|
|
37
|
+
* @returns The effective settings, with `lib` expanded into ECMAScript sub-libs.
|
|
38
|
+
* @throws {Error} If the configuration cannot be read.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readConfiguredTargets(config: string, basePath: string): Promise<PlatformTargets>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads a TypeScript configuration file with its settings and project
|
|
43
|
+
* references.
|
|
44
|
+
*
|
|
45
|
+
* @param path - The absolute path of the configuration file.
|
|
46
|
+
* @returns The settings, the referenced configuration files, the `types` and
|
|
47
|
+
* whether the file is a solution that only references other configurations.
|
|
48
|
+
* @throws {Error} If the configuration cannot be read.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readTsconfig(path: string): Promise<TsconfigFile>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import typescript from 'typescript';
|
|
4
|
+
import { ES5_YEAR } from './es-mapping.js';
|
|
5
|
+
/**
|
|
6
|
+
* The ECMAScript libs of TypeScript, such as `es5`, `es2024` or
|
|
7
|
+
* `es2024.promise`, without `esnext` and `full`.
|
|
8
|
+
*/
|
|
9
|
+
const ES_LIB = /^es(?:5|20\d\d)(?:\.(?!full$)[\d.a-z]+)?$/u;
|
|
10
|
+
const LIB_FILE = /^lib\.(?<name>.+)\.d\.ts$/u;
|
|
11
|
+
const libDirectory = dirname(typescript.getDefaultLibFilePath({}));
|
|
12
|
+
/**
|
|
13
|
+
* The parsed lib files, by lib name.
|
|
14
|
+
*/
|
|
15
|
+
const libCache = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Reads a lib file of the installed TypeScript.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The lib name, such as `es2024.promise`.
|
|
20
|
+
* @returns The references and whether the file declares anything.
|
|
21
|
+
*/
|
|
22
|
+
async function readLib(name) {
|
|
23
|
+
let lib = libCache.get(name);
|
|
24
|
+
if (!lib) {
|
|
25
|
+
lib = readFile(join(libDirectory, `lib.${name}.d.ts`), 'utf8').then(text => ({
|
|
26
|
+
references: typescript
|
|
27
|
+
.preProcessFile(text, false, false)
|
|
28
|
+
.libReferenceDirectives.map(reference => reference.fileName.toLowerCase()),
|
|
29
|
+
declares: typescript.createSourceFile(`lib.${name}.d.ts`, text, typescript.ScriptTarget.Latest).statements.length > 0,
|
|
30
|
+
}));
|
|
31
|
+
libCache.set(name, lib);
|
|
32
|
+
}
|
|
33
|
+
return lib;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Expands libs into the ECMAScript sub-libs they contain.
|
|
37
|
+
*
|
|
38
|
+
* @param names - Lib names, such as `es2025` or `es2024.promise`, in any case.
|
|
39
|
+
* @returns The ECMAScript sub-libs, in lowercase and sorted.
|
|
40
|
+
*/
|
|
41
|
+
export async function expandEsLibs(names) {
|
|
42
|
+
const visited = new Set();
|
|
43
|
+
const result = new Set();
|
|
44
|
+
let pending = names.map(name => name.toLowerCase());
|
|
45
|
+
while (pending.length > 0) {
|
|
46
|
+
const current = pending.filter(name => !visited.has(name));
|
|
47
|
+
for (const name of current)
|
|
48
|
+
visited.add(name);
|
|
49
|
+
const libs = await Promise.all(current.map(async (name) => ({ name, lib: await readLib(name) })));
|
|
50
|
+
pending = [];
|
|
51
|
+
for (const { name, lib } of libs) {
|
|
52
|
+
if (lib.declares && (ES_LIB.test(name) || name.startsWith('esnext.')))
|
|
53
|
+
result.add(name);
|
|
54
|
+
pending.push(...lib.references);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [...result].toSorted((a, b) => a.localeCompare(b));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Lists the ECMAScript sub-libs that the installed TypeScript knows, without
|
|
61
|
+
* `esnext`.
|
|
62
|
+
*
|
|
63
|
+
* @returns The sub-libs, in lowercase and sorted.
|
|
64
|
+
*/
|
|
65
|
+
export async function getTypeScriptEsLibs() {
|
|
66
|
+
const names = (await readdir(libDirectory))
|
|
67
|
+
.map(file => LIB_FILE.exec(file)?.groups?.name)
|
|
68
|
+
.filter((name) => name !== undefined && ES_LIB.test(name));
|
|
69
|
+
return expandEsLibs(names);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Lists the ECMAScript versions that the installed TypeScript accepts as
|
|
73
|
+
* `target`, from ES2015 on.
|
|
74
|
+
*
|
|
75
|
+
* @returns The versions as years, ascending.
|
|
76
|
+
*/
|
|
77
|
+
export function getTypeScriptTargets() {
|
|
78
|
+
return Object.keys(typescript.ScriptTarget)
|
|
79
|
+
.map(name => /^ES(?<year>20\d\d)$/u.exec(name)?.groups?.year)
|
|
80
|
+
.filter((year) => year !== undefined)
|
|
81
|
+
.map(Number)
|
|
82
|
+
.toSorted((a, b) => a - b);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Converts a `target` of TypeScript into a year.
|
|
86
|
+
*
|
|
87
|
+
* @param target - The script target.
|
|
88
|
+
* @returns The year, such as `2024`; `2009` for ES5, `Infinity` for ESNext.
|
|
89
|
+
*/
|
|
90
|
+
function targetToYear(target) {
|
|
91
|
+
// The reverse mapping of the enum may return an alias such as `LatestStandard`.
|
|
92
|
+
for (const [name, value] of Object.entries(typescript.ScriptTarget)) {
|
|
93
|
+
if (value !== target)
|
|
94
|
+
continue;
|
|
95
|
+
if (/^ES[35]$/u.test(name))
|
|
96
|
+
return ES5_YEAR;
|
|
97
|
+
const year = /^ES(?<year>\d{4})$/u.exec(name)?.groups?.year;
|
|
98
|
+
if (year !== undefined)
|
|
99
|
+
return Number(year);
|
|
100
|
+
}
|
|
101
|
+
return Infinity;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Formats a year of an ECMAScript version for messages.
|
|
105
|
+
*
|
|
106
|
+
* @param year - The year, as returned for `target`.
|
|
107
|
+
* @returns The version, such as `ES2024`, `ES5` or `ESNext`.
|
|
108
|
+
*/
|
|
109
|
+
export function formatTarget(year) {
|
|
110
|
+
if (year === Infinity)
|
|
111
|
+
return 'ESNext';
|
|
112
|
+
return year <= ES5_YEAR ? 'ES5' : `ES${year}`;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Derives the settings from parsed compiler options.
|
|
116
|
+
*
|
|
117
|
+
* @param options - The compiler options.
|
|
118
|
+
* @returns The settings, with `lib` expanded into ECMAScript sub-libs.
|
|
119
|
+
*/
|
|
120
|
+
async function toTargets(options) {
|
|
121
|
+
// Without `lib` and `target`, TypeScript uses its defaults, which the
|
|
122
|
+
// default lib file names, such as `lib.es2025.full.d.ts`.
|
|
123
|
+
const defaultLib = typescript.getDefaultLibFileName(options);
|
|
124
|
+
const libFiles = options.lib ?? [defaultLib];
|
|
125
|
+
const libs = await expandEsLibs(libFiles.map(file => LIB_FILE.exec(file)?.groups?.name ?? file));
|
|
126
|
+
let target = options.target === undefined ? undefined : targetToYear(options.target);
|
|
127
|
+
if (target === undefined) {
|
|
128
|
+
const name = LIB_FILE.exec(defaultLib)?.groups?.name ?? '';
|
|
129
|
+
const year = /^es(?<year>\d{4})\.full$/u.exec(name)?.groups?.year;
|
|
130
|
+
target = name === 'esnext.full' ? Infinity : year === undefined ? ES5_YEAR : Number(year);
|
|
131
|
+
}
|
|
132
|
+
return { libs, target, resolveJsonModule: options.resolveJsonModule === true };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Formats the errors of a parsed configuration, without "no inputs found",
|
|
136
|
+
* which does not affect the settings.
|
|
137
|
+
*
|
|
138
|
+
* @param errors - The diagnostics.
|
|
139
|
+
* @returns The error messages.
|
|
140
|
+
*/
|
|
141
|
+
function getConfigErrors(errors) {
|
|
142
|
+
const NO_INPUTS_FOUND = 18_003;
|
|
143
|
+
return errors
|
|
144
|
+
.filter(error => error.code !== NO_INPUTS_FOUND)
|
|
145
|
+
.map(error => typescript.flattenDiagnosticMessageText(error.messageText, ' '));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reads the effective `lib`, `target` and `resolveJsonModule` of a TypeScript
|
|
149
|
+
* configuration, following `extends`.
|
|
150
|
+
*
|
|
151
|
+
* @param config - A configuration file path or a package specifier, as in `extends`.
|
|
152
|
+
* @param basePath - The directory to resolve `config` from.
|
|
153
|
+
* @returns The effective settings, with `lib` expanded into ECMAScript sub-libs.
|
|
154
|
+
* @throws {Error} If the configuration cannot be read.
|
|
155
|
+
*/
|
|
156
|
+
export async function readConfiguredTargets(config, basePath) {
|
|
157
|
+
// The TypeScript configuration API is synchronous.
|
|
158
|
+
const parsed = typescript.parseJsonConfigFileContent({ extends: config, files: [] }, typescript.sys, basePath);
|
|
159
|
+
const errors = getConfigErrors(parsed.errors);
|
|
160
|
+
if (errors.length > 0) {
|
|
161
|
+
throw new Error(`Invalid TypeScript configuration ${config}: ${errors.join('; ')}`);
|
|
162
|
+
}
|
|
163
|
+
return toTargets(parsed.options);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Reads a TypeScript configuration file with its settings and project
|
|
167
|
+
* references.
|
|
168
|
+
*
|
|
169
|
+
* @param path - The absolute path of the configuration file.
|
|
170
|
+
* @returns The settings, the referenced configuration files, the `types` and
|
|
171
|
+
* whether the file is a solution that only references other configurations.
|
|
172
|
+
* @throws {Error} If the configuration cannot be read.
|
|
173
|
+
*/
|
|
174
|
+
export async function readTsconfig(path) {
|
|
175
|
+
const { config, error } = typescript.readConfigFile(path, file => typescript.sys.readFile(file));
|
|
176
|
+
const parsed = typescript.parseJsonConfigFileContent(config, typescript.sys, dirname(path), undefined, path);
|
|
177
|
+
const errors = getConfigErrors(error ? [error, ...parsed.errors] : parsed.errors);
|
|
178
|
+
if (errors.length > 0) {
|
|
179
|
+
throw new Error(`Invalid TypeScript configuration ${path}: ${errors.join('; ')}`);
|
|
180
|
+
}
|
|
181
|
+
const references = (parsed.projectReferences ?? []).map(reference => typescript.resolveProjectReferencePath(reference));
|
|
182
|
+
const raw = (parsed.raw ?? {});
|
|
183
|
+
const solution = references.length > 0 && Array.isArray(raw.files) && raw.files.length === 0 && raw.include === undefined;
|
|
184
|
+
return { targets: await toTargets(parsed.options), references, types: parsed.options.types ?? [], solution };
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=typescript-libs.js.map
|