SvelteKit adapter that automatically detects deployment environment and installs appropriate platform-specific adapter
Overall
score
96%
Build a simple utility that mimics how SvelteKit's automatic adapter detection works by identifying deployment platforms from environment variables.
Create a function that:
Check for these platforms in this specific order (first match wins):
VERCEL environment variable existsCF_PAGES environment variable existsNETLIFY environment variable existsGCP_BUILDPACKS environment variable existsMap detected platforms to their adapter packages:
@sveltejs/adapter-vercel@sveltejs/adapter-cloudflare@sveltejs/adapter-netlify@sveltejs/adapter-nodeIf no platform is detected, return unknown as the platform with null as the adapter.
{VERCEL: '1'}, returns {platform: 'Vercel', adapter: '@sveltejs/adapter-vercel'} @test{CF_PAGES: '1'}, returns {platform: 'Cloudflare Pages', adapter: '@sveltejs/adapter-cloudflare'} @test{NETLIFY: 'true'}, returns {platform: 'Netlify', adapter: '@sveltejs/adapter-netlify'} @test{}, returns {platform: 'unknown', adapter: null} @test@generates
/**
* 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 };Provides environment detection for SvelteKit deployment platforms.
Install with Tessl CLI
npx tessl i tessl/npm-sveltejs--adapter-autodocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10