@sveltejs/adapter-vercel 6.0.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Adapter } from '@sveltejs/kit';
2
2
  import './ambient.js';
3
+ import { RuntimeConfigKey } from './utils.js';
3
4
 
4
5
  export default function plugin(config?: Config): Adapter;
5
6
 
@@ -7,9 +8,8 @@ export interface ServerlessConfig {
7
8
  /**
8
9
  * 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).
9
10
  * @default Same as the build environment
10
- * @deprecated
11
11
  */
12
- runtime?: `nodejs${number}.x`;
12
+ runtime?: Exclude<RuntimeConfigKey, 'edge'>;
13
13
  /**
14
14
  * To which regions to deploy the app. A list of regions.
15
15
  * More info: https://vercel.com/docs/concepts/edge-network/regions
package/index.js CHANGED
@@ -5,7 +5,7 @@ import process from 'node:process';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { nodeFileTrace } from '@vercel/nft';
7
7
  import esbuild from 'esbuild';
8
- import { get_pathname, parse_isr_expiration, pattern_to_src } from './utils.js';
8
+ import { get_pathname, parse_isr_expiration, pattern_to_src, resolve_runtime } from './utils.js';
9
9
  import { VERSION } from '@sveltejs/kit';
10
10
 
11
11
  /**
@@ -24,30 +24,6 @@ const INTERNAL = '![-]'; // this name is guaranteed not to conflict with user ro
24
24
 
25
25
  const [kit_major, kit_minor] = VERSION.split('.');
26
26
 
27
- const get_default_runtime = () => {
28
- const major = Number(process.version.slice(1).split('.')[0]);
29
-
30
- // If we're building on Vercel, we know that the version will be fine because Vercel
31
- // provides Node (and Vercel won't provide something it doesn't support).
32
- // Also means we're not on the hook for updating the adapter every time a new Node
33
- // version is added to Vercel.
34
- if (!process.env.VERCEL) {
35
- if (major < 20 || major > 22) {
36
- throw new Error(
37
- `Building locally with unsupported Node.js version: ${process.version}. Please use Node 20 or 22 to build your project, or explicitly specify a runtime in your adapter configuration.`
38
- );
39
- }
40
-
41
- if (major % 2 !== 0) {
42
- throw new Error(
43
- `Unsupported Node.js version: ${process.version}. Please use an even-numbered Node version to build your project, or explicitly specify a runtime in your adapter configuration.`
44
- );
45
- }
46
- }
47
-
48
- return `nodejs${major}.x`;
49
- };
50
-
51
27
  // https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules
52
28
  const compatible_node_modules = ['async_hooks', 'events', 'buffer', 'assert', 'util'];
53
29
 
@@ -294,8 +270,8 @@ const plugin = function (defaults = {}) {
294
270
 
295
271
  // group routes by config
296
272
  for (const route of builder.routes) {
297
- const runtime = route.config?.runtime ?? defaults?.runtime ?? get_default_runtime();
298
- const config = { runtime, ...defaults, ...route.config };
273
+ const runtime = resolve_runtime(defaults.runtime, route.config.runtime);
274
+ const config = { ...defaults, ...route.config, runtime };
299
275
 
300
276
  if (is_prerendered(route)) {
301
277
  if (config.isr) {
@@ -304,20 +280,12 @@ const plugin = function (defaults = {}) {
304
280
  continue;
305
281
  }
306
282
 
307
- const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
308
- if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 20)) {
309
- throw new Error(
310
- `Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs20.x' or higher ` +
311
- '(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
312
- );
313
- }
314
-
315
283
  if (config.isr) {
316
284
  const directory = path.relative('.', builder.config.kit.files.routes + route.id);
317
285
 
318
- if (!runtime.startsWith('nodejs')) {
286
+ if (runtime === 'edge') {
319
287
  throw new Error(
320
- `${directory}: Routes using \`isr\` must use a Node.js runtime (for example 'nodejs20.x')`
288
+ `${directory}: Routes using \`isr\` must use a Node.js or Bun runtime (for example 'nodejs22.x' or 'experimental_bun1.x')`
321
289
  );
322
290
  }
323
291
 
@@ -400,13 +368,13 @@ const plugin = function (defaults = {}) {
400
368
  // we need to create a catch-all route so that 404s are handled
401
369
  // by SvelteKit rather than Vercel
402
370
 
403
- const runtime = defaults.runtime ?? get_default_runtime();
371
+ const runtime = resolve_runtime(defaults.runtime);
404
372
  const generate_function =
405
373
  runtime === 'edge' ? generate_edge_function : generate_serverless_function;
406
374
 
407
375
  await generate_function(
408
376
  `${INTERNAL}/catchall`,
409
- /** @type {any} */ ({ runtime, ...defaults }),
377
+ /** @type {any} */ ({ ...defaults, runtime }),
410
378
  []
411
379
  );
