Skip to content

Commit f242213

Browse files
Copilotmaartenba
andauthored
Replace incremental handle.write() with fs.writeFile() to avoid partial writes
Agent-Logs-Url: https://github.com/DuendeSoftware/docs.duendesoftware.com/sessions/227e15e2-f727-434d-8cb5-edce0021356f Co-authored-by: maartenba <485230+maartenba@users.noreply.github.com>
1 parent 80f7cfe commit f242213

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

astro/src/plugins/static-redirects.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,15 @@ export async function writeToOutput(hookOptions: any) {
196196
return;
197197
}
198198

199-
// Write redirects.json by streaming to avoid a full in-memory JSON string
200199
const jsonDestinationPath = path.join(
201200
url.fileURLToPath(outDir),
202201
"redirects.json",
203202
);
204-
const handle = await fs.open(jsonDestinationPath, "w");
205-
try {
206-
let first = true;
207-
await handle.write("{\n");
208-
for (const [key, value] of redirectMap) {
209-
if (!first) await handle.write(",\n");
210-
await handle.write(` ${JSON.stringify(key)}: ${JSON.stringify(value)}`);
211-
first = false;
212-
}
213-
await handle.write("\n}\n");
214-
} finally {
215-
await handle.close();
216-
}
203+
await fs.writeFile(
204+
jsonDestinationPath,
205+
JSON.stringify(Object.fromEntries(redirectMap), null, 2),
206+
"utf-8",
207+
);
217208

218209
logger.info(
219210
`Generated ${redirectMap.size} redirects: ${jsonDestinationPath}`,

0 commit comments

Comments
 (0)