Skip to content

Commit

Permalink
Add warning when using assets with non-node adapters (#6533)
Browse files Browse the repository at this point in the history
* feat(assets): Add a warning that the project won't be able to build if used with a non-Node adapter

* chore: changeset
  • Loading branch information
Princesseuh authored Mar 13, 2023
1 parent 875a04d commit cc90d72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-games-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Added a warning when trying to use `experimental.assets` with a not compatible adapter
25 changes: 25 additions & 0 deletions packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bold } from 'kleur/colors';
import MagicString from 'magic-string';
import mime from 'mime';
import fs from 'node:fs/promises';
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit cc90d72

Please sign in to comment.