From 662f35c35ce7b747707eb44337b96d7f404fa21d Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Sun, 11 Apr 2021 12:53:45 -0700 Subject: [PATCH] fix: testing deno compatibility be removing import from `"http"` --- src/middleware/node/get-missing-headers.ts | 5 ++++- src/middleware/node/get-payload.ts | 19 +++++++++++-------- src/middleware/node/middleware.ts | 6 +++++- .../node/on-unhandled-request-default.ts | 6 +++++- src/middleware/node/types.ts | 6 +++++- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/middleware/node/get-missing-headers.ts b/src/middleware/node/get-missing-headers.ts index 6b25de82..d7d878d7 100644 --- a/src/middleware/node/get-missing-headers.ts +++ b/src/middleware/node/get-missing-headers.ts @@ -1,4 +1,7 @@ -import { IncomingMessage } from "http"; +// remove type imports from http for Deno compatibility +// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886 +// import { IncomingMessage } from "http"; +type IncomingMessage = any; const WEBHOOK_HEADERS = [ "x-github-event", diff --git a/src/middleware/node/get-payload.ts b/src/middleware/node/get-payload.ts index f764d389..de96074a 100644 --- a/src/middleware/node/get-payload.ts +++ b/src/middleware/node/get-payload.ts @@ -1,13 +1,16 @@ import { WebhookEvent } from "@octokit/webhooks-definitions/schema"; // @ts-ignore to address #245 import AggregateError from "aggregate-error"; -import { IncomingMessage } from "http"; -declare module "http" { - interface IncomingMessage { - body?: WebhookEvent; - } -} +// remove type imports from http for Deno compatibility +// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886 +// import { IncomingMessage } from "http"; +// declare module "http" { +// interface IncomingMessage { +// body?: WebhookEvent | unknown; +// } +// } +type IncomingMessage = any; export function getPayload(request: IncomingMessage): Promise { // If request.body already exists we can stop here @@ -21,8 +24,8 @@ export function getPayload(request: IncomingMessage): Promise { request.setEncoding("utf8"); // istanbul ignore next - request.on("error", (error) => reject(new AggregateError([error]))); - request.on("data", (chunk) => (data += chunk)); + request.on("error", (error: Error) => reject(new AggregateError([error]))); + request.on("data", (chunk: string) => (data += chunk)); request.on("end", () => { try { resolve(JSON.parse(data)); diff --git a/src/middleware/node/middleware.ts b/src/middleware/node/middleware.ts index 106e95d4..f6dab98f 100644 --- a/src/middleware/node/middleware.ts +++ b/src/middleware/node/middleware.ts @@ -1,4 +1,8 @@ -import { IncomingMessage, ServerResponse } from "http"; +// remove type imports from http for Deno compatibility +// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886 +// import { IncomingMessage, ServerResponse } from "http"; +type IncomingMessage = any; +type ServerResponse = any; import { WebhookEventName } from "@octokit/webhooks-definitions/schema"; diff --git a/src/middleware/node/on-unhandled-request-default.ts b/src/middleware/node/on-unhandled-request-default.ts index c32ef7aa..3664190f 100644 --- a/src/middleware/node/on-unhandled-request-default.ts +++ b/src/middleware/node/on-unhandled-request-default.ts @@ -1,4 +1,8 @@ -import { IncomingMessage, ServerResponse } from "http"; +// remove type imports from http for Deno compatibility +// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886 +// import { IncomingMessage, ServerResponse } from "http"; +type IncomingMessage = any; +type ServerResponse = any; export function onUnhandledRequestDefault( request: IncomingMessage, diff --git a/src/middleware/node/types.ts b/src/middleware/node/types.ts index c114ce22..81c4e0ed 100644 --- a/src/middleware/node/types.ts +++ b/src/middleware/node/types.ts @@ -1,4 +1,8 @@ -import { IncomingMessage, ServerResponse } from "http"; +// remove type imports from http for Deno compatibility +// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886 +// import { IncomingMessage, ServerResponse } from "http"; +type IncomingMessage = any; +type ServerResponse = any; import { Logger } from "../../createLogger";