diff --git a/.gitignore b/.gitignore index bb63c80db..1ab4d9d63 100644 --- a/.gitignore +++ b/.gitignore @@ -279,10 +279,9 @@ __pycache__/ # !tools/packages.config generated/ -lib/ inputfiles/browser.webidl.json .vscode/* !.vscode/launch.template.json yarn.lock TypeScript -deploy/generated \ No newline at end of file +deploy/generated diff --git a/deploy/deployChangedPackages.js b/deploy/deployChangedPackages.js index 9d5348fca..e18ad2236 100644 --- a/deploy/deployChangedPackages.js +++ b/deploy/deployChangedPackages.js @@ -10,7 +10,7 @@ import * as path from "path"; import { spawnSync } from "child_process"; import { Octokit } from "@octokit/rest"; import { printUnifiedDiff } from "print-diff"; -import { generateChangelogFrom } from "../lib/changelog.js"; +import { generateChangelogFrom } from "../src/changelog.ts"; import { packages } from "./createTypesPackages.js"; import { fileURLToPath } from "node:url"; import fetch from "node-fetch"; diff --git a/deploy/jsconfig.json b/deploy/jsconfig.json index ab435e545..65199e820 100644 --- a/deploy/jsconfig.json +++ b/deploy/jsconfig.json @@ -4,6 +4,7 @@ "module": "esnext", // es2022 "moduleResolution": "node", "strict": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "allowImportingTsExtensions": true } } diff --git a/deploy/versionChangelog.js b/deploy/versionChangelog.js index c481af071..eaa9d233f 100644 --- a/deploy/versionChangelog.js +++ b/deploy/versionChangelog.js @@ -2,7 +2,7 @@ // npm run ts-changelog @types/web 0.0.1 0.0.3 -import { gitShowFile, generateChangelogFrom } from "../lib/changelog.js"; +import { gitShowFile, generateChangelogFrom } from "../src/changelog.ts"; import { packages } from "./createTypesPackages.js"; import { basename } from "path"; diff --git a/package-lock.json b/package-lock.json index 37e78a63f..5e75c8bab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,9 @@ "typescript": "^5.9.2", "typescript-eslint": "^8", "webidl2": "^24.5.0" + }, + "engines": { + "node": ">= 22.18.0" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index a1e1ef0bb..0f240adc0 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "@typescript/dom-lib-generator", "version": "0.0.1", "private": true, + "engines": { + "node": ">= 22.18.0" + }, "description": "Provides TypeScript types for the latest web APIs.", "keywords": [ "typescript", @@ -12,15 +15,15 @@ "worklet" ], "scripts": { - "build": "tsc && node ./lib/build.js", + "build": "node ./src/build.ts", "baseline-accept": "cpx \"generated\\**\" baselines\\", "lint": "eslint --max-warnings 0 src deploy/*.js scripts && tsc -p deploy/jsconfig.json", "lint-fix": "eslint --max-warnings 0 src deploy/*.js scripts --fix", - "test": "npm run build && npm run lint && node ./lib/test.js && node ./unittests/index.js", - "changelog": "tsc && node ./lib/changelog.js", + "test": "npm run build && npm run lint && node ./src/test.ts && node ./unittests/index.js", + "changelog": "node ./src/changelog.ts", "ts-changelog": "node ./deploy/versionChangelog.js", "migrate": "node ./deploy/migrate.js", - "version": "npm i && tsc && node ./lib/version.js", + "version": "npm i && node ./src/version.ts", "generate": "npm run build && npm run baseline-accept" }, "author": { diff --git a/src/build.ts b/src/build.ts index 1b1be02ff..166971680 100644 --- a/src/build.ts +++ b/src/build.ts @@ -1,20 +1,20 @@ -import * as Browser from "./build/types.js"; +import type * as Browser from "./build/types.ts"; import { promises as fs } from "fs"; -import { merge, resolveExposure, arrayToMap } from "./build/helpers.js"; -import { type CompilerBehavior, emitWebIdl } from "./build/emitter.js"; -import { convert } from "./build/widlprocess.js"; -import { getExposedTypes } from "./build/expose.js"; +import { merge, resolveExposure, arrayToMap } from "./build/helpers.ts"; +import { type CompilerBehavior, emitWebIdl } from "./build/emitter.ts"; +import { convert } from "./build/widlprocess.ts"; +import { getExposedTypes } from "./build/expose.ts"; import { getDeprecationData, getDocsData, getRemovalData, -} from "./build/bcd.js"; -import { getInterfaceElementMergeData } from "./build/webref/elements.js"; -import { getInterfaceToEventMap } from "./build/webref/events.js"; -import { getWebidls } from "./build/webref/idl.js"; +} from "./build/bcd.ts"; +import { getInterfaceElementMergeData } from "./build/webref/elements.ts"; +import { getInterfaceToEventMap } from "./build/webref/events.ts"; +import { getWebidls } from "./build/webref/idl.ts"; import jsonc from "jsonc-parser"; -import { generateDescriptions } from "./build/mdn-comments.js"; -import readPatches from "./build/patches.js"; +import { generateDescriptions } from "./build/mdn-comments.ts"; +import readPatches from "./build/patches.ts"; function mergeNamesakes(filtered: Browser.WebIdl) { const targets = [ diff --git a/src/build/bcd.ts b/src/build/bcd.ts index c54ceac85..1822fd42a 100644 --- a/src/build/bcd.ts +++ b/src/build/bcd.ts @@ -1,12 +1,12 @@ -import * as Browser from "./types.js"; -import { +import * as Browser from "./types.ts"; +import type { CompatStatement, SimpleSupportStatement, SupportBlock, } from "@mdn/browser-compat-data/types"; -import { forceKeepAlive } from "./bcd/keep-alive.js"; -import { mapToBcdCompat } from "./bcd/mapper.js"; -import { hasStableImplementation } from "./bcd/stable.js"; +import { forceKeepAlive } from "./bcd/keep-alive.ts"; +import { mapToBcdCompat } from "./bcd/mapper.ts"; +import { hasStableImplementation } from "./bcd/stable.ts"; function hasMultipleImplementations(support: SupportBlock, prefix?: string) { const hasStableImpl = ( diff --git a/src/build/bcd/mapper.ts b/src/build/bcd/mapper.ts index 1238cd684..1c75c91dc 100644 --- a/src/build/bcd/mapper.ts +++ b/src/build/bcd/mapper.ts @@ -1,14 +1,14 @@ -import { +import type { BrowserName, CompatStatement, Identifier, SimpleSupportStatement, } from "bcd-idl-mapper"; import api from "bcd-idl-mapper"; -import * as Browser from "../types.js"; -import { filterMapRecord, isEmptyRecord } from "../utils/record.js"; -import { mapDefined } from "../helpers.js"; -import { hasStableImplementation } from "./stable.js"; +import type * as Browser from "../types.ts"; +import { filterMapRecord, isEmptyRecord } from "../utils/record.ts"; +import { mapDefined } from "../helpers.ts"; +import { hasStableImplementation } from "./stable.ts"; interface DataToMap { key: string; diff --git a/src/build/bcd/stable.ts b/src/build/bcd/stable.ts index 759448bc9..50bd31c74 100644 --- a/src/build/bcd/stable.ts +++ b/src/build/bcd/stable.ts @@ -1,4 +1,4 @@ -import { SimpleSupportStatement } from "@mdn/browser-compat-data/types"; +import type { SimpleSupportStatement } from "@mdn/browser-compat-data/types"; export function hasStableImplementation( browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined, diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 000a4fe7f..d09597bdc 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -1,4 +1,4 @@ -import * as Browser from "./types.js"; +import * as Browser from "./types.ts"; import { mapToArray, distinct, @@ -10,15 +10,11 @@ import { baseTypeConversionMap, assertUnique, arrayBufferViewTypes, -} from "./helpers.js"; -import { collectLegacyNamespaceTypes } from "./legacy-namespace.js"; +} from "./helpers.ts"; +import { collectLegacyNamespaceTypes } from "./legacy-namespace.ts"; /// Decide which members of a function to emit -enum EmitScope { - StaticOnly, - InstanceOnly, - All, -} +type EmitScope = "StaticOnly" | "InstanceOnly" | "All"; const tsKeywords = new Set(["default", "delete", "continue"]); const extendConflictsBaseTypes: Record< @@ -38,9 +34,7 @@ const namespacesAsInterfaces = ["console"]; // Used to decide if a member should be emitted given its static property and // the intended scope level. function matchScope(scope: EmitScope, x: { static?: boolean }) { - return ( - scope === EmitScope.All || (scope === EmitScope.StaticOnly) === !!x.static - ); + return scope === "All" || (scope === "StaticOnly") === !!x.static; } /// Parameter cannot be named "default" in JavaScript/Typescript so we need to rename it. @@ -900,7 +894,7 @@ export function emitWebIdl( if ( p.name === "name" && i.name === "Window" && - emitScope === EmitScope.InstanceOnly && + emitScope === "InstanceOnly" && prefix === "declare var " ) { printer.printLine("/** @deprecated */"); @@ -1114,7 +1108,7 @@ export function emitWebIdl( .sort(compareName) .forEach((m) => emitMethod(prefix, m, conflictedMembers)); } - if (i.anonymousMethods && emitScope === EmitScope.InstanceOnly) { + if (i.anonymousMethods && emitScope === "InstanceOnly") { const stringifier = i.anonymousMethods.method.find((m) => m.stringifier); if (stringifier) { printer.printLine("toString(): string;"); @@ -1163,7 +1157,7 @@ export function emitWebIdl( ? "declare function " : ""; emitMethods(methodPrefix, emitScope, i, conflictedMembers); - if (emitScope === EmitScope.InstanceOnly) { + if (emitScope === "InstanceOnly") { emitIteratorForEach(i); } } @@ -1171,7 +1165,7 @@ export function emitWebIdl( /// Emit all members of every interfaces at the root level. /// Called only once on the global polluter object function emitAllMembers(i: Browser.Interface) { - emitMembers(/*prefix*/ "declare var ", EmitScope.InstanceOnly, i); + emitMembers(/*prefix*/ "declare var ", "InstanceOnly", i); for (const relatedIName of iNameToIDependList[i.name]) { const i = allInterfacesMap[relatedIName]; @@ -1275,7 +1269,7 @@ export function emitWebIdl( emitConstants(parent); } } - emitMembers(/*prefix*/ "", EmitScope.StaticOnly, i); + emitMembers(/*prefix*/ "", "StaticOnly", i); printer.decreaseIndent(); printer.printLine("};"); @@ -1493,10 +1487,10 @@ export function emitWebIdl( emitInterfaceDeclaration(i); printer.increaseIndent(); - emitMembers(/*prefix*/ "", EmitScope.InstanceOnly, i); + emitMembers(/*prefix*/ "", "InstanceOnly", i); emitConstants(i); emitEventHandlers(/*prefix*/ "", i); - emitIndexers(EmitScope.InstanceOnly, i); + emitIndexers("InstanceOnly", i); printer.decreaseIndent(); printer.printLine("}"); @@ -1556,8 +1550,8 @@ export function emitWebIdl( namespace.nested.typedefs.sort(compareName).forEach(emitTypeDef); } - emitProperties("var ", EmitScope.InstanceOnly, namespace); - emitMethods("function ", EmitScope.InstanceOnly, namespace, new Set()); + emitProperties("var ", "InstanceOnly", namespace); + emitMethods("function ", "InstanceOnly", namespace, new Set()); printer.decreaseIndent(); printer.printLine("}"); diff --git a/src/build/expose.ts b/src/build/expose.ts index f2a6098bf..09c7d2345 100644 --- a/src/build/expose.ts +++ b/src/build/expose.ts @@ -1,4 +1,4 @@ -import * as Browser from "./types.js"; +import * as Browser from "./types.ts"; import { getEmptyWebIDL, deepFilter, @@ -7,8 +7,8 @@ import { filterProperties, mapToArray, arrayToMap, -} from "./helpers.js"; -import { isEmptyRecord } from "./utils/record.js"; +} from "./helpers.ts"; +import { isEmptyRecord } from "./utils/record.ts"; class LoggedSet extends Set { private unvisited: Set; diff --git a/src/build/helpers.ts b/src/build/helpers.ts index da84f2d91..4a211d4ae 100644 --- a/src/build/helpers.ts +++ b/src/build/helpers.ts @@ -1,4 +1,4 @@ -import * as Browser from "./types.js"; +import * as Browser from "./types.ts"; // Extended types used but not defined in the spec export const arrayBufferViewTypes = new Set([ diff --git a/src/build/legacy-namespace.ts b/src/build/legacy-namespace.ts index 6000ae6c8..c4652262c 100644 --- a/src/build/legacy-namespace.ts +++ b/src/build/legacy-namespace.ts @@ -1,5 +1,5 @@ -import * as Browser from "./types.js"; -import { mapToArray, arrayToMap } from "./helpers.js"; +import * as Browser from "./types.ts"; +import { mapToArray, arrayToMap } from "./helpers.ts"; export function collectLegacyNamespaceTypes( webidl: Browser.WebIdl, diff --git a/src/build/mdn-comments.ts b/src/build/mdn-comments.ts index a69fa013c..654973856 100644 --- a/src/build/mdn-comments.ts +++ b/src/build/mdn-comments.ts @@ -1,5 +1,5 @@ import { readFile } from "fs/promises"; -import { hyphenToCamelCase } from "./utils/css.js"; +import { hyphenToCamelCase } from "./utils/css.ts"; const inputFile = new URL("../../inputfiles/mdn.json", import.meta.url); diff --git a/src/build/patches.ts b/src/build/patches.ts index 26368e585..7733a5f61 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -1,4 +1,4 @@ -import { parse, type Value, type Node, Document } from "kdljs"; +import { parse, type Value, type Node, type Document } from "kdljs"; import type { Enum, Event, @@ -11,9 +11,9 @@ import type { Dictionary, Member, Signature, -} from "./types.js"; +} from "./types.ts"; import { readdir, readFile } from "fs/promises"; -import { merge } from "./helpers.js"; +import { merge } from "./helpers.ts"; type DeepPartial = T extends object ? { [K in keyof T]?: DeepPartial } diff --git a/src/build/webref/css.ts b/src/build/webref/css.ts index 0042e0315..d43e7f5c9 100644 --- a/src/build/webref/css.ts +++ b/src/build/webref/css.ts @@ -1,4 +1,4 @@ -import { hyphenToCamelCase } from "../utils/css.js"; +import { hyphenToCamelCase } from "../utils/css.ts"; export function generateWebIdlFromCssProperties(properties: string[]): string { return `partial interface CSSStyleProperties {${properties diff --git a/src/build/webref/elements.ts b/src/build/webref/elements.ts index 7e2b6ed44..cb19074aa 100644 --- a/src/build/webref/elements.ts +++ b/src/build/webref/elements.ts @@ -1,6 +1,6 @@ -import { listAll, Element as WebrefElement } from "@webref/elements"; -import { Interface, WebIdl } from "../types.js"; -import { addToArrayMap } from "../utils/map.js"; +import { listAll, type Element as WebrefElement } from "@webref/elements"; +import type { Interface, WebIdl } from "../types.ts"; +import { addToArrayMap } from "../utils/map.ts"; async function getInterfaceToElementMap(): Promise< Map diff --git a/src/build/webref/events.ts b/src/build/webref/events.ts index f79895105..5c27951a7 100644 --- a/src/build/webref/events.ts +++ b/src/build/webref/events.ts @@ -1,5 +1,5 @@ import { listAll } from "@webref/events"; -import { addToNestedMap } from "../utils/map.js"; +import { addToNestedMap } from "../utils/map.ts"; export async function getInterfaceToEventMap(): Promise< Map> diff --git a/src/build/webref/idl.ts b/src/build/webref/idl.ts index 55a1c27f0..5896705ff 100644 --- a/src/build/webref/idl.ts +++ b/src/build/webref/idl.ts @@ -1,6 +1,6 @@ import { listAll as listAllIdl } from "@webref/idl"; import { listAll as listAllCss } from "@webref/css"; -import { generateWebIdlFromCssProperties } from "./css.js"; +import { generateWebIdlFromCssProperties } from "./css.ts"; export async function getWebidls(): Promise> { const idl = await listAllIdl(); diff --git a/src/build/widlprocess.ts b/src/build/widlprocess.ts index b7fc1c5e6..d8b5ddeb2 100644 --- a/src/build/widlprocess.ts +++ b/src/build/widlprocess.ts @@ -1,6 +1,6 @@ import * as webidl2 from "webidl2"; -import * as Browser from "./types.js"; -import { getEmptyWebIDL } from "./helpers.js"; +import * as Browser from "./types.ts"; +import { getEmptyWebIDL } from "./helpers.ts"; export function convert(text: string, commentMap: Record) { const rootTypes = webidl2.parse(text); diff --git a/src/version.ts b/src/version.ts index 261f14a4e..38a25d061 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,6 +1,6 @@ import { execSync } from "child_process"; import { readFile, writeFile } from "fs/promises"; -import { generateDefaultFromRecentTag } from "./changelog.js"; +import { generateDefaultFromRecentTag } from "./changelog.ts"; const output = generateDefaultFromRecentTag(); diff --git a/tsconfig.json b/tsconfig.json index 250d50e58..203e88dd5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,17 @@ { - "compilerOptions": { - "target": "es2022", - "module": "nodenext", - "moduleResolution": "nodenext", - "outDir": "./lib", - "strict": true, - "esModuleInterop": true, - "sourceMap": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true - }, - "include": [ - "./src" - ] + "compilerOptions": { + "target": "es2022", + "module": "nodenext", + "moduleResolution": "nodenext", + "outDir": "./lib", + "strict": true, + "esModuleInterop": true, + "sourceMap": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "allowImportingTsExtensions": true, + "noEmit": true, + }, + "include": ["./src"], }