Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"description": "A minimal, modern, generic, hot-reloading local web server to help web developers.",
"main": "server.js",
"type": "module",
"exports": {
"types": "./server.d.ts",
"default": "./server.js"
},
"scripts": {
"test": "npx ava --verbose",
"sample": "node cmd.cjs --input=test/stubs"
Expand Down
187 changes: 187 additions & 0 deletions server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import type { IncomingMessage, ServerResponse } from "node:http";
import type { Server as HttpServer } from "node:http";
import type { Http2SecureServer } from "node:http2";
import type { FSWatcher } from "chokidar";
import type WebSocket from "ws";

export interface MessageOnStartArgs {
hosts: string[];
localhostUrl: string;
startupTime: number;
version: string;
options: EleventyDevServerOptions;
}

export interface MessageOnCloseArgs {
version: string;
options: EleventyDevServerOptions;
}

export interface OnRequestArgs {
url: URL;
pattern: URLPattern;
patternGroups: Record<string, string>;
}

export interface OnRequestResult {
status?: number;
headers?: Headers | Record<string, string>;
body?: string | Buffer;
}

export type OnRequestHandler = (
args: OnRequestArgs,
) =>
| string
| Response
| OnRequestResult
| Promise<string | Response | OnRequestResult | void>
| void;

export interface Logger {
info(...args: any[]): void;
log(...args: any[]): void;
error(...args: any[]): void;
}

export interface HttpsOptions {
key?: string;
cert?: string;
}

export interface EleventyDevServerOptions {
port?: number;

reloadPort?: number | false;

liveReload?: boolean;

showAllHosts?: boolean;

injectedScriptsFolder?: string;

portReassignmentRetryCount?: number;

https?: HttpsOptions;

domDiff?: boolean;

showVersion?: boolean;

encoding?: BufferEncoding;

pathPrefix?: string;

watch?: string[];

chokidarOptions?: Record<string, any>;

chokidar?: FSWatcher;

aliases?: Record<string, string>;

indexFileName?: string;

useCache?: boolean;

headers?: Record<string, string>;

middleware?: Array<
(req: IncomingMessage, res: ServerResponse, next?: () => void) => any
>;

onRequest?: Record<string, OnRequestHandler>;

messageOnStart?: (args: MessageOnStartArgs) => string | false | void;

messageOnClose?: (args: MessageOnCloseArgs) => string | false | void;

logger?: Logger;

/**
* deprecated aliases
*/
folder?: string;

domdiff?: boolean;

enabled?: boolean;
}

export interface ReloadTemplate {
url: string;
inputPath: string;
content: string;
}

export interface ReloadEvent {
subtype?: string;

files?: string[];

build?: {
templates?: ReloadTemplate[];
};
}

export default class EleventyDevServer {
constructor(name: string, dir: string, options?: EleventyDevServerOptions);

static getServer(
name: string,
dir: string,
options?: EleventyDevServerOptions,
): EleventyDevServer;

options: EleventyDevServerOptions;

dir: string;

fileCache: Record<string, string>;

updateServer?: WebSocket.Server;

logger: Logger;

watcher?: FSWatcher;

server: HttpServer | Http2SecureServer;

normalizeOptions(options?: EleventyDevServerOptions): void;

cleanupPathPrefix(pathPrefix?: string): string;

setAliases(aliases: Record<string, string>): void;

getWatcher(): FSWatcher | undefined;

watchFiles(targets: string[]): void;

serve(port: number): void;

ready(): Promise<void>;

close(): Promise<void>;

reload(event?: ReloadEvent): void;

reloadFiles(files: string[], useDomDiffingForHtml?: boolean): void;

sendError(args: { error: Error }): void;

sendUpdateNotification(obj: any): void;

getHosts(): string[];

getServerUrl(host: string, pathname?: string): string;

getServerUrlRaw(host: string, pathname?: string, isRaw?: boolean): string;

getServerPath(pathname: string): string;

getPort(): Promise<number>;

getUrlsFromFilePath(path: string): string[];

getBuildTemplatesFromFilePath(path: string): ReloadTemplate[];
}