diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..43934ec --- /dev/null +++ b/index.d.ts @@ -0,0 +1,23 @@ +import { Duplex } from 'bare-stream' + +declare class IPC extends Duplex { + constructor(port: IPCPort) +} + +declare interface IPCPort { + incoming: string | number + outgoing: string | number + detached: boolean + + connect(): IPC +} + +declare class IPCPort { + constructor(incoming: string | number, outgoing: string | number) +} + +declare namespace IPC { + export function open(): [IPCPort, IPCPort] +} + +export = IPC diff --git a/index.js b/index.js index 87769e0..66b26ef 100644 --- a/index.js +++ b/index.js @@ -78,9 +78,9 @@ class IPCPort { } } -exports.open = function open(opts) { - const a = Pipe.pipe(opts) - const b = Pipe.pipe(opts) +exports.open = function open() { + const a = Pipe.pipe() + const b = Pipe.pipe() - return [new IPCPort(a[0], b[1], opts), new IPCPort(b[0], a[1], opts)] + return [new IPCPort(a[0], b[1]), new IPCPort(b[0], a[1])] } diff --git a/lib/errors.d.ts b/lib/errors.d.ts new file mode 100644 index 0000000..13d9a2a --- /dev/null +++ b/lib/errors.d.ts @@ -0,0 +1,5 @@ +declare class IPCError extends Error { + static ALREADY_CONNECTED(msg: string): IPCError +} + +export = IPCError diff --git a/package.json b/package.json index a1c3240..fdcfe1f 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,19 @@ "version": "1.0.1", "description": "Lightweight pipe-based IPC for Bare", "exports": { - ".": "./index.js", + ".": { + "types": "./index.d.ts", + "default": "./index.js" + }, "./package": "./package.json", - "./errors": "./lib/errors.js" + "./errors": { + "types": "./lib/errors.d.ts", + "default": "./lib/errors.js" + } }, "files": [ "index.js", + "index.d.ts", "lib" ], "scripts": {