CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--adapter-vercel

A SvelteKit adapter that creates a Vercel app

Pending
Overview
Eval results
Files

utilities.mddocs/

Utility Functions

Helper functions used internally by the adapter for route processing and pattern conversion. These functions are part of the adapter's internal implementation and are not exposed in the public API.

Capabilities

Route Pathname Generation

Generates pathname strings from SvelteKit route definitions for ISR (Incremental Static Regeneration) configuration.

/**
 * Generates pathname from route segments for ISR configuration
 * Converts dynamic route segments into numbered placeholders ($1, $2, etc.)
 * @param route - SvelteKit route definition with segment information
 * @returns Pathname string with parameter placeholders
 */
function get_pathname(route: RouteDefinition<any>): string;

// Supporting types from @sveltejs/kit
interface RouteDefinition<Config = any> {
  id: string;
  pattern: RegExp;
  segments: Array<{
    content: string;
    dynamic: boolean;
    rest: boolean;
  }>;
  methods: string[];
  prerender?: boolean | 'auto';
  config?: Config;
}

Internal Usage Examples:

// Example of internal usage within the adapter
// These are not available for external import

// For route: /blog/[slug]
const route = {
  segments: [
    { content: 'blog', dynamic: false, rest: false },
    { content: '[slug]', dynamic: true, rest: false }
  ]
};
const pathname = get_pathname(route);
// Result: "blog/$1"

// For route: /api/[...rest]
const restRoute = {
  segments: [
    { content: 'api', dynamic: false, rest: false },
    { content: '[...rest]', dynamic: true, rest: true }
  ]
};
const restPathname = get_pathname(restRoute);
// Result: "api$1"

// For route with optional parameters: /shop/[[category]]/[id]
const optionalRoute = {
  segments: [
    { content: 'shop', dynamic: false, rest: false },
    { content: '[[category]]', dynamic: true, rest: false },
    { content: '[id]', dynamic: true, rest: false }
  ]
};
const optionalPathname = get_pathname(optionalRoute);
// Result: "shop/$1/$2"

Route Pattern Conversion

Converts SvelteKit route regex patterns to Vercel routing source format for deployment configuration.

/**
 * Adjusts stringified route regex for Vercel's routing system
 * Converts SvelteKit route patterns to Vercel-compatible source patterns
 * @param pattern - Stringified route regex from SvelteKit
 * @returns Source pattern compatible with Vercel routing
 */
function pattern_to_src(pattern: string): string;

Internal Usage Examples:

// Example of internal usage within the adapter
// These are not available for external import

// Root route conversion
const rootPattern = "/^/$/";
const rootSrc = pattern_to_src(rootPattern);
// Result: "^/?"

// Parameter route conversion  
const paramPattern = "/^/foo/([^/]+?)/?$/";
const paramSrc = pattern_to_src(paramPattern);
// Result: "^/foo/([^/]+?)/?$"

// Optional parameter conversion
const optionalPattern = "/^/foo(/[^/]+)?/?$/";  
const optionalSrc = pattern_to_src(optionalPattern);
// Result: "^/foo(/[^/]+)?/?$"

// Rest parameter conversion
const restPattern = "/^/foo(/[^]*)?/?$/";
const restSrc = pattern_to_src(restPattern);
// Result: "^/foo(/[^]*)?/?$"

Internal Processing Details

These utilities handle special cases in route processing:

Dynamic Segment Processing

The get_pathname function processes different types of dynamic segments:

  • Required parameters [param]: Converted to $1, $2, etc.
  • Optional parameters [[param]]: Converted to $1, $2, etc.
  • Rest parameters [...rest]: Converted to $1, $2, etc.
  • Mixed segments prefix-[param]-suffix: Converted to prefix-$1-suffix

Special Handling for Rest Parameters

When a segment contains only a single optional or rest parameter, no leading slash is prepended to avoid incorrect trailing slash redirects in ISR scenarios.

// Single rest parameter segment
{ content: '[...rest]', dynamic: true, rest: true }
// Results in: "$1" (no leading slash)

// Rest parameter in mixed content  
{ content: 'api-[...rest]', dynamic: true, rest: true }
// Results in: "/api-$1" (with leading slash)

Pattern Optimization for Vercel

The pattern_to_src function optimizes patterns for Vercel's routing:

  • Removes regex delimiters and flags
  • Handles root route special case (^/ becomes ^/?)
  • Moves non-capturing groups into following capturing groups for ISR compatibility
  • Prevents false trailing slash redirects in edge cases
// Non-capturing group optimization
// Input: "(?:/([^/]+))"  
// Output: "(/$1)"
// This prevents empty rest parameters from creating unwanted trailing slashes

Install with Tessl CLI

npx tessl i tessl/npm-sveltejs--adapter-vercel

docs

configuration.md

index.md

utilities.md

tile.json