@sveltejs/adapter-vercel 2.3.2 → 2.4.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 (3) hide show
  1. package/index.d.ts +19 -17
  2. package/index.js +46 -14
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -32,23 +32,25 @@ export interface ServerlessConfig {
32
32
  * [Incremental Static Regeneration](https://vercel.com/docs/concepts/incremental-static-regeneration/overview) configuration.
33
33
  * Serverless only.
34
34
  */
35
- isr?: {
36
- /**
37
- * 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.
38
- */
39
- expiration: number | false;
40
- /**
41
- * Random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset
42
- * with a __prerender_bypass=<token> cookie.
43
- *
44
- * Making a `GET` or `HEAD` request with `x-prerender-revalidate: <token>` will force the asset to be re-validated.
45
- */
46
- bypassToken?: string;
47
- /**
48
- * List of query string parameter names that will be cached independently. If an empty array, query values are not considered for caching. If undefined each unique query value is cached independently
49
- */
50
- allowQuery?: string[] | undefined;
51
- };
35
+ isr?:
36
+ | {
37
+ /**
38
+ * 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.
39
+ */
40
+ expiration: number | false;
41
+ /**
42
+ * Random token that can be provided in the URL to bypass the cached version of the asset, by requesting the asset
43
+ * with a __prerender_bypass=<token> cookie.
44
+ *
45
+ * Making a `GET` or `HEAD` request with `x-prerender-revalidate: <token>` will force the asset to be re-validated.
46
+ */
47
+ bypassToken?: string;
48
+ /**
49
+ * List of query string parameter names that will be cached independently. If an empty array, query values are not considered for caching. If undefined each unique query value is cached independently
50
+ */
51
+ allowQuery?: string[] | undefined;
52
+ }
53
+ | false;
52
54
  }
53
55
 
54
56
  export interface EdgeConfig {
package/index.js CHANGED
@@ -153,13 +153,21 @@ const plugin = function (defaults = {}) {
153
153
  /** @type {Map<import('@sveltejs/kit').RouteDefinition<import('.').Config>, { expiration: number | false, bypassToken: string | undefined, allowQuery: string[], group: number, passQuery: true }>} */
154
154
  const isr_config = new Map();
155
155
 
156
+ /** @type {Set<string>} */
157
+ const ignored_isr = new Set();
158
+
156
159
  // group routes by config
157
160
  for (const route of builder.routes) {
158
- if (route.prerender === true) continue;
161
+ const runtime = route.config?.runtime ?? defaults?.runtime ?? get_default_runtime();
162
+ const config = { runtime, ...defaults, ...route.config };
159
163
 
160
- const pattern = route.pattern.toString();
164
+ if (is_prerendered(route)) {
165
+ if (config.isr) {
166
+ ignored_isr.add(route.id);
167
+ }
168
+ continue;
169
+ }
161
170
 
162
- const runtime = route.config?.runtime ?? defaults?.runtime ?? get_default_runtime();
163
171
  if (runtime && !VALID_RUNTIMES.includes(runtime)) {
164
172
  throw new Error(
165
173
  `Invalid runtime '${runtime}' for route ${
@@ -168,8 +176,6 @@ const plugin = function (defaults = {}) {
168
176
  );
169
177
  }
170
178
 
171
- const config = { runtime, ...defaults, ...route.config };
172
-
173
179
  if (config.isr) {
174
180
  const directory = path.relative('.', builder.config.kit.files.routes + route.id);
175
181
 
@@ -197,6 +203,7 @@ const plugin = function (defaults = {}) {
197
203
  const hash = hash_config(config);
198
204
 
199
205
  // first, check there are no routes with incompatible configs that will be merged
206
+ const pattern = route.pattern.toString();
200
207
  const existing = conflicts.get(pattern);
201
208
  if (existing) {
202
209
  if (existing.hash !== hash) {
@@ -219,6 +226,20 @@ const plugin = function (defaults = {}) {
219
226
  group.routes.push(route);
220
227
  }
221
228
 
229
+ if (ignored_isr.size) {
230
+ builder.log.warn(
231
+ `\nWarning: The following routes have an ISR config which is ignored because the route is prerendered:`
232
+ );
233
+
234
+ for (const ignored of ignored_isr) {
235
+ console.log(` - ${ignored}`);
236
+ }
237
+
238
+ console.log(
239
+ 'Either remove the "prerender" option from these routes to use ISR, or remove the ISR config.\n'
240
+ );
241
+ }
242
+
222
243
  const singular = groups.size === 1;
223
244
 
224
245
  for (const group of groups.values()) {
@@ -240,7 +261,7 @@ const plugin = function (defaults = {}) {
240
261
  }
241
262
 
242
263
  for (const route of builder.routes) {
243
- if (route.prerender === true) continue;
264
+ if (is_prerendered(route)) continue;
244
265
 
245
266
  const pattern = route.pattern.toString();
246
267
 
@@ -337,7 +358,8 @@ function hash_config(config) {
337
358
  config.external ?? '',
338
359
  config.regions ?? '',
339
360
  config.memory ?? '',
340
- config.maxDuration ?? ''
361
+ config.maxDuration ?? '',
362
+ !!config.isr // need to distinguish ISR from non-ISR functions, because ISR functions can't use streaming mode
341
363
  ].join('/');
342
364
  }
343
365
 
@@ -456,7 +478,7 @@ async function create_function_bundle(builder, entry, dir, config) {
456
478
  if (resolution_failures.size > 0) {
457
479
  const cwd = process.cwd();
458
480
  builder.log.warn(
459
- 'The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
481
+ 'Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
460
482
  );
461
483
 
462
484
  for (const [importer, modules] of resolution_failures) {
@@ -572,15 +594,25 @@ function validate_vercel_json(builder, vercel_config) {
572
594
  unmatched_paths.push(path);
573
595
  }
574
596
 
575
- builder.log.warn(
576
- `\nvercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your \`handle\` hook):`
577
- );
597
+ if (unmatched_paths.length) {
598
+ builder.log.warn(
599
+ `\nWarning: vercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your \`handle\` hook):`
600
+ );
601
+
602
+ for (const path of unmatched_paths) {
603
+ console.log(` - ${path}`);
604
+ }
578
605
 
579
- for (const path of unmatched_paths) {
580
- console.log(` - ${path}`);
606
+ console.log('');
581
607
  }
608
+ }
582
609
 
583
- console.log('');
610
+ /** @param {import('@sveltejs/kit').RouteDefinition} route */
611
+ function is_prerendered(route) {
612
+ return (
613
+ route.prerender === true ||
614
+ (route.prerender === 'auto' && route.segments.every((segment) => !segment.dynamic))
615
+ );
584
616
  }
585
617
 
586
618
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "2.3.2",
3
+ "version": "2.4.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.12.0"
32
+ "@sveltejs/kit": "^1.14.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.5.0"