@typerighter/rpc-server 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +4 -1
- package/index.js +10 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface RpcServerOptions {
|
|
|
5
5
|
root?: string;
|
|
6
6
|
/** Bind address (default: "127.0.0.1") */
|
|
7
7
|
addr?: string;
|
|
8
|
-
/** Bind port (default:
|
|
8
|
+
/** Bind port (default: 0, OS picks a free port) */
|
|
9
9
|
port?: number;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -27,6 +27,9 @@ export class RpcServer extends EventEmitter {
|
|
|
27
27
|
/** Stop the server. Emits "close" when the process exits */
|
|
28
28
|
close(): this;
|
|
29
29
|
|
|
30
|
+
/** Unref the child process so it does not prevent Node from exiting */
|
|
31
|
+
unref(): this;
|
|
32
|
+
|
|
30
33
|
on(event: 'listening', listener: () => void): this;
|
|
31
34
|
on(event: 'close', listener: (code: number | null, signal: string | null) => void): this;
|
|
32
35
|
on(event: 'error', listener: (error: Error) => void): this;
|
package/index.js
CHANGED
|
@@ -24,14 +24,13 @@ function resolveBin() {
|
|
|
24
24
|
|
|
25
25
|
const bin = resolveBin();
|
|
26
26
|
|
|
27
|
-
const DEFAULT_PORT = 4747;
|
|
28
|
-
|
|
29
27
|
export class RpcServer extends EventEmitter {
|
|
30
28
|
constructor({ root, addr, port } = {}) {
|
|
31
29
|
super();
|
|
32
30
|
this._root = root ?? process.cwd();
|
|
33
31
|
this._addr = addr ?? "127.0.0.1";
|
|
34
|
-
|
|
32
|
+
// Port 0 lets the OS pick a free port, avoiding conflicts between dev and build
|
|
33
|
+
this._port = port ?? 0;
|
|
35
34
|
this._process = undefined;
|
|
36
35
|
this._listening = false;
|
|
37
36
|
this._resolvedAddress = undefined;
|
|
@@ -97,6 +96,14 @@ export class RpcServer extends EventEmitter {
|
|
|
97
96
|
return this;
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
// Unref the child process so it does not keep the Node event loop alive
|
|
100
|
+
unref() {
|
|
101
|
+
if (this._process) {
|
|
102
|
+
this._process.unref();
|
|
103
|
+
}
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
close() {
|
|
101
108
|
if (this._process) {
|
|
102
109
|
this._process.kill();
|