fix: check if content layer files have changed before writing (#12962)

This commit is contained in:
Matt Kane 2025-01-10 14:42:38 +00:00 committed by GitHub
parent 1f9571b2b9
commit 4b7a2ce9e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Skips updating content layer files if content is unchanged

View file

@ -212,6 +212,11 @@ export default new Map([\n${lines.join(',\n')}]);
const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
try {
const oldData = await fs.readFile(filePath, 'utf-8').catch(() => '');
if (oldData === data) {
// If the data hasn't changed, we can skip the write
return;
}
// Write it to a temporary file first and then move it to prevent partial reads.
await fs.writeFile(tempFile, data);
await fs.rename(tempFile, filePath);