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-8/

Custom SvelteKit Build Adapter

Overview

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.

Requirements

Your adapter should:

  1. 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.

  2. 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.

  3. Build Output: When in a SimpleHost environment, use the builder to:

    • Write a static fallback page to output/fallback.html containing "SimpleHost Fallback Page"
    • Copy all static files from the build to the output/static directory
    • Write server files to the output/server directory
  4. Feature Support: Implement a supports property that throws an error with the message "Custom feature not supported" when checking for a feature called customFeature.

  5. Configuration Export: The adapter should be exported as the default export from adapter.js and should accept no configuration parameters.

Test Cases

Test 1: Adapter Interface @test

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');

Test 2: Environment Detection @test

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);
});

Test 3: Feature Support Error @test

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');
}

Dependencies { .dependencies }

@sveltejs/kit { .dependency }

Provides the SvelteKit adapter interface and build tooling.

Constraints

  • Use Node.js standard library for file operations
  • The adapter should work with SvelteKit 2.0 or higher
  • Do not use any external dependencies beyond @sveltejs/kit
  • Keep the implementation straightforward and focused on the core requirements

Install with Tessl CLI

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

tile.json