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
5 changes: 5 additions & 0 deletions .changeset/dirty-breads-wish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a regression where the the routes emitted by the `astro:build:done` hook didn't have the `distURL` array correctly populated.
9 changes: 9 additions & 0 deletions .changeset/fix-cloudflare-configpath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@astrojs/cloudflare': patch
---

fix(cloudflare): forward `configPath` and other `PluginConfig` options to the Cloudflare Vite Plugin

Options like `configPath`, `inspectorPort`, `persistState`, `remoteBindings`, and `auxiliaryWorkers` were accepted by the type system but never forwarded to `cfVitePlugin()`, making them silently ignored.

Also fixes `addWatchFile` for `configPath` which resolved the path relative to the adapter's `node_modules` directory instead of the project root.
5 changes: 5 additions & 0 deletions .changeset/tall-loops-take.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

fix cloudflare image transform ignoring quality parameter
18 changes: 18 additions & 0 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ export async function generatePages(
}
}

// After generation, propagate distURL from the deserialized routes (used during generation)
// back to the original routes in allPages. The prerenderer operates on deserialized route
// objects (reconstructed from the serialized manifest), so distURL mutations during generation
// don't affect the original route objects that are later passed to the astro:build:done hook.
for (const { route: generatedRoute } of filteredPaths) {
if (generatedRoute.distURL && generatedRoute.distURL.length > 0) {
for (const pageData of Object.values(options.allPages)) {
if (
pageData.route.route === generatedRoute.route &&
pageData.route.component === generatedRoute.component
) {
pageData.route.distURL = generatedRoute.distURL;
break;
}
}
}
}

const staticImageList = getStaticImageList();

// Must happen before teardown since collectStaticImages fetches from the prerender server
Expand Down
9 changes: 7 additions & 2 deletions packages/astro/test/static-build-page-dist-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ describe('Static build: pages routes have distURL', () => {
});
it('Pages routes have distURL', async () => {
assert.equal(assets.size > 0, true, 'Pages not found: build end hook not being called');
for (const [p, distURL] of assets.entries()) {
for (const [route, distURL] of assets.entries()) {
assert.equal(
distURL.length > 0,
true,
`Route "${route}" has an empty distURL array — asset URLs were not propagated to astro:build:done`,
);
for (const url of distURL) {
assert.equal(url instanceof URL, true, `${p.pathname} doesn't include distURL`);
assert.equal(url instanceof URL, true, `Route "${route}" distURL entry is not a URL`);
}
}
});
Expand Down
9 changes: 6 additions & 3 deletions packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { parseEnv } from 'node:util';
import { sessionDrivers } from 'astro/config';
import { createCloudflarePrerenderer } from './prerenderer.js';
import { createRequire } from 'node:module';

const CLOUDFLARE_KV_SESSION_DRIVER_ENTRYPOINT = sessionDrivers.cloudflareKVBinding().entrypoint;

Expand Down Expand Up @@ -176,7 +175,11 @@ export default function createIntegration({
session,
vite: {
plugins: [
cfVitePlugin({ ...cfPluginConfig, viteEnvironment: { name: 'ssr' } }),
cfVitePlugin({
...cloudflareOptions,
...cfPluginConfig,
viteEnvironment: { name: 'ssr' },
}),
{
name: '@astrojs/cloudflare:cf-imports',
enforce: 'pre',
Expand Down Expand Up @@ -278,7 +281,7 @@ export default function createIntegration({
});

if (cloudflareOptions.configPath) {
addWatchFile(createRequire(import.meta.url).resolve(cloudflareOptions.configPath));
addWatchFile(new URL(cloudflareOptions.configPath, config.root));
}

addWatchFile(new URL('./wrangler.toml', config.root));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { imageConfig } from 'astro:assets';
import { isRemotePath } from '@astrojs/internal-helpers/path';
import { isRemoteAllowed } from '@astrojs/internal-helpers/remote';
import type { ImageOutputOptions, ImageTransform } from '@cloudflare/workers-types';
import type { ImageQualityPreset } from 'astro';

const qualityTable: Record<ImageQualityPreset, number> = {
low: 25,
mid: 50,
high: 80,
max: 100,
};

export async function transform(
rawUrl: string,
Expand Down Expand Up @@ -43,10 +51,14 @@ export async function transform(
.transform({
width: url.searchParams.has('w') ? Number.parseInt(url.searchParams.get('w')!) : undefined,
height: url.searchParams.has('h') ? Number.parseInt(url.searchParams.get('h')!) : undefined,
// `quality` is documented, but doesn't appear to work in manual testing...
// quality: url.searchParams.get('q'),
fit: url.searchParams.get('fit') as ImageTransform['fit'],
})
.output({ format: outputFormat })
.output({
quality: url.searchParams.get('q')
? (qualityTable[url.searchParams.get('q') as ImageQualityPreset] ??
Number.parseInt(url.searchParams.get('q')!))
: undefined,
format: outputFormat,
})
).response();
}
Loading