deserved 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { createHandler } from "./handlers";
2
+ export { DEFAULT_OPTIONS, type Options } from "./options";
3
+ export { BindError, RootError, type ServerHandle, serve } from "./server";
package/src/live.ts ADDED
@@ -0,0 +1,98 @@
1
+ export const LIVE_PATH = "/__live.js";
2
+ export const EVENTS_PATH = "/__events";
3
+
4
+ // Once the stream drops (server stopped or restarting), the browser's
5
+ // EventSource retries on its own; the first successful reconnect reloads
6
+ // the page. If the server comes back without --watch, /__events 404s and
7
+ // the source closes for good, so reload once to pick up the new server.
8
+ // A source that never connected (a handler with no hub) stays put, so
9
+ // it can't loop.
10
+ export const LIVE_SCRIPT = `(()=>{let down=false;const e=new EventSource("${EVENTS_PATH}");e.onopen=()=>{if(down)location.reload()};e.onmessage=(m)=>{if(m.data==="css"){for(const l of document.querySelectorAll('link[rel="stylesheet"]')){const h=l.href.split("?")[0];l.href=h+"?t="+Date.now()}}else{location.reload()}};e.onerror=()=>{if(down&&e.readyState===2)location.reload();down=true}})()`;
11
+
12
+ const INJECT = `<script src="${LIVE_PATH}"></script>`;
13
+
14
+ export function injectLiveReload(html: string): string {
15
+ const idx = html.toLowerCase().lastIndexOf("</body>");
16
+ if (idx === -1) return html + INJECT;
17
+ return html.slice(0, idx) + INJECT + html.slice(idx);
18
+ }
19
+
20
+ export const SSE_HEADERS = {
21
+ "Content-Type": "text/event-stream",
22
+ "Cache-Control": "no-cache",
23
+ Connection: "keep-alive",
24
+ };
25
+
26
+ export function createSseHub() {
27
+ const clients = new Set<ReadableStreamDefaultController<Uint8Array>>();
28
+ const encoder = new TextEncoder();
29
+ const PING = encoder.encode(": ping\n\n");
30
+
31
+ // Bun force-closes a connection after ~10s of no traffic, which would
32
+ // otherwise drop an idle browser tab's SSE stream and make it reload on
33
+ // reconnect. Keep it warm so it only ever closes on shutdown.
34
+ const heartbeat = setInterval(() => {
35
+ for (const c of clients) {
36
+ try {
37
+ c.enqueue(PING);
38
+ } catch {
39
+ clients.delete(c);
40
+ }
41
+ }
42
+ }, 8000);
43
+ heartbeat.unref();
44
+
45
+ function subscribe(): Response {
46
+ let controller: ReadableStreamDefaultController<Uint8Array>;
47
+
48
+ const stream = new ReadableStream<Uint8Array>({
49
+ start(c) {
50
+ controller = c;
51
+ clients.add(c);
52
+ // retry: how soon the browser reconnects after a restart.
53
+ c.enqueue(encoder.encode("retry: 500\n: connected\n\n"));
54
+ },
55
+ cancel() {
56
+ clients.delete(controller);
57
+ },
58
+ });
59
+
60
+ return new Response(stream, { headers: SSE_HEADERS });
61
+ }
62
+
63
+ function broadcast(data = "reload") {
64
+ const payload = encoder.encode(`data: ${data}\n\n`);
65
+ for (const c of clients) {
66
+ try {
67
+ c.enqueue(payload);
68
+ } catch {
69
+ clients.delete(c);
70
+ }
71
+ }
72
+ }
73
+
74
+ function close() {
75
+ clearInterval(heartbeat);
76
+ for (const c of clients) {
77
+ try {
78
+ c.close();
79
+ } catch {}
80
+ }
81
+ clients.clear();
82
+ }
83
+
84
+ return { subscribe, broadcast, close };
85
+ }
86
+
87
+ export type Hub = ReturnType<typeof createSseHub>;
88
+
89
+ export function isIgnoredWatchPath(filename: string): boolean {
90
+ return filename
91
+ .split(/[/\\]/)
92
+ .some((segment) => segment.startsWith(".") || segment === "node_modules");
93
+ }
94
+
95
+ export function classifyBatch(files: (string | null)[]): "css" | "reload" {
96
+ if (files.length === 0) return "reload";
97
+ return files.every((f) => f?.endsWith(".css")) ? "css" : "reload";
98
+ }
package/src/log.ts ADDED
@@ -0,0 +1,97 @@
1
+ // Plain text when piped (CI logs, `| tee`) or when NO_COLOR is set
2
+ // (https://no-color.org).
3
+ export function shouldColor(
4
+ isTTY: boolean | undefined,
5
+ env: Record<string, string | undefined>,
6
+ ): boolean {
7
+ return isTTY === true && !env.NO_COLOR;
8
+ }
9
+
10
+ const useColor = shouldColor(process.stdout.isTTY, process.env);
11
+ const ansi = (code: number) => (useColor ? `\x1b[${code}m` : "");
12
+
13
+ const c = {
14
+ reset: ansi(0),
15
+ dim: ansi(2),
16
+ green: ansi(32),
17
+ yellow: ansi(33),
18
+ red: ansi(31),
19
+ cyan: ansi(36),
20
+ bold: ansi(1),
21
+ } as const;
22
+
23
+ // eslint-disable-next-line no-control-regex -- strip control chars from logs
24
+ const CONTROL_CHARS = /[\x00-\x1f\x7f]/g;
25
+ // eslint-disable-next-line no-control-regex -- cheap pre-check so the common clean-path case skips replace()
26
+ const HAS_CONTROL = /[\x00-\x1f\x7f]/;
27
+
28
+ function sanitizeForLog(s: string): string {
29
+ return HAS_CONTROL.test(s) ? s.replace(CONTROL_CHARS, "") : s;
30
+ }
31
+
32
+ const ICON_OK = `${c.green}✓${c.reset}`;
33
+ const ICON_REDIRECT = `${c.yellow}○${c.reset}`;
34
+ const ICON_ERR = `${c.red}✗${c.reset}`;
35
+ const DIM = c.dim;
36
+ const RESET = c.reset;
37
+
38
+ // Collapses many synchronous per-request writes into one per tick: a
39
+ // console.log/write per request costs a syscall each, which adds up under
40
+ // load. Lines queue here and flush once, at the end of the current
41
+ // microtask queue.
42
+ let pendingLines: string[] = [];
43
+
44
+ function scheduleFlush(): void {
45
+ if (pendingLines.length === 1) queueMicrotask(flushLogs);
46
+ }
47
+
48
+ export function flushLogs(): void {
49
+ if (pendingLines.length === 0) return;
50
+ const out = pendingLines.join("\n");
51
+ pendingLines = [];
52
+ process.stdout.write(`${out}\n`);
53
+ }
54
+
55
+ export function logRequest(
56
+ method: string,
57
+ status: number,
58
+ path: string,
59
+ quiet: boolean,
60
+ ) {
61
+ if (quiet) return;
62
+ const icon = status < 300 ? ICON_OK : status < 400 ? ICON_REDIRECT : ICON_ERR;
63
+ pendingLines.push(
64
+ `${icon} ${DIM}${method}${RESET} ${status} ${sanitizeForLog(path)}`,
65
+ );
66
+ scheduleFlush();
67
+ }
68
+
69
+ export function logInfo(msg: string, quiet = false) {
70
+ if (quiet) return;
71
+ console.log(`${c.cyan}│${c.reset} ${msg}`);
72
+ }
73
+
74
+ export function logBanner(
75
+ url: string,
76
+ root: string,
77
+ flags: string[],
78
+ networkUrl?: string,
79
+ ) {
80
+ console.log();
81
+ console.log(
82
+ ` ${c.bold}deserved${c.reset} ${c.dim}serving${c.reset} ${root}`,
83
+ );
84
+ console.log(` ${c.green}->${c.reset} ${c.cyan}${url}${c.reset}`);
85
+ if (networkUrl) {
86
+ console.log(` ${c.green}->${c.reset} ${c.cyan}${networkUrl}${c.reset}`);
87
+ }
88
+ if (flags.length) {
89
+ console.log(` ${c.dim}${flags.join(" ")}${c.reset}`);
90
+ }
91
+ console.log();
92
+ }
93
+
94
+ export function logReload(quiet: boolean, kind: "css" | "reload") {
95
+ if (quiet) return;
96
+ console.log(`${c.yellow}*${c.reset} ${kind}`);
97
+ }
package/src/options.ts ADDED
@@ -0,0 +1,29 @@
1
+ /** The server's settings; the CLI's flags set the same keys. */
2
+ export type Options = {
3
+ root: string;
4
+ port: number;
5
+ host: string;
6
+ spa: boolean;
7
+ watch: boolean;
8
+ open: boolean;
9
+ cors: boolean;
10
+ dir: boolean;
11
+ cache: boolean;
12
+ compress: boolean;
13
+ quiet: boolean;
14
+ };
15
+
16
+ /** The settings `serve()` and the CLI start from. */
17
+ export const DEFAULT_OPTIONS = {
18
+ root: ".",
19
+ port: 3000,
20
+ host: "localhost",
21
+ spa: false,
22
+ watch: false,
23
+ open: false,
24
+ cors: false,
25
+ dir: true,
26
+ cache: false,
27
+ compress: true,
28
+ quiet: false,
29
+ } satisfies Options;
package/src/server.ts ADDED
@@ -0,0 +1,202 @@
1
+ import { statSync, watch } from "node:fs";
2
+ import { networkInterfaces } from "node:os";
3
+ import { relative, resolve } from "node:path";
4
+
5
+ import { createHandler } from "./handlers";
6
+ import { classifyBatch, createSseHub, isIgnoredWatchPath } from "./live";
7
+ import { flushLogs, logBanner, logInfo, logReload } from "./log";
8
+ import { DEFAULT_OPTIONS, type Options } from "./options";
9
+
10
+ /** A running server: where it listens, and `stop()` to close it. */
11
+ export type ServerHandle = {
12
+ port: number;
13
+ hostname: string;
14
+ url: string;
15
+ stop: () => Promise<void>;
16
+ };
17
+
18
+ /** The root to serve doesn't exist or isn't a directory. */
19
+ export class RootError extends Error {
20
+ constructor(message: string, options?: ErrorOptions) {
21
+ super(message, options);
22
+ this.name = "RootError";
23
+ }
24
+ }
25
+
26
+ /** The server couldn't listen on the host and port. */
27
+ export class BindError extends Error {
28
+ constructor(host: string, port: number, options?: ErrorOptions) {
29
+ super(`could not bind to ${host}:${port}`, options);
30
+ this.name = "BindError";
31
+ }
32
+ }
33
+
34
+ const MAX_PORT_FALLBACK_ATTEMPTS = 10;
35
+
36
+ function isAddrInUseError(err: unknown): boolean {
37
+ if (
38
+ err &&
39
+ typeof err === "object" &&
40
+ "code" in err &&
41
+ err.code === "EADDRINUSE"
42
+ )
43
+ return true;
44
+ const message = err instanceof Error ? err.message : String(err);
45
+ return /EADDRINUSE|address already in use/i.test(message);
46
+ }
47
+
48
+ export function formatUrl(host: string, port: number): string {
49
+ const bracketed = host.includes(":") ? `[${host}]` : host;
50
+ return `http://${bracketed}:${port}`;
51
+ }
52
+
53
+ function lanAddress(): string | null {
54
+ const nets = networkInterfaces();
55
+ for (const iface of Object.values(nets)) {
56
+ for (const net of iface ?? []) {
57
+ if (net.family === "IPv4" && !net.internal) return net.address;
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+
63
+ function openCommand(url: string): string[] {
64
+ if (process.platform === "darwin") return ["open", url];
65
+ if (process.platform === "win32") return ["cmd", "/c", "start", "", url];
66
+ return ["xdg-open", url];
67
+ }
68
+
69
+ // Fire and forget: some xdg-open setups block until the browser exits,
70
+ // which would otherwise hold up startServer() for the whole session.
71
+ function openBrowser(url: string): void {
72
+ try {
73
+ Bun.spawn(openCommand(url), { stdout: "ignore", stderr: "ignore" }).unref();
74
+ } catch {
75
+ console.error(`Could not open browser for ${url}`);
76
+ }
77
+ }
78
+
79
+ function validateRoot(rootPath: string): void {
80
+ try {
81
+ const st = statSync(rootPath);
82
+ if (!st.isDirectory()) {
83
+ throw new RootError(`not a directory: ${rootPath}`);
84
+ }
85
+ } catch (err) {
86
+ if (err instanceof RootError) throw err;
87
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
88
+ throw new RootError(`directory not found: ${rootPath}`);
89
+ }
90
+ throw new RootError(`not a directory: ${rootPath}`);
91
+ }
92
+ }
93
+
94
+ type StartOptions = {
95
+ // The default port hops to the next free one when taken; an explicit
96
+ // one (the CLI's --port, or any port passed to serve()) never does.
97
+ portExplicit?: boolean;
98
+ // The CLI always prints the banner (-q only silences request logs);
99
+ // serve() skips it when quiet so embedding stays silent.
100
+ banner?: boolean;
101
+ };
102
+
103
+ export async function startServer(
104
+ opts: Options,
105
+ { portExplicit = false, banner = true }: StartOptions = {},
106
+ ): Promise<ServerHandle> {
107
+ const root = resolve(opts.root);
108
+ validateRoot(root);
109
+
110
+ const hub = opts.watch ? createSseHub() : undefined;
111
+ const fetch = createHandler({ ...opts, root }, hub);
112
+
113
+ // Bun.serve misses bind conflicts when hostname is the string "localhost".
114
+ // A literal loopback IP throws. Bind to 127.0.0.1 so a second instance
115
+ // fails cleanly.
116
+ const bindHost = opts.host === "localhost" ? "127.0.0.1" : opts.host;
117
+
118
+ // Port 0 already means "any free port", so there's nothing to hop from.
119
+ const maxHops =
120
+ !portExplicit && opts.port !== 0 ? MAX_PORT_FALLBACK_ATTEMPTS : 0;
121
+
122
+ let server: ReturnType<typeof Bun.serve> | undefined;
123
+ for (let hop = 0; !server; hop++) {
124
+ const port = opts.port + hop;
125
+ try {
126
+ server = Bun.serve({ port, hostname: bindHost, fetch });
127
+ } catch (err) {
128
+ if (hop >= maxHops || !isAddrInUseError(err)) {
129
+ throw new BindError(opts.host, port, { cause: err });
130
+ }
131
+ continue;
132
+ }
133
+ if (hop > 0) logInfo(`port ${opts.port} in use, using ${port}`, opts.quiet);
134
+ }
135
+
136
+ const isWildcardHost = opts.host === "0.0.0.0" || opts.host === "::";
137
+ const displayHost = isWildcardHost ? "localhost" : opts.host;
138
+ const url = formatUrl(displayHost, server.port ?? opts.port);
139
+ const lanIp = isWildcardHost ? lanAddress() : null;
140
+ const networkUrl = lanIp ? `http://${lanIp}:${server.port}` : undefined;
141
+
142
+ const flags: string[] = [];
143
+ if (opts.spa) flags.push("--spa");
144
+ if (opts.watch) flags.push("--watch");
145
+ if (opts.cors) flags.push("--cors");
146
+ if (!opts.dir) flags.push("--no-dir");
147
+ if (!opts.compress) flags.push("--no-compress");
148
+ if (opts.cache) flags.push("--cache");
149
+
150
+ if (banner) {
151
+ logBanner(url, relative(process.cwd(), root) || ".", flags, networkUrl);
152
+ }
153
+
154
+ let watcher: ReturnType<typeof watch> | undefined;
155
+ if (opts.watch && hub) {
156
+ let timer: Timer | null = null;
157
+ const batch = new Set<string | null>();
158
+ watcher = watch(root, { recursive: true }, (_event, filename) => {
159
+ if (filename && isIgnoredWatchPath(filename)) return;
160
+ // Clear before debouncing the reload broadcast, so a request racing
161
+ // the debounce window still sees the post-change state.
162
+ fetch.invalidateResolutionCache();
163
+ fetch.invalidateCompressedCache();
164
+ batch.add(filename);
165
+ if (timer) clearTimeout(timer);
166
+ timer = setTimeout(() => {
167
+ const kind = classifyBatch([...batch]);
168
+ batch.clear();
169
+ logReload(opts.quiet, kind);
170
+ hub.broadcast(kind);
171
+ }, 80);
172
+ });
173
+
174
+ logInfo("watching for changes", opts.quiet);
175
+ }
176
+
177
+ const stop = async () => {
178
+ watcher?.close();
179
+ hub?.close();
180
+ await server.stop();
181
+ flushLogs();
182
+ logInfo("server stopped", opts.quiet);
183
+ };
184
+
185
+ if (opts.open) openBrowser(url);
186
+
187
+ return { port: server.port ?? opts.port, hostname: displayHost, url, stop };
188
+ }
189
+
190
+ /**
191
+ * Starts a server for `options.root`, over the defaults; a bind failure
192
+ * rejects instead of exiting.
193
+ */
194
+ export async function serve(
195
+ options: Partial<Options> = {},
196
+ ): Promise<ServerHandle> {
197
+ const opts = { ...DEFAULT_OPTIONS, ...options };
198
+ return startServer(opts, {
199
+ portExplicit: options.port !== undefined,
200
+ banner: !opts.quiet,
201
+ });
202
+ }
package/chunk-6mm4k23z.js DELETED
@@ -1,38 +0,0 @@
1
- // @bun
2
- var t={root:".",port:3000,host:"localhost",spa:!1,watch:!1,open:!1,cors:!1,dir:!0,cache:!1,compress:!0,quiet:!1};import{readdirSync as Ae,realpathSync as ie,statSync as U}from"fs";import{extname as Oe,isAbsolute as Me,join as ce,resolve as ae,sep as le}from"path";var{escapeHTML:M}=globalThis.Bun;var P="/__live.js",F="/__events",j=`(()=>{let down=false;const e=new EventSource("/__events");e.onopen=()=>{if(down)location.reload()};e.onmessage=(m)=>{if(m.data==="css"){for(const l of document.querySelectorAll('link[rel="stylesheet"]')){const h=l.href.split("?")[0];l.href=h+"?t="+Date.now()}}else{location.reload()}};e.onerror=()=>{if(down&&e.readyState===2)location.reload();down=true}})()`;function z(i){let c=i.toLowerCase().lastIndexOf("</body>");if(c===-1)return i+'<script src="/__live.js"></script>';return i.slice(0,c)+'<script src="/__live.js"></script>'+i.slice(c)}var L={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};function q(){let i=new Set,c=new TextEncoder,a=c.encode(`: ping
3
-
4
- `),l=setInterval(()=>{for(let m of i)try{m.enqueue(a)}catch{i.delete(m)}},8000);l.unref();function p(){let m,h=new ReadableStream({start(y){m=y,i.add(y),y.enqueue(c.encode(`retry: 500
5
- : connected
6
-
7
- `))},cancel(){i.delete(m)}});return new Response(h,{headers:L})}function u(m="reload"){let h=c.encode(`data: ${m}
8
-
9
- `);for(let y of i)try{y.enqueue(h)}catch{i.delete(y)}}function d(){clearInterval(l);for(let m of i)try{m.close()}catch{}i.clear()}return{subscribe:p,broadcast:u,close:d}}function G(i){return i.split(/[/\\]/).some((c)=>c.startsWith(".")||c==="node_modules")}function V(i){if(i.length===0)return"reload";return i.every((c)=>c?.endsWith(".css"))?"css":"reload"}function ye(i,c){return i===!0&&!c.NO_COLOR}var be=ye(process.stdout.isTTY,process.env),O=(i)=>be?`\x1B[${i}m`:"",w={reset:O(0),dim:O(2),green:O(32),yellow:O(33),red:O(31),cyan:O(36),bold:O(1)},xe=/[\x00-\x1f\x7f]/g,we=/[\x00-\x1f\x7f]/;function Ce(i){return we.test(i)?i.replace(xe,""):i}var Re=`${w.green}\u2713${w.reset}`,ve=`${w.yellow}\u25CB${w.reset}`,$e=`${w.red}\u2717${w.reset}`,{dim:Ee,reset:Te}=w,D=[];function Se(){if(D.length===1)queueMicrotask(_)}function _(){if(D.length===0)return;let i=D.join(`
10
- `);D=[],process.stdout.write(`${i}
11
- `)}function B(i,c,a,l){if(l)return;let p=c<300?Re:c<400?ve:$e;D.push(`${p} ${Ee}${i}${Te} ${c} ${Ce(a)}`),Se()}function I(i,c=!1){if(c)return;console.log(`${w.cyan}\u2502${w.reset} ${i}`)}function K(i,c,a,l){if(console.log(),console.log(` ${w.bold}deserved${w.reset} ${w.dim}serving${w.reset} ${c}`),console.log(` ${w.green}->${w.reset} ${w.cyan}${i}${w.reset}`),l)console.log(` ${w.green}->${w.reset} ${w.cyan}${l}${w.reset}`);if(a.length)console.log(` ${w.dim}${a.join(" ")}${w.reset}`);console.log()}function J(i,c){if(i)return;console.log(`${w.yellow}*${w.reset} ${c}`)}var De=new TextEncoder,Y="application/octet-stream",He={".html":"text/html;charset=utf-8",".htm":"text/html;charset=utf-8",".css":"text/css;charset=utf-8",".js":"text/javascript;charset=utf-8",".mjs":"text/javascript;charset=utf-8",".json":"application/json;charset=utf-8",".svg":"image/svg+xml",".txt":"text/plain;charset=utf-8",".xml":"application/xml",".wasm":"application/wasm",".woff":"font/woff",".woff2":"font/woff2",".map":"application/json"};function ze(i,c){let a=i.type;if(a&&a!==Y&&a!=="")return a;let l=Oe(c).toLowerCase();return He[l]??Y}function Ie(i){let c=i.indexOf(";"),a=(c===-1?i:i.slice(0,c)).trim().toLowerCase();return a.startsWith("text/")||a==="application/javascript"||a==="text/javascript"||a==="application/json"||a==="application/xml"||a==="image/svg+xml"||a.endsWith("+json")||a.endsWith("+xml")}function Ne(i){return i.startsWith("text/html")}function Pe(i,c,a=""){return`"${i}-${Math.trunc(c)}${a}"`}function ue(i){return`W/${i}`}function X(i){return i.startsWith("W/")?i.slice(2):i}function Fe(i,c){if(i.indexOf(",")===-1)return X(i.trim())===c;return i.split(",").some((a)=>X(a.trim())===c)}function Le(i,c){let a=i.headers.get("If-Modified-Since");if(!a)return!1;let l=Date.parse(a);if(Number.isNaN(l))return!1;return Math.trunc(c/1000)*1000<=l}function _e(i,c,a){let l=i.headers.get("If-None-Match");return l?Fe(l,c):Le(i,a)}function Be(i,c,a){let l=i.headers.get("If-Range");if(!l)return!0;if(l.startsWith('"')||l.startsWith("W/"))return l===c;let p=Date.parse(l);if(Number.isNaN(p))return!1;return p===Math.trunc(a/1000)*1000}function We(i){let c=i.headers.get("Accept");if(!c||c==="*/*")return!0;return c.includes("text/html")||c.includes("application/xhtml")}function ke(i){let c=i.headers.get("Accept-Encoding");if(!c)return null;if(!c.includes("q=0")){if(c.includes("zstd"))return"zstd";if(c.includes("gzip"))return"gzip";return null}let a=new Set;for(let l of c.split(",")){let[p="",...u]=l.split(";"),d=u.map((m)=>m.trim()).find((m)=>m.startsWith("q="));if(d!==void 0&&Number(d.slice(2))===0)continue;a.add(p.trim().toLowerCase())}if(a.has("zstd"))return"zstd";if(a.has("gzip"))return"gzip";return null}function Ue(i){if(i.startsWith("/__"))return!1;let c=i.lastIndexOf("/");if(c===i.length-1)return!0;return i.indexOf(".",c+1)===-1}var N="/.well-known";function je(i){let c=i.startsWith(N)&&(i.length===N.length||i[N.length]==="/")?N.length:0;return i.indexOf("/.",c)!==-1}function qe(i,c,a){if(!c)return null;let l=a.replace(/^\/+/,""),p=Xe(l);for(let u of p){let d=me(i,u);if(!d)continue;let m=ge(c,d);if(!m)continue;let h=de(m,Ye(u));if(h)return h}return null}function de(i,c){try{let a=U(i);if(a.isFile())return{path:i,file:Bun.file(i),size:a.size,mtimeMs:a.mtimeMs,kind:c}}catch{}return null}var Ge=4096;function Ve(i,c){if(i.size<c)return;let a=i.keys().next().value;if(a!==void 0)i.delete(a)}function fe(i,c,a){i.delete(c),i.set(c,a)}var Ke=500;function Je(i,c,a){let l=new Map,p=new Map;function u(f,x,C,v){let g=f.get(x);if(g&&(a||Date.now()-g.at<Ke)){let S=g.value===null?null:v(g.value);if(g.value===null||S!==null)return fe(f,x,g),S}let b=C(x);return Ve(f,Ge),f.set(x,{value:b,at:Date.now()}),b}let d=(f)=>qe(i,c,f),m=(f)=>Ze(i,c,f),h=a?(f)=>f:(f)=>de(f.path,f.kind),y=(f)=>pe(f)?f:null;return{resolveCached:(f)=>u(l,f,d,h),resolveDirCached:(f)=>u(p,f,m,y),invalidate:()=>{l.clear(),p.clear()},size:()=>l.size}}function pe(i){try{return U(i).isDirectory()}catch{return!1}}function Ye(i){if(i.endsWith("/index.html"))return"dir-index";if(i.endsWith(".html"))return"html-ext";return"file"}function Xe(i){if(!i||i===".")return["index.html"];let c=i.endsWith("/"),a=c?i.slice(0,-1):i;if(!a)return["index.html"];if(c)return[`${a}/index.html`];return[a,`${a}.html`,`${a}/index.html`]}function me(i,c){let a=Me(i)?i:ae(i),l=ce(a,c);if(l!==a&&!l.startsWith(a+le))return null;return l}function ge(i,c){try{let a=ie(c);if(a!==i&&!a.startsWith(i+le))return null;return a}catch{return null}}function Qe(i){try{return ie(i)}catch{return null}}function Ze(i,c,a){if(!c)return null;let l=a.replace(/^\/+/,"").replace(/\/+$/,""),p=me(i,l||".");if(!p)return null;let u=ge(c,p);return u&&pe(u)?u:null}function et(i){if(i===null)return"-";if(i<1024)return`${i} B`;if(i<1048576)return`${(i/1024).toFixed(1)} kB`;return`${(i/1048576).toFixed(1)} MB`}function tt(i){if(i===null)return"-";let c=new Date(i),a=c.getFullYear(),l=String(c.getMonth()+1).padStart(2,"0"),p=String(c.getDate()).padStart(2,"0"),u=String(c.getHours()).padStart(2,"0"),d=String(c.getMinutes()).padStart(2,"0");return`${a}-${l}-${p} ${u}:${d}`}function nt(i){let c=Ae(i,{withFileTypes:!0}),a=[];for(let l of c){if(l.name.startsWith("."))continue;let p=l.isDirectory(),u=null,d=null;if(!p)try{let m=U(ce(i,l.name));u=m.size,d=m.mtimeMs}catch{}a.push({name:l.name,dir:p,size:u,mtimeMs:d})}return a.sort((l,p)=>{if(l.dir!==p.dir)return l.dir?-1:1;return l.name.localeCompare(p.name)})}function rt(i,c){let a=i.endsWith("/")?i:`${i}/`,l=Q(a),p=st(i),u=M(i),d=c.map((h)=>{let y=ot(l,encodeURIComponent(h.name))+(h.dir?"/":""),f=h.dir?`${h.name}/`:h.name,x=et(h.size),C=tt(h.mtimeMs);return` <li><a href="${M(y)}">${M(f)}</a> <span class="meta">${M(x)}</span> <span class="meta">${M(C)}</span></li>`}).join(`
12
- `),m=p!==null?` <li><a href="${M(Q(p))}">../</a> <span class="meta">-</span> <span class="meta">-</span></li>
13
- `:"";return`<!DOCTYPE html>
14
- <html lang="en">
15
- <head>
16
- <meta charset="utf-8">
17
- <meta name="viewport" content="width=device-width, initial-scale=1">
18
- <title>Index of ${u}</title>
19
- <style>
20
- :root { color-scheme: light dark; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
21
- body { max-width: 60rem; margin: 2rem auto; padding: 0 1rem; line-height: 1.5; }
22
- h1 { font-size: 1.1rem; font-weight: 600; }
23
- ul { list-style: none; padding: 0; }
24
- li { padding: 0.2rem 0; display: flex; gap: 2rem; }
25
- li a { color: inherit; text-decoration: none; flex: 1; }
26
- li a:hover { text-decoration: underline; }
27
- .meta { text-align: right; min-width: 5rem; opacity: 0.6; }
28
- </style>
29
- </head>
30
- <body>
31
- <h1>Index of ${u||"/"}</h1>
32
- <ul>
33
- ${m}${d}
34
- </ul>
35
- </body>
36
- </html>
37
- `}function st(i){if(i==="/"||i==="")return null;let c=i.replace(/\/+$/,""),a=c.lastIndexOf("/");if(a<=0)return"/";return c.slice(0,a+1)}function Q(i){return i.split("/").map(encodeURIComponent).join("/")}function ot(i,c){if(i==="/")return`/${c}`;return`${i.replace(/\/+$/,"")}/${c}`}function it(i){let c=i.indexOf("//"),a=i.indexOf("/",c===-1?0:c+2);if(a===-1)return"/";let l=i.length,p=i.indexOf("?",a);if(p!==-1&&p<l)l=p;let u=i.indexOf("#",a);if(u!==-1&&u<l)l=u;let d=i.slice(a,l);return d===""?"/":d}function r(i={},c){let a={...t,...i},l=ae(a.root),p=Qe(l),u=Je(l,p,a.watch),d=dt(),m={opts:a,hub:c,resolveCached:u.resolveCached,resolveDirCached:u.resolveDirCached,getCompressed:d.getCompressed,notFound:null},h=async function(f){let x=it(f.url),C=f.method.toUpperCase(),v;if(x.includes("%"))try{v=decodeURIComponent(x)}catch{let g=new Response("Bad Request",{status:400});return W(C,x,a,g)}else v=x;try{return await ct(f,C,v,x,m)}catch(g){console.error(g);let b=new Response("Internal Server Error",{status:500});return W(C,x,a,b)}};return h.invalidateResolutionCache=()=>{u.invalidate(),m.notFound=null},h.invalidateCompressedCache=d.invalidate,h.resolutionCacheSize=u.size,h.compressedCacheBytes=d.bytes,h}function W(i,c,a,l){return B(i,l.status,c,a.quiet),he(i,k(l,a))}function Z(i,c){let a=i.replace(/^\/+/,"/");return new Response(null,{status:301,headers:{Location:`${a}/${new URL(c).search}`}})}function ee(i,c,a=200){return new Response(c.watch?z(i):i,{status:a,headers:{"Content-Type":"text/html;charset=utf-8","Cache-Control":"no-cache"}})}async function ct(i,c,a,l,p){let{opts:u,hub:d,resolveCached:m,resolveDirCached:h,getCompressed:y}=p,f=(g)=>W(c,a,u,g);if(u.cors&&c==="OPTIONS")return f(new Response(null,{status:204}));if(c!=="GET"&&c!=="HEAD"){let g=new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return f(g)}if(u.watch&&a===P){let g=new Response(j,{headers:{"Content-Type":"text/javascript;charset=utf-8","Cache-Control":"no-store"}});return f(g)}if(u.watch&&a===F&&d){if(c==="HEAD")return f(new Response(null,{headers:L}));let g=d.subscribe();return B(c,200,a,u.quiet),k(g,u)}if(a===P||a===F)return he(c,k(new Response("Not Found",{status:404}),u));let x=je(a),C=x?null:m(a);if(C){if(C.kind==="dir-index"&&!a.endsWith("/"))return f(Z(l,i.url));return f(await ne(y,i,C,u))}let v=We(i);if(u.spa&&v&&Ue(a)){let g=m("/");if(g)return f(await ne(y,i,g,u,!0))}if(u.dir&&!x){let g=h(a);if(g){if(!a.endsWith("/"))return f(Z(l,i.url));let b=rt(a,nt(g));return f(ee(b,u))}}if(v){let g=m("/404.html");if(g){let b=p.notFound,S=b&&b.size===g.size&&b.mtimeMs===g.mtimeMs?b.html:await(async()=>{let E=await g.file.text();return p.notFound={size:g.size,mtimeMs:g.mtimeMs,html:E},E})();return f(ee(S,u,404))}}return f(new Response("Not Found",{status:404}))}var at=67108864;async function lt(i){let c=new CompressionStream("gzip"),a=c.writable.getWriter();return a.write(i),a.close(),new Uint8Array(await new Response(c.readable).arrayBuffer())}async function ut(i,c){if(i==="zstd")return new Uint8Array(await Bun.zstdCompress(c));return lt(c)}function dt(){let i=new Map,c=0,a=new Map;function l(d,m){let h=i.get(d);if(h)c-=h.data.size;fe(i,d,m),c+=m.data.size;while(c>at&&i.size>1){let y=i.keys().next().value;if(y===void 0)break;let f=i.get(y);if(i.delete(y),f)c-=f.data.size}}let p=async(d,m,h)=>{let y=`${d.key}:${m}`,f=i.get(y);if(f&&f.size===d.size&&f.mtimeMs===d.mtimeMs)return l(y,f),f.data;let x=a.get(y);if(x&&x.size===d.size&&x.mtimeMs===d.mtimeMs)return x.promise;let C=(async()=>{try{let g=await h(),b=new Blob([await ut(m,g)]);return l(y,{size:d.size,mtimeMs:d.mtimeMs,data:b}),b}catch{return null}})(),v={size:d.size,mtimeMs:d.mtimeMs,promise:C};return a.set(y,v),C.finally(()=>{if(a.get(y)===v)a.delete(y)}),C};function u(){i.clear(),c=0,a.clear()}return{getCompressed:p,invalidate:u,bytes:()=>c}}async function te(i,c,a,l,p){let u=await i(l,c,p);if(!u)return null;return a["Content-Encoding"]=c,a["Content-Length"]=String(u.size),a.ETag=ue(a.ETag??""),delete a["Accept-Ranges"],a.Vary="Accept-Encoding",new Response(u,{status:200,headers:a})}async function ne(i,c,a,l,p=!1){let{path:u,file:d,size:m,mtimeMs:h}=a,y=ze(d,u),f=p||Ne(y),x=Pe(m,h,l.watch&&f?"-live":""),C=l.compress&&Ie(y),v=l.watch&&f,g=C&&(v||m<2000000)?ke(c):null;if(_e(c,x,h)){let R=oe(x,l,f,h);if(C)R.Vary="Accept-Encoding";if(g)R.ETag=ue(x);return new Response(null,{status:304,headers:R})}let b=oe(x,l,f,h);if(b["Content-Type"]=y,b["Accept-Ranges"]="bytes",C)b.Vary="Accept-Encoding";let S=c.headers.get("Range"),E=S&&Be(c,x,h)?S:null;if(E&&c.method==="GET"){let R=pt(E,m);if(R==="invalid")return b["Content-Range"]=`bytes */${m}`,new Response(null,{status:416,headers:b});if(R){let{start:T,end:A}=R,H=A-T+1;return b["Content-Range"]=`bytes ${T}-${A}/${m}`,b["Content-Length"]=String(H),new Response(d.slice(T,A+1),{status:206,headers:b})}}if(v){if(g){let T=await te(i,g,b,{key:`${u}\x00live`,size:m,mtimeMs:h},async()=>De.encode(z(await d.text())));if(T)return T}let R=z(await d.text());return b["Content-Length"]=String(Buffer.byteLength(R)),new Response(R,{status:200,headers:b})}if(g){let R=await te(i,g,b,{key:u,size:m,mtimeMs:h},()=>d.bytes());if(R)return R}return b["Content-Length"]=String(m),new Response(d,{status:200,headers:b})}var re=Number.NaN,se="";function ft(i){if(i!==re)re=i,se=new Date(i).toUTCString();return se}function oe(i,c,a,l){return{ETag:i,"Last-Modified":ft(l),"Cache-Control":c.watch||!c.cache||a?"no-cache":"public, max-age=31536000, immutable"}}function pt(i,c){let a=/^bytes=(\d*)-(\d*)$/.exec(i.trim());if(!a)return null;let l=a[1],p=a[2],u,d;if(l===""&&p==="")return"invalid";if(l===""){let m=Number(p);if(!Number.isFinite(m)||m<=0)return"invalid";u=Math.max(0,c-m),d=c-1}else u=Number(l),d=p===""?c-1:Number(p);if(!Number.isFinite(u)||!Number.isFinite(d)||u<0||d<u||u>=c)return"invalid";return d=Math.min(d,c-1),{start:u,end:d}}function k(i,c){if(!c.cors)return i;return i.headers.set("Access-Control-Allow-Origin","*"),i.headers.set("Access-Control-Allow-Headers","*"),i.headers.set("Access-Control-Allow-Methods","GET, HEAD, OPTIONS"),i}function he(i,c){if(i!=="HEAD")return c;return new Response(null,{status:c.status,statusText:c.statusText,headers:c.headers})}import{statSync as mt,watch as gt}from"fs";import{networkInterfaces as ht}from"os";import{relative as yt,resolve as bt}from"path";class e extends Error{constructor(i,c){super(i,c);this.name="RootError"}}class n extends Error{constructor(i,c,a){super(`could not bind to ${i}:${c}`,a);this.name="BindError"}}var xt=10;function wt(i){if(i&&typeof i==="object"&&"code"in i&&i.code==="EADDRINUSE")return!0;let c=i instanceof Error?i.message:String(i);return/EADDRINUSE|address already in use/i.test(c)}function Ct(i,c){return`http://${i.includes(":")?`[${i}]`:i}:${c}`}function Rt(){let i=ht();for(let c of Object.values(i))for(let a of c??[])if(a.family==="IPv4"&&!a.internal)return a.address;return null}function vt(i){if(process.platform==="darwin")return["open",i];if(process.platform==="win32")return["cmd","/c","start","",i];return["xdg-open",i]}function $t(i){try{Bun.spawn(vt(i),{stdout:"ignore",stderr:"ignore"}).unref()}catch{console.error(`Could not open browser for ${i}`)}}function Et(i){try{if(!mt(i).isDirectory())throw new e(`not a directory: ${i}`)}catch(c){if(c instanceof e)throw c;if(c instanceof Error&&"code"in c&&c.code==="ENOENT")throw new e(`directory not found: ${i}`);throw new e(`not a directory: ${i}`)}}async function s(i,{portExplicit:c=!1,banner:a=!0}={}){let l=bt(i.root);Et(l);let p=i.watch?q():void 0,u=r({...i,root:l},p),d=i.host==="localhost"?"127.0.0.1":i.host,m=!c&&i.port!==0?xt:0,h;for(let E=0;!h;E++){let R=i.port+E;try{h=Bun.serve({port:R,hostname:d,fetch:u})}catch(T){if(E>=m||!wt(T))throw new n(i.host,R,{cause:T});continue}if(E>0)I(`port ${i.port} in use, using ${R}`,i.quiet)}let y=i.host==="0.0.0.0"||i.host==="::",f=y?"localhost":i.host,x=Ct(f,h.port??i.port),C=y?Rt():null,v=C?`http://${C}:${h.port}`:void 0,g=[];if(i.spa)g.push("--spa");if(i.watch)g.push("--watch");if(i.cors)g.push("--cors");if(!i.dir)g.push("--no-dir");if(!i.compress)g.push("--no-compress");if(i.cache)g.push("--cache");if(a)K(x,yt(process.cwd(),l)||".",g,v);let b;if(i.watch&&p){let E=null,R=new Set;b=gt(l,{recursive:!0},(T,A)=>{if(A&&G(A))return;if(u.invalidateResolutionCache(),u.invalidateCompressedCache(),R.add(A),E)clearTimeout(E);E=setTimeout(()=>{let H=V([...R]);R.clear(),J(i.quiet,H),p.broadcast(H)},80)}),I("watching for changes",i.quiet)}let S=async()=>{b?.close(),p?.close(),await h.stop(),_(),I("server stopped",i.quiet)};if(i.open)$t(x);return{port:h.port??i.port,hostname:f,url:x,stop:S}}async function o(i={}){let c={...t,...i};return s(c,{portExplicit:i.port!==void 0,banner:!c.quiet})}
38
- export{t,r,e,n,s,o};
package/cli.js DELETED
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env bun
2
- // @bun
3
- import{t,e,n,s}from"./chunk-6mm4k23z.js";import{resolve as w}from"path";var v="0.6.0";function y(){console.log(`
4
- deserved - tiny Bun static file server
5
-
6
- Usage
7
- deserved [path] [options]
8
-
9
- Options
10
- -p, --port <n> Port (default: 3000, or $PORT; hops to the next
11
- free port unless set explicitly)
12
- -H, --host <host> Hostname (default: localhost)
13
- -s, --spa SPA fallback to index.html
14
- -w, --watch Live reload on file changes
15
- -o, --open Open browser
16
- --cors Enable CORS
17
- --dir Enable directory listing (default)
18
- --no-dir Disable directory listing
19
- --cache Long-lived, immutable cache headers for assets
20
- --no-cache Disable cache headers (default)
21
- --compress zstd or gzip, negotiated per request (default)
22
- --no-compress Disable compression
23
- -q, --quiet Suppress request logs
24
- -h, --help Show help
25
- -v, --version Show version
26
-
27
- Examples
28
- deserved .
29
- deserved dist --spa
30
- deserved dist --port 8080
31
- deserved docs --watch --open
32
- PORT=8080 deserved dist
33
- `)}var E=new Map([["-s",["spa",!0]],["--spa",["spa",!0]],["-w",["watch",!0]],["--watch",["watch",!0]],["-o",["open",!0]],["--open",["open",!0]],["--cors",["cors",!0]],["--dir",["dir",!0]],["--no-dir",["dir",!1]],["--cache",["cache",!0]],["--no-cache",["cache",!1]],["--compress",["compress",!0]],["--no-compress",["compress",!1]],["-q",["quiet",!0]],["--quiet",["quiet",!0]]]),S=new Map([["-p","port"],["--port","port"],["-H","host"],["--host","host"]]);function R(c,p=Bun.env){let i=c.slice(2),o={...t},h,f=!1;for(let d=0;d<i.length;d++){let r=i[d];if(r===void 0)break;if(r==="-h"||r==="--help")y(),process.exit(0);if(r==="-v"||r==="--version")console.log(v),process.exit(0);let m=E.get(r);if(m){o[m[0]]=m[1];continue}let a=r.startsWith("--")?r.indexOf("="):-1,b=a===-1?r:r.slice(0,a),g=S.get(b);if(g){let l=a===-1?i[++d]:r.slice(a+1);if(!l||a===-1&&l.startsWith("-"))u(`Missing value for ${b}`);if(g==="port")o.port=x(l,a===-1?l:r),f=!0;else o.host=l;continue}if(r.startsWith("-"))u(`Unknown option: ${r}`);if(h!==void 0)u(`Unexpected argument: ${r}`);h=r}if(!f&&p.PORT!==void 0)o.port=x(p.PORT,p.PORT);return o.root=w(h??o.root),{...o,portExplicit:f}}function x(c,p){let i=Number(c);if(c.trim()===""||!Number.isInteger(i)||i<0||i>65535)u(`Invalid port: ${p}`);return i}function u(c){console.error(`Error: ${c}`),console.error("Run deserved --help."),process.exit(1)}if(import.meta.main){let c=R(process.argv),p;try{p=await s(c,{portExplicit:c.portExplicit})}catch(o){if(o instanceof e)console.error(`Error: ${o.message}`),console.error("Run deserved --help."),process.exit(1);if(o instanceof n)console.error(`Error: ${o.message}`),console.error(o.cause instanceof Error?o.cause.message:String(o.cause)),process.exit(1);throw o}let i=async()=>{await p.stop(),process.exit(0)};process.on("SIGINT",i),process.on("SIGTERM",i)}export{R as parseArgs};
package/handlers.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { type Hub } from "./live";
2
- import { type Options } from "./options";
3
- export type ResolvedFile = {
4
- path: string;
5
- file: Bun.BunFile;
6
- size: number;
7
- mtimeMs: number;
8
- kind: "file" | "html-ext" | "dir-index";
9
- };
10
- export type Handler = {
11
- (req: Request): Promise<Response>;
12
- invalidateResolutionCache(): void;
13
- invalidateCompressedCache(): void;
14
- resolutionCacheSize(): number;
15
- compressedCacheBytes(): number;
16
- };
17
- export declare function contentType(file: Bun.BunFile, path: string): string;
18
- export declare function isCompressible(type: string): boolean;
19
- export declare function isHtml(type: string): boolean;
20
- export declare function makeEtag(size: number, mtimeMs: number, tag?: string): string;
21
- export declare function notModifiedSince(req: Request, mtimeMs: number): boolean;
22
- export declare function isNotModified(req: Request, etag: string, mtimeMs: number): boolean;
23
- export declare function ifRangeSatisfied(req: Request, etag: string, mtimeMs: number): boolean;
24
- export declare function acceptsHtml(req: Request): boolean;
25
- export type CompressionEncoding = "zstd" | "gzip";
26
- export declare function pickEncoding(req: Request): CompressionEncoding | null;
27
- export declare function shouldSpaFallback(pathname: string): boolean;
28
- export declare function isHiddenPath(pathname: string): boolean;
29
- export declare function resolveFileWithRoot(rootAbs: string, realRoot: string | null, pathname: string): ResolvedFile | null;
30
- export declare const RESOLUTION_CACHE_LIMIT = 4096;
31
- export declare const RESOLUTION_TTL_MS = 500;
32
- export declare function buildCandidates(relative: string): string[];
33
- export declare function safeJoin(root: string, relative: string): string | null;
34
- export declare function resolveDirWithRoot(rootAbs: string, realRoot: string | null, pathname: string): string | null;
35
- type DirEntry = {
36
- name: string;
37
- dir: boolean;
38
- size: number | null;
39
- mtimeMs: number | null;
40
- };
41
- export declare function listDir(dir: string): DirEntry[];
42
- export declare function directoryListing(pathname: string, entries: DirEntry[]): string;
43
- export declare function createHandler(options?: Partial<Options>, hub?: Hub): Handler;
44
- export declare const COMPRESSED_CACHE_BYTE_BUDGET: number;
45
- export declare function compress(encoding: CompressionEncoding, raw: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
46
- export declare function baseHeaders(etag: string, opts: Options, isHtmlFile: boolean, mtimeMs: number): Record<string, string>;
47
- export declare function parseRange(header: string, size: number): {
48
- start: number;
49
- end: number;
50
- } | null | "invalid";
51
- export declare function withCors(res: Response, opts: Options): Response;
52
- export {};
package/index.js DELETED
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{t,r,e,n,o}from"./chunk-6mm4k23z.js";export{n as BindError,t as DEFAULT_OPTIONS,e as RootError,r as createHandler,o as serve};
package/live.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export declare const LIVE_PATH = "/__live.js";
2
- export declare const EVENTS_PATH = "/__events";
3
- export declare const LIVE_SCRIPT = "(()=>{let down=false;const e=new EventSource(\"/__events\");e.onopen=()=>{if(down)location.reload()};e.onmessage=(m)=>{if(m.data===\"css\"){for(const l of document.querySelectorAll('link[rel=\"stylesheet\"]')){const h=l.href.split(\"?\")[0];l.href=h+\"?t=\"+Date.now()}}else{location.reload()}};e.onerror=()=>{if(down&&e.readyState===2)location.reload();down=true}})()";
4
- export declare function injectLiveReload(html: string): string;
5
- export declare const SSE_HEADERS: {
6
- "Content-Type": string;
7
- "Cache-Control": string;
8
- Connection: string;
9
- };
10
- export declare function createSseHub(): {
11
- subscribe: () => Response;
12
- broadcast: (data?: string) => void;
13
- close: () => void;
14
- };
15
- export type Hub = ReturnType<typeof createSseHub>;
16
- export declare function isIgnoredWatchPath(filename: string): boolean;
17
- export declare function classifyBatch(files: (string | null)[]): "css" | "reload";
package/log.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare function shouldColor(isTTY: boolean | undefined, env: Record<string, string | undefined>): boolean;
2
- export declare function flushLogs(): void;
3
- export declare function logRequest(method: string, status: number, path: string, quiet: boolean): void;
4
- export declare function logInfo(msg: string, quiet?: boolean): void;
5
- export declare function logBanner(url: string, root: string, flags: string[], networkUrl?: string): void;
6
- export declare function logReload(quiet: boolean, kind: "css" | "reload"): void;
package/options.d.ts DELETED
@@ -1,26 +0,0 @@
1
- export type Options = {
2
- root: string;
3
- port: number;
4
- host: string;
5
- spa: boolean;
6
- watch: boolean;
7
- open: boolean;
8
- cors: boolean;
9
- dir: boolean;
10
- cache: boolean;
11
- compress: boolean;
12
- quiet: boolean;
13
- };
14
- export declare const DEFAULT_OPTIONS: {
15
- root: string;
16
- port: number;
17
- host: string;
18
- spa: false;
19
- watch: false;
20
- open: false;
21
- cors: false;
22
- dir: true;
23
- cache: false;
24
- compress: true;
25
- quiet: false;
26
- };