@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,214 @@
1
+ import { access, readFile, realpath } from 'node:fs/promises';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { findUpPackage } from '@simbo/find-up-package';
6
+ import semver from 'semver';
7
+ const MILLISECONDS_PER_DAY = 86_400_000;
8
+ const FETCH_TIMEOUT = 30_000;
9
+ const OWN_DATA_PACKAGES = ['web-features', '@mdn/browser-compat-data'];
10
+ const BROWSERSLIST_DATA_PACKAGES = ['caniuse-lite', 'baseline-browser-mapping'];
11
+ /**
12
+ * Reads the manifest of the package that contains a file.
13
+ *
14
+ * @param file - An absolute file path inside the package.
15
+ * @returns The manifest, or `undefined` if there is no package.
16
+ */
17
+ async function readManifestOf(file) {
18
+ return (await findUpPackage({ workingDir: dirname(file) }))?.packageJson;
19
+ }
20
+ /**
21
+ * Reads the range of a dependency from a manifest.
22
+ *
23
+ * @param manifest - The manifest of the dependent.
24
+ * @param name - The dependency name.
25
+ * @returns The range, or `*` if the manifest does not declare it.
26
+ */
27
+ function getRange(manifest, name) {
28
+ const range = manifest?.dependencies?.[name];
29
+ return typeof range === 'string' ? range : '*';
30
+ }
31
+ /**
32
+ * Describes the installed version of a package that a file belongs to.
33
+ *
34
+ * @param file - An absolute file path inside the package.
35
+ * @param dependent - The manifest of the dependent.
36
+ * @returns The installed package, or `undefined` if it has no name or version.
37
+ */
38
+ async function describeInstalled(file, dependent) {
39
+ const manifest = await readManifestOf(file);
40
+ const { name, version } = manifest ?? {};
41
+ if (typeof name !== 'string' || typeof version !== 'string')
42
+ return undefined;
43
+ const dependentName = typeof dependent?.name === 'string' ? dependent.name : 'unknown';
44
+ return { name, version, range: getRange(dependent, name), dependent: dependentName };
45
+ }
46
+ /**
47
+ * Finds the installed versions of the data packages that this library uses:
48
+ * `web-features` and `@mdn/browser-compat-data`.
49
+ *
50
+ * @returns The installed packages.
51
+ * @throws {Error} If a package cannot be found.
52
+ */
53
+ export async function findOwnDataPackages() {
54
+ const own = await readManifestOf(fileURLToPath(import.meta.url));
55
+ return Promise.all(OWN_DATA_PACKAGES.map(async (name) => {
56
+ const found = await describeInstalled(fileURLToPath(import.meta.resolve(name)), own);
57
+ if (!found)
58
+ throw new Error(`Cannot find the installed package ${name}`);
59
+ return found;
60
+ }));
61
+ }
62
+ /**
63
+ * Finds the `browserslist` package that a directory resolves through its own
64
+ * `node_modules` folders and those of its parents. Unlike `require.resolve`,
65
+ * this ignores `NODE_PATH`, which package managers such as pnpm set for
66
+ * scripts to a folder with all hoisted packages.
67
+ *
68
+ * @param directory - An absolute directory.
69
+ * @returns The real path of the `browserslist` package, or `undefined`.
70
+ */
71
+ async function findBrowserslist(directory) {
72
+ let current;
73
+ try {
74
+ current = await realpath(directory);
75
+ }
76
+ catch {
77
+ return undefined;
78
+ }
79
+ for (;;) {
80
+ const candidate = join(current, 'node_modules', 'browserslist');
81
+ try {
82
+ await access(join(candidate, 'package.json'));
83
+ return await realpath(candidate);
84
+ }
85
+ catch {
86
+ // Not in this folder; continue with the parent.
87
+ }
88
+ if (dirname(current) === current)
89
+ return undefined;
90
+ current = dirname(current);
91
+ }
92
+ }
93
+ /**
94
+ * Finds the installed versions of the Browserslist data packages,
95
+ * `caniuse-lite` and `baseline-browser-mapping`, through the `browserslist`
96
+ * that each directory resolves.
97
+ *
98
+ * @param directories - Absolute directories with a `package.json`.
99
+ * @returns The distinct installed packages, sorted.
100
+ */
101
+ export async function findBrowserslistDataPackages(directories) {
102
+ const browserslists = new Set((await Promise.all(directories.map(async (directory) => findBrowserslist(directory)))).filter(path => path !== undefined));
103
+ const found = await Promise.all([...browserslists].map(async (browserslist) => {
104
+ const manifestPath = join(browserslist, 'package.json');
105
+ const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
106
+ const require = createRequire(manifestPath);
107
+ return Promise.all(BROWSERSLIST_DATA_PACKAGES.map(async (name) => {
108
+ try {
109
+ return await describeInstalled(require.resolve(name), manifest);
110
+ }
111
+ catch {
112
+ // Older versions of browserslist do not depend on all data packages.
113
+ return;
114
+ }
115
+ }));
116
+ }));
117
+ const unique = new Map(found
118
+ .flat()
119
+ .filter(value => value !== undefined)
120
+ .map(value => [`${value.name}@${value.version}@${value.range}`, value]));
121
+ return [...unique.values()].toSorted((a, b) => a.name.localeCompare(b.name) || a.version.localeCompare(b.version, 'en', { numeric: true }));
122
+ }
123
+ /**
124
+ * Fetches the versions, publish dates and the latest version of a package
125
+ * from the npm registry.
126
+ *
127
+ * @param name - The package name.
128
+ * @param fetchFn - The function to fetch the registry data with.
129
+ * @returns The registry data.
130
+ * @throws {Error} If the registry data cannot be fetched.
131
+ */
132
+ export async function fetchRegistryPackage(name, fetchFn = globalThis.fetch) {
133
+ const response = await fetchFn(`https://registry.npmjs.org/${encodeURIComponent(name)}`, {
134
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
135
+ });
136
+ if (!response.ok) {
137
+ throw new Error(`Failed to fetch ${name} from the npm registry: ${response.status} ${response.statusText}`);
138
+ }
139
+ const document = (await response.json());
140
+ return {
141
+ versions: Object.keys(document.versions ?? {}),
142
+ time: document.time ?? {},
143
+ latest: document['dist-tags']?.latest,
144
+ };
145
+ }
146
+ /**
147
+ * Combines an installed package with its registry data.
148
+ *
149
+ * @param installed - The installed package.
150
+ * @param registry - The registry data of the package.
151
+ * @returns The version information.
152
+ */
153
+ export function describeDataPackage(installed, registry) {
154
+ const { name, version, range, dependent } = installed;
155
+ const stable = registry.versions.filter(value => semver.prerelease(value) === null);
156
+ const latestInRange = semver.maxSatisfying(stable, range) ?? version;
157
+ const latest = registry.latest ?? latestInRange;
158
+ return {
159
+ name,
160
+ dependent,
161
+ range,
162
+ installed: version,
163
+ published: registry.time[version] ?? '',
164
+ latestInRange: semver.gt(version, latestInRange) ? version : latestInRange,
165
+ latest,
166
+ latestPublished: registry.time[latest] ?? '',
167
+ };
168
+ }
169
+ /**
170
+ * Calculates the age of a publish date in whole days.
171
+ *
172
+ * @param published - The publish date as an ISO date string.
173
+ * @param date - The date to calculate the age at.
174
+ * @returns The age in days, `NaN` if the publish date is unknown.
175
+ */
176
+ function getAge(published, date) {
177
+ return Math.floor((date.getTime() - new Date(published).getTime()) / MILLISECONDS_PER_DAY);
178
+ }
179
+ /**
180
+ * Checks whether an installed data package is outdated:
181
+ *
182
+ * - a newer version within the range exists, and the installed one is older
183
+ * than the maximum age, which a lockfile update resolves;
184
+ * - a version outside the range has been the latest for longer than the
185
+ * maximum age, which an update of the dependent resolves.
186
+ *
187
+ * @param data - The version information.
188
+ * @param date - The date to check against.
189
+ * @param maxAge - The maximum age in days.
190
+ * @returns The findings.
191
+ */
192
+ export function checkDataPackage(data, date, maxAge) {
193
+ const findings = [];
194
+ const age = getAge(data.published, date);
195
+ if (data.installed !== data.latestInRange && age > maxAge) {
196
+ findings.push({
197
+ check: 'data',
198
+ subject: data.name,
199
+ change: 'update',
200
+ message: `${data.name} ${data.installed} is ${age} days old; update to ${data.latestInRange}`,
201
+ });
202
+ }
203
+ const latestAge = getAge(data.latestPublished, date);
204
+ if (!semver.satisfies(data.latest, data.range) && semver.gt(data.latest, data.latestInRange) && latestAge > maxAge) {
205
+ findings.push({
206
+ check: 'data',
207
+ subject: data.dependent,
208
+ change: 'update',
209
+ message: `${data.dependent} requires ${data.name} ${data.range}, but ${data.latest} is ${latestAge} days old; update ${data.dependent}`,
210
+ });
211
+ }
212
+ return findings;
213
+ }
214
+ //# sourceMappingURL=data-packages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-packages.js","sourceRoot":"","sources":["../src/data-packages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC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AC1D,QAAQ,CAAC,IAAI,CAAC;YACZ,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,OAAO,GAAG,wBAAwB,IAAI,CAAC,aAAa,EAAE;SAC9F,CAAC,CAAC;IACL,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,SAAS,GAAG,MAAM,EAAE,CAAC;QACnH,QAAQ,CAAC,IAAI,CAAC;YACZ,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI,CAAC,SAAS;YACvB,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,MAAM,OAAO,SAAS,qBAAqB,IAAI,CAAC,SAAS,EAAE;SACxI,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { access, readFile, realpath } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { findUpPackage } from '@simbo/find-up-package';\nimport semver from 'semver';\n\nimport type { DataPackage, FetchFn, Finding, InstalledPackage, RegistryPackage } from './platform-check.types.js';\n\nconst MILLISECONDS_PER_DAY = 86_400_000;\n\nconst FETCH_TIMEOUT = 30_000;\n\nconst OWN_DATA_PACKAGES = ['web-features', '@mdn/browser-compat-data'];\n\nconst BROWSERSLIST_DATA_PACKAGES = ['caniuse-lite', 'baseline-browser-mapping'];\n\n/**\n * Reads the manifest of the package that contains a file.\n *\n * @param file - An absolute file path inside the package.\n * @returns The manifest, or `undefined` if there is no package.\n */\nasync function readManifestOf(file: string): Promise<Record<string, unknown> | undefined> {\n return (await findUpPackage({ workingDir: dirname(file) }))?.packageJson;\n}\n\n/**\n * Reads the range of a dependency from a manifest.\n *\n * @param manifest - The manifest of the dependent.\n * @param name - The dependency name.\n * @returns The range, or `*` if the manifest does not declare it.\n */\nfunction getRange(manifest: Record<string, unknown> | undefined, name: string): string {\n const range = (manifest?.dependencies as Partial<Record<string, unknown>> | undefined)?.[name];\n return typeof range === 'string' ? range : '*';\n}\n\n/**\n * Describes the installed version of a package that a file belongs to.\n *\n * @param file - An absolute file path inside the package.\n * @param dependent - The manifest of the dependent.\n * @returns The installed package, or `undefined` if it has no name or version.\n */\nasync function describeInstalled(\n file: string,\n dependent: Record<string, unknown> | undefined,\n): Promise<InstalledPackage | undefined> {\n const manifest = await readManifestOf(file);\n const { name, version } = manifest ?? {};\n if (typeof name !== 'string' || typeof version !== 'string') return undefined;\n const dependentName = typeof dependent?.name === 'string' ? dependent.name : 'unknown';\n return { name, version, range: getRange(dependent, name), dependent: dependentName };\n}\n\n/**\n * Finds the installed versions of the data packages that this library uses:\n * `web-features` and `@mdn/browser-compat-data`.\n *\n * @returns The installed packages.\n * @throws {Error} If a package cannot be found.\n */\nexport async function findOwnDataPackages(): Promise<InstalledPackage[]> {\n const own = await readManifestOf(fileURLToPath(import.meta.url));\n return Promise.all(\n OWN_DATA_PACKAGES.map(async name => {\n const found = await describeInstalled(fileURLToPath(import.meta.resolve(name)), own);\n if (!found) throw new Error(`Cannot find the installed package ${name}`);\n return found;\n }),\n );\n}\n\n/**\n * Finds the `browserslist` package that a directory resolves through its own\n * `node_modules` folders and those of its parents. Unlike `require.resolve`,\n * this ignores `NODE_PATH`, which package managers such as pnpm set for\n * scripts to a folder with all hoisted packages.\n *\n * @param directory - An absolute directory.\n * @returns The real path of the `browserslist` package, or `undefined`.\n */\nasync function findBrowserslist(directory: string): Promise<string | undefined> {\n let current: string;\n try {\n current = await realpath(directory);\n } catch {\n return undefined;\n }\n for (;;) {\n const candidate = join(current, 'node_modules', 'browserslist');\n try {\n await access(join(candidate, 'package.json'));\n return await realpath(candidate);\n } catch {\n // Not in this folder; continue with the parent.\n }\n if (dirname(current) === current) return undefined;\n current = dirname(current);\n }\n}\n\n/**\n * Finds the installed versions of the Browserslist data packages,\n * `caniuse-lite` and `baseline-browser-mapping`, through the `browserslist`\n * that each directory resolves.\n *\n * @param directories - Absolute directories with a `package.json`.\n * @returns The distinct installed packages, sorted.\n */\nexport async function findBrowserslistDataPackages(directories: string[]): Promise<InstalledPackage[]> {\n const browserslists = new Set(\n (await Promise.all(directories.map(async directory => findBrowserslist(directory)))).filter(\n path => path !== undefined,\n ),\n );\n const found = await Promise.all(\n [...browserslists].map(async browserslist => {\n const manifestPath = join(browserslist, 'package.json');\n const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) as Record<string, unknown>;\n const require = createRequire(manifestPath);\n return Promise.all(\n BROWSERSLIST_DATA_PACKAGES.map(async name => {\n try {\n return await describeInstalled(require.resolve(name), manifest);\n } catch {\n // Older versions of browserslist do not depend on all data packages.\n return;\n }\n }),\n );\n }),\n );\n const unique = new Map(\n found\n .flat()\n .filter(value => value !== undefined)\n .map(value => [`${value.name}@${value.version}@${value.range}`, value]),\n );\n return [...unique.values()].toSorted(\n (a, b) => a.name.localeCompare(b.name) || a.version.localeCompare(b.version, 'en', { numeric: true }),\n );\n}\n\n/**\n * Fetches the versions, publish dates and the latest version of a package\n * from the npm registry.\n *\n * @param name - The package name.\n * @param fetchFn - The function to fetch the registry data with.\n * @returns The registry data.\n * @throws {Error} If the registry data cannot be fetched.\n */\nexport async function fetchRegistryPackage(\n name: string,\n fetchFn: FetchFn = globalThis.fetch,\n): Promise<RegistryPackage> {\n const response = await fetchFn(`https://registry.npmjs.org/${encodeURIComponent(name)}`, {\n signal: AbortSignal.timeout(FETCH_TIMEOUT),\n });\n if (!response.ok) {\n throw new Error(`Failed to fetch ${name} from the npm registry: ${response.status} ${response.statusText}`);\n }\n const document = (await response.json()) as {\n versions?: Partial<Record<string, unknown>>;\n time?: Partial<Record<string, string>>;\n 'dist-tags'?: Partial<Record<string, string>>;\n };\n return {\n versions: Object.keys(document.versions ?? {}),\n time: document.time ?? {},\n latest: document['dist-tags']?.latest,\n };\n}\n\n/**\n * Combines an installed package with its registry data.\n *\n * @param installed - The installed package.\n * @param registry - The registry data of the package.\n * @returns The version information.\n */\nexport function describeDataPackage(installed: InstalledPackage, registry: RegistryPackage): DataPackage {\n const { name, version, range, dependent } = installed;\n const stable = registry.versions.filter(value => semver.prerelease(value) === null);\n const latestInRange = semver.maxSatisfying(stable, range) ?? version;\n const latest = registry.latest ?? latestInRange;\n return {\n name,\n dependent,\n range,\n installed: version,\n published: registry.time[version] ?? '',\n latestInRange: semver.gt(version, latestInRange) ? version : latestInRange,\n latest,\n latestPublished: registry.time[latest] ?? '',\n };\n}\n\n/**\n * Calculates the age of a publish date in whole days.\n *\n * @param published - The publish date as an ISO date string.\n * @param date - The date to calculate the age at.\n * @returns The age in days, `NaN` if the publish date is unknown.\n */\nfunction getAge(published: string, date: Date): number {\n return Math.floor((date.getTime() - new Date(published).getTime()) / MILLISECONDS_PER_DAY);\n}\n\n/**\n * Checks whether an installed data package is outdated:\n *\n * - a newer version within the range exists, and the installed one is older\n * than the maximum age, which a lockfile update resolves;\n * - a version outside the range has been the latest for longer than the\n * maximum age, which an update of the dependent resolves.\n *\n * @param data - The version information.\n * @param date - The date to check against.\n * @param maxAge - The maximum age in days.\n * @returns The findings.\n */\nexport function checkDataPackage(data: DataPackage, date: Date, maxAge: number): Finding[] {\n const findings: Finding[] = [];\n const age = getAge(data.published, date);\n if (data.installed !== data.latestInRange && age > maxAge) {\n findings.push({\n check: 'data',\n subject: data.name,\n change: 'update',\n message: `${data.name} ${data.installed} is ${age} days old; update to ${data.latestInRange}`,\n });\n }\n const latestAge = getAge(data.latestPublished, date);\n if (!semver.satisfies(data.latest, data.range) && semver.gt(data.latest, data.latestInRange) && latestAge > maxAge) {\n findings.push({\n check: 'data',\n subject: data.dependent,\n change: 'update',\n message: `${data.dependent} requires ${data.name} ${data.range}, but ${data.latest} is ${latestAge} days old; update ${data.dependent}`,\n });\n }\n return findings;\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The year that stands for ES5 and older versions.
3
+ */
4
+ export declare const ES5_YEAR = 2009;
5
+ /**
6
+ * The first ECMAScript version that the mapping covers. Sub-libs and syntax of
7
+ * older versions are assumed to be supported everywhere.
8
+ */
9
+ export declare const ES_MAPPING_FLOOR = 2022;
10
+ /**
11
+ * The features of each TypeScript ECMAScript sub-lib, as browser-compat-data
12
+ * keys. A sub-lib is available where all of its features are.
13
+ */
14
+ export declare const LIB_FEATURES: Readonly<Partial<Record<string, readonly string[]>>>;
15
+ /**
16
+ * The syntax features that TypeScript transpiles or rejects below a `target`,
17
+ * per ECMAScript version, as browser-compat-data keys. A version without such
18
+ * syntax has an empty list. A `target` is possible where the syntax of all
19
+ * versions up to it is supported.
20
+ */
21
+ export declare const SYNTAX_FEATURES: Readonly<Partial<Record<number, readonly string[]>>>;
22
+ /**
23
+ * The features of standard JSON modules, as browser-compat-data keys.
24
+ * `resolveJsonModule` is possible where all of them are supported.
25
+ */
26
+ export declare const JSON_MODULES_FEATURES: readonly string[];
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The year that stands for ES5 and older versions.
3
+ */
4
+ export const ES5_YEAR = 2009;
5
+ /**
6
+ * The first ECMAScript version that the mapping covers. Sub-libs and syntax of
7
+ * older versions are assumed to be supported everywhere.
8
+ */
9
+ export const ES_MAPPING_FLOOR = 2022;
10
+ /**
11
+ * The features of each TypeScript ECMAScript sub-lib, as browser-compat-data
12
+ * keys. A sub-lib is available where all of its features are.
13
+ */
14
+ export const LIB_FEATURES = {
15
+ 'es2022.array': ['javascript.builtins.Array.at', 'javascript.builtins.TypedArray.at'],
16
+ 'es2022.error': ['javascript.builtins.Error.cause', 'javascript.builtins.Error.Error.options_cause_parameter'],
17
+ 'es2022.intl': [
18
+ 'javascript.builtins.Intl.Segmenter',
19
+ 'javascript.builtins.Intl.Segmenter.segment',
20
+ 'javascript.builtins.Intl.Segments.containing',
21
+ 'javascript.builtins.Intl.supportedValuesOf',
22
+ ],
23
+ 'es2022.object': ['javascript.builtins.Object.hasOwn'],
24
+ 'es2022.regexp': ['javascript.builtins.RegExp.hasIndices'],
25
+ 'es2022.string': ['javascript.builtins.String.at'],
26
+ 'es2023.array': [
27
+ 'javascript.builtins.Array.findLast',
28
+ 'javascript.builtins.Array.findLastIndex',
29
+ 'javascript.builtins.Array.toReversed',
30
+ 'javascript.builtins.Array.toSorted',
31
+ 'javascript.builtins.Array.toSpliced',
32
+ 'javascript.builtins.Array.with',
33
+ 'javascript.builtins.TypedArray.findLast',
34
+ 'javascript.builtins.TypedArray.findLastIndex',
35
+ 'javascript.builtins.TypedArray.toReversed',
36
+ 'javascript.builtins.TypedArray.toSorted',
37
+ 'javascript.builtins.TypedArray.with',
38
+ ],
39
+ 'es2023.collection': [
40
+ 'javascript.builtins.WeakMap.symbol_as_keys',
41
+ 'javascript.builtins.WeakSet.symbol_as_keys',
42
+ 'javascript.builtins.WeakRef.WeakRef.symbol_as_target',
43
+ 'javascript.builtins.FinalizationRegistry.register.symbol_as_target',
44
+ ],
45
+ 'es2023.intl': [
46
+ 'javascript.builtins.Intl.NumberFormat.formatRange',
47
+ 'javascript.builtins.Intl.NumberFormat.formatRangeToParts',
48
+ 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingIncrement_parameter',
49
+ 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingMode_parameter',
50
+ 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingPriority_parameter',
51
+ 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_trailingZeroDisplay_parameter',
52
+ 'javascript.builtins.Intl.NumberFormat.format.number_parameter-string_decimal',
53
+ ],
54
+ 'es2024.arraybuffer': [
55
+ 'javascript.builtins.ArrayBuffer.ArrayBuffer.maxByteLength_option',
56
+ 'javascript.builtins.ArrayBuffer.maxByteLength',
57
+ 'javascript.builtins.ArrayBuffer.resizable',
58
+ 'javascript.builtins.ArrayBuffer.resize',
59
+ 'javascript.builtins.ArrayBuffer.detached',
60
+ 'javascript.builtins.ArrayBuffer.transfer',
61
+ 'javascript.builtins.ArrayBuffer.transferToFixedLength',
62
+ ],
63
+ 'es2024.collection': ['javascript.builtins.Map.groupBy'],
64
+ 'es2024.object': ['javascript.builtins.Object.groupBy'],
65
+ 'es2024.promise': ['javascript.builtins.Promise.withResolvers'],
66
+ 'es2024.regexp': ['javascript.builtins.RegExp.unicodeSets'],
67
+ 'es2024.sharedmemory': [
68
+ 'javascript.builtins.Atomics.waitAsync',
69
+ 'javascript.builtins.SharedArrayBuffer.SharedArrayBuffer.maxByteLength_option',
70
+ 'javascript.builtins.SharedArrayBuffer.grow',
71
+ 'javascript.builtins.SharedArrayBuffer.growable',
72
+ 'javascript.builtins.SharedArrayBuffer.maxByteLength',
73
+ ],
74
+ 'es2024.string': ['javascript.builtins.String.isWellFormed', 'javascript.builtins.String.toWellFormed'],
75
+ 'es2025.collection': [
76
+ 'javascript.builtins.Set.difference',
77
+ 'javascript.builtins.Set.intersection',
78
+ 'javascript.builtins.Set.isDisjointFrom',
79
+ 'javascript.builtins.Set.isSubsetOf',
80
+ 'javascript.builtins.Set.isSupersetOf',
81
+ 'javascript.builtins.Set.symmetricDifference',
82
+ 'javascript.builtins.Set.union',
83
+ ],
84
+ 'es2025.float16': [
85
+ 'javascript.builtins.Float16Array',
86
+ 'javascript.builtins.Math.f16round',
87
+ 'javascript.builtins.DataView.getFloat16',
88
+ 'javascript.builtins.DataView.setFloat16',
89
+ ],
90
+ 'es2025.intl': [
91
+ 'javascript.builtins.Intl.DurationFormat',
92
+ 'javascript.builtins.Intl.DurationFormat.format',
93
+ 'javascript.builtins.Intl.DurationFormat.formatToParts',
94
+ 'javascript.builtins.Intl.DurationFormat.resolvedOptions',
95
+ ],
96
+ 'es2025.iterator': [
97
+ 'javascript.builtins.Iterator.Iterator',
98
+ 'javascript.builtins.Iterator.drop',
99
+ 'javascript.builtins.Iterator.every',
100
+ 'javascript.builtins.Iterator.filter',
101
+ 'javascript.builtins.Iterator.find',
102
+ 'javascript.builtins.Iterator.flatMap',
103
+ 'javascript.builtins.Iterator.forEach',
104
+ 'javascript.builtins.Iterator.from',
105
+ 'javascript.builtins.Iterator.map',
106
+ 'javascript.builtins.Iterator.reduce',
107
+ 'javascript.builtins.Iterator.some',
108
+ 'javascript.builtins.Iterator.take',
109
+ 'javascript.builtins.Iterator.toArray',
110
+ ],
111
+ 'es2025.promise': ['javascript.builtins.Promise.try'],
112
+ 'es2025.regexp': ['javascript.builtins.RegExp.escape'],
113
+ };
114
+ /**
115
+ * The syntax features that TypeScript transpiles or rejects below a `target`,
116
+ * per ECMAScript version, as browser-compat-data keys. A version without such
117
+ * syntax has an empty list. A `target` is possible where the syntax of all
118
+ * versions up to it is supported.
119
+ */
120
+ export const SYNTAX_FEATURES = {
121
+ 2022: [
122
+ 'javascript.classes.private_class_fields',
123
+ 'javascript.classes.private_class_fields_in',
124
+ 'javascript.classes.private_class_methods',
125
+ 'javascript.classes.public_class_fields',
126
+ 'javascript.classes.static.initialization_blocks',
127
+ // The `d` flag of regular expressions.
128
+ 'javascript.builtins.RegExp.hasIndices',
129
+ ],
130
+ 2023: [],
131
+ // The `v` flag of regular expressions.
132
+ 2024: ['javascript.builtins.RegExp.unicodeSets'],
133
+ 2025: [
134
+ 'javascript.regular_expressions.modifier',
135
+ 'javascript.regular_expressions.named_capturing_group.duplicate_named_capturing_groups',
136
+ ],
137
+ };
138
+ /**
139
+ * The features of standard JSON modules, as browser-compat-data keys.
140
+ * `resolveJsonModule` is possible where all of them are supported.
141
+ */
142
+ export const JSON_MODULES_FEATURES = ['javascript.statements.import.import_attributes.type_json'];
143
+ //# sourceMappingURL=es-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"es-mapping.js","sourceRoot":"","sources":["../src/es-mapping.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAyD;IAChF,cAAc,EAAE,CAAC,8BAA8B,EAAE,mCAAmC,CAAC;IACrF,cAAc,EAAE,CAAC,iCAAiC,EAAE,yDAAyD,CAAC;IAC9G,aAAa,EAAE;QACb,oCAAoC;QACpC,4CAA4C;QAC5C,8CAA8C;QAC9C,4CAA4C;KAC7C;IACD,eAAe,EAAE,CAAC,mCAAmC,CAAC;IACtD,eAAe,EAAE,CAAC,uCAAuC,CAAC;IAC1D,eAAe,EAAE,CAAC,+BAA+B,CAAC;IAClD,cAAc,EAAE;QACd,oCAAoC;QACpC,yCAAyC;QACzC,sCAAsC;QACtC,oCAAoC;QACpC,qCAAqC;QACrC,gCAAgC;QAChC,yCAAyC;QACzC,8CAA8C;QAC9C,2CAA2C;QAC3C,yCAAyC;QACzC,qCAAqC;KACtC;IACD,mBAAmB,EAAE;QACnB,4CAA4C;QAC5C,4CAA4C;QAC5C,sDAAsD;QACtD,oEAAoE;KACrE;IACD,aAAa,EAAE;QACb,mDAAmD;QACnD,0DAA0D;QAC1D,0GAA0G;QAC1G,qGAAqG;QACrG,yGAAyG;QACzG,4GAA4G;QAC5G,8EAA8E;KAC/E;IACD,oBAAoB,EAAE;QACpB,kEAAkE;QAClE,+CAA+C;QAC/C,2CAA2C;QAC3C,wCAAwC;QACxC,0CAA0C;QAC1C,0CAA0C;QAC1C,uDAAuD;KACxD;IACD,mBAAmB,EAAE,CAAC,iCAAiC,CAAC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qB,GAAsB,CAAC,0DAA0D,CAAC,CAAC","sourcesContent":["/**\n * The year that stands for ES5 and older versions.\n */\nexport const ES5_YEAR = 2009;\n\n/**\n * The first ECMAScript version that the mapping covers. Sub-libs and syntax of\n * older versions are assumed to be supported everywhere.\n */\nexport const ES_MAPPING_FLOOR = 2022;\n\n/**\n * The features of each TypeScript ECMAScript sub-lib, as browser-compat-data\n * keys. A sub-lib is available where all of its features are.\n */\nexport const LIB_FEATURES: Readonly<Partial<Record<string, readonly string[]>>> = {\n 'es2022.array': ['javascript.builtins.Array.at', 'javascript.builtins.TypedArray.at'],\n 'es2022.error': ['javascript.builtins.Error.cause', 'javascript.builtins.Error.Error.options_cause_parameter'],\n 'es2022.intl': [\n 'javascript.builtins.Intl.Segmenter',\n 'javascript.builtins.Intl.Segmenter.segment',\n 'javascript.builtins.Intl.Segments.containing',\n 'javascript.builtins.Intl.supportedValuesOf',\n ],\n 'es2022.object': ['javascript.builtins.Object.hasOwn'],\n 'es2022.regexp': ['javascript.builtins.RegExp.hasIndices'],\n 'es2022.string': ['javascript.builtins.String.at'],\n 'es2023.array': [\n 'javascript.builtins.Array.findLast',\n 'javascript.builtins.Array.findLastIndex',\n 'javascript.builtins.Array.toReversed',\n 'javascript.builtins.Array.toSorted',\n 'javascript.builtins.Array.toSpliced',\n 'javascript.builtins.Array.with',\n 'javascript.builtins.TypedArray.findLast',\n 'javascript.builtins.TypedArray.findLastIndex',\n 'javascript.builtins.TypedArray.toReversed',\n 'javascript.builtins.TypedArray.toSorted',\n 'javascript.builtins.TypedArray.with',\n ],\n 'es2023.collection': [\n 'javascript.builtins.WeakMap.symbol_as_keys',\n 'javascript.builtins.WeakSet.symbol_as_keys',\n 'javascript.builtins.WeakRef.WeakRef.symbol_as_target',\n 'javascript.builtins.FinalizationRegistry.register.symbol_as_target',\n ],\n 'es2023.intl': [\n 'javascript.builtins.Intl.NumberFormat.formatRange',\n 'javascript.builtins.Intl.NumberFormat.formatRangeToParts',\n 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingIncrement_parameter',\n 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingMode_parameter',\n 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_roundingPriority_parameter',\n 'javascript.builtins.Intl.NumberFormat.NumberFormat.options_parameter.options_trailingZeroDisplay_parameter',\n 'javascript.builtins.Intl.NumberFormat.format.number_parameter-string_decimal',\n ],\n 'es2024.arraybuffer': [\n 'javascript.builtins.ArrayBuffer.ArrayBuffer.maxByteLength_option',\n 'javascript.builtins.ArrayBuffer.maxByteLength',\n 'javascript.builtins.ArrayBuffer.resizable',\n 'javascript.builtins.ArrayBuffer.resize',\n 'javascript.builtins.ArrayBuffer.detached',\n 'javascript.builtins.ArrayBuffer.transfer',\n 'javascript.builtins.ArrayBuffer.transferToFixedLength',\n ],\n 'es2024.collection': ['javascript.builtins.Map.groupBy'],\n 'es2024.object': ['javascript.builtins.Object.groupBy'],\n 'es2024.promise': ['javascript.builtins.Promise.withResolvers'],\n 'es2024.regexp': ['javascript.builtins.RegExp.unicodeSets'],\n 'es2024.sharedmemory': [\n 'javascript.builtins.Atomics.waitAsync',\n 'javascript.builtins.SharedArrayBuffer.SharedArrayBuffer.maxByteLength_option',\n 'javascript.builtins.SharedArrayBuffer.grow',\n 'javascript.builtins.SharedArrayBuffer.growable',\n 'javascript.builtins.SharedArrayBuffer.maxByteLength',\n ],\n 'es2024.string': ['javascript.builtins.String.isWellFormed', 'javascript.builtins.String.toWellFormed'],\n 'es2025.collection': [\n 'javascript.builtins.Set.difference',\n 'javascript.builtins.Set.intersection',\n 'javascript.builtins.Set.isDisjointFrom',\n 'javascript.builtins.Set.isSubsetOf',\n 'javascript.builtins.Set.isSupersetOf',\n 'javascript.builtins.Set.symmetricDifference',\n 'javascript.builtins.Set.union',\n ],\n 'es2025.float16': [\n 'javascript.builtins.Float16Array',\n 'javascript.builtins.Math.f16round',\n 'javascript.builtins.DataView.getFloat16',\n 'javascript.builtins.DataView.setFloat16',\n ],\n 'es2025.intl': [\n 'javascript.builtins.Intl.DurationFormat',\n 'javascript.builtins.Intl.DurationFormat.format',\n 'javascript.builtins.Intl.DurationFormat.formatToParts',\n 'javascript.builtins.Intl.DurationFormat.resolvedOptions',\n ],\n 'es2025.iterator': [\n 'javascript.builtins.Iterator.Iterator',\n 'javascript.builtins.Iterator.drop',\n 'javascript.builtins.Iterator.every',\n 'javascript.builtins.Iterator.filter',\n 'javascript.builtins.Iterator.find',\n 'javascript.builtins.Iterator.flatMap',\n 'javascript.builtins.Iterator.forEach',\n 'javascript.builtins.Iterator.from',\n 'javascript.builtins.Iterator.map',\n 'javascript.builtins.Iterator.reduce',\n 'javascript.builtins.Iterator.some',\n 'javascript.builtins.Iterator.take',\n 'javascript.builtins.Iterator.toArray',\n ],\n 'es2025.promise': ['javascript.builtins.Promise.try'],\n 'es2025.regexp': ['javascript.builtins.RegExp.escape'],\n};\n\n/**\n * The syntax features that TypeScript transpiles or rejects below a `target`,\n * per ECMAScript version, as browser-compat-data keys. A version without such\n * syntax has an empty list. A `target` is possible where the syntax of all\n * versions up to it is supported.\n */\nexport const SYNTAX_FEATURES: Readonly<Partial<Record<number, readonly string[]>>> = {\n 2022: [\n 'javascript.classes.private_class_fields',\n 'javascript.classes.private_class_fields_in',\n 'javascript.classes.private_class_methods',\n 'javascript.classes.public_class_fields',\n 'javascript.classes.static.initialization_blocks',\n // The `d` flag of regular expressions.\n 'javascript.builtins.RegExp.hasIndices',\n ],\n 2023: [],\n // The `v` flag of regular expressions.\n 2024: ['javascript.builtins.RegExp.unicodeSets'],\n 2025: [\n 'javascript.regular_expressions.modifier',\n 'javascript.regular_expressions.named_capturing_group.duplicate_named_capturing_groups',\n ],\n};\n\n/**\n * The features of standard JSON modules, as browser-compat-data keys.\n * `resolveJsonModule` is possible where all of them are supported.\n */\nexport const JSON_MODULES_FEATURES: readonly string[] = ['javascript.statements.import.import_attributes.type_json'];\n"]}
@@ -0,0 +1,48 @@
1
+ import type { CompatData, Platform, PlatformTargets } from './platform-check.types.js';
2
+ /**
3
+ * Returns the ECMAScript version of a sub-lib as a year.
4
+ *
5
+ * @param lib - The sub-lib, such as `es2024.promise`.
6
+ * @returns The year, `2009` for `es5`.
7
+ */
8
+ export declare function getLibYear(lib: string): number;
9
+ /**
10
+ * Derives the TypeScript settings that an environment supports.
11
+ *
12
+ * @param platform - The environment.
13
+ * @param nodeVersion - The lowest supported Node.js version; required for `node` and `universal`.
14
+ * @param compatData - The compatibility checks.
15
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
16
+ * @returns The libs, the target and whether JSON modules are supported.
17
+ * @throws {Error} If `nodeVersion` is missing for `node` or `universal`.
18
+ */
19
+ export declare function getExpectedTargets(platform: Platform, nodeVersion: string | undefined, compatData: CompatData, esLibs: string[]): PlatformTargets;
20
+ /**
21
+ * Finds the ECMAScript sub-libs and versions that TypeScript knows but the
22
+ * mapping does not cover.
23
+ *
24
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
25
+ * @param targets - The ECMAScript versions that TypeScript accepts as `target`.
26
+ * @returns The unmapped sub-libs and versions.
27
+ */
28
+ export declare function getUnmapped(esLibs: string[], targets: number[]): {
29
+ libs: string[];
30
+ targets: number[];
31
+ };
32
+ /**
33
+ * Finds the keys of the mapping that the installed browser-compat-data or
34
+ * web-features do not know or have no data for.
35
+ *
36
+ * @param compatData - The compatibility checks.
37
+ * @returns The unknown keys, sorted.
38
+ */
39
+ export declare function getUnknownKeys(compatData: CompatData): string[];
40
+ /**
41
+ * Formats ECMAScript sub-libs compactly: the highest version whose sub-libs are
42
+ * all included, followed by the included sub-libs of newer versions.
43
+ *
44
+ * @param libs - The included sub-libs.
45
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
46
+ * @returns The formatted libs, such as `ES2023 + es2024.object, es2024.promise`.
47
+ */
48
+ export declare function formatLibs(libs: string[], esLibs: string[]): string;
@@ -0,0 +1,93 @@
1
+ import { ES_MAPPING_FLOOR, ES5_YEAR, JSON_MODULES_FEATURES, LIB_FEATURES, SYNTAX_FEATURES } from './es-mapping.js';
2
+ import { formatTarget } from './typescript-libs.js';
3
+ /**
4
+ * Returns the ECMAScript version of a sub-lib as a year.
5
+ *
6
+ * @param lib - The sub-lib, such as `es2024.promise`.
7
+ * @returns The year, `2009` for `es5`.
8
+ */
9
+ export function getLibYear(lib) {
10
+ const year = /^es(?<year>\d{4})\b/u.exec(lib)?.groups?.year;
11
+ return year === undefined ? ES5_YEAR : Number(year);
12
+ }
13
+ /**
14
+ * Derives the TypeScript settings that an environment supports.
15
+ *
16
+ * @param platform - The environment.
17
+ * @param nodeVersion - The lowest supported Node.js version; required for `node` and `universal`.
18
+ * @param compatData - The compatibility checks.
19
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
20
+ * @returns The libs, the target and whether JSON modules are supported.
21
+ * @throws {Error} If `nodeVersion` is missing for `node` or `universal`.
22
+ */
23
+ export function getExpectedTargets(platform, nodeVersion, compatData, esLibs) {
24
+ if (platform !== 'browser' && nodeVersion === undefined) {
25
+ throw new Error(`The ${platform} environment requires a Node.js version from engines.node`);
26
+ }
27
+ const isSupported = (key) => (platform === 'node' || compatData.isWidelyAvailable(key)) &&
28
+ (platform === 'browser' || compatData.isSupportedByNode(key, nodeVersion ?? ''));
29
+ const libs = esLibs.filter(lib => {
30
+ if (getLibYear(lib) < ES_MAPPING_FLOOR)
31
+ return true;
32
+ const keys = LIB_FEATURES[lib];
33
+ return keys?.every(key => isSupported(key)) ?? false;
34
+ });
35
+ let target = ES_MAPPING_FLOOR - 1;
36
+ const syntax = Object.entries(SYNTAX_FEATURES).toSorted(([a], [b]) => Number(a) - Number(b));
37
+ for (const [year, keys = []] of syntax) {
38
+ if (keys.some(key => !isSupported(key)))
39
+ break;
40
+ target = Number(year);
41
+ }
42
+ return { libs, target, resolveJsonModule: JSON_MODULES_FEATURES.every(key => isSupported(key)) };
43
+ }
44
+ /**
45
+ * Finds the ECMAScript sub-libs and versions that TypeScript knows but the
46
+ * mapping does not cover.
47
+ *
48
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
49
+ * @param targets - The ECMAScript versions that TypeScript accepts as `target`.
50
+ * @returns The unmapped sub-libs and versions.
51
+ */
52
+ export function getUnmapped(esLibs, targets) {
53
+ return {
54
+ libs: esLibs.filter(lib => getLibYear(lib) >= ES_MAPPING_FLOOR && LIB_FEATURES[lib] === undefined),
55
+ targets: targets.filter(year => year >= ES_MAPPING_FLOOR && SYNTAX_FEATURES[year] === undefined),
56
+ };
57
+ }
58
+ /**
59
+ * Finds the keys of the mapping that the installed browser-compat-data or
60
+ * web-features do not know or have no data for.
61
+ *
62
+ * @param compatData - The compatibility checks.
63
+ * @returns The unknown keys, sorted.
64
+ */
65
+ export function getUnknownKeys(compatData) {
66
+ const keys = [
67
+ ...Object.values(LIB_FEATURES).flat(),
68
+ ...Object.values(SYNTAX_FEATURES).flat(),
69
+ ...JSON_MODULES_FEATURES,
70
+ ].filter(key => key !== undefined);
71
+ return [...new Set(keys)].filter(key => !compatData.isKnown(key)).toSorted((a, b) => a.localeCompare(b));
72
+ }
73
+ /**
74
+ * Formats ECMAScript sub-libs compactly: the highest version whose sub-libs are
75
+ * all included, followed by the included sub-libs of newer versions.
76
+ *
77
+ * @param libs - The included sub-libs.
78
+ * @param esLibs - The ECMAScript sub-libs that TypeScript knows.
79
+ * @returns The formatted libs, such as `ES2023 + es2024.object, es2024.promise`.
80
+ */
81
+ export function formatLibs(libs, esLibs) {
82
+ const years = [...new Set(esLibs.map(lib => getLibYear(lib)))].toSorted((a, b) => a - b);
83
+ let complete;
84
+ for (const year of years) {
85
+ if (esLibs.some(lib => getLibYear(lib) === year && !libs.includes(lib)))
86
+ break;
87
+ complete = year;
88
+ }
89
+ const rest = libs.filter(lib => complete === undefined || getLibYear(lib) > complete);
90
+ const base = complete === undefined ? [] : [formatTarget(complete)];
91
+ return [...base, rest.join(', ')].filter(part => part !== '').join(' + ');
92
+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,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IACtF,MAAM,IAAI,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import { ES_MAPPING_FLOOR, ES5_YEAR, JSON_MODULES_FEATURES, LIB_FEATURES, SYNTAX_FEATURES } from './es-mapping.js';\nimport type { CompatData, Platform, PlatformTargets } from './platform-check.types.js';\nimport { formatTarget } from './typescript-libs.js';\n\n/**\n * Returns the ECMAScript version of a sub-lib as a year.\n *\n * @param lib - The sub-lib, such as `es2024.promise`.\n * @returns The year, `2009` for `es5`.\n */\nexport function getLibYear(lib: string): number {\n const year = /^es(?<year>\\d{4})\\b/u.exec(lib)?.groups?.year;\n return year === undefined ? ES5_YEAR : Number(year);\n}\n\n/**\n * Derives the TypeScript settings that an environment supports.\n *\n * @param platform - The environment.\n * @param nodeVersion - The lowest supported Node.js version; required for `node` and `universal`.\n * @param compatData - The compatibility checks.\n * @param esLibs - The ECMAScript sub-libs that TypeScript knows.\n * @returns The libs, the target and whether JSON modules are supported.\n * @throws {Error} If `nodeVersion` is missing for `node` or `universal`.\n */\nexport function getExpectedTargets(\n platform: Platform,\n nodeVersion: string | undefined,\n compatData: CompatData,\n esLibs: string[],\n): PlatformTargets {\n if (platform !== 'browser' && nodeVersion === undefined) {\n throw new Error(`The ${platform} environment requires a Node.js version from engines.node`);\n }\n const isSupported = (key: string): boolean =>\n (platform === 'node' || compatData.isWidelyAvailable(key)) &&\n (platform === 'browser' || compatData.isSupportedByNode(key, nodeVersion ?? ''));\n\n const libs = esLibs.filter(lib => {\n if (getLibYear(lib) < ES_MAPPING_FLOOR) return true;\n const keys = LIB_FEATURES[lib];\n return keys?.every(key => isSupported(key)) ?? false;\n });\n\n let target = ES_MAPPING_FLOOR - 1;\n const syntax = Object.entries(SYNTAX_FEATURES).toSorted(([a], [b]) => Number(a) - Number(b));\n for (const [year, keys = []] of syntax) {\n if (keys.some(key => !isSupported(key))) break;\n target = Number(year);\n }\n\n return { libs, target, resolveJsonModule: JSON_MODULES_FEATURES.every(key => isSupported(key)) };\n}\n\n/**\n * Finds the ECMAScript sub-libs and versions that TypeScript knows but the\n * mapping does not cover.\n *\n * @param esLibs - The ECMAScript sub-libs that TypeScript knows.\n * @param targets - The ECMAScript versions that TypeScript accepts as `target`.\n * @returns The unmapped sub-libs and versions.\n */\nexport function getUnmapped(esLibs: string[], targets: number[]): { libs: string[]; targets: number[] } {\n return {\n libs: esLibs.filter(lib => getLibYear(lib) >= ES_MAPPING_FLOOR && LIB_FEATURES[lib] === undefined),\n targets: targets.filter(year => year >= ES_MAPPING_FLOOR && SYNTAX_FEATURES[year] === undefined),\n };\n}\n\n/**\n * Finds the keys of the mapping that the installed browser-compat-data or\n * web-features do not know or have no data for.\n *\n * @param compatData - The compatibility checks.\n * @returns The unknown keys, sorted.\n */\nexport function getUnknownKeys(compatData: CompatData): string[] {\n const keys = [\n ...Object.values(LIB_FEATURES).flat(),\n ...Object.values(SYNTAX_FEATURES).flat(),\n ...JSON_MODULES_FEATURES,\n ].filter(key => key !== undefined);\n return [...new Set(keys)].filter(key => !compatData.isKnown(key)).toSorted((a, b) => a.localeCompare(b));\n}\n\n/**\n * Formats ECMAScript sub-libs compactly: the highest version whose sub-libs are\n * all included, followed by the included sub-libs of newer versions.\n *\n * @param libs - The included sub-libs.\n * @param esLibs - The ECMAScript sub-libs that TypeScript knows.\n * @returns The formatted libs, such as `ES2023 + es2024.object, es2024.promise`.\n */\nexport function formatLibs(libs: string[], esLibs: string[]): string {\n const years = [...new Set(esLibs.map(lib => getLibYear(lib)))].toSorted((a, b) => a - b);\n let complete: number | undefined;\n for (const year of years) {\n if (esLibs.some(lib => getLibYear(lib) === year && !libs.includes(lib))) break;\n complete = year;\n }\n const rest = libs.filter(lib => complete === undefined || getLibYear(lib) > complete);\n const base = complete === undefined ? [] : [formatTarget(complete)];\n return [...base, rest.join(', ')].filter(part => part !== '').join(' + ');\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { formatLibs } from './expected-targets.js';
2
+ export { DEFAULT_PRESETS, optionsSchema, validateOptions } from './options-schema.js';
3
+ export { platformCheck } from './platform-check.js';
4
+ export type * from './platform-check.types.js';
5
+ export { formatTarget } from './typescript-libs.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { formatLibs } from './expected-targets.js';
2
+ export { DEFAULT_PRESETS, optionsSchema, validateOptions } from './options-schema.js';
3
+ export { platformCheck } from './platform-check.js';
4
+ export { formatTarget } from './typescript-libs.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { formatLibs } from './expected-targets.js';\nexport { DEFAULT_PRESETS, optionsSchema, validateOptions } from './options-schema.js';\nexport { platformCheck } from './platform-check.js';\nexport type * from './platform-check.types.js';\nexport { formatTarget } from './typescript-libs.js';\n"]}