Skip to content

Commit 3a5ed2b

Browse files
authored
Add experimental Bun support (#14817)
1 parent 102aecf commit 3a5ed2b

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

.changeset/sour-fans-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': minor
3+
---
4+
5+
feat: Add experimental support for Bun runtime

packages/adapter-vercel/index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export interface ServerlessConfig {
77
/**
88
* 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).
99
* @default Same as the build environment
10-
* @deprecated
1110
*/
12-
runtime?: `nodejs${number}.x`;
11+
runtime?: `nodejs${number}.x` | `experimental_bun1.x`;
1312
/**
1413
* To which regions to deploy the app. A list of regions.
1514
* More info: https://vercel.com/docs/concepts/edge-network/regions

packages/adapter-vercel/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ const plugin = function (defaults = {}) {
294294

295295
// group routes by config
296296
for (const route of builder.routes) {
297-
const runtime = route.config?.runtime ?? defaults?.runtime ?? get_default_runtime();
297+
const runtime = (
298+
route.config?.runtime ??
299+
defaults?.runtime ??
300+
get_default_runtime()
301+
).replace('experimental_', '');
298302
const config = { runtime, ...defaults, ...route.config };
299303

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

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

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

318-
if (!runtime.startsWith('nodejs')) {
327+
if (!runtime.startsWith('nodejs') && !bun_runtime) {
319328
throw new Error(
320-
`${directory}: Routes using \`isr\` must use a Node.js runtime (for example 'nodejs20.x')`
329+
`${directory}: Routes using \`isr\` must use a Node.js or Bun runtime (for example 'nodejs22.x' or 'experimental_bun1.x')`
321330
);
322331
}
323332

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

403-
const runtime = defaults.runtime ?? get_default_runtime();
412+
const runtime = (defaults.runtime ?? get_default_runtime()).replace('experimental_', '');
404413
const generate_function =
405414
runtime === 'edge' ? generate_edge_function : generate_serverless_function;
406415

0 commit comments

Comments
 (0)