@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.
Files changed (43) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +157 -2
  4. package/dist/compare-targets.d.ts +11 -0
  5. package/dist/compare-targets.js +66 -0
  6. package/dist/compare-targets.js.map +1 -0
  7. package/dist/compat-data.d.ts +19 -0
  8. package/dist/compat-data.js +109 -0
  9. package/dist/compat-data.js.map +1 -0
  10. package/dist/data-packages.d.ts +50 -0
  11. package/dist/data-packages.js +214 -0
  12. package/dist/data-packages.js.map +1 -0
  13. package/dist/es-mapping.d.ts +26 -0
  14. package/dist/es-mapping.js +143 -0
  15. package/dist/es-mapping.js.map +1 -0
  16. package/dist/expected-targets.d.ts +48 -0
  17. package/dist/expected-targets.js +93 -0
  18. package/dist/expected-targets.js.map +1 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.js +5 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/internal.types.d.ts +54 -0
  23. package/dist/internal.types.js +2 -0
  24. package/dist/internal.types.js.map +1 -0
  25. package/dist/node-checks.d.ts +34 -0
  26. package/dist/node-checks.js +96 -0
  27. package/dist/node-checks.js.map +1 -0
  28. package/dist/node-schedule.d.ts +39 -0
  29. package/dist/node-schedule.js +61 -0
  30. package/dist/node-schedule.js.map +1 -0
  31. package/dist/options-schema.d.ts +63 -0
  32. package/dist/options-schema.js +55 -0
  33. package/dist/options-schema.js.map +1 -0
  34. package/dist/platform-check.d.ts +25 -0
  35. package/dist/platform-check.js +334 -0
  36. package/dist/platform-check.js.map +1 -0
  37. package/dist/platform-check.types.d.ts +419 -0
  38. package/dist/platform-check.types.js +2 -0
  39. package/dist/platform-check.types.js.map +1 -0
  40. package/dist/typescript-libs.d.ts +50 -0
  41. package/dist/typescript-libs.js +186 -0
  42. package/dist/typescript-libs.js.map +1 -0
  43. package/package.json +78 -3
