Skip to content

Commit 918d3f4

Browse files
Replace fs Node module usages with Bun I/O API
1 parent da6043b commit 918d3f4

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

downloadPages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from "fs";
21
import headers from "./headers.ts";
32
import reportRateLimit from "./reportRateLimit.ts";
43

@@ -29,7 +28,7 @@ export default async function downloadPages(initialUrl: string) {
2928

3029
// Save response to a file marked to be uploaded as an artifact for debugging
3130
const fileNameBits = url.match(/\w+/g) ?? [];
32-
await fs.promises.writeFile(
31+
await Bun.write(
3332
`${fileNameBits.join("-") || "response"}.${
3433
response.status
3534
}.artifact.json`,

index.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// This is a test edit from the Github iOS app
22

3-
import fs from "fs";
43
import todo from "todo";
54
import date from "./date.ts";
65
import downloadPages from "./downloadPages.ts";
@@ -92,10 +91,7 @@ for (const login of logins) {
9291
followers.push({ login, followed_at, unfollowed_at });
9392
}
9493

95-
await fs.promises.writeFile(
96-
"followers.json",
97-
JSON.stringify(followers, null, 2)
98-
);
94+
await Bun.write("followers.json", JSON.stringify(followers, null, 2));
9995

10096
// Keep a list of accounts found to be dead to skip in unfollow-follow events
10197
const deadLogins: string[] = [];
@@ -211,7 +207,7 @@ for (const [field, order] of [
211207
markdown += `📒 ${repository.description}\n\n`;
212208
}
213209

214-
await fs.promises.writeFile(`by-${field}-${order}.md`, markdown);
210+
await Bun.write(`by-${field}-${order}.md`, markdown);
215211
console.groupEnd();
216212
}
217213

@@ -314,7 +310,7 @@ for (const repository of repositories) {
314310
}
315311

316312
content = Buffer.from(content.content, "base64");
317-
await fs.promises.writeFile(name + "." + readme, content);
313+
await Bun.write(name + "." + readme, content);
318314

319315
if (!todos[name]) {
320316
todos[name] ??= {};
@@ -329,7 +325,7 @@ for (const repository of repositories) {
329325
todos[name].todos.push(text);
330326
}
331327

332-
await fs.promises.unlink(name + "." + readme);
328+
await Bun.file(name + "." + readme).delete();
333329
}
334330
}
335331

@@ -339,13 +335,13 @@ for (const name in todos) {
339335
}
340336
}
341337

342-
await fs.promises.writeFile(
338+
await Bun.write(
343339
"todos.json",
344340
JSON.stringify(Object.fromEntries(Object.entries(todos).sort()), null, 2)
345341
);
346342

347343
// Sort the repositories object by key before persisting it to the change
348-
await fs.promises.writeFile(
344+
await Bun.write(
349345
"repositories.json",
350346
JSON.stringify(
351347
Object.fromEntries(Object.entries(_repositories).sort()),
@@ -423,7 +419,7 @@ const issuesMarkDown =
423419
)
424420
.join("\n\n") +
425421
"\n";
426-
await fs.promises.writeFile("issues.md", issuesMarkDown);
422+
await Bun.write("issues.md", issuesMarkDown);
427423

428424
const prs = issuesAndPrs
429425
.filter((issueOrPr: any) => issueOrPr.pull_request)
@@ -451,7 +447,7 @@ const prsMarkDown =
451447
)
452448
.join("\n\n") +
453449
"\n";
454-
await fs.promises.writeFile("prs.md", prsMarkDown);
450+
await Bun.write("prs.md", prsMarkDown);
455451

456452
const forkPrs = [
457453
...(await downloadPages(
@@ -493,12 +489,12 @@ const identicalForksMarkDown =
493489
: identicalForks.length === 1
494490
? `\n[One${nbsp}identical${nbsp}fork:${nbsp}\`${identicalForks[0]}\`${nbsp}🍴⚠️](${process.env.GITHUB_SERVER_URL}/${login}/${identicalForks[0]})`
495491
: `\n[${identicalForks.length}${nbsp}identical${nbsp}forks${nbsp}🍴⚠️](identical-forks.json)`;
496-
await fs.promises.writeFile(
492+
await Bun.write(
497493
"identical-forks.json",
498494
JSON.stringify(identicalForks, null, 2)
499495
);
500496
if (identicalForks.length === 0) {
501-
await fs.promises.unlink("identical-forks.json");
497+
await Bun.file("identical-forks.json").delete();
502498
}
503499

504500
const followerCount = followers.filter(
@@ -594,4 +590,4 @@ for (const event of events) {
594590
markdown += "\n";
595591
markdown += "</details>\n";
596592

597-
await fs.promises.writeFile("readme.md", markdown);
593+
await Bun.write("readme.md", markdown);

0 commit comments

Comments
 (0)