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:
parent
875a04db16
commit
cc90d72197
2 changed files with 30 additions and 0 deletions
5
.changeset/famous-games-warn.md
Normal file
5
.changeset/famous-games-warn.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added a warning when trying to use `experimental.assets` with a not compatible adapter
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { bold } from 'kleur/colors';
|
||||||
import MagicString from 'magic-string';
|
import MagicString from 'magic-string';
|
||||||
import mime from 'mime';
|
import mime from 'mime';
|
||||||
import fs from 'node:fs/promises';
|
import fs from 'node:fs/promises';
|
||||||
|
@ -28,6 +29,30 @@ export default function assets({
|
||||||
|
|
||||||
globalThis.astroAsset = {};
|
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 [
|
return [
|
||||||
// Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
|
// Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue