SvelteKit adapter that automatically detects deployment environment and installs appropriate platform-specific adapter
96
Pending
Does it follow best practices?
Impact
96%
1.01xAverage score across 10 eval scenarios
Pending
The risk profile of this skill
Automatically chooses the SvelteKit adapter for your current environment, if possible. This adapter analyzes environment variables to detect deployment platforms and automatically installs and configures the appropriate platform-specific adapter.
npm install -D @sveltejs/adapter-autoimport adapter from '@sveltejs/adapter-auto';For CommonJS (not recommended as this is an ESM package):
const adapter = require('@sveltejs/adapter-auto').default;// svelte.config.js
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
}
};
export default config;The adapter uses a detection system with the following components:
The primary export that creates a SvelteKit adapter with automatic platform detection.
/**
* Creates a SvelteKit adapter that automatically detects the deployment environment
* @returns {Adapter} SvelteKit adapter with auto-detection capabilities
*/
export default function(): Adapter;The adapter automatically detects these deployment environments using an internal configuration array:
Supported Platforms:
Vercel: Detected via VERCEL environment variable
@sveltejs/adapter-vercel@5Cloudflare Pages: Detected via CF_PAGES environment variable
@sveltejs/adapter-cloudflare@7Netlify: Detected via NETLIFY environment variable
@sveltejs/adapter-netlify@5Azure Static Web Apps: Detected via GITHUB_ACTION_REPOSITORY === 'Azure/static-web-apps-deploy'
svelte-adapter-azure-swa@0.20AWS via SST: Detected via SST environment variable
svelte-kit-sst@2Google Cloud Run: Detected via GCP_BUILDPACKS environment variable
@sveltejs/adapter-node@5Supports automatic installation using any of these package managers:
The adapter uses internal command templates to install adapters with the detected package manager.
The adapter automatically detects the package manager by looking for lockfiles in this priority order:
pnpm-lock.yaml → pnpmyarn.lock → yarnpackage-lock.json → npmbun.lockb or bun.lock → bundeno.lock → denoThe adapter handles several error scenarios:
read function)The adapter includes internal error handling that provides context-aware error messages when unsupported features are used.
/**
* SvelteKit Adapter interface - returned by the default export function
*/
interface Adapter {
/** The name of the adapter, using for logging. Will typically correspond to the package name. */
name: string;
/** This function is called after SvelteKit has built your app. */
adapt(builder: Builder): MaybePromise<void>;
/** Checks called during dev and build to determine whether specific features will work in production with this adapter. */
supports?: {
/** Test support for `read` from `$app/server`. */
read?(details: { config: any; route: { id: string } }): boolean;
};
/** Creates an `Emulator`, which allows the adapter to influence the environment during dev, build and prerendering. */
emulate?(): MaybePromise<Emulator>;
}
/**
* SvelteKit Builder interface (from @sveltejs/kit)
* This object is passed to the `adapt` function of adapters.
* It contains various methods and properties that are useful for adapting the app.
*/
interface Builder {
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
log: Logger;
/** Remove `dir` and all its contents. */
rimraf(dir: string): void;
/** Create `dir` and any required parent directories. */
mkdirp(dir: string): void;
/** The fully resolved Svelte config. */
config: ValidatedConfig;
/** Information about prerendered pages and assets, if any. */
prerendered: Prerendered;
/** An array of all routes (including prerendered) */
routes: RouteDefinition[];
/** Find all the assets imported by server files belonging to `routes` */
findServerAssets(routes: RouteDefinition[]): string[];
/** Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps. */
generateFallback(dest: string): Promise<void>;
/** Generate a module exposing build-time environment variables as `$env/dynamic/public`. */
generateEnvModule(): void;
/** Generate a server-side manifest to initialise the SvelteKit server with. */
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
/** Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`. */
getBuildDirectory(name: string): string;
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
getClientDirectory(): string;
/** Get the fully resolved path to the directory containing server-side code. */
getServerDirectory(): string;
/** Get the application path including any configured `base` path, e.g. `my-base-path/_app`. */
getAppPath(): string;
/** Write client assets to `dest`. */
writeClient(dest: string): string[];
/** Write prerendered files to `dest`. */
writePrerendered(dest: string): string[];
/** Write server-side code to `dest`. */
writeServer(dest: string): string[];
/** Copy a file or directory. */
copy(
from: string,
to: string,
opts?: {
filter?(basename: string): boolean;
replace?: Record<string, string>;
}
): string[];
/** Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals. */
compress(directory: string): Promise<void>;
}
/**
* Logger interface used by Builder.log
*/
interface Logger {
(msg: string): void;
success(msg: string): void;
error(msg: string): void;
warn(msg: string): void;
minor(msg: string): void;
info(msg: string): void;
}
/**
* A collection of functions that influence the environment during dev, build and prerendering
*/
interface Emulator {
/** A function that is called with the current route `config` and `prerender` option and returns an `App.Platform` object */
platform?(details: { config: any; prerender: PrerenderOption }): MaybePromise<App.Platform>;
}
/** Helper type for values that may or may not be wrapped in a Promise */
type MaybePromise<T> = T | Promise<T>;
/** Configuration interfaces and other supporting types are imported from @sveltejs/kit */
interface ValidatedConfig extends Record<string, any> {}
interface Prerendered extends Record<string, any> {}
interface RouteDefinition extends Record<string, any> {}
type PrerenderOption = boolean | 'auto'When a supported environment is detected:
The adapter provides helpful error messages in various scenarios: