@sveltejs/adapter-vercel 5.9.1 → 5.10.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.
@@ -1,5 +1,5 @@
1
1
  import { installPolyfills } from '@sveltejs/kit/node/polyfills';
2
- import { getRequest, setResponse, createReadableStream } from '@sveltejs/kit/node';
2
+ import { createReadableStream } from '@sveltejs/kit/node';
3
3
  import { Server } from 'SERVER';
4
4
  import { manifest } from 'MANIFEST';
5
5
  import process from 'node:process';
@@ -15,33 +15,31 @@ await server.init({
15
15
 
16
16
  const DATA_SUFFIX = '/__data.json';
17
17
 
18
- /**
19
- * @param {import('http').IncomingMessage} req
20
- * @param {import('http').ServerResponse} res
21
- */
22
- export default async (req, res) => {
23
- if (req.url) {
24
- const [path, search] = req.url.split('?');
25
-
26
- const params = new URLSearchParams(search);
27
- let pathname = params.get('__pathname');
18
+ export default {
19
+ /**
20
+ * @param {Request} request
21
+ * @returns {Promise<Response>}
22
+ */
23
+ fetch(request) {
24
+ // If this is an ISR request, the requested pathname is encoded
25
+ // as a search parameter, so we need to extract it
26
+ const url = new URL(request.url);
27
+ let pathname = url.searchParams.get('__pathname');
28
28
 
29
29
  if (pathname) {
30
- params.delete('__pathname');
31
30
  // Optional routes' pathname replacements look like `/foo/$1/bar` which means we could end up with an url like /foo//bar
32
31
  pathname = pathname.replace(/\/+/g, '/');
33
- req.url = `${pathname}${path.endsWith(DATA_SUFFIX) ? DATA_SUFFIX : ''}?${params}`;
34
- }
35
- }
36
32
 
37
- const request = await getRequest({ base: `https://${req.headers.host}`, request: req });
33
+ url.pathname = pathname + (url.pathname.endsWith(DATA_SUFFIX) ? DATA_SUFFIX : '');
34
+ url.searchParams.delete('__pathname');
38
35
 
39
- void setResponse(
40
- res,
41
- await server.respond(request, {
36
+ request = new Request(url, request);
37
+ }
38
+
39
+ return server.respond(request, {
42
40
  getClientAddress() {
43
41
  return /** @type {string} */ (request.headers.get('x-forwarded-for'));
44
42
  }
45
- })
46
- );
43
+ });
44
+ }
47
45
  };
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ 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
10
11
  */
11
12
  runtime?: `nodejs${number}.x`;
12
13
  /**
@@ -74,6 +75,7 @@ type ImagesConfig = {
74
75
  contentDispositionType?: string;
75
76
  };
76
77
 
78
+ /** @deprecated */
77
79
  export interface EdgeConfig {
78
80
  /**
79
81
  * 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).
package/index.js CHANGED
@@ -131,12 +131,21 @@ const plugin = function (defaults = {}) {
131
131
  }
132
132
  }
133
133
 
134
+ let warned = false;
135
+
134
136
  /**
135
137
  * @param {string} name
136
138
  * @param {import('./index.js').EdgeConfig} config
137
139
  * @param {import('@sveltejs/kit').RouteDefinition<import('./index.js').EdgeConfig>[]} routes
138
140
  */
139
141
  async function generate_edge_function(name, config, routes) {
142
+ if (!warned) {
143
+ warned = true;
144
+ builder.log.warn(
145
+ `The \`runtime: 'edge'\` option is deprecated, and will be removed in a future version of adapter-vercel`
146
+ );
147
+ }
148
+
140
149
  const tmp = builder.getBuildDirectory(`vercel-tmp/${name}`);
141
150
  const relativePath = path.posix.relative(tmp, builder.getServerDirectory());
142
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "5.9.1",
3
+ "version": "5.10.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.3",
45
- "@sveltejs/kit": "^2.31.1"
45
+ "@sveltejs/kit": "^2.33.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": "^2.4.0"