CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--adapter-auto

SvelteKit adapter that automatically detects deployment environment and installs appropriate platform-specific adapter

Overall
score

96%

Overview
Eval results
Files

task.mdevals/scenario-3/

Environment Detector

Build a simple utility that mimics how SvelteKit's automatic adapter detection works by identifying deployment platforms from environment variables.

Requirements

Create a function that:

  1. Accepts an object of environment variables
  2. Identifies which deployment platform is present based on specific environment variable checks
  3. Returns the platform name and corresponding adapter package name

Platform Detection Rules

Check for these platforms in this specific order (first match wins):

  • Vercel: check if VERCEL environment variable exists
  • Cloudflare Pages: check if CF_PAGES environment variable exists
  • Netlify: check if NETLIFY environment variable exists
  • Google Cloud Run: check if GCP_BUILDPACKS environment variable exists

Map detected platforms to their adapter packages:

  • Vercel → @sveltejs/adapter-vercel
  • Cloudflare Pages → @sveltejs/adapter-cloudflare
  • Netlify → @sveltejs/adapter-netlify
  • Google Cloud Run → @sveltejs/adapter-node

If no platform is detected, return unknown as the platform with null as the adapter.

Test Cases

  • When given {VERCEL: '1'}, returns {platform: 'Vercel', adapter: '@sveltejs/adapter-vercel'} @test
  • When given {CF_PAGES: '1'}, returns {platform: 'Cloudflare Pages', adapter: '@sveltejs/adapter-cloudflare'} @test
  • When given {NETLIFY: 'true'}, returns {platform: 'Netlify', adapter: '@sveltejs/adapter-netlify'} @test
  • When given {}, returns {platform: 'unknown', adapter: null} @test

@generates

API

/**
 * Detects the deployment environment based on environment variables
 *
 * @param {Object} envVars - An object containing environment variable key-value pairs
 * @returns {Object} An object with 'platform' (string) and 'adapter' (string|null) properties
 */
function detectEnvironment(envVars) {
  // Implementation here
}

module.exports = { detectEnvironment };

Dependencies { .dependencies }

@sveltejs/adapter-auto { .dependency }

Provides environment detection for SvelteKit deployment platforms.

Install with Tessl CLI

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

tile.json