@simbo/platform-check 0.0.0-stage → 1.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +29 -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,54 @@
1
+ import type { PlatformTargets } from './platform-check.types.js';
2
+ /**
3
+ * A lib file of TypeScript.
4
+ */
5
+ export interface LibFile {
6
+ /**
7
+ * The libs that the file references.
8
+ */
9
+ references: string[];
10
+ /**
11
+ * Whether the file declares anything itself, unlike libs that only
12
+ * reference others, such as `es2024`.
13
+ */
14
+ declares: boolean;
15
+ }
16
+ /**
17
+ * A `package.json` of the repository.
18
+ */
19
+ export interface Manifest {
20
+ /**
21
+ * The directory relative to the repository root, `.` for the root.
22
+ */
23
+ path: string;
24
+ /**
25
+ * The absolute directory.
26
+ */
27
+ absolutePath: string;
28
+ /**
29
+ * The parsed manifest.
30
+ */
31
+ packageJson: Record<string, unknown>;
32
+ }
33
+ /**
34
+ * A TypeScript configuration file of a workspace.
35
+ */
36
+ export interface TsconfigFile {
37
+ /**
38
+ * The effective settings.
39
+ */
40
+ targets: PlatformTargets;
41
+ /**
42
+ * The absolute paths of the referenced configuration files.
43
+ */
44
+ references: string[];
45
+ /**
46
+ * The effective `types`.
47
+ */
48
+ types: string[];
49
+ /**
50
+ * Whether the file only references other configurations, with an empty
51
+ * `files` list and no `include`.
52
+ */
53
+ solution: boolean;
54
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=internal.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.types.js","sourceRoot":"","sources":["../src/internal.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PlatformTargets } from './platform-check.types.js';\n\n/**\n * A lib file of TypeScript.\n */\nexport interface LibFile {\n /**\n * The libs that the file references.\n */\n references: string[];\n\n /**\n * Whether the file declares anything itself, unlike libs that only\n * reference others, such as `es2024`.\n */\n declares: boolean;\n}\n\n/**\n * A `package.json` of the repository.\n */\nexport interface Manifest {\n /**\n * The directory relative to the repository root, `.` for the root.\n */\n path: string;\n\n /**\n * The absolute directory.\n */\n absolutePath: string;\n\n /**\n * The parsed manifest.\n */\n packageJson: Record<string, unknown>;\n}\n\n/**\n * A TypeScript configuration file of a workspace.\n */\nexport interface TsconfigFile {\n /**\n * The effective settings.\n */\n targets: PlatformTargets;\n\n /**\n * The absolute paths of the referenced configuration files.\n */\n references: string[];\n\n /**\n * The effective `types`.\n */\n types: string[];\n\n /**\n * Whether the file only references other configurations, with an empty\n * `files` list and no `include`.\n */\n solution: boolean;\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import type { Finding, NodeSchedule, NodeSupport } from './platform-check.types.js';
2
+ /**
3
+ * Checks that an `engines.node` range covers exactly the maintained Node.js
4
+ * release lines. An open upper bound and the minimum patch version are not
5
+ * checked.
6
+ *
7
+ * @param subject - The manifest path.
8
+ * @param range - The `engines.node` range.
9
+ * @param schedule - The release schedule.
10
+ * @param date - The date to check against.
11
+ * @param droppedLines - Major versions of maintained release lines that are deliberately not supported.
12
+ * @returns The findings.
13
+ */
14
+ export declare function checkEngines(subject: string, range: string, schedule: NodeSchedule, date: Date, droppedLines?: number[]): Finding[];
15
+ /**
16
+ * Checks that an `@types/node` range follows the lowest maintained Node.js
17
+ * release line. Specifiers with a protocol, such as `catalog:`, are skipped.
18
+ *
19
+ * @param subject - The manifest path.
20
+ * @param range - The `@types/node` range.
21
+ * @param support - The maintained release lines.
22
+ * @returns The findings.
23
+ */
24
+ export declare function checkTypesNode(subject: string, range: string, support: NodeSupport): Finding[];
25
+ /**
26
+ * Checks that an `.nvmrc` holds a version of the Active LTS release line.
27
+ * Aliases such as `lts/*` are not checked.
28
+ *
29
+ * @param subject - The `.nvmrc` path.
30
+ * @param content - The content of the file.
31
+ * @param support - The maintained release lines.
32
+ * @returns The findings.
33
+ */
34
+ export declare function checkNvmrc(subject: string, content: string, support: NodeSupport): Finding[];
@@ -0,0 +1,96 @@
1
+ import semver from 'semver';
2
+ import { getReleaseLines, toIsoDate } from './node-schedule.js';
3
+ /**
4
+ * Checks that an `engines.node` range covers exactly the maintained Node.js
5
+ * release lines. An open upper bound and the minimum patch version are not
6
+ * checked.
7
+ *
8
+ * @param subject - The manifest path.
9
+ * @param range - The `engines.node` range.
10
+ * @param schedule - The release schedule.
11
+ * @param date - The date to check against.
12
+ * @param droppedLines - Major versions of maintained release lines that are deliberately not supported.
13
+ * @returns The findings.
14
+ */
15
+ export function checkEngines(subject, range, schedule, date, droppedLines = []) {
16
+ if (semver.validRange(range) === null) {
17
+ return [{ check: 'engines', subject, change: 'update', message: `engines.node is not a valid range: ${range}` }];
18
+ }
19
+ const today = toIsoDate(date);
20
+ const findings = [];
21
+ const lines = getReleaseLines(schedule).toSorted((a, b) => a.major - b.major);
22
+ for (const { major, start, end } of lines) {
23
+ if (start > today || (droppedLines.includes(major) && today < end))
24
+ continue;
25
+ const covered = semver.intersects(range, `^${major}.0.0`);
26
+ if (!covered && today < end) {
27
+ findings.push({
28
+ check: 'engines',
29
+ subject,
30
+ change: 'add',
31
+ message: `engines.node ${range} does not cover the maintained Node.js ${major}`,
32
+ });
33
+ }
34
+ else if (covered && today >= end) {
35
+ findings.push({
36
+ check: 'engines',
37
+ subject,
38
+ change: 'remove',
39
+ message: `engines.node ${range} still covers Node.js ${major}, which reached its end of life on ${end}`,
40
+ });
41
+ }
42
+ }
43
+ return findings;
44
+ }
45
+ /**
46
+ * Checks that an `@types/node` range follows the lowest maintained Node.js
47
+ * release line. Specifiers with a protocol, such as `catalog:`, are skipped.
48
+ *
49
+ * @param subject - The manifest path.
50
+ * @param range - The `@types/node` range.
51
+ * @param support - The maintained release lines.
52
+ * @returns The findings.
53
+ */
54
+ export function checkTypesNode(subject, range, support) {
55
+ // Protocols such as `catalog:`, `workspace:` or `npm:` are resolved elsewhere.
56
+ if (semver.validRange(range) === null && /^[a-z]+:/u.test(range))
57
+ return [];
58
+ const lowest = support.maintained.at(0);
59
+ const major = semver.validRange(range) === null ? undefined : semver.minVersion(range)?.major;
60
+ if (lowest === undefined || major === lowest)
61
+ return [];
62
+ return [
63
+ {
64
+ check: 'types-node',
65
+ subject,
66
+ change: major === undefined ? 'update' : major > lowest ? 'lower' : 'raise',
67
+ message: `@types/node ${range} does not follow the lowest maintained Node.js ${lowest}`,
68
+ },
69
+ ];
70
+ }
71
+ /**
72
+ * Checks that an `.nvmrc` holds a version of the Active LTS release line.
73
+ * Aliases such as `lts/*` are not checked.
74
+ *
75
+ * @param subject - The `.nvmrc` path.
76
+ * @param content - The content of the file.
77
+ * @param support - The maintained release lines.
78
+ * @returns The findings.
79
+ */
80
+ export function checkNvmrc(subject, content, support) {
81
+ const version = content.trim();
82
+ if (!/^v?\d/u.test(version) || support.activeLts === undefined)
83
+ return [];
84
+ const major = semver.coerce(version)?.major;
85
+ if (major === support.activeLts)
86
+ return [];
87
+ return [
88
+ {
89
+ check: 'nvmrc',
90
+ subject,
91
+ change: 'update',
92
+ message: `.nvmrc ${version} is not the Active LTS Node.js ${support.activeLts}`,
93
+ },
94
+ ];
95
+ }
96
+ //# sourceMappingURL=node-checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-checks.js","sourceRoot":"","sources":["../src/node-checks.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGhE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,KAAa,EACb,QAAsB,EACtB,IAAU,EACV,eAAyB,EAAE;IAE3B,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QACtC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,sCAAsC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnH,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,eAAe,CAAC,QAAQ,CAAC,C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C,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9F,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC;IACxD,OAAO;QACL;YACE,KAAK,EAAE,YAAY;YACnB,OAAO;YACP,MAAM,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO;YAC3E,OAAO,EAAE,eAAe,KAAK,kDAAkD,MAAM,EAAE;SACxF;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,OAAe,EAAE,OAAoB;IAC/E,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;IAC5C,IAAI,KAAK,KAAK,OAAO,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC3C,OAAO;QACL;YACE,KAAK,EAAE,OAAO;YACd,OAAO;YACP,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,UAAU,OAAO,kCAAkC,OAAO,CAAC,SAAS,EAAE;SAChF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import semver from 'semver';\n\nimport { getReleaseLines, toIsoDate } from './node-schedule.js';\nimport type { Finding, NodeSchedule, NodeSupport } from './platform-check.types.js';\n\n/**\n * Checks that an `engines.node` range covers exactly the maintained Node.js\n * release lines. An open upper bound and the minimum patch version are not\n * checked.\n *\n * @param subject - The manifest path.\n * @param range - The `engines.node` range.\n * @param schedule - The release schedule.\n * @param date - The date to check against.\n * @param droppedLines - Major versions of maintained release lines that are deliberately not supported.\n * @returns The findings.\n */\nexport function checkEngines(\n subject: string,\n range: string,\n schedule: NodeSchedule,\n date: Date,\n droppedLines: number[] = [],\n): Finding[] {\n if (semver.validRange(range) === null) {\n return [{ check: 'engines', subject, change: 'update', message: `engines.node is not a valid range: ${range}` }];\n }\n const today = toIsoDate(date);\n const findings: Finding[] = [];\n const lines = getReleaseLines(schedule).toSorted((a, b) => a.major - b.major);\n for (const { major, start, end } of lines) {\n if (start > today || (droppedLines.includes(major) && today < end)) continue;\n const covered = semver.intersects(range, `^${major}.0.0`);\n if (!covered && today < end) {\n findings.push({\n check: 'engines',\n subject,\n change: 'add',\n message: `engines.node ${range} does not cover the maintained Node.js ${major}`,\n });\n } else if (covered && today >= end) {\n findings.push({\n check: 'engines',\n subject,\n change: 'remove',\n message: `engines.node ${range} still covers Node.js ${major}, which reached its end of life on ${end}`,\n });\n }\n }\n return findings;\n}\n\n/**\n * Checks that an `@types/node` range follows the lowest maintained Node.js\n * release line. Specifiers with a protocol, such as `catalog:`, are skipped.\n *\n * @param subject - The manifest path.\n * @param range - The `@types/node` range.\n * @param support - The maintained release lines.\n * @returns The findings.\n */\nexport function checkTypesNode(subject: string, range: string, support: NodeSupport): Finding[] {\n // Protocols such as `catalog:`, `workspace:` or `npm:` are resolved elsewhere.\n if (semver.validRange(range) === null && /^[a-z]+:/u.test(range)) return [];\n const lowest = support.maintained.at(0);\n const major = semver.validRange(range) === null ? undefined : semver.minVersion(range)?.major;\n if (lowest === undefined || major === lowest) return [];\n return [\n {\n check: 'types-node',\n subject,\n change: major === undefined ? 'update' : major > lowest ? 'lower' : 'raise',\n message: `@types/node ${range} does not follow the lowest maintained Node.js ${lowest}`,\n },\n ];\n}\n\n/**\n * Checks that an `.nvmrc` holds a version of the Active LTS release line.\n * Aliases such as `lts/*` are not checked.\n *\n * @param subject - The `.nvmrc` path.\n * @param content - The content of the file.\n * @param support - The maintained release lines.\n * @returns The findings.\n */\nexport function checkNvmrc(subject: string, content: string, support: NodeSupport): Finding[] {\n const version = content.trim();\n if (!/^v?\\d/u.test(version) || support.activeLts === undefined) return [];\n const major = semver.coerce(version)?.major;\n if (major === support.activeLts) return [];\n return [\n {\n check: 'nvmrc',\n subject,\n change: 'update',\n message: `.nvmrc ${version} is not the Active LTS Node.js ${support.activeLts}`,\n },\n ];\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type { FetchFn, NodeSchedule, NodeSupport } from './platform-check.types.js';
2
+ /**
3
+ * The URL of the Node.js release schedule.
4
+ */
5
+ export declare const NODE_SCHEDULE_URL = "https://raw.githubusercontent.com/nodejs/Release/main/schedule.json";
6
+ /**
7
+ * Fetches the Node.js release schedule.
8
+ *
9
+ * @param fetchFn - The function to fetch the schedule with.
10
+ * @returns The release schedule.
11
+ * @throws {Error} If the schedule cannot be fetched.
12
+ */
13
+ export declare function fetchNodeSchedule(fetchFn?: FetchFn): Promise<NodeSchedule>;
14
+ /**
15
+ * Formats a date as `YYYY-MM-DD` in UTC.
16
+ *
17
+ * @param date - The date.
18
+ * @returns The formatted date.
19
+ */
20
+ export declare function toIsoDate(date: Date): string;
21
+ /**
22
+ * Lists the release lines of the schedule with an integer major version.
23
+ *
24
+ * @param schedule - The release schedule.
25
+ * @returns The release lines with their major versions.
26
+ */
27
+ export declare function getReleaseLines(schedule: NodeSchedule): {
28
+ major: number;
29
+ start: string;
30
+ end: string;
31
+ }[];
32
+ /**
33
+ * Determines the release lines that Node.js maintains on a date.
34
+ *
35
+ * @param schedule - The release schedule.
36
+ * @param date - The date.
37
+ * @returns The maintained release lines and the Active LTS line.
38
+ */
39
+ export declare function getNodeSupport(schedule: NodeSchedule, date: Date): NodeSupport;
@@ -0,0 +1,61 @@
1
+ const ISO_DATE_LENGTH = 10;
2
+ const FETCH_TIMEOUT = 30_000;
3
+ /**
4
+ * The URL of the Node.js release schedule.
5
+ */
6
+ export const NODE_SCHEDULE_URL = 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json';
7
+ /**
8
+ * Fetches the Node.js release schedule.
9
+ *
10
+ * @param fetchFn - The function to fetch the schedule with.
11
+ * @returns The release schedule.
12
+ * @throws {Error} If the schedule cannot be fetched.
13
+ */
14
+ export async function fetchNodeSchedule(fetchFn = globalThis.fetch) {
15
+ const response = await fetchFn(NODE_SCHEDULE_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT) });
16
+ if (!response.ok) {
17
+ throw new Error(`Failed to fetch the Node.js release schedule: ${response.status} ${response.statusText}`);
18
+ }
19
+ return (await response.json());
20
+ }
21
+ /**
22
+ * Formats a date as `YYYY-MM-DD` in UTC.
23
+ *
24
+ * @param date - The date.
25
+ * @returns The formatted date.
26
+ */
27
+ export function toIsoDate(date) {
28
+ return date.toISOString().slice(0, ISO_DATE_LENGTH);
29
+ }
30
+ /**
31
+ * Lists the release lines of the schedule with an integer major version.
32
+ *
33
+ * @param schedule - The release schedule.
34
+ * @returns The release lines with their major versions.
35
+ */
36
+ export function getReleaseLines(schedule) {
37
+ return Object.entries(schedule)
38
+ .map(([line, { start, end }]) => ({ major: /^v(?<major>\d+)$/u.exec(line)?.groups?.major, start, end }))
39
+ .filter(line => line.major !== undefined)
40
+ .map(({ major, start, end }) => ({ major: Number(major), start, end }));
41
+ }
42
+ /**
43
+ * Determines the release lines that Node.js maintains on a date.
44
+ *
45
+ * @param schedule - The release schedule.
46
+ * @param date - The date.
47
+ * @returns The maintained release lines and the Active LTS line.
48
+ */
49
+ export function getNodeSupport(schedule, date) {
50
+ const today = toIsoDate(date);
51
+ const maintained = getReleaseLines(schedule)
52
+ .filter(({ start, end }) => start <= today && today < end)
53
+ .map(({ major }) => major)
54
+ .toSorted((a, b) => a - b);
55
+ const activeLts = maintained.find(major => {
56
+ const { lts, maintenance } = schedule[`v${major}`] ?? {};
57
+ return lts !== undefined && lts <= today && (maintenance === undefined || today < maintenance);
58
+ });
59
+ return { maintained, activeLts };
60
+ }
61
+ //# sourceMappingURL=node-schedule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-schedule.js","sourceRoot":"","sources":["../src/node-schedule.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,qEAAqE,CAAC;AAEvG;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAmB,UAAU,CAAC,KAAK;IACzE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAClG,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,iDAAiD,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiB,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,QAAsB;IACpD,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;SAC5B,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK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ETCH_TIMEOUT = 30_000;\n\n/**\n * The URL of the Node.js release schedule.\n */\nexport const NODE_SCHEDULE_URL = 'https://raw.githubusercontent.com/nodejs/Release/main/schedule.json';\n\n/**\n * Fetches the Node.js release schedule.\n *\n * @param fetchFn - The function to fetch the schedule with.\n * @returns The release schedule.\n * @throws {Error} If the schedule cannot be fetched.\n */\nexport async function fetchNodeSchedule(fetchFn: FetchFn = globalThis.fetch): Promise<NodeSchedule> {\n const response = await fetchFn(NODE_SCHEDULE_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT) });\n if (!response.ok) {\n throw new Error(`Failed to fetch the Node.js release schedule: ${response.status} ${response.statusText}`);\n }\n return (await response.json()) as NodeSchedule;\n}\n\n/**\n * Formats a date as `YYYY-MM-DD` in UTC.\n *\n * @param date - The date.\n * @returns The formatted date.\n */\nexport function toIsoDate(date: Date): string {\n return date.toISOString().slice(0, ISO_DATE_LENGTH);\n}\n\n/**\n * Lists the release lines of the schedule with an integer major version.\n *\n * @param schedule - The release schedule.\n * @returns The release lines with their major versions.\n */\nexport function getReleaseLines(schedule: NodeSchedule): { major: number; start: string; end: string }[] {\n return Object.entries(schedule)\n .map(([line, { start, end }]) => ({ major: /^v(?<major>\\d+)$/u.exec(line)?.groups?.major, start, end }))\n .filter(line => line.major !== undefined)\n .map(({ major, start, end }) => ({ major: Number(major), start, end }));\n}\n\n/**\n * Determines the release lines that Node.js maintains on a date.\n *\n * @param schedule - The release schedule.\n * @param date - The date.\n * @returns The maintained release lines and the Active LTS line.\n */\nexport function getNodeSupport(schedule: NodeSchedule, date: Date): NodeSupport {\n const today = toIsoDate(date);\n const maintained = getReleaseLines(schedule)\n .filter(({ start, end }) => start <= today && today < end)\n .map(({ major }) => major)\n .toSorted((a, b) => a - b);\n const activeLts = maintained.find(major => {\n const { lts, maintenance } = schedule[`v${major}`] ?? {};\n return lts !== undefined && lts <= today && (maintenance === undefined || today < maintenance);\n });\n return { maintained, activeLts };\n}\n"]}
@@ -0,0 +1,63 @@
1
+ import { z } from 'zod';
2
+ import type { FetchFn, PresetOption } from './platform-check.types.js';
3
+ /**
4
+ * The presets that are checked by default: the `node`, `browser` and
5
+ * `universal` configurations of `@simbo/tsconfig`.
6
+ */
7
+ export declare const DEFAULT_PRESETS: readonly PresetOption[];
8
+ /**
9
+ * The schema for the options of the platform check.
10
+ */
11
+ export declare const optionsSchema: z.ZodObject<{
12
+ workingDir: z.ZodDefault<z.ZodOptional<z.ZodString>>;
13
+ date: z.ZodDefault<z.ZodOptional<z.ZodDate>>;
14
+ nvmrc: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<false>]>>>;
15
+ droppedNodeLines: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
16
+ major: z.ZodNumber;
17
+ reason: z.ZodString;
18
+ }, z.core.$strict>>>>;
19
+ presets: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
20
+ config: z.ZodString;
21
+ platform: z.ZodEnum<{
22
+ node: "node";
23
+ browser: "browser";
24
+ universal: "universal";
25
+ }>;
26
+ }, z.core.$strict>>>>;
27
+ workspaces: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
28
+ libExceptions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
29
+ workspace: z.ZodString;
30
+ libs: z.ZodArray<z.ZodString>;
31
+ reason: z.ZodString;
32
+ }, z.core.$strict>>>>;
33
+ maxDataAge: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
34
+ fetch: z.ZodDefault<z.ZodOptional<z.ZodType<FetchFn, FetchFn, z.core.$ZodTypeInternals<FetchFn, FetchFn>>>>;
35
+ }, z.core.$strict>;
36
+ /**
37
+ * Parses the options of the platform check.
38
+ *
39
+ * @param input - The options to validate.
40
+ * @returns The parsed options with defaults.
41
+ * @throws {ValidationError} If the options are invalid.
42
+ */
43
+ export declare const validateOptions: (input: unknown) => {
44
+ workingDir: string;
45
+ date: Date;
46
+ nvmrc: string | false;
47
+ droppedNodeLines: {
48
+ major: number;
49
+ reason: string;
50
+ }[];
51
+ presets: {
52
+ config: string;
53
+ platform: "node" | "browser" | "universal";
54
+ }[];
55
+ workspaces: boolean;
56
+ libExceptions: {
57
+ workspace: string;
58
+ libs: string[];
59
+ reason: string;
60
+ }[];
61
+ maxDataAge: number;
62
+ fetch: FetchFn;
63
+ };
@@ -0,0 +1,55 @@
1
+ import { cwd } from 'node:process';
2
+ import { createFunctionSchema, createValidationFunction, nonEmptyStringSchema } from '@simbo/zodpak';
3
+ import { z } from 'zod';
4
+ /**
5
+ * The presets that are checked by default: the `node`, `browser` and
6
+ * `universal` configurations of `@simbo/tsconfig`.
7
+ */
8
+ export const DEFAULT_PRESETS = [
9
+ { config: '@simbo/tsconfig/node', platform: 'node' },
10
+ { config: '@simbo/tsconfig/browser', platform: 'browser' },
11
+ { config: '@simbo/tsconfig/universal', platform: 'universal' },
12
+ ];
13
+ const DEFAULT_MAX_DATA_AGE = 60;
14
+ const platformSchema = z.enum(['node', 'browser', 'universal']);
15
+ const droppedNodeLineSchema = z.strictObject({ major: z.number().int().nonnegative(), reason: nonEmptyStringSchema });
16
+ const presetSchema = z.strictObject({ config: nonEmptyStringSchema, platform: platformSchema });
17
+ const libExceptionSchema = z.strictObject({
18
+ workspace: nonEmptyStringSchema,
19
+ libs: z.array(nonEmptyStringSchema).min(1),
20
+ reason: nonEmptyStringSchema,
21
+ });
22
+ /**
23
+ * The schema for the options of the platform check.
24
+ */
25
+ export const optionsSchema = z.strictObject({
26
+ workingDir: nonEmptyStringSchema.optional().default(() => cwd()),
27
+ date: z
28
+ .date()
29
+ .optional()
30
+ .default(() => new Date()),
31
+ nvmrc: z
32
+ .union([nonEmptyStringSchema, z.literal(false)])
33
+ .optional()
34
+ .default('.nvmrc'),
35
+ droppedNodeLines: z.array(droppedNodeLineSchema).optional().default([]),
36
+ presets: z
37
+ .array(presetSchema)
38
+ .optional()
39
+ .default(() => DEFAULT_PRESETS.map(preset => ({ ...preset }))),
40
+ workspaces: z.boolean().optional().default(true),
41
+ libExceptions: z.array(libExceptionSchema).optional().default([]),
42
+ maxDataAge: z.number().int().nonnegative().optional().default(DEFAULT_MAX_DATA_AGE),
43
+ fetch: createFunctionSchema()
44
+ .optional()
45
+ .default(() => globalThis.fetch),
46
+ });
47
+ /**
48
+ * Parses the options of the platform check.
49
+ *
50
+ * @param input - The options to validate.
51
+ * @returns The parsed options with defaults.
52
+ * @throws {ValidationError} If the options are invalid.
53
+ */
54
+ export const validateOptions = createValidationFunction(optionsSchema);
55
+ //# sourceMappingURL=options-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options-schema.js","sourceRoot":"","sources":["../src/options-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAA4B;IACtD,EAAE,MAAM,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,EAAE;IACpD,EAAE,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,SAAS,EAAE;IAC1D,EAAE,MAAM,EAAE,2BAA2B,EAAE,QAAQ,EAAE,WAAW,EAAE;CAC/D,CAAC;AAEF,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;AAEhE,MAAM,qBAAqB,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAEtH,MAAM,YAAY,GAAG,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,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACjE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACnF,KAAK,EAAE,oBAAoB,EAAW;SACnC,QAAQ,EAAE;SACV,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;CACnC,CAA8B,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { cwd } from 'node:process';\n\nimport { createFunctionSchema, createValidationFunction, nonEmptyStringSchema } from '@simbo/zodpak';\nimport { z } from 'zod';\n\nimport type { FetchFn, Options, PresetOption } from './platform-check.types.js';\n\n/**\n * The presets that are checked by default: the `node`, `browser` and\n * `universal` configurations of `@simbo/tsconfig`.\n */\nexport const DEFAULT_PRESETS: readonly PresetOption[] = [\n { config: '@simbo/tsconfig/node', platform: 'node' },\n { config: '@simbo/tsconfig/browser', platform: 'browser' },\n { config: '@simbo/tsconfig/universal', platform: 'universal' },\n];\n\nconst DEFAULT_MAX_DATA_AGE = 60;\n\nconst platformSchema = z.enum(['node', 'browser', 'universal']);\n\nconst droppedNodeLineSchema = z.strictObject({ major: z.number().int().nonnegative(), reason: nonEmptyStringSchema });\n\nconst presetSchema = z.strictObject({ config: nonEmptyStringSchema, platform: platformSchema });\n\nconst libExceptionSchema = z.strictObject({\n workspace: nonEmptyStringSchema,\n libs: z.array(nonEmptyStringSchema).min(1),\n reason: nonEmptyStringSchema,\n});\n\n/**\n * The schema for the options of the platform check.\n */\nexport const optionsSchema = z.strictObject({\n workingDir: nonEmptyStringSchema.optional().default(() => cwd()),\n date: z\n .date()\n .optional()\n .default(() => new Date()),\n nvmrc: z\n .union([nonEmptyStringSchema, z.literal(false)])\n .optional()\n .default('.nvmrc'),\n droppedNodeLines: z.array(droppedNodeLineSchema).optional().default([]),\n presets: z\n .array(presetSchema)\n .optional()\n .default(() => DEFAULT_PRESETS.map(preset => ({ ...preset }))),\n workspaces: z.boolean().optional().default(true),\n libExceptions: z.array(libExceptionSchema).optional().default([]),\n maxDataAge: z.number().int().nonnegative().optional().default(DEFAULT_MAX_DATA_AGE),\n fetch: createFunctionSchema<FetchFn>()\n .optional()\n .default(() => globalThis.fetch),\n}) satisfies z.ZodType<Options>;\n\n/**\n * Parses the options of the platform check.\n *\n * @param input - The options to validate.\n * @returns The parsed options with defaults.\n * @throws {ValidationError} If the options are invalid.\n */\nexport const validateOptions = createValidationFunction(optionsSchema);\n"]}
@@ -0,0 +1,25 @@
1
+ import type { Options, Platform, PlatformCheckResult } from './platform-check.types.js';
2
+ /**
3
+ * Checks whether the Node.js and ECMAScript platform targets of a repository
4
+ * are still current.
5
+ *
6
+ * It checks `engines.node`, `@types/node` and `.nvmrc` against the Node.js
7
+ * release schedule, and the `lib`, `target` and `resolveJsonModule` of shared
8
+ * TypeScript configurations and of all workspaces against the APIs and syntax
9
+ * that the supported environments have: the lowest supported Node.js version
10
+ * and Baseline Widely Available browsers.
11
+ *
12
+ * @param options - The options of the check.
13
+ * @returns The result with all findings; empty findings mean everything is current.
14
+ * @throws {ValidationError} If the options are invalid.
15
+ * @throws {Error} If data cannot be fetched or a configuration cannot be read.
16
+ */
17
+ export declare function platformCheck(options?: Options): Promise<PlatformCheckResult>;
18
+ /**
19
+ * Derives the environment of a package from its manifest: `engines.node`
20
+ * alone is `node`, `browserslist` alone is `browser`, both are `universal`.
21
+ *
22
+ * @param packageJson - The manifest.
23
+ * @returns The environment, or `undefined` if the manifest declares neither.
24
+ */
25
+ export declare function getPlatform(packageJson: Record<string, unknown>): Platform | undefined;