@@ -0,0 +1,334 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join, relative } from 'node:path';
3
+ import { findMonorepoRoot, getWorkspacePaths } from '@simbo/monorepo-utils';
4
+ import semver from 'semver';
5
+ import typescript from 'typescript';
6
+ import { compareTargets } from './compare-targets.js';
7
+ import { loadCompatData } from './compat-data.js';
8
+ import { checkDataPackage, describeDataPackage, fetchRegistryPackage, findBrowserslistDataPackages, findOwnDataPackages, } from './data-packages.js';
9
+ import { getExpectedTargets, getUnknownKeys, getUnmapped } from './expected-targets.js';
10
+ import { checkEngines, checkNvmrc, checkTypesNode } from './node-checks.js';
11
+ import { fetchNodeSchedule, getNodeSupport, toIsoDate } from './node-schedule.js';
12
+ import { validateOptions } from './options-schema.js';
13
+ import { expandEsLibs, formatTarget, getTypeScriptEsLibs, getTypeScriptTargets, readConfiguredTargets, readTsconfig, } from './typescript-libs.js';
14
+ const TSCONFIG_FILES = ['tsconfig.json', 'tsconfig.build.json'];
15
+ /**
16
+ * Checks whether the Node.js and ECMAScript platform targets of a repository
17
+ * are still current.
18
+ *
19
+ * It checks `engines.node`, `@types/node` and `.nvmrc` against the Node.js
20
+ * release schedule, and the `lib`, `target` and `resolveJsonModule` of shared
21
+ * TypeScript configurations and of all workspaces against the APIs and syntax
22
+ * that the supported environments have: the lowest supported Node.js version
23
+ * and Baseline Widely Available browsers.
24
+ *
25
+ * @param options - The options of the check.
26
+ * @returns The result with all findings; empty findings mean everything is current.
27
+ * @throws {ValidationError} If the options are invalid.
28
+ * @throws {Error} If data cannot be fetched or a configuration cannot be read.
29
+ */
30
+ export async function platformCheck(options = {}) {
31
+ const { workingDir, date, nvmrc, droppedNodeLines, presets, workspaces, libExceptions, maxDataAge, fetch } = validateOptions(options);
32
+ const monorepoRoot = await findMonorepoRoot({ workingDir });
33
+ const root = monorepoRoot ?? workingDir;
34
+ const manifests = await readManifests(root, monorepoRoot !== undefined);
35
+ const [schedule, compatData, esLibs, data] = await Promise.all([
36
+ fetchNodeSchedule(fetch),
37
+ loadCompatData(date),
38
+ getTypeScriptEsLibs(),
39
+ readDataPackages(manifests, fetch),
40
+ ]);
41
+ const support = getNodeSupport(schedule, date);
42
+ const dropped = droppedNodeLines.map(line => line.major).filter(major => support.maintained.includes(major));
43
+ // Node.js versions
44
+ const node = checkNodeVersions(manifests, schedule, date, support, dropped);
45
+ const findings = [...node.findings];
46
+ if (nvmrc !== false) {
47
+ const content = await readOptional(join(root, nvmrc));
48
+ if (content !== undefined)
49
+ findings.push(...checkNvmrc(nvmrc, content, support));
50
+ }
51
+ const lowestVersion = [...node.minVersions.values()].toSorted(semver.compare).at(0);
52
+ // TypeScript settings
53
+ const getExpected = createExpectedTargets(compatData, esLibs);
54
+ const expected = {};
55
+ const presetFindings = await Promise.all(presets.map(async ({ config, platform }) => {
56
+ const targets = getExpected(platform, lowestVersion);
57
+ expected[platform] = targets;
58
+ return compareTargets(config, targets, await readConfiguredTargets(config, root), { reportBehind: true });
59
+ }));
60
+ findings.push(...presetFindings.flat());
61
+ if (workspaces) {
62
+ const workspaceFindings = await Promise.all(manifests.map(async (manifest) => {
63
+ const platform = getPlatform(manifest.packageJson);
64
+ // Workspaces without a valid `engines.node` have an engines finding already.
65
+ if (platform === undefined || (platform !== 'browser' && !node.minVersions.has(manifest.path)))
66
+ return [];
67
+ const getTargets = (configPlatform) => getExpected(configPlatform, node.minVersions.get(manifest.path) ?? lowestVersion);
68
+ return checkWorkspaceTargets(manifest, platform, getTargets, libExceptions);
69
+ }));
70
+ findings.push(...workspaceFindings.flat());
71
+ }
72
+ findings.push(...checkMapping(esLibs, compatData), ...checkConfiguration(droppedNodeLines, support, libExceptions, manifests), ...data.flatMap(entry => checkDataPackage(entry, date, maxDataAge)));
73
+ return {
74
+ date: toIsoDate(date),
75
+ node: { ...support, dropped, lowestVersion },
76
+ typescript: { version: typescript.version, esLibs },
77
+ expected,
78
+ data,
79
+ findings,
80
+ };
81
+ }
82
+ /**
83
+ * Finds the installed data packages and looks up their registry data, once
84
+ * per package name.
85
+ *
86
+ * @param manifests - The manifests, whose directories resolve `browserslist`.
87
+ * @param fetchFn - The function to fetch the registry data with.
88
+ * @returns The version information of the data packages.
89
+ */
90
+ async function readDataPackages(manifests, fetchFn) {
91
+ const installed = [
92
+ ...(await findOwnDataPackages()),
93
+ ...(await findBrowserslistDataPackages(manifests.map(manifest => manifest.absolutePath))),
94
+ ];
95
+ const registry = new Map();
96
+ for (const { name } of installed) {
97
+ if (!registry.has(name))
98
+ registry.set(name, fetchRegistryPackage(name, fetchFn));
99
+ }
100
+ return Promise.all(installed.map(async (entry) => describeDataPackage(entry, await registry.get(entry.name))));
101
+ }
102
+ /**
103
+ * Checks `engines.node` and `@types/node` of all manifests and collects the
104
+ * minimum Node.js version of each.
105
+ *
106
+ * @param manifests - The manifests.
107
+ * @param schedule - The Node.js release schedule.
108
+ * @param date - The date to check against.
109
+ * @param support - The maintained release lines.
110
+ * @param dropped - Maintained release lines that are deliberately not supported.
111
+ * @returns The findings and the minimum Node.js versions by manifest path.
112
+ */
113
+ function checkNodeVersions(manifests, schedule, date, support, dropped) {
114
+ const supported = { ...support, maintained: support.maintained.filter(major => !dropped.includes(major)) };
115
+ const findings = [];
116
+ const minVersions = new Map();
117
+ for (const { path, packageJson } of manifests) {
118
+ const subject = join(path, 'package.json');
119
+ const engines = getEnginesNode(packageJson);
120
+ if (engines !== undefined) {
121
+ findings.push(...checkEngines(subject, engines, schedule, date, dropped));
122
+ const minVersion = semver.validRange(engines) === null ? undefined : semver.minVersion(engines)?.version;
123
+ if (minVersion !== undefined)
124
+ minVersions.set(path, minVersion);
125
+ }
126
+ const typesNode = getDependencyRange(packageJson, '@types/node');
127
+ if (typesNode !== undefined)
128
+ findings.push(...checkTypesNode(subject, typesNode, supported));
129
+ }
130
+ return { findings, minVersions };
131
+ }
132
+ /**
133
+ * Checks the TypeScript configurations of a workspace against its
134
+ * environment, following project references. Only settings ahead of the
135
+ * environment are reported; the shared presets report settings that could be
136
+ * raised. Solution files that only reference other configurations are not
137
+ * compared themselves, and configurations with `node` in `types` are compared
138
+ * with Node.js, such as the configuration for `vite.config.ts`.
139
+ *
140
+ * @param manifest - The workspace manifest.
141
+ * @param platform - The environment of the workspace.
142
+ * @param getTargets - Returns the expected settings of an environment.
143
+ * @param libExceptions - Libs that workspaces may provide beyond their environment.
144
+ * @returns The findings.
145
+ */
146
+ async function checkWorkspaceTargets(manifest, platform, getTargets, libExceptions) {
147
+ const { path, absolutePath } = manifest;
148
+ const allowedLibs = await expandEsLibs(libExceptions.filter(exception => exception.workspace === path).flatMap(exception => exception.libs));
149
+ const existing = await Promise.all(TSCONFIG_FILES.map(async (file) => {
150
+ const filePath = join(absolutePath, file);
151
+ return (await readOptional(filePath)) === undefined ? undefined : filePath;
152
+ }));
153
+ const pending = existing.filter(file => file !== undefined);
154
+ const visited = new Set();
155
+ const findings = [];
156
+ while (pending.length > 0) {
157
+ const file = pending.shift();
158
+ if (visited.has(file))
159
+ continue;
160
+ visited.add(file);
161
+ const tsconfig = await readTsconfig(file);
162
+ pending.push(...tsconfig.references);
163
+ if (tsconfig.solution)
164
+ continue;
165
+ const configPlatform = platform === 'browser' && tsconfig.types.includes('node') ? 'node' : platform;
166
+ const subject = join(path, relative(absolutePath, file));
167
+ findings.push(...compareTargets(subject, getTargets(configPlatform), tsconfig.targets, { reportBehind: false, allowedLibs }));
168
+ }
169
+ return findings;
170
+ }
171
+ /**
172
+ * Checks that the mapping covers the ECMAScript sub-libs and versions that the
173
+ * installed TypeScript knows, and that the data knows the keys of the mapping.
174
+ *
175
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
176
+ * @param compatData - The compatibility checks.
177
+ * @returns The findings.
178
+ */
179
+ function checkMapping(esLibs, compatData) {
180
+ const unmapped = getUnmapped(esLibs, getTypeScriptTargets());
181
+ const missing = [...unmapped.libs, ...unmapped.targets.map(year => `target ${formatTarget(year)}`)];
182
+ const unknown = getUnknownKeys(compatData);
183
+ const findings = [];
184
+ if (missing.length > 0) {
185
+ findings.push({
186
+ check: 'mapping',
187
+ subject: '@simbo/platform-check',
188
+ change: 'update',
189
+ message: `The mapping does not cover what TypeScript knows: ${missing.join(', ')}`,
190
+ });
191
+ }
192
+ if (unknown.length > 0) {
193
+ findings.push({
194
+ check: 'mapping',
195
+ subject: '@simbo/platform-check',
196
+ change: 'update',
197
+ message: `The data has no support information for these keys of the mapping, which count as unsupported: ${unknown.join(', ')}`,
198
+ });
199
+ }
200
+ return findings;
201
+ }
202
+ /**
203
+ * Checks the configuration for entries that no longer apply: dropped release
204
+ * lines that are no longer maintained and lib exceptions for unknown
205
+ * workspaces.
206
+ *
207
+ * @param droppedNodeLines - The dropped release lines.
208
+ * @param support - The maintained release lines.
209
+ * @param libExceptions - The lib exceptions.
210
+ * @param manifests - The manifests.
211
+ * @returns The findings.
212
+ */
213
+ function checkConfiguration(droppedNodeLines, support, libExceptions, manifests) {
214
+ const paths = new Set(manifests.map(manifest => manifest.path));
215
+ return [
216
+ ...droppedNodeLines
217
+ .filter(({ major }) => !support.maintained.includes(major))
218
+ .map(({ major }) => ({
219
+ check: 'config',
220
+ subject: 'droppedNodeLines',
221
+ change: 'remove',
222
+ message: `Node.js ${major} is no longer maintained; remove it from droppedNodeLines`,
223
+ })),
224
+ ...libExceptions
225
+ .filter(({ workspace }) => !paths.has(workspace))
226
+ .map(({ workspace }) => ({
227
+ check: 'config',
228
+ subject: 'libExceptions',
229
+ change: 'update',
230
+ message: `libExceptions names ${workspace}, which is no workspace path`,
231
+ })),
232
+ ];
233
+ }
234
+ /**
235
+ * Creates a cached lookup of the expected settings per environment and
236
+ * Node.js version.
237
+ *
238
+ * @param compatData - The compatibility checks.
239
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
240
+ * @returns The lookup function.
241
+ */
242
+ function createExpectedTargets(compatData, esLibs) {
243
+ const cache = new Map();
244
+ return (platform, nodeVersion) => {
245
+ const key = `${platform}@${nodeVersion ?? ''}`;
246
+ let targets = cache.get(key);
247
+ if (!targets) {
248
+ targets = getExpectedTargets(platform, nodeVersion, compatData, esLibs);
249
+ cache.set(key, targets);
250
+ }
251
+ return targets;
252
+ };
253
+ }
254
+ /**
255
+ * Reads the root manifest and, in a monorepo, the manifests of all workspaces,
256
+ * private ones included.
257
+ *
258
+ * @param root - The repository root.
259
+ * @param isMonorepo - Whether the root is a monorepo root.
260
+ * @returns The manifests.
261
+ */
262
+ async function readManifests(root, isMonorepo) {
263
+ const paths = isMonorepo ? await getWorkspacePaths({ workingDir: root }) : [];
264
+ const manifests = await Promise.all(['.', ...paths.filter(path => path !== '.' && path !== '')].map(async (path) => {
265
+ const absolutePath = join(root, path);
266
+ const content = await readOptional(join(absolutePath, 'package.json'));
267
+ return content === undefined
268
+ ? undefined
269
+ : { path, absolutePath, packageJson: JSON.parse(content) };
270
+ }));
271
+ return manifests.filter(manifest => manifest !== undefined);
272
+ }
273
+ /**
274
+ * Derives the environment of a package from its manifest: `engines.node`
275
+ * alone is `node`, `browserslist` alone is `browser`, both are `universal`.
276
+ *
277
+ * @param packageJson - The manifest.
278
+ * @returns The environment, or `undefined` if the manifest declares neither.
279
+ */
280
+ export function getPlatform(packageJson) {
281
+ const node = getEnginesNode(packageJson) !== undefined;
282
+ const browser = packageJson.browserslist !== undefined;
283
+ if (node && browser)
284
+ return 'universal';
285
+ return node ? 'node' : browser ? 'browser' : undefined;
286
+ }
287
+ /**
288
+ * Reads `engines.node` of a manifest.
289
+ *
290
+ * @param packageJson - The manifest.
291
+ * @returns The range, or `undefined`.
292
+ */
293
+ function getEnginesNode(packageJson) {
294
+ const { engines } = packageJson;
295
+ const range = typeof engines === 'object' && engines !== null ? engines.node : undefined;
296
+ return typeof range === 'string' ? range : undefined;
297
+ }
298
+ /**
299
+ * Reads the range of a dependency from the dependencies or development
300
+ * dependencies of a manifest.
301
+ *
302
+ * @param packageJson - The manifest.
303
+ * @param name - The dependency name.
304
+ * @returns The range, or `undefined`.
305
+ */
306
+ function getDependencyRange(packageJson, name) {
307
+ for (const field of ['dependencies', 'devDependencies']) {
308
+ const dependencies = packageJson[field];
309
+ const range = typeof dependencies === 'object' && dependencies !== null
310
+ ? dependencies[name]
311
+ : undefined;
312
+ if (typeof range === 'string')
313
+ return range;
314
+ }
315
+ return undefined;
316
+ }
317
+ /**
318
+ * Reads a file if it exists.
319
+ *
320
+ * @param path - The file path.
321
+ * @returns The content, or `undefined` if the file does not exist.
322
+ * @throws {Error} If the file exists but cannot be read.
323
+ */
324
+ async function readOptional(path) {
325
+ try {
326
+ return await readFile(path, 'utf8');
327
+ }
328
+ catch (error) {
329
+ if (error.code === 'ENOENT')
330
+ return undefined;
331
+ throw error;
332
+ }
333
+ }
334
+ //# sourceMappingURL=platform-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-check.js","sourceRoot":"","sources":["../src/platform-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oB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,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\n\nimport { findMonorepoRoot, getWorkspacePaths } from '@simbo/monorepo-utils';\nimport semver from 'semver';\nimport typescript from 'typescript';\n\nimport { compareTargets } from './compare-targets.js';\nimport { loadCompatData } from './compat-data.js';\nimport {\n checkDataPackage,\n describeDataPackage,\n fetchRegistryPackage,\n findBrowserslistDataPackages,\n findOwnDataPackages,\n} from './data-packages.js';\nimport { getExpectedTargets, getUnknownKeys, getUnmapped } from './expected-targets.js';\nimport type { Manifest } from './internal.types.js';\nimport { checkEngines, checkNvmrc, checkTypesNode } from './node-checks.js';\nimport { fetchNodeSchedule, getNodeSupport, toIsoDate } from './node-schedule.js';\nimport { validateOptions } from './options-schema.js';\nimport type {\n CompatData,\n DataPackage,\n DroppedNodeLine,\n FetchFn,\n Finding,\n InstalledPackage,\n LibException,\n NodeSchedule,\n NodeSupport,\n Options,\n Platform,\n PlatformCheckResult,\n PlatformTargets,\n RegistryPackage,\n} from './platform-check.types.js';\nimport {\n expandEsLibs,\n formatTarget,\n getTypeScriptEsLibs,\n getTypeScriptTargets,\n readConfiguredTargets,\n readTsconfig,\n} from './typescript-libs.js';\n\nconst TSCONFIG_FILES = ['tsconfig.json', 'tsconfig.build.json'];\n\n/**\n * Checks whether the Node.js and ECMAScript platform targets of a repository\n * are still current.\n *\n * It checks `engines.node`, `@types/node` and `.nvmrc` against the Node.js\n * release schedule, and the `lib`, `target` and `resolveJsonModule` of shared\n * TypeScript configurations and of all workspaces against the APIs and syntax\n * that the supported environments have: the lowest supported Node.js version\n * and Baseline Widely Available browsers.\n *\n * @param options - The options of the check.\n * @returns The result with all findings; empty findings mean everything is current.\n * @throws {ValidationError} If the options are invalid.\n * @throws {Error} If data cannot be fetched or a configuration cannot be read.\n */\nexport async function platformCheck(options: Options = {}): Promise<PlatformCheckResult> {\n const { workingDir, date, nvmrc, droppedNodeLines, presets, workspaces, libExceptions, maxDataAge, fetch } =\n validateOptions(options);\n\n const monorepoRoot = await findMonorepoRoot({ workingDir });\n const root = monorepoRoot ?? workingDir;\n const manifests = await readManifests(root, monorepoRoot !== undefined);\n\n const [schedule, compatData, esLibs, data] = await Promise.all([\n fetchNodeSchedule(fetch),\n loadCompatData(date),\n getTypeScriptEsLibs(),\n readDataPackages(manifests, fetch),\n ]);\n const support = getNodeSupport(schedule, date);\n const dropped = droppedNodeLines.map(line => line.major).filter(major => support.maintained.includes(major));\n\n // Node.js versions\n const node = checkNodeVersions(manifests, schedule, date, support, dropped);\n const findings = [...node.findings];\n if (nvmrc !== false) {\n const content = await readOptional(join(root, nvmrc));\n if (content !== undefined) findings.push(...checkNvmrc(nvmrc, content, support));\n }\n const lowestVersion = [...node.minVersions.values()].toSorted(semver.compare).at(0);\n\n // TypeScript settings\n const getExpected = createExpectedTargets(compatData, esLibs);\n const expected: PlatformCheckResult['expected'] = {};\n const presetFindings = await Promise.all(\n presets.map(async ({ config, platform }) => {\n const targets = getExpected(platform, lowestVersion);\n expected[platform] = targets;\n return compareTargets(config, targets, await readConfiguredTargets(config, root), { reportBehind: true });\n }),\n );\n findings.push(...presetFindings.flat());\n if (workspaces) {\n const workspaceFindings = await Promise.all(\n manifests.map(async manifest => {\n const platform = getPlatform(manifest.packageJson);\n // Workspaces without a valid `engines.node` have an engines finding already.\n if (platform === undefined || (platform !== 'browser' && !node.minVersions.has(manifest.path))) return [];\n const getTargets = (configPlatform: Platform): PlatformTargets =>\n getExpected(configPlatform, node.minVersions.get(manifest.path) ?? lowestVersion);\n return checkWorkspaceTargets(manifest, platform, getTargets, libExceptions);\n }),\n );\n findings.push(...workspaceFindings.flat());\n }\n\n findings.push(\n ...checkMapping(esLibs, compatData),\n ...checkConfiguration(droppedNodeLines, support, libExceptions, manifests),\n ...data.flatMap(entry => checkDataPackage(entry, date, maxDataAge)),\n );\n\n return {\n date: toIsoDate(date),\n node: { ...support, dropped, lowestVersion },\n typescript: { version: typescript.version, esLibs },\n expected,\n data,\n findings,\n };\n}\n\n/**\n * Finds the installed data packages and looks up their registry data, once\n * per package name.\n *\n * @param manifests - The manifests, whose directories resolve `browserslist`.\n * @param fetchFn - The function to fetch the registry data with.\n * @returns The version information of the data packages.\n */\nasync function readDataPackages(manifests: Manifest[], fetchFn: FetchFn): Promise<DataPackage[]> {\n const installed: InstalledPackage[] = [\n ...(await findOwnDataPackages()),\n ...(await findBrowserslistDataPackages(manifests.map(manifest => manifest.absolutePath))),\n ];\n const registry = new Map<string, Promise<RegistryPackage>>();\n for (const { name } of installed) {\n if (!registry.has(name)) registry.set(name, fetchRegistryPackage(name, fetchFn));\n }\n return Promise.all(\n installed.map(async entry =>\n describeDataPackage(entry, await (registry.get(entry.name) as Promise<RegistryPackage>)),\n ),\n );\n}\n\n/**\n * Checks `engines.node` and `@types/node` of all manifests and collects the\n * minimum Node.js version of each.\n *\n * @param manifests - The manifests.\n * @param schedule - The Node.js release schedule.\n * @param date - The date to check against.\n * @param support - The maintained release lines.\n * @param dropped - Maintained release lines that are deliberately not supported.\n * @returns The findings and the minimum Node.js versions by manifest path.\n */\nfunction checkNodeVersions(\n manifests: Manifest[],\n schedule: NodeSchedule,\n date: Date,\n support: NodeSupport,\n dropped: number[],\n): { findings: Finding[]; minVersions: Map<string, string> } {\n const supported = { ...support, maintained: support.maintained.filter(major => !dropped.includes(major)) };\n const findings: Finding[] = [];\n const minVersions = new Map<string, string>();\n for (const { path, packageJson } of manifests) {\n const subject = join(path, 'package.json');\n const engines = getEnginesNode(packageJson);\n if (engines !== undefined) {\n findings.push(...checkEngines(subject, engines, schedule, date, dropped));\n const minVersion = semver.validRange(engines) === null ? undefined : semver.minVersion(engines)?.version;\n if (minVersion !== undefined) minVersions.set(path, minVersion);\n }\n const typesNode = getDependencyRange(packageJson, '@types/node');\n if (typesNode !== undefined) findings.push(...checkTypesNode(subject, typesNode, supported));\n }\n return { findings, minVersions };\n}\n\n/**\n * Checks the TypeScript configurations of a workspace against its\n * environment, following project references. Only settings ahead of the\n * environment are reported; the shared presets report settings that could be\n * raised. Solution files that only reference other configurations are not\n * compared themselves, and configurations with `node` in `types` are compared\n * with Node.js, such as the configuration for `vite.config.ts`.\n *\n * @param manifest - The workspace manifest.\n * @param platform - The environment of the workspace.\n * @param getTargets - Returns the expected settings of an environment.\n * @param libExceptions - Libs that workspaces may provide beyond their environment.\n * @returns The findings.\n */\nasync function checkWorkspaceTargets(\n manifest: Manifest,\n platform: Platform,\n getTargets: (platform: Platform) => PlatformTargets,\n libExceptions: LibException[],\n): Promise<Finding[]> {\n const { path, absolutePath } = manifest;\n const allowedLibs = await expandEsLibs(\n libExceptions.filter(exception => exception.workspace === path).flatMap(exception => exception.libs),\n );\n const existing = await Promise.all(\n TSCONFIG_FILES.map(async file => {\n const filePath = join(absolutePath, file);\n return (await readOptional(filePath)) === undefined ? undefined : filePath;\n }),\n );\n const pending = existing.filter(file => file !== undefined);\n const visited = new Set<string>();\n const findings: Finding[] = [];\n while (pending.length > 0) {\n const file = pending.shift() as string;\n if (visited.has(file)) continue;\n visited.add(file);\n const tsconfig = await readTsconfig(file);\n pending.push(...tsconfig.references);\n if (tsconfig.solution) continue;\n const configPlatform = platform === 'browser' && tsconfig.types.includes('node') ? 'node' : platform;\n const subject = join(path, relative(absolutePath, file));\n findings.push(\n ...compareTargets(subject, getTargets(configPlatform), tsconfig.targets, { reportBehind: false, allowedLibs }),\n );\n }\n return findings;\n}\n\n/**\n * Checks that the mapping covers the ECMAScript sub-libs and versions that the\n * installed TypeScript knows, and that the data knows the keys of the mapping.\n *\n * @param esLibs - The ECMAScript sub-libs that TypeScript knows.\n * @param compatData - The compatibility checks.\n * @returns The findings.\n */\nfunction checkMapping(esLibs: string[], compatData: CompatData): Finding[] {\n const unmapped = getUnmapped(esLibs, getTypeScriptTargets());\n const missing = [...unmapped.libs, ...unmapped.targets.map(year => `target ${formatTarget(year)}`)];\n const unknown = getUnknownKeys(compatData);\n const findings: Finding[] = [];\n if (missing.length > 0) {\n findings.push({\n check: 'mapping',\n subject: '@simbo/platform-check',\n change: 'update',\n message: `The mapping does not cover what TypeScript knows: ${missing.join(', ')}`,\n });\n }\n if (unknown.length > 0) {\n findings.push({\n check: 'mapping',\n subject: '@simbo/platform-check',\n change: 'update',\n message: `The data has no support information for these keys of the mapping, which count as unsupported: ${unknown.join(', ')}`,\n });\n }\n return findings;\n}\n\n/**\n * Checks the configuration for entries that no longer apply: dropped release\n * lines that are no longer maintained and lib exceptions for unknown\n * workspaces.\n *\n * @param droppedNodeLines - The dropped release lines.\n * @param support - The maintained release lines.\n * @param libExceptions - The lib exceptions.\n * @param manifests - The manifests.\n * @returns The findings.\n */\nfunction checkConfiguration(\n droppedNodeLines: DroppedNodeLine[],\n support: NodeSupport,\n libExceptions: LibException[],\n manifests: Manifest[],\n): Finding[] {\n const paths = new Set(manifests.map(manifest => manifest.path));\n return [\n ...droppedNodeLines\n .filter(({ major }) => !support.maintained.includes(major))\n .map(({ major }): Finding => ({\n check: 'config',\n subject: 'droppedNodeLines',\n change: 'remove',\n message: `Node.js ${major} is no longer maintained; remove it from droppedNodeLines`,\n })),\n ...libExceptions\n .filter(({ workspace }) => !paths.has(workspace))\n .map(({ workspace }): Finding => ({\n check: 'config',\n subject: 'libExceptions',\n change: 'update',\n message: `libExceptions names ${workspace}, which is no workspace path`,\n })),\n ];\n}\n\n/**\n * Creates a cached lookup of the expected settings per environment and\n * Node.js version.\n *\n * @param compatData - The compatibility checks.\n * @param esLibs - The ECMAScript sub-libs that TypeScript knows.\n * @returns The lookup function.\n */\nfunction createExpectedTargets(\n compatData: CompatData,\n esLibs: string[],\n): (platform: Platform, nodeVersion: string | undefined) => PlatformTargets {\n const cache = new Map<string, PlatformTargets>();\n return (platform, nodeVersion) => {\n const key = `${platform}@${nodeVersion ?? ''}`;\n let targets = cache.get(key);\n if (!targets) {\n targets = getExpectedTargets(platform, nodeVersion, compatData, esLibs);\n cache.set(key, targets);\n }\n return targets;\n };\n}\n\n/**\n * Reads the root manifest and, in a monorepo, the manifests of all workspaces,\n * private ones included.\n *\n * @param root - The repository root.\n * @param isMonorepo - Whether the root is a monorepo root.\n * @returns The manifests.\n */\nasync function readManifests(root: string, isMonorepo: boolean): Promise<Manifest[]> {\n const paths = isMonorepo ? await getWorkspacePaths({ workingDir: root }) : [];\n const manifests = await Promise.all(\n ['.', ...paths.filter(path => path !== '.' && path !== '')].map(async path => {\n const absolutePath = join(root, path);\n const content = await readOptional(join(absolutePath, 'package.json'));\n return content === undefined\n ? undefined\n : { path, absolutePath, packageJson: JSON.parse(content) as Record<string, unknown> };\n }),\n );\n return manifests.filter(manifest => manifest !== undefined);\n}\n\n/**\n * Derives the environment of a package from its manifest: `engines.node`\n * alone is `node`, `browserslist` alone is `browser`, both are `universal`.\n *\n * @param packageJson - The manifest.\n * @returns The environment, or `undefined` if the manifest declares neither.\n */\nexport function getPlatform(packageJson: Record<string, unknown>): Platform | undefined {\n const node = getEnginesNode(packageJson) !== undefined;\n const browser = packageJson.browserslist !== undefined;\n if (node && browser) return 'universal';\n return node ? 'node' : browser ? 'browser' : undefined;\n}\n\n/**\n * Reads `engines.node` of a manifest.\n *\n * @param packageJson - The manifest.\n * @returns The range, or `undefined`.\n */\nfunction getEnginesNode(packageJson: Record<string, unknown>): string | undefined {\n const { engines } = packageJson;\n const range = typeof engines === 'object' && engines !== null ? (engines as Record<string, unknown>).node : undefined;\n return typeof range === 'string' ? range : undefined;\n}\n\n/**\n * Reads the range of a dependency from the dependencies or development\n * dependencies of a manifest.\n *\n * @param packageJson - The manifest.\n * @param name - The dependency name.\n * @returns The range, or `undefined`.\n */\nfunction getDependencyRange(packageJson: Record<string, unknown>, name: string): string | undefined {\n for (const field of ['dependencies', 'devDependencies']) {\n const dependencies = packageJson[field];\n const range =\n typeof dependencies === 'object' && dependencies !== null\n ? (dependencies as Record<string, unknown>)[name]\n : undefined;\n if (typeof range === 'string') return range;\n }\n return undefined;\n}\n\n/**\n * Reads a file if it exists.\n *\n * @param path - The file path.\n * @returns The content, or `undefined` if the file does not exist.\n * @throws {Error} If the file exists but cannot be read.\n */\nasync function readOptional(path: string): Promise<string | undefined> {\n try {\n return await readFile(path, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined;\n throw error;\n }\n}\n"]}