Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/sour-fans-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': minor
---

feat: Add experimental support for Bun runtime
3 changes: 1 addition & 2 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export interface ServerlessConfig {
/**
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) (`'edge'`) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) (`'nodejs18.x'`, `'nodejs20.x'` etc).
* @default Same as the build environment
* @deprecated
*/
runtime?: `nodejs${number}.x`;
runtime?: `nodejs${number}.x` | `experimental_bun1.x`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should change this while we're at it, IIUC we only support 20 and 22. this will give better autocomplete as well as being more accurate

Suggested change
runtime?: `nodejs${number}.x` | `experimental_bun1.x`;
runtime?: `nodejs20.x` | `nodejs22.x` | `experimental_bun1.x`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna make a followup PR for improving validation, I agree we can do better

/**
* To which regions to deploy the app. A list of regions.
* More info: https://vercel.com/docs/concepts/edge-network/regions
Expand Down
21 changes: 15 additions & 6 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ const plugin = function (defaults = {}) {

// group routes by config
for (const route of builder.routes) {
const runtime = route.config?.runtime ?? defaults?.runtime ?? get_default_runtime();
const runtime = (
route.config?.runtime ??
defaults?.runtime ??
get_default_runtime()
).replace('experimental_', '');
const config = { runtime, ...defaults, ...route.config };

if (is_prerendered(route)) {
Expand All @@ -305,19 +309,24 @@ const plugin = function (defaults = {}) {
}

const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 20)) {
const bun_runtime = /^bun/.exec(runtime);
if (
runtime !== 'edge' &&
!bun_runtime &&
(!node_runtime || parseInt(node_runtime[1]) < 20)
) {
throw new Error(
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs20.x' or higher ` +
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge', 'experimental_bun1.x', 'nodejs20.x' or 'nodejs22.x' ` +
'(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
);
}

if (config.isr) {
const directory = path.relative('.', builder.config.kit.files.routes + route.id);

if (!runtime.startsWith('nodejs')) {
if (!runtime.startsWith('nodejs') && !bun_runtime) {
throw new Error(
`${directory}: Routes using \`isr\` must use a Node.js runtime (for example 'nodejs20.x')`
`${directory}: Routes using \`isr\` must use a Node.js or Bun runtime (for example 'nodejs22.x' or 'experimental_bun1.x')`
);
}

Expand Down Expand Up @@ -400,7 +409,7 @@ const plugin = function (defaults = {}) {
// we need to create a catch-all route so that 404s are handled
// by SvelteKit rather than Vercel

const runtime = defaults.runtime ?? get_default_runtime();
const runtime = (defaults.runtime ?? get_default_runtime()).replace('experimental_', '');
const generate_function =
runtime === 'edge' ? generate_edge_function : generate_serverless_function;

Expand Down
Loading