fix: don't allow ':' in log file and project dir

Windows does not allow ':' in file or directory names. Make sure the log
file and the project directory do not contain ':' to prevent ENOENT
errors.
This commit is contained in:
Matthew Glazar 2025-06-22 18:41:10 -04:00 committed by Dax Raad
parent 6bc32551a0
commit 7fa2d78c3d
2 changed files with 11 additions and 2 deletions

View file

@ -46,7 +46,7 @@ export namespace App {
const data = path.join(
Global.Path.data,
"project",
git ? git.split(path.sep).filter(Boolean).join("-") : "global",
git ? directory(git) : "global",
)
const stateFile = Bun.file(path.join(data, APP_JSON))
const state = (await stateFile.json().catch(() => ({}))) as {
@ -133,4 +133,13 @@ export namespace App {
}),
)
}
function directory(input: string): string {
return input
.split(path.sep)
.filter(Boolean)
.join("-")
.replace(/[^A-Za-z0-9_]/g, "-")
}
}

View file

@ -19,7 +19,7 @@ export namespace Log {
await fs.mkdir(dir, { recursive: true })
cleanup(dir)
if (options.print) return
logpath = path.join(dir, new Date().toISOString().split(".")[0] + ".log")
logpath = path.join(dir, new Date().toISOString().split(".")[0].replace(/:/g, "") + ".log")
const logfile = Bun.file(logpath)
await fs.truncate(logpath).catch(() => {})
const writer = logfile.writer()