@sveltejs/adapter-vercel 5.10.3 → 6.0.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.
- package/files/serverless.js +0 -3
- package/index.d.ts +1 -1
- package/index.js +10 -6
- package/package.json +5 -2
- package/utils.js +39 -0
package/files/serverless.js
CHANGED
|
@@ -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
|
@@ -39,7 +39,7 @@ export interface ServerlessConfig {
|
|
|
39
39
|
/**
|
|
40
40
|
* 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
41
|
*/
|
|
42
|
-
expiration: number | false;
|
|
42
|
+
expiration: number | string | false;
|
|
43
43
|
/**
|
|
44
44
|
* Random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset
|
|
45
45
|
* 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 <
|
|
35
|
+
if (major < 20 || major > 22) {
|
|
36
36
|
throw new Error(
|
|
37
|
-
`Building locally with unsupported Node.js version: ${process.version}. Please use Node
|
|
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
|
|
|
@@ -305,9 +305,9 @@ const plugin = function (defaults = {}) {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
|
|
308
|
-
if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) <
|
|
308
|
+
if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 20)) {
|
|
309
309
|
throw new Error(
|
|
310
|
-
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and '
|
|
310
|
+
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs20.x' or higher ` +
|
|
311
311
|
'(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
|
|
312
312
|
);
|
|
313
313
|
}
|
|
@@ -433,7 +433,11 @@ const plugin = function (defaults = {}) {
|
|
|
433
433
|
fs.symlinkSync(`../${relative}`, `${base}/__data.json.func`);
|
|
434
434
|
|
|
435
435
|
const pathname = get_pathname(route);
|
|
436
|
-
const json = JSON.stringify(
|
|
436
|
+
const json = JSON.stringify(
|
|
437
|
+
{ ...isr, expiration: parse_isr_expiration(isr.expiration, route.id) },
|
|
438
|
+
null,
|
|
439
|
+
'\t'
|
|
440
|
+
);
|
|
437
441
|
|
|
438
442
|
write(`${base}.prerender-config.json`, json);
|
|
439
443
|
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": "
|
|
3
|
+
"version": "6.0.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.
|
|
45
|
+
"@sveltejs/kit": "^2.47.0"
|
|
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
|
+
}
|