diff --git a/.changeset/sour-fans-pay.md b/.changeset/sour-fans-pay.md new file mode 100644 index 000000000000..127139fb9521 --- /dev/null +++ b/.changeset/sour-fans-pay.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': minor +--- + +feat: Add experimental support for Bun runtime diff --git a/packages/adapter-vercel/index.d.ts b/packages/adapter-vercel/index.d.ts index d44e8a70fcbf..792dfe5b4f00 100644 --- a/packages/adapter-vercel/index.d.ts +++ b/packages/adapter-vercel/index.d.ts @@ -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`; /** * To which regions to deploy the app. A list of regions. * More info: https://vercel.com/docs/concepts/edge-network/regions diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index d4ec606663b0..809c6dea3382 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -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)) { @@ -305,9 +309,14 @@ 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).' ); } @@ -315,9 +324,9 @@ const plugin = function (defaults = {}) { 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')` ); } @@ -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;