Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: document astro features #3924

Merged
merged 6 commits into from
Aug 19, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion src/content/docs/en/reference/adapter-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Astro Adapter API
i18nReady: true
---
import Since from '~/components/Since.astro';


Astro is designed to make it easy to deploy to any cloud provider for SSR (server-side rendering). This ability is provided by __adapters__, which are [integrations](/en/reference/integrations-reference/). See the [SSR guide](/en/guides/server-side-rendering/#adding-an-adapter) to learn how to use an existing adapter.

Expand All @@ -26,7 +28,10 @@ export default function createIntegration() {
'astro:config:done': ({ setAdapter }) => {
setAdapter({
name: '@matthewp/my-adapter',
serverEntrypoint: '@matthewp/my-adapter/server.js'
serverEntrypoint: '@matthewp/my-adapter/server.js',
supportedAstroFeatures: {
staticOutput: 'stable'
}
});
},
},
Expand All @@ -41,6 +46,40 @@ interface AstroAdapter {
name: string;
serverEntrypoint?: string;
exports?: string[];
supportedAstroFeatures: AstroFeatureMap;
}

export type SupportsKind = 'unsupported' | 'stable' | 'experimental' | 'deprecated';

export type AstroFeatureMap = {
/**
* The adapter is able to serve static pages
*/
staticOutput?: SupportsKind;
/**
* The adapter is able to serve pages that are static or rendered via server
*/
hybridOutput?: SupportsKind;
/**
* The adapter is able to serve SSR pages
*/
serverOutput?: SupportsKind;
/**
* The adapter can emit static assets
*/
assets?: AstroAssetsFeature;
};

export interface AstroAssetsFeature {
supportKind?: SupportsKind;
/**
* Whether if this adapter deploys files in an environment that is compatible with the library `sharp`
*/
isSharpCompatible?: boolean;
/**
* Whether if this adapter deploys files in an environment that is compatible with the library `squoosh`
ematipico marked this conversation as resolved.
Show resolved Hide resolved
*/
isSquooshCompatible?: boolean;
}
```

Expand All @@ -49,6 +88,7 @@ The properties are:
* __name__: A unique name for your adapter, used for logging.
* __serverEntrypoint__: The entrypoint for server-side rendering.
* __exports__: An array of named exports when used in conjunction with `createExports` (explained below).
* __supportedAstroFeatures__: A map of Astro built-in features. Sometime adapters can't support those features, and maybe they want to deprecate them.
ematipico marked this conversation as resolved.
Show resolved Hide resolved

### Server Entrypoint

Expand Down Expand Up @@ -188,3 +228,54 @@ You can usually call `app.render(request)` without using `.match` because Astro
```

Once you [publish your adapter to npm](https://docs.npmjs.com/cli/v8/commands/npm-publish), running `astro add example` will install your package with any peer dependencies specified in your `package.json`. We will also instruct users to update their project config manually.


## Astro features

<Since v="3.0.0" />

Astro features are a way for an adapter to tell Astro if they are able to support a feature - and its level of support.
ematipico marked this conversation as resolved.
Show resolved Hide resolved

When using these properties, Astro will:
- run specific validation;
- emit contextual to the logs;

These operations are run based on the features supported or not supported, their level of support, and the configuration that the user uses.

```js title="my-adapter.mjs" ins={9-15}
export default function createIntegration() {
return {
name: '@matthewp/my-adapter',
hooks: {
'astro:config:done': ({ setAdapter }) => {
setAdapter({
name: '@matthewp/my-adapter',
serverEntrypoint: '@matthewp/my-adapter/server.js',
supportedAstroFeatures: {
assets: {
supportKind: "experimental",
isSharpCompatible: false,
isSquooshCompatible: false
}
}
});
},
},
};
}
```
```

In this example, we're telling Astro that this adapter has experimental support for assets, but it's not compatible with the built-in services.
ematipico marked this conversation as resolved.
Show resolved Hide resolved

Astro will log a **warning** to the terminal
ematipico marked this conversation as resolved.
Show resolved Hide resolved

```
[@matthewp/my-adapter] The feature is experimental and subject to issues or changes.
```

and an error if the service used for assets is not compatible with the adapter
ematipico marked this conversation as resolved.
Show resolved Hide resolved

```
[@matthewp/my-adapter] The currently selected adapter `@matthewp/my-adapter` is not compatible with the service "Sharp". Your project will NOT be able to build.
```
Loading