Skip to content

Commit 2cef977

Browse files
florian-lefebvresarah11918ArmandPhilippot
authored
improve naming of new adapter api (#13253)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 6626f8f commit 2cef977

File tree

2 files changed

+340
-213
lines changed

2 files changed

+340
-213
lines changed

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Integration and adapter maintainers should pay special attention to changes affe
112112
- [generating routes with `RouteData`](#removed-routedatagenerate-adapter-api)
113113
- [routes with percent-encoded percent signs (e.g. `%25`)](#removed-percent-encoding-in-routes)
114114
- [`astro:ssr-manifest` virtual module](#removed-astrossr-manifest-virtual-module-integration-api)
115+
- [`createExports()` and `start()`](#deprecated-createexports-and-start-adapter-api)
115116

116117
### Zod 4
117118

@@ -374,6 +375,96 @@ export default defineConfig({
374375

375376
<ReadMore>Learn more about [available session drivers](/en/reference/session-driver-reference/#building-a-session-driver).</ReadMore>
376377

378+
### Deprecated: `createExports()` and `start()` (Adapter API)
379+
380+
<SourcePR number="15461" title="feat: improve naming of new adapter api" />
381+
382+
In Astro 5.x, adapters had to provide the exports required by the host in their server entrypoint using a `createExports()` function before passing them to `setAdapter()` as an `exports` list.
383+
384+
Astro 6.0 introduces a simpler yet more powerful way of making server entrypoints. This relies on passing a new option `entrypointResolution: "auto"` to `setAdapter()`.
385+
386+
However, for backwards compatibility with existing adapters, the default value of `entrypointResolution` (`"explicit"`) mimics Astro 5.x API behavior. This means that your adapters can to continue to function until you can fully migrate your adapter to the `auto` value, as shown below.
387+
388+
Note that `entrypointResolution: "explicit"` (maintaining v5 API behavior) is considered deprecated usage, but the option has been provided so that no immediate change to your adapter is required and to allow adapter authors time to update. This option will be removed in a future major version in favor of all adapters using `entrypointResolution: "auto"`.
389+
390+
#### What should I do?
391+
392+
If you are an adapter author with a public repository and [include the `astro-adapter` keyword in your `package.json`](/en/reference/publish-to-npm/#categories), the Astro core team will attempt to make a PR to your repository directly to help you migrate your code if you have not yet followed the steps below.
393+
394+
If you are seeing warnings because you are using a community adapter that is not yet updated, please reach out to the adapter author directly to let them know. It is ultimately their responsibility to update their adapters. You can also let the Astro core team know in the [`#integrations` channel of our Discord](https://astro.build/chat) and we will attempt to help the adapter author upgrade.
395+
396+
If you have built an adapter, follow these steps to remove the legacy v5 behaviour:
397+
398+
<Steps>
399+
400+
1. Update your `setAdapter()`: set `entrypointResolution: "auto"`, remove `exports` and `args`
401+
402+
```js title="my-adapter.mjs" ins={3} del={4-5}
403+
setAdapter({
404+
// ...
405+
entrypointResolution: 'auto',
406+
exports: ['handler'],
407+
args: { assets: config.build.assets }
408+
})
409+
```
410+
411+
2. Update your server entrypoint to provide any required exports without `createExports()`:
412+
413+
```js title="my-adapter/server.js" del={1-11} ins={12-18}
414+
import { App } from 'astro/app';
415+
416+
export function createExports(manifest) {
417+
const app = new App(manifest);
418+
419+
const handler = (event, context) => {
420+
// ...
421+
};
422+
423+
return { handler };
424+
}
425+
import { createApp } from 'astro/app/entrypoint';
426+
427+
const app = createApp();
428+
429+
export const handler = (event, context) => {
430+
// ...
431+
}
432+
```
433+
434+
3. If your adapter provides a `start()` function, update your server entrypoint to call the code directly:
435+
436+
```js title="my-adapter/server.js" del={1-9} ins={10-16}
437+
import { App } from 'astro/app';
438+
439+
export function start(manifest) {
440+
const app = new App(manifest);
441+
442+
addEventListener('fetch', event => {
443+
// ...
444+
});
445+
}
446+
import { createApp } from 'astro/app/entrypoint';
447+
448+
const app = createApp();
449+
450+
addEventListener('fetch', event => {
451+
// ...
452+
});
453+
```
454+
455+
4. If you were relying on `args`, [create a virtual module to pass the build time configuration](/en/reference/adapter-reference/#passing-build-time-configuration) and import them from the virtual module instead:
456+
457+
```js title="my-adapter/server.js" del={1-3} ins={4}
458+
export function createExports(manifest, { assets }) {
459+
// ...
460+
}
461+
import { assets } from 'virtual:@example/my-adapter:config';
462+
```
463+
464+
</Steps>
465+
466+
<ReadMore>Learn more about [the Adapter API](/en/reference/adapter-reference/).</ReadMore>
467+
377468
## Removed
378469

379470
The following features have now been entirely removed from the code base and can no longer be used. Some of these features may have continued to work in your project even after deprecation. Others may have silently had no effect.
@@ -1502,6 +1593,7 @@ const driver = await manifest.sessionDriver?.();
15021593
```
15031594

15041595
<ReadMore>Learn more about [the Adapter API](/en/reference/adapter-reference/).</ReadMore>
1596+
15051597
### Changed: schema types are inferred instead of generated (Content Loader API)
15061598

15071599
<SourcePR number="14759" title="feat: loader.createSchema()" />

0 commit comments

Comments
 (0)