Skip to content

Commit 9afe136

Browse files
committed
-
1 parent 7f82e1f commit 9afe136

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/build.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function emitFlavor(
5050
mergeNamesakes(exposed);
5151
exposed.events = webidl.events;
5252

53-
const result = emitWebIdl(
53+
const result = await emitWebIdl(
5454
exposed,
5555
options.global[0],
5656
"",
@@ -61,7 +61,7 @@ async function emitFlavor(
6161
result,
6262
);
6363

64-
const iterators = emitWebIdl(
64+
const iterators = await emitWebIdl(
6565
exposed,
6666
options.global[0],
6767
"sync",
@@ -72,7 +72,7 @@ async function emitFlavor(
7272
iterators,
7373
);
7474

75-
const asyncIterators = emitWebIdl(
75+
const asyncIterators = await emitWebIdl(
7676
exposed,
7777
options.global[0],
7878
"async",
@@ -94,7 +94,7 @@ async function emitDom() {
9494
const overriddenItems = await readInputJSON("overridingTypes.jsonc");
9595
const addedItems = await readInputJSON("addedTypes.jsonc");
9696
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
97-
const documentationFromMDN = generateDescriptions();
97+
const documentationFromMDN = await generateDescriptions();
9898
const removedItems = await readInputJSON("removedTypes.jsonc");
9999

100100
async function readInputJSON(filename: string) {

src/build/mdn-comments.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import fs from "fs";
1+
import { readFileSync } from "fs";
2+
import fs from "fs/promises";
23
import { basename } from "path";
34

45
const basePath = new URL(
@@ -50,9 +51,11 @@ function extractSummary(markdown: string): string {
5051
return normalizedText.split(" ")[0] || ""; // Fallback: first word if no sentence found
5152
}
5253

53-
function getDirectories(dirPath: URL): URL[] {
54+
async function getDirectories(dirPath: URL): Promise<URL[]> {
5455
try {
55-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
56+
const entries = await fs.readdir(dirPath, {
57+
withFileTypes: true,
58+
});
5659
return entries
5760
.filter((entry) => entry.isDirectory())
5861
.map((entry) => new URL(entry.name + "/", dirPath));
@@ -62,14 +65,16 @@ function getDirectories(dirPath: URL): URL[] {
6265
}
6366
}
6467

65-
function getIndexMdContents(folders: URL[]): { [key: string]: string } {
68+
async function getIndexMdContents(
69+
folders: URL[],
70+
): Promise<{ [key: string]: string }> {
6671
const results: { [key: string]: string } = {};
6772

6873
for (const folder of folders) {
6974
const indexPath = new URL("index.md", folder);
7075

7176
try {
72-
const content = fs.readFileSync(indexPath, "utf-8");
77+
const content = await fs.readFile(indexPath, "utf-8");
7378

7479
// Improved title extraction
7580
const titleMatch = content.match(/title:\s*["']?([^"'\n]+)["']?/);
@@ -88,26 +93,24 @@ function getIndexMdContents(folders: URL[]): { [key: string]: string } {
8893
return results;
8994
}
9095

91-
export function generateDescriptions(): Record<string, string> {
92-
const stats = fs.statSync(basePath);
96+
export async function generateDescriptions(): Promise<Record<string, string>> {
97+
const stats = await fs.stat(basePath);
9398
if (!stats.isDirectory()) {
9499
throw new Error(
95100
"MDN submodule does not exist; try running `git submodule update --init`",
96101
);
97102
}
98-
99103
try {
100-
const folders = getDirectories(basePath);
104+
const folders = await getDirectories(basePath);
101105
if (folders.length > 0) {
102-
return getIndexMdContents(folders);
106+
return await getIndexMdContents(folders);
103107
}
104108
} catch (error) {
105109
console.error("Error generating API descriptions:", error);
106110
}
107111

108112
return {};
109113
}
110-
111114
export function extractSummaryFromFile(url: string): string {
112115
const relativePath = url
113116
.replace("https://developer.mozilla.org/docs/", "")
@@ -120,7 +123,7 @@ export function extractSummaryFromFile(url: string): string {
120123
);
121124

122125
try {
123-
const content = fs.readFileSync(filePath, "utf-8");
126+
const content = readFileSync(filePath, "utf-8");
124127
return extractSummary(content);
125128
} catch (error) {
126129
console.error(

0 commit comments

Comments
 (0)