SvelteKit adapter that automatically detects deployment environment and installs appropriate platform-specific adapter
Overall
score
96%
Create a custom SvelteKit adapter that integrates with the SvelteKit build process to generate a deployment-ready output for a hypothetical platform called "SimpleHost". The adapter should detect when running in a SimpleHost environment and provide appropriate build configuration.
Your adapter should:
Implement the SvelteKit Adapter Interface: Create an adapter that properly implements the required interface with a name property and an adapt method that receives a builder object.
Environment Detection: Detect when the build is running in a SimpleHost environment by checking for the environment variable SIMPLE_HOST=true. Log an appropriate message when this environment is detected.
Build Output: When in a SimpleHost environment, use the builder to:
output/fallback.html containing "SimpleHost Fallback Page"output/static directoryoutput/server directoryFeature Support: Implement a supports property that throws an error with the message "Custom feature not supported" when checking for a feature called customFeature.
Configuration Export: The adapter should be exported as the default export from adapter.js and should accept no configuration parameters.
The adapter should export a default function that returns an object with required properties.
Test file: adapter.test.js
import adapter from './adapter.js';
const instance = adapter();
console.assert(typeof instance.name === 'string', 'Adapter must have a name property');
console.assert(typeof instance.adapt === 'function', 'Adapter must have an adapt method');
console.assert(typeof instance.supports === 'object', 'Adapter must have a supports property');
console.log('Test 1 passed: Adapter interface implemented correctly');The adapter should detect the SimpleHost environment variable.
Test file: environment.test.js
import adapter from './adapter.js';
process.env.SIMPLE_HOST = 'true';
const instance = adapter();
const mockBuilder = {
log: { minor: (msg) => console.log('Log:', msg) },
writeClient: (dest) => console.log('Writing client to:', dest),
writeServer: (dest) => console.log('Writing server to:', dest),
writeStatic: (dest) => console.log('Writing static to:', dest),
generateFallback: (dest) => console.log('Generating fallback at:', dest)
};
// This should log a message about SimpleHost detection
instance.adapt(mockBuilder).then(() => {
console.log('Test 2 passed: Environment detection working');
}).catch(err => {
console.error('Test 2 failed:', err);
});The adapter should throw an error for unsupported features.
Test file: supports.test.js
import adapter from './adapter.js';
const instance = adapter();
try {
instance.supports.customFeature();
console.error('Test 3 failed: Should have thrown an error');
} catch (err) {
console.assert(err.message === 'Custom feature not supported', 'Error message should match');
console.log('Test 3 passed: Feature support errors working correctly');
}Provides the SvelteKit adapter interface and build tooling.
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