@sveltejs/adapter-vercel 2.3.1 → 2.4.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.
Files changed (3) hide show
  1. package/index.d.ts +19 -17
  2. package/index.js +55 -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,11 +176,19 @@ const plugin = function (defaults = {}) {
168
176
  );
169
177
  }
170
178
 
171
- const config = { runtime, ...defaults, ...route.config };
172
-
173
179
  if (config.isr) {
180
+ const directory = path.relative('.', builder.config.kit.files.routes + route.id);
181
+
182
+ if (runtime !== 'nodejs16.x' && runtime !== 'nodejs18.x') {
183
+ throw new Error(
184
+ `${directory}: Routes using \`isr\` must use either \`runtime: 'nodejs16.x'\` or \`runtime: 'nodejs18.x'\``
185
+ );
186
+ }
187
+
174
188
  if (config.isr.allowQuery?.includes('__pathname')) {
175
- throw new Error('__pathname is a reserved query parameter for isr.allowQuery');
189
+ throw new Error(
190
+ `${directory}: \`__pathname\` is a reserved query parameter for \`isr.allowQuery\``
191
+ );
176
192
  }
177
193
 
178
194
  isr_config.set(route, {
@@ -187,6 +203,7 @@ const plugin = function (defaults = {}) {
187
203
  const hash = hash_config(config);
188
204
 
189
205
  // first, check there are no routes with incompatible configs that will be merged
206
+ const pattern = route.pattern.toString();
190
207
  const existing = conflicts.get(pattern);
191
208
  if (existing) {
192
209
  if (existing.hash !== hash) {
@@ -209,6 +226,20 @@ const plugin = function (defaults = {}) {
209
226
  group.routes.push(route);
210
227
  }
211
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
+
212
243
  const singular = groups.size === 1;
213
244
 
214
245
  for (const group of groups.values()) {
@@ -230,7 +261,7 @@ const plugin = function (defaults = {}) {
230
261
  }
231
262
 
232
263
  for (const route of builder.routes) {
233
- if (route.prerender === true) continue;
264
+ if (is_prerendered(route)) continue;
234
265
 
235
266
  const pattern = route.pattern.toString();
236
267
 
@@ -446,7 +477,7 @@ async function create_function_bundle(builder, entry, dir, config) {
446
477
  if (resolution_failures.size > 0) {
447
478
  const cwd = process.cwd();
448
479
  builder.log.warn(
449
- 'The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
480
+ 'Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
450
481
  );
451
482
 
452
483
  for (const [importer, modules] of resolution_failures) {
@@ -562,15 +593,25 @@ function validate_vercel_json(builder, vercel_config) {
562
593
  unmatched_paths.push(path);
563
594
  }
564
595
 
565
- builder.log.warn(
566
- `\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):`
567
- );
596
+ if (unmatched_paths.length) {
597
+ builder.log.warn(
598
+ `\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):`
599
+ );
568
600
 
569
- for (const path of unmatched_paths) {
570
- console.log(` - ${path}`);
601
+ for (const path of unmatched_paths) {
602
+ console.log(` - ${path}`);
603
+ }
604
+
605
+ console.log('');
571
606
  }
607
+ }
572
608
 
573
- console.log('');
609
+ /** @param {import('@sveltejs/kit').RouteDefinition} route */
610
+ function is_prerendered(route) {
611
+ return (
612
+ route.prerender === true ||
613
+ (route.prerender === 'auto' && route.segments.every((segment) => !segment.dynamic))
614
+ );
574
615
  }
575
616
 
576
617
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
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.11.0"
32
+ "@sveltejs/kit": "^1.12.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.5.0"