Skip to content

Commit 80458ef

Browse files
committed
Use JSONC file extension for input json files
1 parent a90dfff commit 80458ef

File tree

7 files changed

+26
-37
lines changed

7 files changed

+26
-37
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

package-lock.json

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"eslint-config-prettier": "^8.3.0",
5555
"eslint-plugin-prettier": "^3.4.0",
5656
"jsdom": "^16.6.0",
57-
"json5": "^2.2.0",
57+
"jsonc-parser": "^3.0.0",
5858
"node-fetch": "^2.6.1",
5959
"prettier": "^2.3.2",
6060
"print-diff": "^1.0.0",

src/build.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import * as Browser from "./build/types.js";
22
import { promises as fs } from "fs";
3-
import { createRequire } from "module";
4-
import { fileURLToPath } from "url";
53
import { merge, resolveExposure, arrayToMap } from "./build/helpers.js";
64
import { emitWebIdl } from "./build/emitter.js";
75
import { convert } from "./build/widlprocess.js";
86
import { getExposedTypes } from "./build/expose.js";
97
import { getDeprecationData, getRemovalData } from "./build/bcd.js";
10-
import { createTryRequire } from "./build/utils/require.js";
118
import { getInterfaceElementMergeData } from "./build/webref/elements.js";
129
import { getWebidls } from "./build/webref/idl.js";
13-
import JSON5 from "json5";
14-
15-
const require = createRequire(import.meta.url);
16-
const tryRequire = createTryRequire(import.meta.url);
10+
import jsonc from "jsonc-parser";
1711

1812
function mergeNamesakes(filtered: Browser.WebIdl) {
1913
const targets = [
@@ -93,29 +87,29 @@ async function emitDom() {
9387
recursive: true,
9488
});
9589

96-
const overriddenItems = await readInputJSON("overridingTypes.json");
97-
const addedItems = await readInputJSON("addedTypes.json");
90+
const overriddenItems = await readInputJSON("overridingTypes.jsonc");
91+
const addedItems = await readInputJSON("addedTypes.jsonc");
9892
const comments = await readInputJSON("comments.json");
9993
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
10094
const documentationFromMDN = await readInputJSON("mdn/apiDescriptions.json");
101-
const removedItems = await readInputJSON("removedTypes.json");
95+
const removedItems = await readInputJSON("removedTypes.jsonc");
10296

10397
async function readInputJSON(filename: string) {
10498
const content = await fs.readFile(new URL(filename, inputFolder), "utf8");
105-
return JSON5.parse(content);
99+
return jsonc.parse(content);
106100
}
107101

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

112106
async function convertWidl([shortName, idl]: string[]) {
113-
const commentsMapFilePath = new URL(
114-
`idl/${shortName}.commentmap.json`,
115-
inputFolder
116-
);
117-
const commentsMap: Record<string, string> =
118-
(await tryRequire(fileURLToPath(commentsMapFilePath))) ?? {};
107+
let commentsMap: Record<string, string>;
108+
try {
109+
commentsMap = await readInputJSON(`idl/${shortName}.commentmap.json`);
110+
} catch {
111+
commentsMap = {};
112+
}
119113
commentCleanup(commentsMap);
120114
const result = convert(idl, commentsMap);
121115
return result;
@@ -249,9 +243,7 @@ async function emitDom() {
249243
}
250244
}
251245

252-
const knownTypes = require(fileURLToPath(
253-
new URL("knownTypes.json", inputFolder)
254-
));
246+
const knownTypes = await readInputJSON("knownTypes.json");
255247

256248
emitFlavor(webidl, new Set(knownTypes.Window), {
257249
name: "dom",

src/build/utils/require.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)