@sveltejs/adapter-vercel 5.10.3 → 6.1.0

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.
@@ -1,11 +1,8 @@
1
- import { installPolyfills } from '@sveltejs/kit/node/polyfills';
2
1
  import { createReadableStream } from '@sveltejs/kit/node';
3
2
  import { Server } from 'SERVER';
4
3
  import { manifest } from 'MANIFEST';
5
4
  import process from 'node:process';
6
5
 
7
- installPolyfills();
8
-
9
6
  const server = new Server(manifest);
10
7
 
11
8
  await server.init({
package/index.d.ts CHANGED
@@ -7,9 +7,8 @@ export interface ServerlessConfig {
7
7
  /**
8
8
  * 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
9
  * @default Same as the build environment
10
- * @deprecated
11
10
  */
12
- runtime?: `nodejs${number}.x`;
11
+ runtime?: `nodejs${number}.x` | `experimental_bun1.x`;
13
12
  /**
14
13
  * To which regions to deploy the app. A list of regions.
15
14
  * More info: https://vercel.com/docs/concepts/edge-network/regions
@@ -39,7 +38,7 @@ export interface ServerlessConfig {
39
38
  /**
40
39
  * Expiration time (in seconds) before the cached asset will be re-generated by invoking the Serverless Function. Setting the value to `false` means it will never expire.
41
40
  */
42
- expiration: number | false;
41
+ expiration: number | string | false;
43
42
  /**
44
43
  * Random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset
45
44
  * with a __prerender_bypass=<token> cookie.
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, pattern_to_src } from './utils.js';
8
+ import { get_pathname, parse_isr_expiration, pattern_to_src } from './utils.js';
9
9
  import { VERSION } from '@sveltejs/kit';
10
10
 
11
11
  /**
@@ -32,9 +32,9 @@ const get_default_runtime = () => {
32
32
  // Also means we're not on the hook for updating the adapter every time a new Node
33
33
  // version is added to Vercel.
34
34
  if (!process.env.VERCEL) {
35
- if (major < 18 || major > 22) {
35
+ if (major < 20 || major > 22) {
36
36
  throw new Error(
37
- `Building locally with unsupported Node.js version: ${process.version}. Please use Node 18, 20 or 22 to build your project, or explicitly specify a runtime in your adapter configuration.`
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
38
  );
39
39
  }
40
40
 
@@ -294,7 +294,11 @@ const plugin = function (defaults = {}) {
294
294
 
295
295
  // group routes by config
296
296
  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_', '');
298
302
  const config = { runtime, ...defaults, ...route.config };
299
303
 
300
304
  if (is_prerendered(route)) {
@@ -305,9 +309,14 @@ const plugin = function (defaults = {}) {
305
309
  }
306
310
 
307
311
  const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
308
- if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 18)) {
312
+ const bun_runtime = /^bun/.exec(runtime);
313
+ if (
314
+ runtime !== 'edge' &&
315
+ !bun_runtime &&
316
+ (!node_runtime || parseInt(node_runtime[1]) < 20)
317
+ ) {
309
318
  throw new Error(
310
- `Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs18.x' or higher ` +
319
+ `Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge', 'experimental_bun1.x', 'nodejs20.x' or 'nodejs22.x' ` +
311
320
  '(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
312
321
  );
313
322
  }
@@ -315,9 +324,9 @@ const plugin = function (defaults = {}) {
315
324
  if (config.isr) {
316
325
  const directory = path.relative('.', builder.config.kit.files.routes + route.id);
317
326
 
318
- if (!runtime.startsWith('nodejs')) {
327
+ if (!runtime.startsWith('nodejs') && !bun_runtime) {
319
328
  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')`
321
330
  );
322
331
  }
323
332
 
@@ -400,7 +409,7 @@ const plugin = function (defaults = {}) {
400
409
  // we need to create a catch-all route so that 404s are handled
401
410
  // by SvelteKit rather than Vercel
402
411
 
403
- const runtime = defaults.runtime ?? get_default_runtime();
412
+ const runtime = (defaults.runtime ?? get_default_runtime()).replace('experimental_', '');
404
413
  const generate_function =
405
414
  runtime === 'edge' ? generate_edge_function : generate_serverless_function;
406
415
 
@@ -433,7 +442,11 @@ const plugin = function (defaults = {}) {
433
442
  fs.symlinkSync(`../${relative}`, `${base}/__data.json.func`);
434
443
 
435
444
  const pathname = get_pathname(route);
436
- const json = JSON.stringify(isr, null, '\t');
445
+ const json = JSON.stringify(
446
+ { ...isr, expiration: parse_isr_expiration(isr.expiration, route.id) },
447
+ null,
448
+ '\t'
449
+ );
437
450
 
438
451
  write(`${base}.prerender-config.json`, json);
439
452
  write(`${base}/__data.json.prerender-config.json`, json);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "5.10.3",
3
+ "version": "6.1.0",
4
4
  "description": "A SvelteKit adapter that creates a Vercel app",
5
5
  "keywords": [
6
6
  "adapter",
@@ -42,11 +42,14 @@
42
42
  "@types/node": "^18.19.119",
43
43
  "typescript": "^5.3.3",
44
44
  "vitest": "^3.2.4",
45
- "@sveltejs/kit": "^2.43.7"
45
+ "@sveltejs/kit": "^2.48.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": "^2.4.0"
49
49
  },
50
+ "engines": {
51
+ "node": ">=20.0"
52
+ },
50
53
  "scripts": {
51
54
  "lint": "prettier --check .",
52
55
  "format": "pnpm lint --write",
package/utils.js CHANGED
@@ -67,3 +67,42 @@ export function pattern_to_src(pattern) {
67
67
 
68
68
  return src;
69
69
  }
70
+
71
+ const integer = /^\d+$/;
72
+
73
+ /**
74
+ * @param {false | string | number} value
75
+ * @param {string} route_id
76
+ * @returns {number | false}
77
+ */
78
+ export function parse_isr_expiration(value, route_id) {
79
+ if (value === false || value === 'false') return false; // 1 year
80
+
81
+ /** @param {string} desc */
82
+ const err = (desc) => {
83
+ throw new Error(
84
+ `Invalid isr.expiration value: ${JSON.stringify(value)} (${desc}, in ${route_id})`
85
+ );
86
+ };
87
+
88
+ let parsed;
89
+ if (typeof value === 'string') {
90
+ if (!integer.test(value)) {
91
+ err('value was a string but could not be parsed as an integer');
92
+ }
93
+ parsed = Number.parseInt(value, 10);
94
+ } else {
95
+ if (!Number.isInteger(value)) {
96
+ err('should be an integer');
97
+ }
98
+ parsed = value;
99
+ }
100
+
101
+ if (Number.isNaN(parsed)) {
102
+ err('should be a number');
103
+ }
104
+ if (parsed < 0) {
105
+ err('should be non-negative');
106
+ }
107
+ return parsed;
108
+ }