diff --git a/packages/integrations/image/src/build/ssg.ts b/packages/integrations/image/src/build/ssg.ts index a3e410709..951f62331 100644 --- a/packages/integrations/image/src/build/ssg.ts +++ b/packages/integrations/image/src/build/ssg.ts @@ -2,9 +2,9 @@ import fs from 'fs/promises'; import path from 'path'; import { fileURLToPath } from 'url'; import { OUTPUT_DIR } from '../constants.js'; -import { ensureDir } from '../utils/paths.js'; -import { isRemoteImage, loadRemoteImage, loadLocalImage } from '../utils/images.js'; import type { SSRImageService, TransformOptions } from '../types.js'; +import { isRemoteImage, loadLocalImage, loadRemoteImage } from '../utils/images.js'; +import { ensureDir } from '../utils/paths.js'; export interface SSGBuildParams { loader: SSRImageService; @@ -13,12 +13,7 @@ export interface SSGBuildParams { outDir: URL; } -export async function ssgBuild({ - loader, - staticImages, - srcDir, - outDir, -}: SSGBuildParams) { +export async function ssgBuild({ loader, staticImages, srcDir, outDir }: SSGBuildParams) { const inputFiles = new Set(); // process transforms one original image file at a time @@ -51,10 +46,7 @@ export async function ssgBuild({ let outputFile: string; if (isRemoteImage(src)) { - const outputFileURL = new URL( - path.join('./', OUTPUT_DIR, path.basename(filename)), - outDir - ); + const outputFileURL = new URL(path.join('./', OUTPUT_DIR, path.basename(filename)), outDir); outputFile = fileURLToPath(outputFileURL); } else { const outputFileURL = new URL(path.join('./', OUTPUT_DIR, filename), outDir); diff --git a/packages/integrations/image/src/build/ssr.ts b/packages/integrations/image/src/build/ssr.ts index 90a699451..2585868b9 100644 --- a/packages/integrations/image/src/build/ssr.ts +++ b/packages/integrations/image/src/build/ssr.ts @@ -6,10 +6,9 @@ import { ensureDir } from '../utils/paths.js'; async function globImages(dir: URL) { const srcPath = fileURLToPath(dir); - return await glob( - `${srcPath}/**/*.{heic,heif,avif,jpeg,jpg,png,tiff,webp,gif}`, - { absolute: true } - ); + return await glob(`${srcPath}/**/*.{heic,heif,avif,jpeg,jpg,png,tiff,webp,gif}`, { + absolute: true, + }); } export interface SSRBuildParams { diff --git a/packages/integrations/image/src/integration.ts b/packages/integrations/image/src/integration.ts index 0b9542caa..afbeb00a9 100644 --- a/packages/integrations/image/src/integration.ts +++ b/packages/integrations/image/src/integration.ts @@ -2,8 +2,8 @@ import type { AstroConfig, AstroIntegration } from 'astro'; import { ssgBuild } from './build/ssg.js'; import { ssrBuild } from './build/ssr.js'; import { PKG_NAME, ROUTE_PATTERN } from './constants.js'; -import { filenameFormat, propsToFilename } from './utils/paths.js'; import { IntegrationOptions, TransformOptions } from './types.js'; +import { filenameFormat, propsToFilename } from './utils/paths.js'; import { createPlugin } from './vite-plugin-astro-image.js'; export default function integration(options: IntegrationOptions = {}): AstroIntegration { diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 60a6b60da..e0f57e873 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -101,9 +101,7 @@ async function resolveTransform(input: GetImageTransform): Promise` element. */ -export async function getImage( - transform: GetImageTransform -): Promise { +export async function getImage(transform: GetImageTransform): Promise { if (!transform.src) { throw new Error('[@astrojs/image] `src` is required'); } diff --git a/packages/integrations/image/src/lib/get-picture.ts b/packages/integrations/image/src/lib/get-picture.ts index a214e1fe6..7b7273616 100644 --- a/packages/integrations/image/src/lib/get-picture.ts +++ b/packages/integrations/image/src/lib/get-picture.ts @@ -1,13 +1,8 @@ import { lookup } from 'mrmime'; import { extname } from 'path'; -import { getImage } from './get-image.js'; -import { - ImageAttributes, - ImageMetadata, - OutputFormat, - TransformOptions, -} from '../types.js'; +import { ImageAttributes, ImageMetadata, OutputFormat, TransformOptions } from '../types.js'; import { parseAspectRatio } from '../utils/images.js'; +import { getImage } from './get-image.js'; export interface GetPictureParams { src: string | ImageMetadata | Promise<{ default: ImageMetadata }>; @@ -45,7 +40,7 @@ async function resolveFormats({ src, formats }: GetPictureParams) { export async function getPicture(params: GetPictureParams): Promise { const { src, widths } = params; - + if (!src) { throw new Error('[@astrojs/image] `src` is required'); } diff --git a/packages/integrations/image/src/utils/paths.ts b/packages/integrations/image/src/utils/paths.ts index 90e744252..1ba299526 100644 --- a/packages/integrations/image/src/utils/paths.ts +++ b/packages/integrations/image/src/utils/paths.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; import { OUTPUT_DIR } from '../constants.js'; +import type { TransformOptions } from '../types.js'; import { isRemoteImage } from './images.js'; import { shorthash } from './shorthash.js'; -import type { TransformOptions } from '../types.js'; export function ensureDir(dir: string) { fs.mkdirSync(dir, { recursive: true }); @@ -32,9 +32,5 @@ export function propsToFilename({ src, width, height, format }: TransformOptions export function filenameFormat(transform: TransformOptions) { return isRemoteImage(transform.src) ? path.join(OUTPUT_DIR, path.basename(propsToFilename(transform))) - : path.join( - OUTPUT_DIR, - path.dirname(transform.src), - path.basename(propsToFilename(transform)) - ); + : path.join(OUTPUT_DIR, path.dirname(transform.src), path.basename(propsToFilename(transform))); } diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index 5ca9c1571..7a494e989 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -3,8 +3,8 @@ import type { PluginContext } from 'rollup'; import slash from 'slash'; import { pathToFileURL } from 'url'; import type { Plugin, ResolvedConfig } from 'vite'; -import { metadata } from './utils/metadata.js'; import type { IntegrationOptions } from './types.js'; +import { metadata } from './utils/metadata.js'; export function createPlugin(config: AstroConfig, options: Required): Plugin { const filter = (id: string) => @@ -60,6 +60,6 @@ export function createPlugin(config: AstroConfig, options: Required { - ['/assets/social.jpg', '/assets/social.png', '/assets/blog/introducing-astro.jpg'].map(verifyImage); + ['/assets/social.jpg', '/assets/social.png', '/assets/blog/introducing-astro.jpg'].map( + verifyImage + ); }); }); diff --git a/packages/integrations/image/test/picture-ssr.test.js b/packages/integrations/image/test/picture-ssr.test.js index 8810ec760..080cdbd2b 100644 --- a/packages/integrations/image/test/picture-ssr.test.js +++ b/packages/integrations/image/test/picture-ssr.test.js @@ -87,7 +87,9 @@ describe('SSR pictures - build', function () { }); it('includes the original images', () => { - ['/assets/social.jpg', '/assets/social.png', '/assets/blog/introducing-astro.jpg'].map(verifyImage); + ['/assets/social.jpg', '/assets/social.png', '/assets/blog/introducing-astro.jpg'].map( + verifyImage + ); }); }); diff --git a/packages/integrations/image/test/rotation.test.js b/packages/integrations/image/test/rotation.test.js index 9eee72918..19333e572 100644 --- a/packages/integrations/image/test/rotation.test.js +++ b/packages/integrations/image/test/rotation.test.js @@ -33,16 +33,20 @@ describe('Image rotation', function () { it('includes attributes', () => { for (let i = 0; i < 9; i++) { const image = $(`#landscape-${i}`); - + expect(image.attr('src')).to.equal(`/_image/assets/Landscape_${i}_1800x1200.jpg`); expect(image.attr('width')).to.equal('1800'); expect(image.attr('height')).to.equal('1200'); } }); - + it('built the optimized image', () => { for (let i = 0; i < 9; i++) { - verifyImage(`/_image/assets/Landscape_${i}_1800x1200.jpg`, { width: 1800, height: 1200, type: 'jpg' }); + verifyImage(`/_image/assets/Landscape_${i}_1800x1200.jpg`, { + width: 1800, + height: 1200, + type: 'jpg', + }); } }); }); @@ -51,16 +55,20 @@ describe('Image rotation', function () { it('includes attributes', () => { for (let i = 0; i < 9; i++) { const image = $(`#portrait-${i}`); - + expect(image.attr('src')).to.equal(`/_image/assets/Portrait_${i}_1200x1800.jpg`); expect(image.attr('width')).to.equal('1200'); expect(image.attr('height')).to.equal('1800'); } }); - + it('built the optimized image', () => { for (let i = 0; i < 9; i++) { - verifyImage(`/_image/assets/Portrait_${i}_1200x1800.jpg`, { width: 1200, height: 1800, type: 'jpg' }); + verifyImage(`/_image/assets/Portrait_${i}_1200x1800.jpg`, { + width: 1200, + height: 1800, + type: 'jpg', + }); } }); });