@sveltejs/adapter-vercel 2.4.0 → 2.4.2

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.
@@ -22,10 +22,12 @@ export default async (req, res) => {
22
22
  const [path, search] = req.url.split('?');
23
23
 
24
24
  const params = new URLSearchParams(search);
25
- const pathname = params.get('__pathname');
25
+ let pathname = params.get('__pathname');
26
26
 
27
27
  if (pathname) {
28
28
  params.delete('__pathname');
29
+ // Optional routes' pathname replacements look like `/foo/$1/bar` which means we could end up with an url like /foo//bar
30
+ pathname = pathname.replace(/\/+/g, '/');
29
31
  req.url = `${pathname}${path.endsWith(DATA_SUFFIX) ? DATA_SUFFIX : ''}?${params}`;
30
32
  }
31
33
  }
package/index.js CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { nodeFileTrace } from '@vercel/nft';
5
5
  import esbuild from 'esbuild';
6
+ import { get_pathname } from './utils.js';
6
7
 
7
8
  const VALID_RUNTIMES = ['edge', 'nodejs16.x', 'nodejs18.x'];
8
9
 
@@ -292,13 +293,7 @@ const plugin = function (defaults = {}) {
292
293
  fs.symlinkSync(relative, `${base}.func`);
293
294
  fs.symlinkSync(`../${relative}`, `${base}/__data.json.func`);
294
295
 
295
- let i = 1;
296
- const pathname = route.segments
297
- .map((segment) => {
298
- return segment.dynamic ? `$${i++}` : segment.content;
299
- })
300
- .join('/');
301
-
296
+ const pathname = get_pathname(route);
302
297
  const json = JSON.stringify(isr, null, '\t');
303
298
 
304
299
  write(`${base}.prerender-config.json`, json);
@@ -358,7 +353,8 @@ function hash_config(config) {
358
353
  config.external ?? '',
359
354
  config.regions ?? '',
360
355
  config.memory ?? '',
361
- config.maxDuration ?? ''
356
+ config.maxDuration ?? '',
357
+ !!config.isr // need to distinguish ISR from non-ISR functions, because ISR functions can't use streaming mode
362
358
  ].join('/');
363
359
  }
364
360
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
+ "description": "A SvelteKit adapter that creates a Vercel app",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/sveltejs/kit",
@@ -20,6 +21,7 @@
20
21
  "files": [
21
22
  "files",
22
23
  "index.js",
24
+ "utils.js",
23
25
  "index.d.ts"
24
26
  ],
25
27
  "dependencies": {
@@ -29,7 +31,8 @@
29
31
  "devDependencies": {
30
32
  "@types/node": "^16.18.6",
31
33
  "typescript": "^4.9.4",
32
- "@sveltejs/kit": "^1.12.0"
34
+ "uvu": "^0.5.6",
35
+ "@sveltejs/kit": "^1.15.7"
33
36
  },
34
37
  "peerDependencies": {
35
38
  "@sveltejs/kit": "^1.5.0"
@@ -37,6 +40,7 @@
37
40
  "scripts": {
38
41
  "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
39
42
  "format": "pnpm lint --write",
40
- "check": "tsc"
43
+ "check": "tsc",
44
+ "test": "uvu test .spec.js"
41
45
  }
42
46
  }
package/utils.js ADDED
@@ -0,0 +1,23 @@
1
+ /** @param {import("@sveltejs/kit").RouteDefinition<any>} route */
2
+ export function get_pathname(route) {
3
+ let i = 1;
4
+
5
+ return route.segments
6
+ .map((segment) => {
7
+ if (!segment.dynamic) {
8
+ return segment.content;
9
+ }
10
+
11
+ const parts = segment.content.split(/\[(.+?)\](?!\])/);
12
+ return parts
13
+ .map((content, j) => {
14
+ if (j % 2) {
15
+ return `$${i++}`;
16
+ } else {
17
+ return content;
18
+ }
19
+ })
20
+ .join('');
21
+ })
22
+ .join('/');
23
+ }