412
380
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "6.0.0",
3
+ "version": "6.1.1",
4
4
  "description": "A SvelteKit adapter that creates a Vercel app",
5
5
  "keywords": [
6
6
  "adapter",
@@ -42,7 +42,7 @@
42
42
  "@types/node": "^18.19.119",
43
43
  "typescript": "^5.3.3",
44
44
  "vitest": "^3.2.4",
45
- "@sveltejs/kit": "^2.47.0"
45
+ "@sveltejs/kit": "^2.48.3"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": "^2.4.0"
package/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ import process from 'node:process';
2
+
1
3
  /** @param {import("@sveltejs/kit").RouteDefinition<any>} route */
2
4
  export function get_pathname(route) {
3
5
  let i = 1;
@@ -106,3 +108,47 @@ export function parse_isr_expiration(value, route_id) {
106
108
  }
107
109
  return parsed;
108
110
  }
111
+
112
+ /**
113
+ * @param {string | undefined} default_key
114
+ * @param {string | undefined} [override_key]
115
+ * @returns {RuntimeKey}
116
+ */
117
+ export function resolve_runtime(default_key, override_key) {
118
+ const key = (override_key ?? default_key ?? get_default_runtime()).replace('experimental_', '');
119
+ assert_is_valid_runtime(key);
120
+ return key;
121
+ }
122
+
123
+ /** @returns {RuntimeKey} */
124
+ function get_default_runtime() {
125
+ // TODO may someday need to auto-detect Bun, but this will be complicated because you may want to run your build
126
+ // with Bun but not have your serverless runtime be in Bun. Vercel will likely have to attach something to `globalThis` or similar
127
+ // to tell us what the bun configuration is.
128
+ const major = Number(process.version.slice(1).split('.')[0]);
129
+
130
+ if (major !== 20 && major !== 22) {
131
+ throw new Error(
132
+ `Unsupported Node.js version: ${process.version}. Please use Node 20 or 22 to build your project, or explicitly specify a runtime in your adapter configuration.`
133
+ );
134
+ }
135
+
136
+ return `nodejs${major}.x`;
137
+ }
138
+
139
+ const valid_runtimes = /** @type {const} */ (['nodejs20.x', 'nodejs22.x', 'bun1.x', 'edge']);
140
+
141
+ /**
142
+ * @param {string} key
143
+ * @returns {asserts key is RuntimeKey}
144
+ */
145
+ function assert_is_valid_runtime(key) {
146
+ if (!valid_runtimes.includes(/** @type {RuntimeKey} */ (key))) {
147
+ throw new Error(
148
+ `Unsupported runtime: ${key}. Supported runtimes are: ${valid_runtimes.join(', ')}. See the Node.js Version section in your Vercel project settings for info on the currently supported versions.`
149
+ );
150
+ }
151
+ }
152
+
153
+ /** @typedef {Exclude<RuntimeKey, 'bun1.x'> | 'experimental_bun1.x'} RuntimeConfigKey */
154
+ /** @typedef {typeof valid_runtimes[number]} RuntimeKey */