@sveltejs/adapter-netlify 6.0.3 → 6.0.4

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 +18 -8
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -260,7 +260,9 @@ function generate_lambda_functions({ builder, publish, split }) {
260
260
 
261
261
  // skip routes with identical patterns, they were already folded into another function
262
262
  if (seen.has(pattern)) continue;
263
- seen.add(pattern);
263
+
264
+ const patterns = [pattern, `${pattern === '/' ? '' : pattern}/__data.json`];
265
+ patterns.forEach((p) => seen.add(p));
264
266
 
265
267
  // figure out which lower priority routes should be considered fallbacks
266
268
  for (let j = i + 1; j < builder.routes.length; j += 1) {
@@ -275,12 +277,18 @@ function generate_lambda_functions({ builder, publish, split }) {
275
277
  generate_serverless_function({
276
278
  builder,
277
279
  routes,
278
- patterns: [pattern, `${pattern === '/' ? '' : pattern}/__data.json`],
280
+ patterns,
279
281
  name
280
282
  });
281
283
  }
282
284
 
283
- // TODO: add a catch-all to display a 404 page if no other functions are invoked, similar to the Vercel adapter
285
+ generate_serverless_function({
286
+ builder,
287
+ routes: [],
288
+ patterns: ['/*'],
289
+ name: `${FUNCTION_PREFIX}catch-all`,
290
+ exclude: Array.from(seen)
291
+ });
284
292
  } else {
285
293
  generate_serverless_function({
286
294
  builder,
@@ -375,17 +383,18 @@ function matches(a, b) {
375
383
  * builder: import('@sveltejs/kit').Builder,
376
384
  * routes: import('@sveltejs/kit').RouteDefinition[] | undefined,
377
385
  * patterns: string[],
378
- * name: string
386
+ * name: string,
387
+ * exclude?: string[]
379
388
  * }} opts
380
389
  */
381
- function generate_serverless_function({ builder, routes, patterns, name }) {
390
+ function generate_serverless_function({ builder, routes, patterns, name, exclude }) {
382
391
  const manifest = builder.generateManifest({
383
392
  relativePath: '../server',
384
393
  routes
385
394
  });
386
395
 
387
396
  const fn = generate_serverless_function_module(manifest);
388
- const config = generate_config_export(patterns);
397
+ const config = generate_config_export(patterns, exclude);
389
398
 
390
399
  if (builder.hasServerInstrumentationFile()) {
391
400
  writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
@@ -416,14 +425,15 @@ export default init(${manifest});
416
425
 
417
426
  /**
418
427
  * @param {string[]} patterns
428
+ * @param {string[]} [exclude]
419
429
  * @returns {string}
420
430
  */
421
- function generate_config_export(patterns) {
431
+ function generate_config_export(patterns, exclude = []) {
422
432
  // TODO: add a human friendly name for the function https://docs.netlify.com/build/frameworks/frameworks-api/#configuration-options-2
423
433
  return `\
424
434
  export const config = {
425
435
  path: [${patterns.map((s) => JSON.stringify(s)).join(', ')}],
426
- excludedPath: "/.netlify/*",
436
+ excludedPath: [${['/.netlify/*', ...exclude].map((s) => JSON.stringify(s)).join(', ')}],
427
437
  preferStatic: true
428
438
  };
429
439
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "6.0.3",
3
+ "version": "6.0.4",
4
4
  "description": "A SvelteKit adapter that creates a Netlify app",
5
5
  "keywords": [
6
6
  "adapter",
@@ -50,7 +50,7 @@
50
50
  "rollup": "^4.14.2",
51
51
  "typescript": "^5.3.3",
52
52
  "vitest": "^4.0.0",
53
- "@sveltejs/kit": "^2.53.0"
53
+ "@sveltejs/kit": "^2.53.1"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@sveltejs/kit": "^2.31.0"