Add warning when using assets with non-node adapters (#6533)

* feat(assets): Add a warning that the project won't be able to build if used with a non-Node adapter

* chore: changeset
This commit is contained in:
Erika 2023-03-13 18:16:17 +01:00 committed by GitHub
parent 875a04db16
commit cc90d72197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Added a warning when trying to use `experimental.assets` with a not compatible adapter

View file

@ -1,3 +1,4 @@
import { bold } from 'kleur/colors';
import MagicString from 'magic-string';
import mime from 'mime';
import fs from 'node:fs/promises';
@ -28,6 +29,30 @@ export default function assets({
globalThis.astroAsset = {};
const UNSUPPORTED_ADAPTERS = new Set([
'@astrojs/cloudflare',
'@astrojs/deno',
'@astrojs/netlify/edge-functions',
'@astrojs/vercel/edge',
]);
const adapterName = settings.config.adapter?.name;
if (
['astro/assets/services/sharp', 'astro/assets/services/squoosh'].includes(
settings.config.image.service
) &&
adapterName &&
UNSUPPORTED_ADAPTERS.has(adapterName)
) {
error(
logging,
'assets',
`The currently selected adapter \`${adapterName}\` does not run on Node, however the currently used image service depends on Node built-ins. ${bold(
'Your project will NOT be able to build.'
)}`
);
}
return [
// Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
{