Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored and astrobot-houston committed Jan 9, 2025
1 parent 8e64bb7 commit 2c99b52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions packages/astro/test/core-image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 2c99b52

Please sign in to comment.