Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jsdom": "^16.6.0",
"json5": "^2.2.0",
"jsonc-parser": "^3.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is seemingly the parser used by VSCode for "JSON with Comments" parsing mode.

"node-fetch": "^2.6.1",
"prettier": "^2.3.2",
"print-diff": "^1.0.0",
Expand Down
32 changes: 12 additions & 20 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import * as Browser from "./build/types.js";
import { promises as fs } from "fs";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import { merge, resolveExposure, arrayToMap } from "./build/helpers.js";
import { emitWebIdl } from "./build/emitter.js";
import { convert } from "./build/widlprocess.js";
import { getExposedTypes } from "./build/expose.js";
import { getDeprecationData, getRemovalData } from "./build/bcd.js";
import { createTryRequire } from "./build/utils/require.js";
import { getInterfaceElementMergeData } from "./build/webref/elements.js";
import { getWebidls } from "./build/webref/idl.js";
import JSON5 from "json5";

const require = createRequire(import.meta.url);
const tryRequire = createTryRequire(import.meta.url);
import jsonc from "jsonc-parser";

function mergeNamesakes(filtered: Browser.WebIdl) {
const targets = [
Expand Down Expand Up @@ -93,29 +87,29 @@ async function emitDom() {
recursive: true,
});

const overriddenItems = await readInputJSON("overridingTypes.json");
const addedItems = await readInputJSON("addedTypes.json");
const overriddenItems = await readInputJSON("overridingTypes.jsonc");
const addedItems = await readInputJSON("addedTypes.jsonc");
const comments = await readInputJSON("comments.json");
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
const documentationFromMDN = await readInputJSON("mdn/apiDescriptions.json");
const removedItems = await readInputJSON("removedTypes.json");
const removedItems = await readInputJSON("removedTypes.jsonc");

async function readInputJSON(filename: string) {
const content = await fs.readFile(new URL(filename, inputFolder), "utf8");
return JSON5.parse(content);
return jsonc.parse(content);
}

const widlStandardTypes = (
await Promise.all([...(await getWebidls()).entries()].map(convertWidl))
).filter((i) => i) as ReturnType<typeof convert>[];

async function convertWidl([shortName, idl]: string[]) {
const commentsMapFilePath = new URL(
`idl/${shortName}.commentmap.json`,
inputFolder
);
const commentsMap: Record<string, string> =
(await tryRequire(fileURLToPath(commentsMapFilePath))) ?? {};
let commentsMap: Record<string, string>;
try {
commentsMap = await readInputJSON(`idl/${shortName}.commentmap.json`);
} catch {
commentsMap = {};
}
commentCleanup(commentsMap);
const result = convert(idl, commentsMap);
return result;
Expand Down Expand Up @@ -249,9 +243,7 @@ async function emitDom() {
}
}

const knownTypes = require(fileURLToPath(
new URL("knownTypes.json", inputFolder)
));
const knownTypes = await readInputJSON("knownTypes.json");

emitFlavor(webidl, new Set(knownTypes.Window), {
name: "dom",
Expand Down
15 changes: 0 additions & 15 deletions src/build/utils/require.ts

This file was deleted.