From 47b380ef13b849dfdbdfebf2e56d1c566c058066 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 4 Mar 2022 17:48:17 -0500 Subject: [PATCH] expose Builder --- packages/adapter-cloudflare-workers/index.js | 2 +- packages/adapter-netlify/index.js | 2 +- packages/kit/types/index.d.ts | 70 +++++++++++++++++++- packages/kit/types/private.d.ts | 65 +----------------- 4 files changed, 71 insertions(+), 68 deletions(-) diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index 996219fa909c..f161a109cb37 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -67,7 +67,7 @@ export default function () { }; } -/** @param {any} builder */ +/** @param {import('@sveltejs/kit').Builder} builder */ function validate_config(builder) { if (existsSync('wrangler.toml')) { let wrangler_config; diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 4cbca7229059..4d6aa3eea4c9 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -153,7 +153,7 @@ function get_netlify_config() { /** * @param {NetlifyConfig} netlify_config - * @param {any} builder + * @param {import('@sveltejs/kit').Builder} builder **/ function get_publish_directory(netlify_config, builder) { if (netlify_config) { diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 40fb058f00a3..0698718e4dbc 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -5,29 +5,95 @@ import './ambient'; import { CompileOptions } from 'svelte/types/compiler/interfaces'; import { + AdapterEntry, Body, - Builder, CspDirectives, Either, ErrorLoadInput, Fallthrough, LoadInput, LoadOutput, + Logger, MaybePromise, + Prerendered, PrerenderOnErrorValue, RequestEvent, RequestOptions, ResolveOptions, ResponseHeaders, + RouteDefinition, TrailingSlash } from './private'; -import { SSRNodeLoader, SSRRoute } from './internal'; +import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal'; export interface Adapter { name: string; adapt(builder: Builder): Promise; } +export interface Builder { + log: Logger; + rimraf(dir: string): void; + mkdirp(dir: string): void; + + config: ValidatedConfig; + prerendered: Prerendered; + + /** + * Create entry points that map to individual functions + * @param fn A function that groups a set of routes into an entry point + */ + createEntries(fn: (route: RouteDefinition) => AdapterEntry): void; + + generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string; + + getBuildDirectory(name: string): string; + getClientDirectory(): string; + getServerDirectory(): string; + getStaticDirectory(): string; + + /** + * @param dest the destination folder to which files should be copied + * @returns an array of paths corresponding to the files that have been created by the copy + */ + writeClient(dest: string): string[]; + /** + * + * @param dest + */ + writePrerendered( + dest: string, + opts?: { + fallback?: string; + } + ): string[]; + /** + * @param dest the destination folder to which files should be copied + * @returns an array of paths corresponding to the files that have been created by the copy + */ + writeServer(dest: string): string[]; + /** + * @param dest the destination folder to which files should be copied + * @returns an array of paths corresponding to the files that have been created by the copy + */ + writeStatic(dest: string): string[]; + /** + * @param from the source file or folder + * @param to the destination file or folder + * @param opts.filter a function to determine whether a file or folder should be copied + * @param opts.replace a map of strings to replace + * @returns an array of paths corresponding to the files that have been created by the copy + */ + copy( + from: string, + to: string, + opts?: { + filter?: (basename: string) => boolean; + replace?: Record; + } + ): string[]; +} + export interface Config { compilerOptions?: CompileOptions; extensions?: string[]; diff --git a/packages/kit/types/private.d.ts b/packages/kit/types/private.d.ts index ffa93c7b79b3..b8c7f9660f14 100644 --- a/packages/kit/types/private.d.ts +++ b/packages/kit/types/private.d.ts @@ -2,7 +2,7 @@ // but which cannot be imported from `@sveltejs/kit`. Care should // be taken to avoid breaking changes when editing this file -import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal'; +import { ValidatedConfig } from './internal'; export interface AdapterEntry { /** @@ -30,69 +30,6 @@ export interface AdapterEntry { export type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable; -export interface Builder { - log: Logger; - rimraf(dir: string): void; - mkdirp(dir: string): void; - - config: ValidatedConfig; - prerendered: Prerendered; - - /** - * Create entry points that map to individual functions - * @param fn A function that groups a set of routes into an entry point - */ - createEntries(fn: (route: RouteDefinition) => AdapterEntry): void; - - generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string; - - getBuildDirectory(name: string): string; - getClientDirectory(): string; - getServerDirectory(): string; - getStaticDirectory(): string; - - /** - * @param dest the destination folder to which files should be copied - * @returns an array of paths corresponding to the files that have been created by the copy - */ - writeClient(dest: string): string[]; - /** - * - * @param dest - */ - writePrerendered( - dest: string, - opts?: { - fallback?: string; - } - ): string[]; - /** - * @param dest the destination folder to which files should be copied - * @returns an array of paths corresponding to the files that have been created by the copy - */ - writeServer(dest: string): string[]; - /** - * @param dest the destination folder to which files should be copied - * @returns an array of paths corresponding to the files that have been created by the copy - */ - writeStatic(dest: string): string[]; - /** - * @param from the source file or folder - * @param to the destination file or folder - * @param opts.filter a function to determine whether a file or folder should be copied - * @param opts.replace a map of strings to replace - * @returns an array of paths corresponding to the files that have been created by the copy - */ - copy( - from: string, - to: string, - opts?: { - filter?: (basename: string) => boolean; - replace?: Record; - } - ): string[]; -} - // Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts // // MIT License