Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 57856c2

Browse files
committed
Clean up
1 parent 03f431f commit 57856c2

23 files changed

+132
-133
lines changed

cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
22
import { readLines } from "https://deno.land/[email protected]/io/mod.ts";
33
import { writeAll } from "https://deno.land/[email protected]/streams/conversion.ts";
44
import { basename, resolve } from "https://deno.land/[email protected]/path/mod.ts";
5-
import { readImportMap } from "./server/config.ts";
5+
import { readImportMap } from "./server/helpers.ts";
66
import { findFile } from "./lib/fs.ts";
77
import log, { bold, dim, stripColor } from "./lib/log.ts";
88
import { serveDir } from "./lib/serve.ts";

commands/build.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
22
import { findFile } from "../lib/fs.ts";
3-
import { builtinModuleExts } from "../lib/helpers.ts";
43
import log, { blue, bold } from "../lib/log.ts";
5-
import { initModuleLoaders, loadImportMap } from "../server/config.ts";
64
import { build } from "../server/build.ts";
5+
import { builtinModuleExts, initModuleLoaders, loadImportMap } from "../server/helpers.ts";
76
import { serve } from "../server/mod.ts";
87
import { proxyModules } from "../server/proxy_modules.ts";
98

commands/dev.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { basename, relative } from "https://deno.land/[email protected]/path/mod.ts";
22
import mitt, { Emitter } from "https://esm.sh/[email protected]";
33
import { findFile, watchFs } from "../lib/fs.ts";
4-
import { builtinModuleExts } from "../lib/helpers.ts";
54
import log, { blue } from "../lib/log.ts";
65
import util from "../lib/util.ts";
76
import { serve as httpServe } from "../lib/serve.ts";
8-
import { initModuleLoaders, loadImportMap } from "../server/config.ts";
7+
import { builtinModuleExts, initModuleLoaders, loadImportMap } from "../server/helpers.ts";
98
import { serve } from "../server/mod.ts";
109
import { initRoutes, toRouteRegExp } from "../server/routing.ts";
1110
import type { DependencyGraph } from "../server/graph.ts";

commands/start.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { basename, join } from "https://deno.land/[email protected]/path/mod.ts";
22
import { serve as stdServe, serveTls } from "https://deno.land/[email protected]/http/server.ts";
33
import { findFile } from "../lib/fs.ts";
4-
import { builtinModuleExts } from "../lib/helpers.ts";
54
import log, { blue } from "../lib/log.ts";
6-
import { initModuleLoaders, loadImportMap } from "../server/config.ts";
75
import { build } from "../server/build.ts";
6+
import { builtinModuleExts, initModuleLoaders, loadImportMap } from "../server/helpers.ts";
87
import { serve } from "../server/mod.ts";
98
import { proxyModules } from "../server/proxy_modules.ts";
109
import type { AlephConfig } from "../server/types.ts";

framework/react/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
2-
import { FetchError } from "../../lib/helpers.ts";
2+
import FetchError from "../../lib/fetch_error.ts";
33
import { DataContext } from "./context.ts";
44

55
export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";

framework/react/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { FC, ReactElement, ReactNode } from "react";
22
import { createElement, useContext, useEffect, useMemo, useState } from "react";
3-
import { FetchError } from "../../lib/helpers.ts";
3+
import FetchError from "../../lib/fetch_error.ts";
44
import type { Route, RouteMeta, RouteModule, Routes } from "../../lib/route.ts";
55
import { matchRoutes } from "../../lib/route.ts";
6-
import { URLPatternCompat } from "../../lib/urlpattern.ts";
6+
import { URLPatternCompat } from "../../lib/url_pattern.ts";
77
import events from "../core/events.ts";
88
import { redirect } from "../core/redirect.ts";
99
import { DataContext, ForwardPropsContext, RouterContext } from "./context.ts";

lib/fetch_error.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default class FetchError extends Error {
2+
constructor(
3+
public status: number,
4+
public details: Record<string, unknown>,
5+
message: string,
6+
opts?: ErrorOptions,
7+
) {
8+
super(message, opts);
9+
}
10+
11+
static async fromResponse(res: Response): Promise<FetchError> {
12+
let message = res.statusText;
13+
let details: Record<string, unknown> = {};
14+
if (res.headers.get("content-type")?.startsWith("application/json")) {
15+
details = await res.json();
16+
if (typeof details.message === "string") {
17+
message = details.message;
18+
}
19+
} else {
20+
message = await res.text();
21+
}
22+
return new FetchError(res.status, details, message);
23+
}
24+
}

lib/helpers.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

lib/log.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,23 @@ export enum Level {
1111
}
1212

1313
export class Timing {
14-
#t: number;
15-
16-
constructor(quit?: boolean) {
17-
this.#t = !quit ? performance.now() : 0;
18-
}
14+
#t = performance.now();
1915

2016
reset() {
21-
if (this.#t > 0) {
22-
this.#t = performance.now();
23-
}
17+
this.#t = performance.now();
2418
}
2519

2620
stop(message: string) {
27-
if (this.#t > 0) {
28-
const now = performance.now();
29-
const d = Math.round(now - this.#t);
30-
let cf = green;
31-
if (d > 10000) {
32-
cf = red;
33-
} else if (d > 1000) {
34-
cf = yellow;
35-
}
36-
this.#t = now;
37-
console.debug(dim("TIMING"), message, "in", cf(d + "ms"));
21+
const now = performance.now();
22+
const d = Math.round(now - this.#t);
23+
let cf = green;
24+
if (d > 10000) {
25+
cf = red;
26+
} else if (d > 1000) {
27+
cf = yellow;
3828
}
29+
console.debug(dim("TIMING"), message, "in", cf(d + "ms"));
30+
this.#t = now;
3931
}
4032
}
4133

@@ -97,10 +89,13 @@ export class Logger {
9789
}
9890
}
9991

100-
timing(): Timing {
101-
return new Timing(this.level > Level.Debug);
92+
timing(): { reset(): void; stop(message: string): void } {
93+
if (this.level === Level.Debug) {
94+
return new Timing();
95+
}
96+
return { reset: () => {}, stop: () => {} };
10297
}
10398
}
10499

105-
export default new Logger();
106100
export { blue, bold, dim, green, red, stripColor, yellow };
101+
export default new Logger();

lib/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { URLPatternCompat, URLPatternInput, URLPatternResult } from "./urlpattern.ts";
2-
import { createStaticURLPatternResult } from "./urlpattern.ts";
1+
import type { URLPatternCompat, URLPatternInput, URLPatternResult } from "./url_pattern.ts";
2+
import { createStaticURLPatternResult } from "./url_pattern.ts";
33
import util from "./util.ts";
44

55
export type RouteModule = {

0 commit comments

Comments
 (0)