From 82887101c7f933cc0820979baa0efe43fed30187 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Sat, 17 May 2025 16:02:24 -0300 Subject: [PATCH 01/11] Clarify and reduce Cloudflare integration logs --- packages/integrations/cloudflare/src/index.ts | 32 ++++++++++++------- .../cloudflare/src/utils/image-config.ts | 6 ++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index d5c2e0be900e..fe495e38d8ba 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -25,13 +25,13 @@ import { } from './utils/cloudflare-module-loader.js'; import { createGetEnv } from './utils/env.js'; import { createRoutesFile, getParts } from './utils/generate-routes-json.js'; -import { setImageConfig } from './utils/image-config.js'; +import { type ImageService, setImageConfig } from './utils/image-config.js'; export type { Runtime } from './entrypoints/server.js'; export type Options = { /** Options for handling images. */ - imageService?: 'passthrough' | 'cloudflare' | 'compile' | 'custom'; + imageService?: ImageService; /** Configuration for `_routes.json` generation. A _routes.json file controls when your Function is invoked. This file will include three different properties: * * - version: Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible. @@ -148,12 +148,17 @@ export default function createIntegration(args?: Options): AstroIntegration { if (!session?.driver) { const sessionDir = isBuild ? undefined : createCodegenDir(); const bindingName = args?.sessionKVBindingName ?? 'SESSION'; + logger.info( - `Enabling sessions with ${isBuild ? 'Cloudflare KV' : 'filesystem storage'}. Be sure to define a KV binding named "${bindingName}".`, - ); - logger.info( - `If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`, + `Enabling sessions with Cloudflare KV for production with the "${bindingName}" KV binding.`, ); + + if (isBuild) { + logger.info( + `If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`, + ); + } + session = isBuild ? { ...session, @@ -238,11 +243,16 @@ export default function createIntegration(args?: Options): AstroIntegration { hybridOutput: 'stable', staticOutput: 'unsupported', i18nDomains: 'experimental', - sharpImageService: { - support: 'limited', - message: - 'Cloudflare does not support sharp. You can use the `compile` image service to compile images at build time. It will not work for any on-demand rendered images.', - }, + // For explicitly set image services, this hack is used to suppress the warning about using `sharp` + // by inferring the user is aware of its implications. + // TODO: If an option to supress the warnings for `supportedAstroFeatures` is added, we should use it instead. + sharpImageService: args?.imageService + ? 'stable' + : { + support: 'limited', + message: + 'Cloudflare does not support sharp at runtime, but the `compile` image service can be used to optimize images with sharp on pre-rendered pages during build time.', + }, envGetSecret: 'stable', }, }); diff --git a/packages/integrations/cloudflare/src/utils/image-config.ts b/packages/integrations/cloudflare/src/utils/image-config.ts index f9ed1a709fd1..967b1b014390 100644 --- a/packages/integrations/cloudflare/src/utils/image-config.ts +++ b/packages/integrations/cloudflare/src/utils/image-config.ts @@ -1,8 +1,10 @@ import type { AstroConfig, AstroIntegrationLogger, HookParameters } from 'astro'; import { passthroughImageService, sharpImageService } from 'astro/config'; +export type ImageService = 'passthrough' | 'cloudflare' | 'compile' | 'custom'; + export function setImageConfig( - service: string, + service: ImageService, config: AstroConfig['image'], command: HookParameters<'astro:config:setup'>['command'], logger: AstroIntegrationLogger, @@ -35,7 +37,7 @@ export function setImageConfig( default: if (config.service.entrypoint === 'astro/assets/services/sharp') { logger.warn( - `The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`, + `The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'passthrough' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`, ); return { ...config, service: passthroughImageService() }; } From f592fa3e70d8a2dbd95f0d6ad42df4323f34900e Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 20 May 2025 07:58:03 -0300 Subject: [PATCH 02/11] Simplify log Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --- packages/integrations/cloudflare/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index fe495e38d8ba..bc7d303f8e27 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -251,7 +251,7 @@ export default function createIntegration(args?: Options): AstroIntegration { : { support: 'limited', message: - 'Cloudflare does not support sharp at runtime, but the `compile` image service can be used to optimize images with sharp on pre-rendered pages during build time.', + 'Cloudflare does not support sharp at runtime. However, you can configure `image service: 'compile'` to optimize images with sharp on prerendered pages during build time.', }, envGetSecret: 'stable', }, From 6b361459133b6ea1f220e3993491076267f40b4d Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 20 May 2025 08:01:25 -0300 Subject: [PATCH 03/11] Move enabling sessions log to only show in build --- packages/integrations/cloudflare/src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index bc7d303f8e27..358ae80ef666 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -149,11 +149,10 @@ export default function createIntegration(args?: Options): AstroIntegration { const sessionDir = isBuild ? undefined : createCodegenDir(); const bindingName = args?.sessionKVBindingName ?? 'SESSION'; - logger.info( - `Enabling sessions with Cloudflare KV for production with the "${bindingName}" KV binding.`, - ); - if (isBuild) { + logger.info( + `Enabling sessions with Cloudflare KV for production with the "${bindingName}" KV binding.`, + ); logger.info( `If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`, ); From 624778095495bdb2936d54b9233c1960b52baa38 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 20 May 2025 08:02:14 -0300 Subject: [PATCH 04/11] Use double quotes instead --- packages/integrations/cloudflare/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 358ae80ef666..c8854482f4d2 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -250,7 +250,7 @@ export default function createIntegration(args?: Options): AstroIntegration { : { support: 'limited', message: - 'Cloudflare does not support sharp at runtime. However, you can configure `image service: 'compile'` to optimize images with sharp on prerendered pages during build time.', + 'Cloudflare does not support sharp at runtime. However, you can configure `image service: "compile"` to optimize images with sharp on prerendered pages during build time.', }, envGetSecret: 'stable', }, From ce490e20d10927234bbfe2bccc6e7cf8ce956a5c Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Thu, 22 May 2025 16:34:21 -0300 Subject: [PATCH 05/11] Add option to suppress adapter feature support log --- .../src/integrations/features-validation.ts | 68 +++++++++++-------- .../astro/src/types/public/integrations.ts | 9 +++ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/packages/astro/src/integrations/features-validation.ts b/packages/astro/src/integrations/features-validation.ts index 0edcb7bb9139..058758627311 100644 --- a/packages/astro/src/integrations/features-validation.ts +++ b/packages/astro/src/integrations/features-validation.ts @@ -108,6 +108,10 @@ function getSupportMessage(supportKind: AdapterSupport): string | undefined { return typeof supportKind === 'object' ? supportKind.message : undefined; } +function getSupportMessageSuppression(supportKind: AdapterSupport): 'all' | 'default' | undefined { + return typeof supportKind === 'object' ? supportKind.suppress : undefined; +} + function validateSupportKind( supportKind: AdapterSupport, adapterName: string, @@ -117,6 +121,7 @@ function validateSupportKind( ): boolean { const supportValue = unwrapSupportKind(supportKind); const message = getSupportMessage(supportKind); + const suppress = getSupportMessageSuppression(supportKind); if (!supportValue) { return false; @@ -126,7 +131,7 @@ function validateSupportKind( return true; } else if (hasCorrectConfig()) { // If the user has the relevant configuration, but the adapter doesn't support it, warn the user - logFeatureSupport(adapterName, logger, featureName, supportValue, message); + logFeatureSupport(adapterName, logger, featureName, supportValue, message, suppress); } return false; @@ -138,38 +143,41 @@ function logFeatureSupport( featureName: string, supportKind: AdapterSupport, adapterMessage?: string, + suppress?: 'all' | 'default', ) { - switch (supportKind) { - case AdapterFeatureStability.STABLE: - break; - case AdapterFeatureStability.DEPRECATED: - logger.warn( - 'config', - `The adapter ${adapterName} has deprecated its support for "${featureName}", and future compatibility is not guaranteed. The adapter may completely remove support for this feature without warning.`, - ); - break; - case AdapterFeatureStability.EXPERIMENTAL: - logger.warn( - 'config', - `The adapter ${adapterName} provides experimental support for "${featureName}". You may experience issues or breaking changes until this feature is fully supported by the adapter.`, - ); - break; - case AdapterFeatureStability.LIMITED: - logger.warn( - 'config', - `The adapter ${adapterName} has limited support for "${featureName}". Certain features may not work as expected.`, - ); - break; - case AdapterFeatureStability.UNSUPPORTED: - logger.error( - 'config', - `The adapter ${adapterName} does not currently support the feature "${featureName}". Your project may not build correctly.`, - ); - break; + if (!suppress) { + switch (supportKind) { + case AdapterFeatureStability.STABLE: + break; + case AdapterFeatureStability.DEPRECATED: + logger.warn( + 'config', + `The adapter ${adapterName} has deprecated its support for "${featureName}", and future compatibility is not guaranteed. The adapter may completely remove support for this feature without warning.`, + ); + break; + case AdapterFeatureStability.EXPERIMENTAL: + logger.warn( + 'config', + `The adapter ${adapterName} provides experimental support for "${featureName}". You may experience issues or breaking changes until this feature is fully supported by the adapter.`, + ); + break; + case AdapterFeatureStability.LIMITED: + logger.warn( + 'config', + `The adapter ${adapterName} has limited support for "${featureName}". Certain features may not work as expected.`, + ); + break; + case AdapterFeatureStability.UNSUPPORTED: + logger.error( + 'config', + `The adapter ${adapterName} does not currently support the feature "${featureName}". Your project may not build correctly.`, + ); + break; + } } - // If the adapter specified a custom message, log it after the default message - if (adapterMessage) { + // If the adapter specified a custom message, log it after the default message (when not suppressed) + if (adapterMessage && suppress !== 'all') { logger.warn('adapter', adapterMessage); } } diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts index 2d0b13e96300..32e94b9c9169 100644 --- a/packages/astro/src/types/public/integrations.ts +++ b/packages/astro/src/types/public/integrations.ts @@ -67,6 +67,15 @@ export type AdapterSupportsKind = export type AdapterSupportWithMessage = { support: Exclude; message: string; + /** + * Determines if a feature support warning/error in the adapter should be suppressed: + * - `"default"`: Suppresses the default warning/error message. + * - `"all"`: Suppresses both the custom and the default warning/error message. + * + * This is useful when the warning/error might not be aplicable in certain contexts. + * Or the default message might cause confusion and conflict with the custom one. + */ + suppress?: 'all' | 'default'; }; export type AdapterSupport = AdapterSupportsKind | AdapterSupportWithMessage; From ec46803b0dd6d263c08f54fd884e939328f87f06 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Thu, 22 May 2025 16:34:40 -0300 Subject: [PATCH 06/11] Add fixture to test option --- .../astro.config.mjs | 29 +++++++++++++++++++ .../package.json | 15 ++++++++++ .../src/pages/index.astro | 0 pnpm-lock.yaml | 6 ++++ 4 files changed, 50 insertions(+) create mode 100644 packages/astro/test/fixtures/feature-support-message-suppresion/astro.config.mjs create mode 100644 packages/astro/test/fixtures/feature-support-message-suppresion/package.json create mode 100644 packages/astro/test/fixtures/feature-support-message-suppresion/src/pages/index.astro diff --git a/packages/astro/test/fixtures/feature-support-message-suppresion/astro.config.mjs b/packages/astro/test/fixtures/feature-support-message-suppresion/astro.config.mjs new file mode 100644 index 000000000000..a28113763aff --- /dev/null +++ b/packages/astro/test/fixtures/feature-support-message-suppresion/astro.config.mjs @@ -0,0 +1,29 @@ +import { defineConfig } from 'astro/config'; +export default defineConfig({ + integrations: [ + { + name: 'astro-test-feature-support-message-suppression', + hooks: { + 'astro:config:done': ({ setAdapter }) => { + setAdapter({ + name: 'astro-test-feature-support-message-suppression', + supportedAstroFeatures: { + staticOutput: "stable", + hybridOutput: "stable", + serverOutput: { + support: "experimental", + message: "This should be logged.", + suppress: "default", + }, + sharpImageService: { + support: 'limited', + message: 'This shouldn\'t be logged.', + suppress: "all", + }, + } + }) + }, + }, + }, + ], +}); diff --git a/packages/astro/test/fixtures/feature-support-message-suppresion/package.json b/packages/astro/test/fixtures/feature-support-message-suppresion/package.json new file mode 100644 index 000000000000..f34355172460 --- /dev/null +++ b/packages/astro/test/fixtures/feature-support-message-suppresion/package.json @@ -0,0 +1,15 @@ +{ + "name": "@test/feature-support-message-suppresion", + "type": "module", + "version": "0.0.1", + "private": true, + "scripts": { + "dev": "astro dev", + "build": "astro build", + "preview": "astro preview", + "astro": "astro" + }, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/feature-support-message-suppresion/src/pages/index.astro b/packages/astro/test/fixtures/feature-support-message-suppresion/src/pages/index.astro new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6457aedc5ac4..3e627fd964e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3086,6 +3086,12 @@ importers: specifier: workspace:* version: link:../../.. + packages/astro/test/fixtures/feature-support-message-suppresion: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/fetch: dependencies: '@astrojs/preact': From 908afe9ebf7635a1677befabc48e382c3ac4ce3c Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Fri, 23 May 2025 20:43:06 -0300 Subject: [PATCH 07/11] Add changeset --- .changeset/dull-beers-move.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .changeset/dull-beers-move.md diff --git a/.changeset/dull-beers-move.md b/.changeset/dull-beers-move.md new file mode 100644 index 000000000000..6df041ad8949 --- /dev/null +++ b/.changeset/dull-beers-move.md @@ -0,0 +1,21 @@ +--- +"astro": minor +--- + +Adds an option to suppress warning/errors in adapters' `supportedAstroFeatures`. This is useful when either an warning/error isn't applicable in a specific context or the default one might conflict and confuse users. + +To do so, you can add `suppress: "all"` (to suppress both the default and custom message) or `suppress: "default"` (to only suppress the default one): +```ts +setAdapter({ + name: 'my-astro-integration', + supportedAstroFeatures: { + staticOutput: "stable", + hybridOutput: "stable", + sharpImageService: { + support: 'limited', + message: 'The sharp image service isn't available in the deploy environment, but will be used by prerendered pages on build.', + suppress: "default", + }, + } +}) +``` From 7fbd8a65673c099ea266dd7c4a21fec3fb18bd0d Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:21:29 -0300 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Matt Kane --- .changeset/dull-beers-move.md | 8 +++++--- packages/astro/src/types/public/integrations.ts | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.changeset/dull-beers-move.md b/.changeset/dull-beers-move.md index 6df041ad8949..5c5679bdc9e2 100644 --- a/.changeset/dull-beers-move.md +++ b/.changeset/dull-beers-move.md @@ -2,7 +2,7 @@ "astro": minor --- -Adds an option to suppress warning/errors in adapters' `supportedAstroFeatures`. This is useful when either an warning/error isn't applicable in a specific context or the default one might conflict and confuse users. +Adds an option for integration authors to suppress adapter warning/errors in `supportedAstroFeatures`. This is useful when either an warning/error isn't applicable in a specific context or the default one might conflict and confuse users. To do so, you can add `suppress: "all"` (to suppress both the default and custom message) or `suppress: "default"` (to only suppress the default one): ```ts @@ -12,10 +12,12 @@ setAdapter({ staticOutput: "stable", hybridOutput: "stable", sharpImageService: { - support: 'limited', - message: 'The sharp image service isn't available in the deploy environment, but will be used by prerendered pages on build.', + support: "limited", + message: "The sharp image service isn't available in the deploy environment, but will be used by prerendered pages on build.", suppress: "default", }, } }) ``` + +For more information, see the [Adapter API reference docs](https://docs.astro.build/en/reference/adapter-reference/#astro-features). diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts index 32e94b9c9169..6bb437f31509 100644 --- a/packages/astro/src/types/public/integrations.ts +++ b/packages/astro/src/types/public/integrations.ts @@ -72,8 +72,8 @@ export type AdapterSupportWithMessage = { * - `"default"`: Suppresses the default warning/error message. * - `"all"`: Suppresses both the custom and the default warning/error message. * - * This is useful when the warning/error might not be aplicable in certain contexts. - * Or the default message might cause confusion and conflict with the custom one. + * This is useful when the warning/error might not be applicable in certain contexts, + * or the default message might cause confusion and conflict with a custom one. */ suppress?: 'all' | 'default'; }; From 7c8d9977eec1b751ac670489be8a802096355cfe Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:05:22 -0300 Subject: [PATCH 09/11] Use `suppress` option instead of hack --- packages/integrations/cloudflare/src/index.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index c8854482f4d2..7476c29ff47c 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -242,16 +242,14 @@ export default function createIntegration(args?: Options): AstroIntegration { hybridOutput: 'stable', staticOutput: 'unsupported', i18nDomains: 'experimental', - // For explicitly set image services, this hack is used to suppress the warning about using `sharp` - // by inferring the user is aware of its implications. - // TODO: If an option to supress the warnings for `supportedAstroFeatures` is added, we should use it instead. - sharpImageService: args?.imageService - ? 'stable' - : { - support: 'limited', - message: - 'Cloudflare does not support sharp at runtime. However, you can configure `image service: "compile"` to optimize images with sharp on prerendered pages during build time.', - }, + sharpImageService: { + support: 'limited', + message: + 'Cloudflare does not support sharp at runtime. However, you can configure `imageService: "compile"` to optimize images with sharp on prerendered pages during build time.', + // For explicitly set image services, we suppress the warning about sharp not being supported at runtime, + // inferring the user is aware of the limitations. + suppress: args?.imageService ? 'all' : 'default', + }, envGetSecret: 'stable', }, }); From ba9360a527431ebe19ec98799f28dcb7bc91b318 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:12:23 -0300 Subject: [PATCH 10/11] Create fast-planets-shout.md --- .changeset/fast-planets-shout.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/fast-planets-shout.md diff --git a/.changeset/fast-planets-shout.md b/.changeset/fast-planets-shout.md new file mode 100644 index 000000000000..1bf441249725 --- /dev/null +++ b/.changeset/fast-planets-shout.md @@ -0,0 +1,7 @@ +--- +"@astrojs/cloudflare": minor +--- + +Clarifies and reduces a few logs when starting the dev server with `@astrojs/cloudflare`. + +Warnings about sharp support will now be suppressed when you have explicitly set an `imageService` option. From ca703e10710777a9a15c1cc5deb1d1f6b1e35688 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:42:47 -0300 Subject: [PATCH 11/11] Update .changeset/fast-planets-shout.md Co-authored-by: Matt Kane --- .changeset/fast-planets-shout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fast-planets-shout.md b/.changeset/fast-planets-shout.md index 1bf441249725..65216f7c9fe8 100644 --- a/.changeset/fast-planets-shout.md +++ b/.changeset/fast-planets-shout.md @@ -1,5 +1,5 @@ --- -"@astrojs/cloudflare": minor +"@astrojs/cloudflare": patch --- Clarifies and reduces a few logs when starting the dev server with `@astrojs/cloudflare`.