Skip to content

Commit

Permalink
fix(event-http): properly type listen method
Browse files Browse the repository at this point in the history
  • Loading branch information
mav-rik committed Jan 31, 2024
1 parent 16216ce commit 06243cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 27 additions & 2 deletions packages/event-http/src/http-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable @typescript-eslint/unified-signatures */
import type { TConsoleBase } from '@prostojs/logger'
import type { TEventOptions } from '@wooksjs/event-core'
import type { IncomingMessage, Server, ServerResponse } from 'http'
import http from 'http'
import type { ListenOptions } from 'net'
import type { TWooksHandler, TWooksOptions, Wooks } from 'wooks'
import { WooksAdapterBase } from 'wooks'

Expand Down Expand Up @@ -90,12 +92,35 @@ export class WooksHttp extends WooksAdapterBase {
*
* Use this only if you rely on Wooks server.
*/
public async listen(...args: Parameters<Server['listen']>) {
// @ts-expect-error
public listen(
port?: number,
hostname?: string,
backlog?: number,
listeningListener?: () => void
): this
public listen(port?: number, hostname?: string, listeningListener?: () => void): this
public listen(port?: number, backlog?: number, listeningListener?: () => void): this
public listen(port?: number, listeningListener?: () => void): this
public listen(path: string, backlog?: number, listeningListener?: () => void): this
public listen(path: string, listeningListener?: () => void): this
public listen(options: ListenOptions, listeningListener?: () => void): this
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public listen(handle: any, backlog?: number, listeningListener?: () => void): this
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public listen(handle: any, listeningListener?: () => void): this
public async listen(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
port?: number | string | ListenOptions | any,
hostname?: number | string | (() => void),
backlog?: number | (() => void),
listeningListener?: () => void
) {
const server = (this.server = http.createServer(this.getServerCb() as http.RequestListener))
return new Promise((resolve, reject) => {
server.once('listening', resolve)
server.once('error', reject)
server.listen(...args)
server.listen(port as number, hostname as string, backlog as number, listeningListener)
})
}

Expand Down
4 changes: 1 addition & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { readdirSync, rmSync, statSync } from 'node:fs'
import { dye } from '@prostojs/dye'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'

// import commonJS from '@rollup/plugin-commonjs'
import { createRequire } from 'module'
import { dts } from 'rollup-plugin-dts'
import typescript from 'rollup-plugin-typescript2'
Expand All @@ -27,7 +25,7 @@ const dyeModifiers = [
]
const dyeColors = ['red', 'green', 'cyan', 'blue', 'yellow', 'white', 'magenta', 'black']

const external = ['url', 'crypto', 'stream', 'packages/*/src', 'http']
const external = ['url', 'crypto', 'stream', 'packages/*/src', 'http', 'net']

const replacePlugin = replace({
values: {
Expand Down

0 comments on commit 06243cf

Please sign in to comment.