Skip to content

Commit

Permalink
Add TypeScript typings
Browse files Browse the repository at this point in the history
  • Loading branch information
yassernasc committed Jan 15, 2025
1 parent a951280 commit cbb5ed5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
23 changes: 23 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
}
5 changes: 5 additions & 0 deletions lib/errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare class IPCError extends Error {
static ALREADY_CONNECTED(msg: string): IPCError
}

export = IPCError
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit cbb5ed5

Please sign in to comment.