@sveltejs/adapter-vercel 3.0.3 → 4.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 +1 -9
- package/index.d.ts +29 -3
- package/index.js +19 -13
- package/package.json +10 -9
package/files/serverless.js
CHANGED
|
@@ -32,15 +32,7 @@ export default async (req, res) => {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
let request;
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
request = await getRequest({ base: `https://${req.headers.host}`, request: req });
|
|
40
|
-
} catch (err) {
|
|
41
|
-
res.statusCode = /** @type {any} */ (err).status || 400;
|
|
42
|
-
return res.end('Invalid request body');
|
|
43
|
-
}
|
|
35
|
+
const request = await getRequest({ base: `https://${req.headers.host}`, request: req });
|
|
44
36
|
|
|
45
37
|
setResponse(
|
|
46
38
|
res,
|
package/index.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ export default function plugin(config?: Config): Adapter;
|
|
|
5
5
|
|
|
6
6
|
export interface ServerlessConfig {
|
|
7
7
|
/**
|
|
8
|
-
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions)
|
|
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 'nodejs18.x'
|
|
10
10
|
*/
|
|
11
|
-
runtime?:
|
|
11
|
+
runtime?: `nodejs${number}.x`;
|
|
12
12
|
/**
|
|
13
13
|
* To which regions to deploy the app. A list of regions.
|
|
14
14
|
* More info: https://vercel.com/docs/concepts/edge-network/regions
|
|
@@ -28,6 +28,12 @@ export interface ServerlessConfig {
|
|
|
28
28
|
* If `true`, this route will always be deployed as its own separate function
|
|
29
29
|
*/
|
|
30
30
|
split?: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* https://vercel.com/docs/build-output-api/v3/configuration#images
|
|
34
|
+
*/
|
|
35
|
+
images?: ImagesConfig;
|
|
36
|
+
|
|
31
37
|
/**
|
|
32
38
|
* [Incremental Static Regeneration](https://vercel.com/docs/concepts/incremental-static-regeneration/overview) configuration.
|
|
33
39
|
* Serverless only.
|
|
@@ -53,9 +59,29 @@ export interface ServerlessConfig {
|
|
|
53
59
|
| false;
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
type ImageFormat = 'image/avif' | 'image/webp';
|
|
63
|
+
|
|
64
|
+
type RemotePattern = {
|
|
65
|
+
protocol?: 'http' | 'https';
|
|
66
|
+
hostname: string;
|
|
67
|
+
port?: string;
|
|
68
|
+
pathname?: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type ImagesConfig = {
|
|
72
|
+
sizes: number[];
|
|
73
|
+
domains: string[];
|
|
74
|
+
remotePatterns?: RemotePattern[];
|
|
75
|
+
minimumCacheTTL?: number; // seconds
|
|
76
|
+
formats?: ImageFormat[];
|
|
77
|
+
dangerouslyAllowSVG?: boolean;
|
|
78
|
+
contentSecurityPolicy?: string;
|
|
79
|
+
contentDispositionType?: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
56
82
|
export interface EdgeConfig {
|
|
57
83
|
/**
|
|
58
|
-
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions)
|
|
84
|
+
* 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).
|
|
59
85
|
*/
|
|
60
86
|
runtime?: 'edge';
|
|
61
87
|
/**
|
package/index.js
CHANGED
|
@@ -5,17 +5,16 @@ import { nodeFileTrace } from '@vercel/nft';
|
|
|
5
5
|
import esbuild from 'esbuild';
|
|
6
6
|
import { get_pathname } from './utils.js';
|
|
7
7
|
|
|
8
|
-
const VALID_RUNTIMES = ['edge', 'nodejs16.x', 'nodejs18.x'];
|
|
9
|
-
|
|
10
8
|
const DEFAULT_FUNCTION_NAME = 'fn';
|
|
11
9
|
|
|
12
10
|
const get_default_runtime = () => {
|
|
13
11
|
const major = process.version.slice(1).split('.')[0];
|
|
14
12
|
if (major === '16') return 'nodejs16.x';
|
|
15
13
|
if (major === '18') return 'nodejs18.x';
|
|
14
|
+
if (major === '20') return 'nodejs20.x';
|
|
16
15
|
|
|
17
16
|
throw new Error(
|
|
18
|
-
`Unsupported Node.js version: ${process.version}. Please use Node 16 or Node
|
|
17
|
+
`Unsupported Node.js version: ${process.version}. Please use Node 16, Node 18 or Node 20 to build your project, or explicitly specify a runtime in your adapter configuration.`
|
|
19
18
|
);
|
|
20
19
|
};
|
|
21
20
|
|
|
@@ -55,7 +54,7 @@ const plugin = function (defaults = {}) {
|
|
|
55
54
|
functions: `${dir}/functions`
|
|
56
55
|
};
|
|
57
56
|
|
|
58
|
-
const static_config = static_vercel_config(builder);
|
|
57
|
+
const static_config = static_vercel_config(builder, defaults);
|
|
59
58
|
|
|
60
59
|
builder.log.minor('Generating serverless function...');
|
|
61
60
|
|
|
@@ -164,20 +163,20 @@ const plugin = function (defaults = {}) {
|
|
|
164
163
|
continue;
|
|
165
164
|
}
|
|
166
165
|
|
|
167
|
-
|
|
166
|
+
const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
|
|
167
|
+
if (runtime !== 'edge' && (!node_runtime || node_runtime[1] < 16)) {
|
|
168
168
|
throw new Error(
|
|
169
|
-
`Invalid runtime '${runtime}' for route ${
|
|
170
|
-
|
|
171
|
-
}. Valid runtimes are ${VALID_RUNTIMES.join(', ')}`
|
|
169
|
+
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs16.x' or higher ` +
|
|
170
|
+
'(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
|
|
172
171
|
);
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
if (config.isr) {
|
|
176
175
|
const directory = path.relative('.', builder.config.kit.files.routes + route.id);
|
|
177
176
|
|
|
178
|
-
if (runtime
|
|
177
|
+
if (!runtime.startsWith('nodejs')) {
|
|
179
178
|
throw new Error(
|
|
180
|
-
`${directory}: Routes using \`isr\` must use
|
|
179
|
+
`${directory}: Routes using \`isr\` must use a Node.js runtime (for example 'nodejs20.x')`
|
|
181
180
|
);
|
|
182
181
|
}
|
|
183
182
|
|
|
@@ -368,14 +367,20 @@ function write(file, data) {
|
|
|
368
367
|
}
|
|
369
368
|
|
|
370
369
|
// This function is duplicated in adapter-static
|
|
371
|
-
/**
|
|
372
|
-
|
|
370
|
+
/**
|
|
371
|
+
* @param {import('@sveltejs/kit').Builder} builder
|
|
372
|
+
* @param {import('.').Config} config
|
|
373
|
+
*/
|
|
374
|
+
function static_vercel_config(builder, config) {
|
|
373
375
|
/** @type {any[]} */
|
|
374
376
|
const prerendered_redirects = [];
|
|
375
377
|
|
|
376
378
|
/** @type {Record<string, { path: string }>} */
|
|
377
379
|
const overrides = {};
|
|
378
380
|
|
|
381
|
+
/** @type {import('./index').ImagesConfig} */
|
|
382
|
+
const images = config.images;
|
|
383
|
+
|
|
379
384
|
for (const [src, redirect] of builder.prerendered.redirects) {
|
|
380
385
|
prerendered_redirects.push({
|
|
381
386
|
src,
|
|
@@ -421,7 +426,8 @@ function static_vercel_config(builder) {
|
|
|
421
426
|
handle: 'filesystem'
|
|
422
427
|
}
|
|
423
428
|
],
|
|
424
|
-
overrides
|
|
429
|
+
overrides,
|
|
430
|
+
images
|
|
425
431
|
};
|
|
426
432
|
}
|
|
427
433
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Vercel app",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,20 +25,21 @@
|
|
|
25
25
|
"index.d.ts"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@vercel/nft": "^0.
|
|
29
|
-
"esbuild": "^0.
|
|
28
|
+
"@vercel/nft": "^0.24.4",
|
|
29
|
+
"esbuild": "^0.19.9"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
32
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|
|
33
|
+
"@types/node": "^18.19.3",
|
|
34
|
+
"typescript": "^5.3.3",
|
|
35
|
+
"vitest": "^1.0.4",
|
|
36
|
+
"@sveltejs/kit": "^2.0.0"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
|
-
"@sveltejs/kit": "^
|
|
39
|
+
"@sveltejs/kit": "^2.0.0"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
|
-
"lint": "prettier --check .
|
|
42
|
+
"lint": "prettier --check .",
|
|
42
43
|
"format": "pnpm lint --write",
|
|
43
44
|
"check": "tsc",
|
|
44
45
|
"test": "vitest run"
|