chore(core): improve the logging of assets feature (#8615)

* improve assets logging

* changeset

* fix typo

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>

* improve log message

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* update log message

* update changeset

---------

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
Alexander Niebuhr 2023-09-23 18:15:49 +02:00 committed by GitHub
parent 1d4f91b033
commit 4c4ad9d167
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improve the logging of assets for adapters that do not support image optimization

View file

@ -131,7 +131,7 @@ function validateAssetsFeature(
isSquooshCompatible = false,
} = assets;
if (config?.image?.service?.entrypoint === SHARP_SERVICE && !isSharpCompatible) {
logger.error(
logger.warn(
'astro',
`The currently selected adapter \`${adapterName}\` is not compatible with the image service "Sharp".`
);
@ -139,7 +139,7 @@ function validateAssetsFeature(
}
if (config?.image?.service?.entrypoint === SQUOOSH_SERVICE && !isSquooshCompatible) {
logger.error(
logger.warn(
'astro',
`The currently selected adapter \`${adapterName}\` is not compatible with the image service "Squoosh".`
);

View file

@ -221,7 +221,11 @@ export async function runHookConfigDone({
logger
);
for (const [featureName, supported] of Object.entries(validationResult)) {
if (!supported) {
// If `supported` / `validationResult[featureName]` only allows boolean,
// in theory 'assets' false, doesn't mean that the feature is not supported, but rather that the chosen image service is unsupported
// in this case we should not show an error, that the featrue is not supported
// if we would refactor the validation to support more than boolean, we could still be able to differentiate between the two cases
if (!supported && featureName !== 'assets') {
logger.error(
'astro',
`The adapter ${adapter.name} doesn't support the feature ${featureName}. Your project won't be built. You should not use it.`
@ -229,9 +233,9 @@ export async function runHookConfigDone({
}
}
if (!validationResult.assets) {
logger.info(
logger.warn(
'astro',
`The selected adapter ${adapter.name} does not support Sharp or Squoosh for image processing. To ensure your project is still able to build, image processing has been disabled.`
`The selected adapter ${adapter.name} 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`
);
settings.config.image.service = {
entrypoint: 'astro/assets/services/noop',