|
1 | 1 | import * as Browser from "./build/types.js";
|
2 | 2 | import { promises as fs } from "fs";
|
3 |
| -import { createRequire } from "module"; |
4 |
| -import { fileURLToPath } from "url"; |
5 | 3 | import { merge, resolveExposure, arrayToMap } from "./build/helpers.js";
|
6 | 4 | import { emitWebIdl } from "./build/emitter.js";
|
7 | 5 | import { convert } from "./build/widlprocess.js";
|
8 | 6 | import { getExposedTypes } from "./build/expose.js";
|
9 | 7 | import { getDeprecationData, getRemovalData } from "./build/bcd.js";
|
10 |
| -import { createTryRequire } from "./build/utils/require.js"; |
11 | 8 | import { getInterfaceElementMergeData } from "./build/webref/elements.js";
|
12 | 9 | 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"; |
17 | 11 |
|
18 | 12 | function mergeNamesakes(filtered: Browser.WebIdl) {
|
19 | 13 | const targets = [
|
@@ -93,29 +87,29 @@ async function emitDom() {
|
93 | 87 | recursive: true,
|
94 | 88 | });
|
95 | 89 |
|
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"); |
98 | 92 | const comments = await readInputJSON("comments.json");
|
99 | 93 | const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
|
100 | 94 | const documentationFromMDN = await readInputJSON("mdn/apiDescriptions.json");
|
101 |
| - const removedItems = await readInputJSON("removedTypes.json"); |
| 95 | + const removedItems = await readInputJSON("removedTypes.jsonc"); |
102 | 96 |
|
103 | 97 | async function readInputJSON(filename: string) {
|
104 | 98 | const content = await fs.readFile(new URL(filename, inputFolder), "utf8");
|
105 |
| - return JSON5.parse(content); |
| 99 | + return jsonc.parse(content); |
106 | 100 | }
|
107 | 101 |
|
108 | 102 | const widlStandardTypes = (
|
109 | 103 | await Promise.all([...(await getWebidls()).entries()].map(convertWidl))
|
110 | 104 | ).filter((i) => i) as ReturnType<typeof convert>[];
|
111 | 105 |
|
112 | 106 | 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 | + } |
119 | 113 | commentCleanup(commentsMap);
|
120 | 114 | const result = convert(idl, commentsMap);
|
121 | 115 | return result;
|
@@ -249,9 +243,7 @@ async function emitDom() {
|
249 | 243 | }
|
250 | 244 | }
|
251 | 245 |
|
252 |
| - const knownTypes = require(fileURLToPath( |
253 |
| - new URL("knownTypes.json", inputFolder) |
254 |
| - )); |
| 246 | + const knownTypes = await readInputJSON("knownTypes.json"); |
255 | 247 |
|
256 | 248 | emitFlavor(webidl, new Set(knownTypes.Window), {
|
257 | 249 | name: "dom",
|
|
0 commit comments