Skip to content

Commit

Permalink
expose Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 4, 2022
1 parent 704648d commit 47b380e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 68 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/index.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Expand Up @@ -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) {
Expand Down
70 changes: 68 additions & 2 deletions packages/kit/types/index.d.ts
Expand Up @@ -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<void>;
}

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, string>;
}
): string[];
}

export interface Config {
compilerOptions?: CompileOptions;
extensions?: string[];
Expand Down
65 changes: 1 addition & 64 deletions packages/kit/types/private.d.ts
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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, string>;
}
): string[];
}

// Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
//
// MIT License
Expand Down

0 comments on commit 47b380e

Please sign in to comment.