(filePath: string, line: string)
| 72 | } |
| 73 | |
| 74 | async function appendLine(filePath: string, line: string): Promise<void> { |
| 75 | await enqueueWrite(async () => { |
| 76 | await ensureParentDirectory(filePath); |
| 77 | let current = ""; |
| 78 | try { |
| 79 | current = await readFile(filePath, "utf8"); |
| 80 | } catch (error) { |
| 81 | const typed = asError(error); |
| 82 | if ((typed as NodeJS.ErrnoException).code !== "ENOENT") { |
| 83 | throw typed; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const tempPath = `${filePath}.${crypto.randomUUID()}.tmp`; |
| 88 | await writeFile(tempPath, `${current}${line}\n`, "utf8"); |
| 89 | await rename(tempPath, filePath); |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | async function appendLog(filePath: string, line: string): Promise<void> { |
| 94 | await appendLine(filePath, `[${new Date().toISOString()}] ${line}`); |
no test coverage detected