diff options
author | 2024-11-16 01:25:42 +0800 | |
---|---|---|
committer | 2024-11-15 18:25:42 +0100 | |
commit | 25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b (patch) | |
tree | 6bdb98237c5e729167a3a7233a88756de6bc4e7f | |
parent | cec4af8fe59ff895c0ca82aab8b6ed6a81ad1f4d (diff) | |
download | astro-25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b.tar.gz astro-25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b.tar.zst astro-25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b.zip |
Ensure final asset directory exists before writing cached files (#12418)mandar1jn/ci-repo-check
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r-- | .changeset/thick-shrimps-hammer.md | 5 | ||||
-rw-r--r-- | packages/astro/src/assets/build/generate.ts | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/.changeset/thick-shrimps-hammer.md b/.changeset/thick-shrimps-hammer.md new file mode 100644 index 000000000..b46b9ad6c --- /dev/null +++ b/.changeset/thick-shrimps-hammer.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix cached image redownloading if it is the first asset diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index 645a0acdc..da76cafa3 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -153,6 +153,9 @@ export async function generateImagesForPath( const isLocalImage = isESMImportedImage(options.src); const finalFileURL = new URL('.' + filepath, env.clientRoot); + const finalFolderURL = new URL('./', finalFileURL); + await fs.promises.mkdir(finalFolderURL, { recursive: true }); + // For remote images, instead of saving the image directly, we save a JSON file with the image data and expiration date from the server const cacheFile = basename(filepath) + (isLocalImage ? '' : '.json'); const cachedFileURL = new URL(cacheFile, env.assetsCacheDir); @@ -194,9 +197,6 @@ export async function generateImagesForPath( // If the cache file doesn't exist, just move on, and we'll generate it } - const finalFolderURL = new URL('./', finalFileURL); - await fs.promises.mkdir(finalFolderURL, { recursive: true }); - // The original filepath or URL from the image transform const originalImagePath = isLocalImage ? (options.src as ImageMetadata).src |