Skip to content

Commit 61d9bfe

Browse files
committed
refactor: optimize file system operations by removing async/await for synchronous methods
1 parent 11ef599 commit 61d9bfe

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function emitDom() {
9595
const addedItems = await readInputJSON("addedTypes.jsonc");
9696
const comments = await readInputJSON("comments.json");
9797
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
98-
const documentationFromMDN = await generateDescription();
98+
const documentationFromMDN = generateDescription();
9999
const removedItems = await readInputJSON("removedTypes.jsonc");
100100

101101
async function readInputJSON(filename: string) {

src/build/mdn-comments.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from "fs/promises";
1+
import fs from "fs";
22
import { basename } from "path";
33

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

53-
async function getDirectories(dirPath: URL): Promise<URL[]> {
53+
function getDirectories(dirPath: URL): URL[] {
5454
try {
55-
const entries = await fs.readdir(dirPath, {
56-
withFileTypes: true,
57-
});
55+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
5856
return entries
5957
.filter((entry) => entry.isDirectory())
6058
.map((entry) => new URL(entry.name + "/", dirPath));
@@ -64,16 +62,14 @@ async function getDirectories(dirPath: URL): Promise<URL[]> {
6462
}
6563
}
6664

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

7268
for (const folder of folders) {
7369
const indexPath = new URL("index.md", folder);
7470

7571
try {
76-
const content = await fs.readFile(indexPath, "utf-8");
72+
const content = fs.readFileSync(indexPath, "utf-8");
7773

7874
// Improved title extraction
7975
const titleMatch = content.match(/title:\s*["']?([^"'\n]+)["']?/);
@@ -92,17 +88,18 @@ async function getIndexMdContents(
9288
return results;
9389
}
9490

95-
export async function generateDescription(): Promise<Record<string, string>> {
96-
const stats = await fs.stat(basePath);
91+
export function generateDescription(): Record<string, string> {
92+
const stats = fs.statSync(basePath);
9793
if (!stats.isDirectory()) {
9894
throw new Error(
9995
"MDN submodule does not exist; try running `git submodule update --init`",
10096
);
10197
}
98+
10299
try {
103-
const folders = await getDirectories(basePath);
100+
const folders = getDirectories(basePath);
104101
if (folders.length > 0) {
105-
return await getIndexMdContents(folders);
102+
return getIndexMdContents(folders);
106103
}
107104
} catch (error) {
108105
console.error("Error generating API descriptions:", error);

0 commit comments

Comments
 (0)