Skip to content

Commit 25baa4e

Browse files
oliverlynchPrincesseuh
andauthoredNov 15, 2024··
Ensure final asset directory exists before writing cached files (#12418)
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
1 parent cec4af8 commit 25baa4e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎.changeset/thick-shrimps-hammer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix cached image redownloading if it is the first asset

‎packages/astro/src/assets/build/generate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ export async function generateImagesForPath(
153153
const isLocalImage = isESMImportedImage(options.src);
154154
const finalFileURL = new URL('.' + filepath, env.clientRoot);
155155

156+
const finalFolderURL = new URL('./', finalFileURL);
157+
await fs.promises.mkdir(finalFolderURL, { recursive: true });
158+
156159
// For remote images, instead of saving the image directly, we save a JSON file with the image data and expiration date from the server
157160
const cacheFile = basename(filepath) + (isLocalImage ? '' : '.json');
158161
const cachedFileURL = new URL(cacheFile, env.assetsCacheDir);
@@ -194,9 +197,6 @@ export async function generateImagesForPath(
194197
// If the cache file doesn't exist, just move on, and we'll generate it
195198
}
196199

197-
const finalFolderURL = new URL('./', finalFileURL);
198-
await fs.promises.mkdir(finalFolderURL, { recursive: true });
199-
200200
// The original filepath or URL from the image transform
201201
const originalImagePath = isLocalImage
202202
? (options.src as ImageMetadata).src

0 commit comments

Comments
 (0)
Please sign in to comment.