Skip to content

Commit 19c6039

Browse files
committed
refactor(webref): drop browser-specs
1 parent 3ba381f commit 19c6039

File tree

10 files changed

+63
-77
lines changed

10 files changed

+63
-77
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Get types for the latest web APIs as soon as they become widely available!
77
[The default types generator](https://github.com/microsoft/TypeScript-DOM-lib-generator/) for TypeScript requires manual review for every update, and thus does not provide types for every latest API in a timely manner. `types-web` solves this issue by deploying automation by following tools:
88

99
* [`@mdn/browser-compat-data`](https://www.npmjs.com/package/@mdn/browser-compat-data) provides which features are supported by which browsers, so that undersupported features can be disabled automatically.
10-
* [`browser-specs`](https://www.npmjs.com/package/browser-specs) provides a full list of web specs, so that every latest feature can be covered.
1110
* [`webref`](https://github.com/w3c/webref) provides IDL code from the specs, so that the features can be properly typed.
1211

1312
See how many types have been added in the [changelog](CHANGELOG.md).

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"@webref/css": "1.1.0",
4343
"@webref/elements": "1.0.0",
4444
"@webref/idl": "2.2.1",
45-
"browser-specs": "^1.38.1",
4645
"cpx2": "^3.0.0",
4746
"eslint": "^7.28.0",
4847
"eslint-config-prettier": "^8.3.0",

src/build.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { convert } from "./build/widlprocess.js";
88
import { getExposedTypes } from "./build/expose.js";
99
import { getDeprecationData, getRemovalData } from "./build/bcd.js";
1010
import { createTryRequire } from "./build/utils/require.js";
11-
import { getIdl } from "./build/webref.js";
12-
import { getLatestSpecNames } from "./build/browser-specs.js";
1311
import { getInterfaceElementMergeData } from "./build/webref/elements.js";
12+
import { getWebidls } from "./build/webref/idl.js";
1413

1514
const require = createRequire(import.meta.url);
1615
const tryRequire = createTryRequire(import.meta.url);
@@ -112,15 +111,10 @@ async function emitDom() {
112111
new URL("removedTypes.json", inputFolder)
113112
));
114113
const widlStandardTypes = (
115-
await Promise.all(getLatestSpecNames().map(convertWidl))
114+
await Promise.all([...(await getWebidls()).entries()].map(convertWidl))
116115
).filter((i) => i) as ReturnType<typeof convert>[];
117116

118-
async function convertWidl(shortName: string) {
119-
// Specs that need to fix their syntax, etc.
120-
const idl = await getIdl(shortName);
121-
if (!idl.trim().length) {
122-
return;
123-
}
117+
async function convertWidl([shortName, idl]: string[]) {
124118
const commentsMapFilePath = new URL(
125119
`idl/${shortName}.commentmap.json`,
126120
inputFolder

src/build/utils/map.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ export function addToArrayMap<T>(
77
array.push(value);
88
map.set(name, array);
99
}
10+
11+
export function addToStringMap(
12+
map: Map<string, string>,
13+
name: string,
14+
value: string
15+
): void {
16+
const old = map.get(name) || "";
17+
map.set(name, `${old}\n${value}\n`);
18+
}

src/build/webref.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/build/webref/css.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function hyphenToCamelCase(name: string) {
2+
const camel = name
3+
.replace(/^-(\w)/, (_, c) => c)
4+
.replace(/-(\w)/g, (_, c) => c.toUpperCase());
5+
return camel === "float" ? "_float" : camel;
6+
}
7+
8+
export function generateWebIdlFromCssProperties(properties: string[]): string {
9+
return `partial interface CSSStyleDeclaration {${properties
10+
.map(
11+
(property) =>
12+
`\n [CEReactions] attribute [LegacyNullToEmptyString] CSSOMString ${hyphenToCamelCase(
13+
property
14+
)};`
15+
)
16+
.join("")}\n};`;
17+
}

src/build/webref/idl.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { listAll as listAllIdl } from "@webref/idl";
2+
import { listAll as listAllCss } from "@webref/css";
3+
import { generateWebIdlFromCssProperties } from "./css.js";
4+
import { addToStringMap } from "../utils/map.js";
5+
6+
export async function getWebidls(): Promise<Map<string, string>> {
7+
const idl = await listAllIdl();
8+
const css = await listAllCss();
9+
10+
const map = new Map<string, string>();
11+
for (const [key, file] of Object.entries(idl)) {
12+
const text = await file.text();
13+
map.set(key, text);
14+
}
15+
for (const [key, data] of Object.entries(css)) {
16+
const properties = Object.keys(data.properties);
17+
if (properties.length) {
18+
addToStringMap(map, key, generateWebIdlFromCssProperties(properties));
19+
}
20+
}
21+
return map;
22+
}

src/build/webref/webref-css.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module "@webref/css" {
2+
interface Data {
3+
properties: Record<string, unknown>;
4+
}
5+
function listAll(): Promise<Record<string, Data>>;
6+
}

src/build/webref/webref-idl.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module "@webref/idl" {
2+
interface IDLFile {
3+
text(): Promise<string>;
4+
}
5+
function listAll(): Promise<Record<string, IDLFile>>;
6+
}

0 commit comments

Comments
 (0)