diff --git a/.changeset/long-bees-promise.md b/.changeset/long-bees-promise.md new file mode 100644 index 000000000..af9b1a31f --- /dev/null +++ b/.changeset/long-bees-promise.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Fixes a bug related to local image files in SSR builds on Windows diff --git a/packages/integrations/image/README.md b/packages/integrations/image/README.md index 60c347ef9..07b191ba6 100644 --- a/packages/integrations/image/README.md +++ b/packages/integrations/image/README.md @@ -216,17 +216,15 @@ The list of sizes that should be built for responsive images. This is combined w
**Type:** `number` | `string`
-**Required:** `true`
+**Default:** `undefined`
**Type:** `Array<'avif' | 'jpeg' | 'png' | 'webp'>`
diff --git a/packages/integrations/image/src/build/ssr.ts b/packages/integrations/image/src/build/ssr.ts
index e8de6ae3c..19fea5aff 100644
--- a/packages/integrations/image/src/build/ssr.ts
+++ b/packages/integrations/image/src/build/ssr.ts
@@ -6,8 +6,8 @@ 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('./**/*.{heic,heif,avif,jpeg,jpg,png,tiff,webp,gif}', {
+ cwd: fileURLToPath(dir)
});
}
@@ -19,10 +19,11 @@ export interface SSRBuildParams {
export async function ssrBuild({ srcDir, outDir }: SSRBuildParams) {
const images = await globImages(srcDir);
- for await (const image of images) {
- const to = image.replace(fileURLToPath(srcDir), fileURLToPath(outDir));
+ for (const image of images) {
+ const from = path.join(fileURLToPath(srcDir), image);
+ const to = path.join(fileURLToPath(outDir), image);
await ensureDir(path.dirname(to));
- await fs.copyFile(image, to);
+ await fs.copyFile(from, to);
}
}
diff --git a/packages/integrations/image/src/endpoints/prod.ts b/packages/integrations/image/src/endpoints/prod.ts
index 657f3856d..667410a8b 100644
--- a/packages/integrations/image/src/endpoints/prod.ts
+++ b/packages/integrations/image/src/endpoints/prod.ts
@@ -21,7 +21,7 @@ export const get: APIRoute = async ({ request }) => {
} else {
const clientRoot = new URL('../client/', import.meta.url);
const localPath = new URL('.' + transform.src, clientRoot);
- inputBuffer = await loadLocalImage(localPath.pathname);
+ inputBuffer = await loadLocalImage(localPath);
}
if (!inputBuffer) {
diff --git a/packages/integrations/image/src/utils/images.ts b/packages/integrations/image/src/utils/images.ts
index f3c519657..cc5a26cdc 100644
--- a/packages/integrations/image/src/utils/images.ts
+++ b/packages/integrations/image/src/utils/images.ts
@@ -13,7 +13,7 @@ export function isRemoteImage(src: string) {
return /^http(s?):\/\//.test(src);
}
-export async function loadLocalImage(src: string) {
+export async function loadLocalImage(src: string | URL) {
try {
return await fs.readFile(src);
} catch {