Skip to content

Commit

Permalink
chore(core): improve the logging of assets feature (#8615)
Browse files Browse the repository at this point in the history
* improve assets logging

* changeset

* fix typo

Co-authored-by: Florian Lefebvre <[email protected]>

* improve log message

Co-authored-by: Sarah Rainsberger <[email protected]>

* update log message

* update changeset

---------

Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2023
1 parent 1d4f91b commit 4c4ad9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-dragons-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improve the logging of assets for adapters that do not support image optimization
4 changes: 2 additions & 2 deletions packages/astro/src/integrations/astroFeaturesValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ 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".`
);
return false;
}

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".`
);
Expand Down
10 changes: 7 additions & 3 deletions packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,21 @@ 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.`
);
}
}
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',
Expand Down

0 comments on commit 4c4ad9d

Please sign in to comment.