Change event emitter to tseep
This commit is contained in:
@@ -17,17 +17,17 @@ bun install github:pygmyapp/ipc-client
|
||||
- Clone this repository
|
||||
- Install dependencies with `bun install`
|
||||
|
||||
## Build
|
||||
|
||||
You can then build the library:
|
||||
```sh
|
||||
bun run build
|
||||
```
|
||||
|
||||
## Scripts
|
||||
|
||||
- `bun run lint`: runs Biome's linting, applies safe fixes, suggests fixes to errors, and auto-organizes imports
|
||||
- `bun run lint`: runs Biome linting, applies safe fixes, and auto-organizes imports
|
||||
|
||||
## Licence
|
||||
Copyright (c) 2025 Pygmy & contributors
|
||||
Copyright (c) 2025 Pygmy & contributors
|
||||
|
||||
All code & assets are licensed under GNU GPL v3 unless stated otherwise.
|
||||
See `LICENSE` or [see here](https://www.gnu.org/licenses/gpl-3.0.txt).
|
||||
3
bun.lock
3
bun.lock
@@ -5,6 +5,7 @@
|
||||
"name": "ipc-client",
|
||||
"dependencies": {
|
||||
"node-ipc": "npm:@achrinza/node-ipc@^10.1.11",
|
||||
"tseep": "^1.3.1",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "2.1.3",
|
||||
@@ -60,6 +61,8 @@
|
||||
|
||||
"node-ipc": ["@achrinza/node-ipc@10.1.11", "", { "dependencies": { "@achrinza/event-pubsub": "5.0.11", "@achrinza/strong-type": "1.1.20", "@node-ipc/js-queue": "2.0.3", "js-message": "1.0.7" } }, "sha512-3z2yix2G8KP8gW6dWgRPj61Mu2nleqbWqTuS5vluZiXe2VDFkimqaeb4fnuS6JV2nhJz4gX+PR5PQjRKsuXm8w=="],
|
||||
|
||||
"tseep": ["tseep@1.3.1", "", {}, "sha512-ZPtfk1tQnZVyr7BPtbJ93qaAh2lZuIOpTMjhrYa4XctT8xe7t4SAW9LIxrySDuYMsfNNayE51E/WNGrNVgVicQ=="],
|
||||
|
||||
"typescript": ["typescript@5.9.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="],
|
||||
|
||||
"undici-types": ["undici-types@7.10.0", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="],
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
@@ -1,5 +1,5 @@
|
||||
import EventEmitter from 'node:events';
|
||||
import IPCModule from 'node-ipc';
|
||||
import { EventEmitter } from 'tseep';
|
||||
/**
|
||||
* Handles Inter-Process Communication (IPC) via. server/socket
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ipc-client",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"module": "dist/index.js",
|
||||
"type": "module",
|
||||
"files": ["dist/**/*"],
|
||||
@@ -17,6 +17,7 @@
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-ipc": "npm:@achrinza/node-ipc@^10.1.11"
|
||||
"node-ipc": "npm:@achrinza/node-ipc@^10.1.11",
|
||||
"tseep": "^1.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
14
src/index.ts
14
src/index.ts
@@ -1,10 +1,10 @@
|
||||
import EventEmitter from 'node:events';
|
||||
import IPCModule from 'node-ipc';
|
||||
import { EventEmitter } from 'tseep';
|
||||
|
||||
export interface IPCMessage {
|
||||
from: string;
|
||||
to: string;
|
||||
payload: any;
|
||||
payload: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,11 @@ export interface IPCMessage {
|
||||
* console.log(`Message:`, message);
|
||||
* });
|
||||
*/
|
||||
export default class IPC extends EventEmitter {
|
||||
export default class IPC extends EventEmitter<{
|
||||
connect: () => void;
|
||||
disconnect: () => void;
|
||||
message: (message: IPCMessage) => void;
|
||||
}> {
|
||||
name: string;
|
||||
ready: boolean;
|
||||
ipc: typeof IPCModule;
|
||||
@@ -70,7 +74,7 @@ export default class IPC extends EventEmitter {
|
||||
* @param to Who to send the message to
|
||||
* @param data JSON data to send to the process
|
||||
*/
|
||||
send(to: string, data: any) {
|
||||
send(to: string, data: unknown) {
|
||||
if (!this.ready) return;
|
||||
|
||||
const message: IPCMessage = {
|
||||
@@ -102,7 +106,7 @@ export default class IPC extends EventEmitter {
|
||||
const message: IPCMessage = {
|
||||
from: raw.from,
|
||||
to: raw.to,
|
||||
payload: JSON.parse(raw.payload)
|
||||
payload: JSON.parse(raw.payload as string)
|
||||
};
|
||||
|
||||
this.emit('message', message);
|
||||
|
||||
Reference in New Issue
Block a user