mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
fix: check if content layer files have changed before writing (#12962)
This commit is contained in:
parent
1f9571b2b9
commit
4b7a2ce9e7
2 changed files with 10 additions and 0 deletions
5
.changeset/light-meals-press.md
Normal file
5
.changeset/light-meals-press.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Skips updating content layer files if content is unchanged
|
|
@ -212,6 +212,11 @@ export default new Map([\n${lines.join(',\n')}]);
|
||||||
|
|
||||||
const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
|
const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
|
||||||
try {
|
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.
|
// Write it to a temporary file first and then move it to prevent partial reads.
|
||||||
await fs.writeFile(tempFile, data);
|
await fs.writeFile(tempFile, data);
|
||||||
await fs.rename(tempFile, filePath);
|
await fs.rename(tempFile, filePath);
|
||||||
|
|
Loading…
Add table
Reference in a new issue