summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/assets/build/generate.ts14
-rw-r--r--packages/astro/test/core-image.test.js9
2 files changed, 13 insertions, 10 deletions
diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts
index c7cf720aa..57c3344ab 100644
--- a/packages/astro/src/assets/build/generate.ts
+++ b/packages/astro/src/assets/build/generate.ts
@@ -166,7 +166,7 @@ export async function generateImagesForPath(
const cacheFile = basename(filepath);
const cachedFileURL = new URL(cacheFile, env.assetsCacheDir);
-
+
// For remote images, we also save a JSON file with the expiration date, etag and last-modified date from the server
const cacheMetaFile = cacheFile + '.json';
const cachedMetaFileURL = new URL(cacheMetaFile, env.assetsCacheDir);
@@ -194,17 +194,17 @@ export async function generateImagesForPath(
`Malformed cache entry for ${filepath}, cache will be regenerated for this file.`,
);
}
-
+
// Upgrade old base64 encoded asset cache to the new format
if (JSONData.data) {
const { data, ...meta } = JSONData;
-
+
await Promise.all([
fs.promises.writeFile(cachedFileURL, Buffer.from(data, 'base64')),
writeCacheMetaFile(cachedMetaFileURL, meta, env),
]);
}
-
+
// If the cache entry is not expired, use it
if (JSONData.expires > Date.now()) {
await fs.promises.copyFile(cachedFileURL, finalFileURL, fs.constants.COPYFILE_FICLONE);
@@ -229,7 +229,11 @@ export async function generateImagesForPath(
// Freshen cache on disk
await writeCacheMetaFile(cachedMetaFileURL, revalidatedData, env);
- await fs.promises.copyFile(cachedFileURL, finalFileURL, fs.constants.COPYFILE_FICLONE);
+ await fs.promises.copyFile(
+ cachedFileURL,
+ finalFileURL,
+ fs.constants.COPYFILE_FICLONE,
+ );
return { cached: 'revalidated' };
}
} catch (e) {
diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js
index 8ff73b14e..a2ebfb88d 100644
--- a/packages/astro/test/core-image.test.js
+++ b/packages/astro/test/core-image.test.js
@@ -1004,9 +1004,7 @@ describe('astro:image', () => {
const generatedImages = (await fixture.glob('_astro/**/*.webp'))
.map((path) => basename(path))
.sort();
- const cachedImages = [
- ...(await fixture.glob('../node_modules/.astro/assets/**/*.webp')),
- ]
+ const cachedImages = [...(await fixture.glob('../node_modules/.astro/assets/**/*.webp'))]
.map((path) => basename(path))
.sort();
@@ -1038,11 +1036,12 @@ describe('astro:image', () => {
it('writes remote image cache metadata', async () => {
const html = await fixture.readFile('/remote/index.html');
const $ = cheerio.load(html);
- const metaSrc = "../node_modules/.astro/assets/" + basename($('#remote img').attr('src')) + ".json";
+ const metaSrc =
+ '../node_modules/.astro/assets/' + basename($('#remote img').attr('src')) + '.json';
const data = await fixture.readFile(metaSrc, null);
assert.equal(data instanceof Buffer, true);
const metadata = JSON.parse(data.toString());
- assert.equal(typeof metadata.expires, "number");
+ assert.equal(typeof metadata.expires, 'number');
});
it('client images are written to build', async () => {