@sveltejs/adapter-vercel 2.2.0 → 2.2.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.
Files changed (2) hide show
  1. package/index.js +20 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -6,6 +6,8 @@ import esbuild from 'esbuild';
6
6
 
7
7
  const VALID_RUNTIMES = ['edge', 'nodejs16.x', 'nodejs18.x'];
8
8
 
9
+ const DEFAULT_FUNCTION_NAME = 'fn';
10
+
9
11
  const get_default_runtime = () => {
10
12
  const major = process.version.slice(1).split('.')[0];
11
13
  if (major === '16') return 'nodejs16.x';
@@ -214,7 +216,7 @@ const plugin = function (defaults = {}) {
214
216
  group.config.runtime === 'edge' ? generate_edge_function : generate_serverless_function;
215
217
 
216
218
  // generate one function for the group
217
- const name = singular ? 'fn' : `fn-${group.i}`;
219
+ const name = singular ? DEFAULT_FUNCTION_NAME : `fn-${group.i}`;
218
220
 
219
221
  await generate_function(
220
222
  name,
@@ -287,12 +289,25 @@ const plugin = function (defaults = {}) {
287
289
  }
288
290
  }
289
291
 
290
- if (singular) {
291
- // Common case: One function for all routes
292
- // Needs to happen after ISR or else regex swallows all other matches
293
- static_config.routes.push({ src: '/.*', dest: `/fn` });
292
+ if (!singular) {
293
+ // we need to create a catch-all route so that 404s are handled
294
+ // by SvelteKit rather than Vercel
295
+
296
+ const runtime = defaults.runtime ?? get_default_runtime();
297
+ const generate_function =
298
+ runtime === 'edge' ? generate_edge_function : generate_serverless_function;
299
+
300
+ await generate_function(
301
+ DEFAULT_FUNCTION_NAME,
302
+ /** @type {any} */ ({ runtime, ...defaults }),
303
+ []
304
+ );
294
305
  }
295
306
 
307
+ // Catch-all route must come at the end, otherwise it will swallow all other routes,
308
+ // including ISR aliases if there is only one function
309
+ static_config.routes.push({ src: '/.*', dest: `/${DEFAULT_FUNCTION_NAME}` });
310
+
296
311
  builder.log.minor('Copying assets...');
297
312
 
298
313
  builder.writeClient(dirs.static);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -29,7 +29,7 @@
29
29
  "devDependencies": {
30
30
  "@types/node": "^16.18.6",
31
31
  "typescript": "^4.9.4",
32
- "@sveltejs/kit": "^1.8.7"
32
+ "@sveltejs/kit": "^1.9.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.5.0"