refactor: migrate src/util/log.ts from Bun.file() to Node.js fs module (#14136)

This commit is contained in:
Dax
2026-02-18 17:28:08 -05:00
committed by GitHub
parent 97520c827e
commit 48dfa45a9a

View File

@@ -1,5 +1,6 @@
import path from "path"
import fs from "fs/promises"
import { createWriteStream } from "fs"
import { Global } from "../global"
import z from "zod"
@@ -63,13 +64,15 @@ export namespace Log {
Global.Path.log,
options.dev ? "dev.log" : new Date().toISOString().split(".")[0].replace(/:/g, "") + ".log",
)
const logfile = Bun.file(logpath)
await fs.truncate(logpath).catch(() => {})
const writer = logfile.writer()
const stream = createWriteStream(logpath, { flags: "a" })
write = async (msg: any) => {
const num = writer.write(msg)
writer.flush()
return num
return new Promise((resolve, reject) => {
stream.write(msg, (err) => {
if (err) reject(err)
else resolve(msg.length)
})
})
}
}