Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/forty-peaches-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/cloudflare': patch
'@astrojs/netlify': patch
---

Unify imported images detection across adapters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ExternalImageService } from 'astro';

import { joinPaths } from '@astrojs/internal-helpers/path';
import { baseService } from 'astro/assets';
import { isESMImportedImage, isRemoteAllowed } from '../utils/assets.js';
import { isESMImportedImage } from 'astro/assets/utils';
import { isRemoteAllowed } from '../utils/assets.js';

const service: ExternalImageService = {
...baseService,
Expand Down
5 changes: 1 addition & 4 deletions packages/integrations/cloudflare/src/utils/assets.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import type { AstroConfig, ImageMetadata, RemotePattern } from 'astro';
import type { AstroConfig, RemotePattern } from 'astro';

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
}
function matchHostname(url: URL, hostname?: string, allowWildcard?: boolean) {
if (!hostname) {
return true;
Expand Down
7 changes: 2 additions & 5 deletions packages/integrations/netlify/src/image-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { ExternalImageService, ImageMetadata } from 'astro';
import type { ExternalImageService } from 'astro';
import { baseService } from 'astro/assets';
import { isESMImportedImage } from 'astro/assets/utils';
import { AstroError } from 'astro/errors';

const SUPPORTED_FORMATS = ['avif', 'jpg', 'png', 'webp'];
const QUALITY_NAMES: Record<string, number> = { low: 25, mid: 50, high: 90, max: 100 };

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
}

function removeLeadingForwardSlash(path: string) {
return path.startsWith('/') ? path.substring(1) : path;
}
Expand Down