Skip to content

Commit

Permalink
refactor: update deno types
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 15, 2024
1 parent 98e7af7 commit 9598308
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default defineBuildConfig({
},
},
},
externals: ["@deno/types", "bun"],
externals: ["deno", "bun"],
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"cookie-es": "^1.2.2"
},
"devDependencies": {
"@deno/types": "^0.0.1",
"@hono/node-server": "^1.13.2",
"@mjackson/node-fetch-server": "^0.1.0",
"@types/bun": "^1.1.11",
"@types/deno": "^2.0.0",
"@types/node": "^22.7.5",
"@vitest/coverage-v8": "^2.1.3",
"automd": "^0.3.12",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/deno.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ServerOptions } from "./types";
import type DenoTypes from "@deno/types";
import { Server } from "./server.ts";
import { resolvePort } from "./_common.ts";

Expand All @@ -9,8 +8,6 @@ export function serve(options: ServerOptions): Server {

// https://docs.deno.com/api/deno/~/Deno.serve

declare const Deno: typeof DenoTypes.Deno;

class DenoServer extends Server {
readonly runtime = "deno";

Expand All @@ -19,12 +16,12 @@ class DenoServer extends Server {
protected _listen() {
const onListenPromise = Promise.withResolvers<void>();

let serverFetch = this.fetch as DenoTypes.Deno.ServeHandler;
let serverFetch = this.fetch as Deno.ServeHandler;
if (this.options.xRemoteAddress) {
const userFetch = serverFetch as typeof this.fetch;
serverFetch = (request, info) => {
Object.defineProperty(request, "xRemoteAddress", {
get: () => info?.remoteAddr?.hostname,
get: () => (info?.remoteAddr as Deno.NetAddr)?.hostname,
enumerable: true,
});
return userFetch(request);
Expand Down
1 change: 0 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type * as NodeHttp from "node:http";
import type BunTypes from "bun";
import type { Deno } from "@deno/types";
import type { ServerHandler, ServerOptions } from "./types.ts";
import { applyPlugins } from "./_plugin.ts";

Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type * as NodeHttp from "node:http";
import type * as NodeNet from "node:net";
import type * as Bun from "bun";
import Deno from "@deno/types";

import type { Server } from "./server.ts";

Expand Down Expand Up @@ -95,7 +94,7 @@ export interface ServerOptions {
*
* @docs https://docs.deno.com/api/deno/~/Deno.serve
*/
deno?: Deno.Deno.ServeOptions;
deno?: Deno.ServeOptions;
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 9598308

Please sign in to comment.