From 66cdc7e4d0123cee4b57ec2d9bc1328339e5d9ec Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 5 Aug 2022 20:15:51 +0000 Subject: [PATCH 1/3] [ci] format --- turbo.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/turbo.json b/turbo.json index 190298a0ca27..813cdbdf6fab 100644 --- a/turbo.json +++ b/turbo.json @@ -15,10 +15,7 @@ }, "test": { "outputs": [], - "dependsOn": [ - "$RUNNER_OS", - "$NODE_VERSION" - ] + "dependsOn": ["$RUNNER_OS", "$NODE_VERSION"] }, "benchmark": { "dependsOn": ["^build"], From 5811208182fb70fad730b0e495d054ba970b9353 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Fri, 5 Aug 2022 20:36:30 +0000 Subject: [PATCH 2/3] Fixes local image resolution in SSR builds on Windows (#4173) * fixing SSR local file resolution path on windows * chore: add changeset * nit: fixing typo in image README file Co-authored-by: Nate Moore --- .changeset/long-bees-promise.md | 5 +++++ packages/integrations/image/README.md | 6 ++---- packages/integrations/image/src/build/ssr.ts | 11 ++++++----- packages/integrations/image/src/endpoints/prod.ts | 2 +- packages/integrations/image/src/utils/images.ts | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .changeset/long-bees-promise.md diff --git a/.changeset/long-bees-promise.md b/.changeset/long-bees-promise.md new file mode 100644 index 000000000000..af9b1a31f620 --- /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 60c347ef9d2c..07b191ba646a 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`

-The desired aspect ratio of the output image. This is combined with `widhts` to calculate the final dimensions of each built image. +The desired aspect ratio of the output image. This is combined with `widths` to calculate the final dimensions of each built image. A `string` can be provided in the form of `{width}:{height}`, ex: `16:9` or `3:4`. A `number` can also be provided, useful when the aspect ratio is calculated at build time. This can be an inline number such as `1.777` or inlined as a JSX expression like `aspectRatio={16/9}`. -#### formats -

**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 e8de6ae3c710..19fea5aff3ac 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 657f3856dac5..667410a8b7d4 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 f3c5196573a6..cc5a26cdcb21 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 { From 14d27c1d6f8f9d7143547bf330398bbc6a5ee4f4 Mon Sep 17 00:00:00 2001 From: tony-sull Date: Fri, 5 Aug 2022 20:38:06 +0000 Subject: [PATCH 3/3] [ci] format --- packages/integrations/image/src/build/ssr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/image/src/build/ssr.ts b/packages/integrations/image/src/build/ssr.ts index 19fea5aff3ac..940fc5249929 100644 --- a/packages/integrations/image/src/build/ssr.ts +++ b/packages/integrations/image/src/build/ssr.ts @@ -7,7 +7,7 @@ import { ensureDir } from '../utils/paths.js'; async function globImages(dir: URL) { const srcPath = fileURLToPath(dir); return await glob('./**/*.{heic,heif,avif,jpeg,jpg,png,tiff,webp,gif}', { - cwd: fileURLToPath(dir) + cwd: fileURLToPath(dir), }); }