@ac-kit/node 0.1.0
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/LICENSE +28 -0
- package/README.md +39 -0
- package/dist/child-process/exec-async.d.ts +24 -0
- package/dist/child-process/exec-async.d.ts.map +1 -0
- package/dist/child-process/exec-async.js +33 -0
- package/dist/child-process/exec-async.js.map +1 -0
- package/dist/error/node-aggregate-error.d.ts +18 -0
- package/dist/error/node-aggregate-error.d.ts.map +1 -0
- package/dist/error/node-aggregate-error.js +13 -0
- package/dist/error/node-aggregate-error.js.map +1 -0
- package/dist/error/node-error.d.ts +26 -0
- package/dist/error/node-error.d.ts.map +1 -0
- package/dist/error/node-error.js +21 -0
- package/dist/error/node-error.js.map +1 -0
- package/dist/error/node-exec-error.d.ts +21 -0
- package/dist/error/node-exec-error.d.ts.map +1 -0
- package/dist/error/node-exec-error.js +17 -0
- package/dist/error/node-exec-error.js.map +1 -0
- package/dist/error/node-system-error.d.ts +46 -0
- package/dist/error/node-system-error.d.ts.map +1 -0
- package/dist/error/node-system-error.js +35 -0
- package/dist/error/node-system-error.js.map +1 -0
- package/dist/error/process-exit-error.d.ts +22 -0
- package/dist/error/process-exit-error.d.ts.map +1 -0
- package/dist/error/process-exit-error.js +46 -0
- package/dist/error/process-exit-error.js.map +1 -0
- package/dist/fs/compress-file.d.ts +42 -0
- package/dist/fs/compress-file.d.ts.map +1 -0
- package/dist/fs/compress-file.js +72 -0
- package/dist/fs/compress-file.js.map +1 -0
- package/dist/fs/create-temp-dir.d.ts +13 -0
- package/dist/fs/create-temp-dir.d.ts.map +1 -0
- package/dist/fs/create-temp-dir.js +18 -0
- package/dist/fs/create-temp-dir.js.map +1 -0
- package/dist/fs/escape-path.d.ts +19 -0
- package/dist/fs/escape-path.d.ts.map +1 -0
- package/dist/fs/escape-path.js +20 -0
- package/dist/fs/escape-path.js.map +1 -0
- package/dist/fs/exists-async.d.ts +9 -0
- package/dist/fs/exists-async.d.ts.map +1 -0
- package/dist/fs/exists-async.js +17 -0
- package/dist/fs/exists-async.js.map +1 -0
- package/dist/fs/file-content-equal.d.ts +18 -0
- package/dist/fs/file-content-equal.d.ts.map +1 -0
- package/dist/fs/file-content-equal.js +50 -0
- package/dist/fs/file-content-equal.js.map +1 -0
- package/dist/fs/is-directory-async.d.ts +11 -0
- package/dist/fs/is-directory-async.d.ts.map +1 -0
- package/dist/fs/is-directory-async.js +18 -0
- package/dist/fs/is-directory-async.js.map +1 -0
- package/dist/fs/types.d.ts +19 -0
- package/dist/fs/types.d.ts.map +1 -0
- package/dist/fs/types.js +23 -0
- package/dist/fs/types.js.map +1 -0
- package/dist/fs/walk-paths.d.ts +108 -0
- package/dist/fs/walk-paths.d.ts.map +1 -0
- package/dist/fs/walk-paths.js +197 -0
- package/dist/fs/walk-paths.js.map +1 -0
- package/dist/fs/write-file-atomic.d.ts +42 -0
- package/dist/fs/write-file-atomic.d.ts.map +1 -0
- package/dist/fs/write-file-atomic.js +126 -0
- package/dist/fs/write-file-atomic.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/module/import-module.d.ts +13 -0
- package/dist/module/import-module.d.ts.map +1 -0
- package/dist/module/import-module.js +18 -0
- package/dist/module/import-module.js.map +1 -0
- package/dist/module/optional-import.d.ts +19 -0
- package/dist/module/optional-import.d.ts.map +1 -0
- package/dist/module/optional-import.js +30 -0
- package/dist/module/optional-import.js.map +1 -0
- package/dist/module/resolve-module.d.ts +13 -0
- package/dist/module/resolve-module.d.ts.map +1 -0
- package/dist/module/resolve-module.js +26 -0
- package/dist/module/resolve-module.js.map +1 -0
- package/dist/net/dgram-socket.d.ts +235 -0
- package/dist/net/dgram-socket.d.ts.map +1 -0
- package/dist/net/dgram-socket.js +341 -0
- package/dist/net/dgram-socket.js.map +1 -0
- package/dist/net/ipc-socket.d.ts +34 -0
- package/dist/net/ipc-socket.d.ts.map +1 -0
- package/dist/net/ipc-socket.js +63 -0
- package/dist/net/ipc-socket.js.map +1 -0
- package/dist/net/stream-socket.d.ts +156 -0
- package/dist/net/stream-socket.d.ts.map +1 -0
- package/dist/net/stream-socket.js +188 -0
- package/dist/net/stream-socket.js.map +1 -0
- package/dist/net/tcp-server.d.ts +110 -0
- package/dist/net/tcp-server.d.ts.map +1 -0
- package/dist/net/tcp-server.js +198 -0
- package/dist/net/tcp-server.js.map +1 -0
- package/dist/net/tcp-socket.d.ts +87 -0
- package/dist/net/tcp-socket.d.ts.map +1 -0
- package/dist/net/tcp-socket.js +153 -0
- package/dist/net/tcp-socket.js.map +1 -0
- package/dist/net/tls-socket.d.ts +45 -0
- package/dist/net/tls-socket.d.ts.map +1 -0
- package/dist/net/tls-socket.js +148 -0
- package/dist/net/tls-socket.js.map +1 -0
- package/dist/process/fork-process.d.ts +63 -0
- package/dist/process/fork-process.d.ts.map +1 -0
- package/dist/process/fork-process.js +98 -0
- package/dist/process/fork-process.js.map +1 -0
- package/dist/process/guarded.d.ts +12 -0
- package/dist/process/guarded.d.ts.map +1 -0
- package/dist/process/guarded.js +25 -0
- package/dist/process/guarded.js.map +1 -0
- package/dist/process/spawn-process.d.ts +37 -0
- package/dist/process/spawn-process.d.ts.map +1 -0
- package/dist/process/spawn-process.js +73 -0
- package/dist/process/spawn-process.js.map +1 -0
- package/dist/process/spawned-process.d.ts +102 -0
- package/dist/process/spawned-process.d.ts.map +1 -0
- package/dist/process/spawned-process.js +226 -0
- package/dist/process/spawned-process.js.map +1 -0
- package/dist/process/start-process.d.ts +54 -0
- package/dist/process/start-process.d.ts.map +1 -0
- package/dist/process/start-process.js +73 -0
- package/dist/process/start-process.js.map +1 -0
- package/dist/shell/escape-command-arg.d.ts +9 -0
- package/dist/shell/escape-command-arg.d.ts.map +1 -0
- package/dist/shell/escape-command-arg.js +13 -0
- package/dist/shell/escape-command-arg.js.map +1 -0
- package/dist/shell/escape-command.d.ts +10 -0
- package/dist/shell/escape-command.d.ts.map +1 -0
- package/dist/shell/escape-command.js +12 -0
- package/dist/shell/escape-command.js.map +1 -0
- package/dist/stream/non-closing-writable-stream.d.ts +14 -0
- package/dist/stream/non-closing-writable-stream.d.ts.map +1 -0
- package/dist/stream/non-closing-writable-stream.js +20 -0
- package/dist/stream/non-closing-writable-stream.js.map +1 -0
- package/dist/stream/write-async.d.ts +12 -0
- package/dist/stream/write-async.d.ts.map +1 -0
- package/dist/stream/write-async.js +22 -0
- package/dist/stream/write-async.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
import { composeInetAddress, } from "@ac-kit/core";
|
|
3
|
+
import { StreamSocket } from "./stream-socket.js";
|
|
4
|
+
/**
|
|
5
|
+
* TCP socket for establishing connections to TCP servers.
|
|
6
|
+
*
|
|
7
|
+
* Example usage:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const tcpSocket = new TcpSocket.from();
|
|
11
|
+
* await tcpSocket.connect(80, "example.com");
|
|
12
|
+
* await tcpSocket.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n");
|
|
13
|
+
* await tcpSocket.end({ waitForClose: true });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class TcpSocket extends StreamSocket {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new {@link TcpSocket} instance.
|
|
19
|
+
*
|
|
20
|
+
* @param options Options for creating the underlying Node.js socket.
|
|
21
|
+
* @returns A new `TcpSocket` instance.
|
|
22
|
+
*/
|
|
23
|
+
static from(options) {
|
|
24
|
+
return new TcpSocket(new net.Socket(options));
|
|
25
|
+
}
|
|
26
|
+
constructor(sock) {
|
|
27
|
+
super(sock);
|
|
28
|
+
this.setupEventForwarding();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the remote endpoint information of the socket.
|
|
32
|
+
*
|
|
33
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
34
|
+
*/
|
|
35
|
+
get remoteEndpoint() {
|
|
36
|
+
const address = this.sock.remoteAddress;
|
|
37
|
+
const port = this.sock.remotePort;
|
|
38
|
+
const familyStr = this.sock.remoteFamily;
|
|
39
|
+
if (address === undefined ||
|
|
40
|
+
port === undefined ||
|
|
41
|
+
familyStr === undefined) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
...composeInetAddress(familyStr, address),
|
|
46
|
+
port,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the local endpoint information of the socket.
|
|
51
|
+
*
|
|
52
|
+
* @throws {UnsupportedError} If the socket family is not IPv4 or IPv6.
|
|
53
|
+
*/
|
|
54
|
+
get localEndpoint() {
|
|
55
|
+
const address = this.sock.localAddress;
|
|
56
|
+
const port = this.sock.localPort;
|
|
57
|
+
const familyStr = this.sock.localFamily;
|
|
58
|
+
if (address === undefined ||
|
|
59
|
+
port === undefined ||
|
|
60
|
+
familyStr === undefined) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...composeInetAddress(familyStr, address),
|
|
65
|
+
port,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sets the keep-alive option for the socket.
|
|
70
|
+
*
|
|
71
|
+
* @param enable Whether to enable keep-alive.
|
|
72
|
+
* @param initialDelay The initial delay in milliseconds before the first
|
|
73
|
+
* keep-alive probe.
|
|
74
|
+
*/
|
|
75
|
+
setKeepAlive(enable, initialDelay) {
|
|
76
|
+
this.sock.setKeepAlive(enable, initialDelay);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Disables the Nagle algorithm for the socket.
|
|
80
|
+
*
|
|
81
|
+
* @param noDelay Whether to disable the Nagle algorithm.
|
|
82
|
+
*/
|
|
83
|
+
setNoDelay(noDelay) {
|
|
84
|
+
this.sock.setNoDelay(noDelay);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Establishes a TCP connection to the specified port and host.
|
|
88
|
+
*
|
|
89
|
+
* @param port The port to connect to.
|
|
90
|
+
* @param host The host to connect to (defaults to `localhost`).
|
|
91
|
+
* @param options Connection options.
|
|
92
|
+
* @returns A promise that resolves when the connection is successfully
|
|
93
|
+
* established.
|
|
94
|
+
*/
|
|
95
|
+
async connect(port, options) {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
const { signal, ...connectOptions } = options ?? {};
|
|
98
|
+
signal?.throwIfAborted();
|
|
99
|
+
const handleError = (error) => {
|
|
100
|
+
this.handledErrorEvents.add(error);
|
|
101
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
102
|
+
reject(error);
|
|
103
|
+
};
|
|
104
|
+
this.sock.prependOnceListener("error", handleError);
|
|
105
|
+
const handleAbort = () => {
|
|
106
|
+
this.sock.removeListener("error", handleError);
|
|
107
|
+
this.sock.destroy();
|
|
108
|
+
reject(signal?.reason);
|
|
109
|
+
};
|
|
110
|
+
signal?.addEventListener("abort", handleAbort, { once: true });
|
|
111
|
+
this.sock.connect({
|
|
112
|
+
...connectOptions,
|
|
113
|
+
port,
|
|
114
|
+
}, () => {
|
|
115
|
+
this.sock.removeListener("error", handleError);
|
|
116
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
117
|
+
resolve();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
setupEventForwarding() {
|
|
122
|
+
super.setupEventForwarding();
|
|
123
|
+
this.sock.on("connectionAttempt", (ip, port, family) => {
|
|
124
|
+
this.dispatch("connectionAttempt", [
|
|
125
|
+
{
|
|
126
|
+
...composeInetAddress(family, ip),
|
|
127
|
+
port,
|
|
128
|
+
},
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
this.sock.on("connectionAttemptFailed", (ip, port, family, error) => {
|
|
132
|
+
this.dispatch("connectionAttemptFailed", [
|
|
133
|
+
{
|
|
134
|
+
...composeInetAddress(family, ip),
|
|
135
|
+
port,
|
|
136
|
+
},
|
|
137
|
+
error,
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
this.sock.on("connectionAttemptTimeout", (ip, port, family) => {
|
|
141
|
+
this.dispatch("connectionAttemptTimeout", [
|
|
142
|
+
{
|
|
143
|
+
...composeInetAddress(family, ip),
|
|
144
|
+
port,
|
|
145
|
+
},
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
this.sock.on("lookup", (err, address, family, host) => {
|
|
149
|
+
this.dispatch("lookup", [err, composeInetAddress(family, address), host]);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=tcp-socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tcp-socket.js","sourceRoot":"","sources":["../../src/net/tcp-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,EACN,kBAAkB,GAIlB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAiC3E;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,SAGX,SAAQ,YAA4B;IACrC;;;;;OAKG;IACH,MAAM,CAAU,IAAI,CACnB,OAAiD;QAEjD,OAAO,IAAI,SAAS,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,YAAY,IAAW;QACtB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAAI,cAAc;QACjB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAA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AC,EAAE,CAAC,yBAAyB,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YACnE,IAAI,CAAC,QAAQ,CAAC,yBAAyB,EAAE;gBACxC;oBACC,GAAG,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC;oBACjC,IAAI;iBACJ;gBACD,KAAK;aACL,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,0BAA0B,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YAC7D,IAAI,CAAC,QAAQ,CAAC,0BAA0B,EAAE;gBACzC;oBACC,GAAG,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC;oBACjC,IAAI;iBACJ;aACD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;YACrD,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { X509Certificate } from "node:crypto";
|
|
2
|
+
import type { Duplex } from "node:stream";
|
|
3
|
+
import * as tls from "node:tls";
|
|
4
|
+
import type { Except } from "type-fest";
|
|
5
|
+
import type { StreamSocketEvents } from "./stream-socket.js";
|
|
6
|
+
import { StreamSocket } from "./stream-socket.js";
|
|
7
|
+
export type TlsSocketEvents = StreamSocketEvents & {
|
|
8
|
+
secureConnect: [];
|
|
9
|
+
ocspResponse: [response: Buffer | null];
|
|
10
|
+
keylog: [line: Buffer];
|
|
11
|
+
session: [session: Buffer];
|
|
12
|
+
};
|
|
13
|
+
export type TlsSocketOptions = Except<tls.TLSSocketOptions, "isServer" | "server" | keyof tls.SecureContextOptions>;
|
|
14
|
+
export type TlsSocketConnectOptions = Except<tls.ConnectionOptions, "port"> & {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
};
|
|
17
|
+
export declare class TlsSocket extends StreamSocket<tls.TLSSocket, TlsSocketEvents> {
|
|
18
|
+
static from(stream: Duplex, options?: TlsSocketOptions): TlsSocket;
|
|
19
|
+
static connect(port: number, options?: TlsSocketConnectOptions): Promise<TlsSocket>;
|
|
20
|
+
get encrypted(): boolean;
|
|
21
|
+
get authorized(): boolean;
|
|
22
|
+
get authorizationError(): Error | null;
|
|
23
|
+
get alpnProtocol(): string | null;
|
|
24
|
+
getCertificate(): tls.PeerCertificate | null;
|
|
25
|
+
getCipher(): tls.CipherNameAndProtocol;
|
|
26
|
+
getEphemeralKeyInfo(): tls.EphemeralKeyInfo | object | null;
|
|
27
|
+
getFinished(): Buffer | null;
|
|
28
|
+
getPeerCertificate<T extends boolean | undefined, R = T extends true ? tls.DetailedPeerCertificate : tls.PeerCertificate>(detailed?: T): R;
|
|
29
|
+
getPeerFinished(): Buffer | null;
|
|
30
|
+
getProtocol(): string | null;
|
|
31
|
+
getSession(): Buffer | null;
|
|
32
|
+
getSharedSigalgs(): string[];
|
|
33
|
+
getTicket(): Buffer | null;
|
|
34
|
+
isSessionReused(): boolean;
|
|
35
|
+
renegotiate(options: Parameters<tls.TLSSocket["renegotiate"]>[0]): Promise<void>;
|
|
36
|
+
setKeyCert(context: tls.SecureContext): void;
|
|
37
|
+
setMaxSendFragment(size: number): boolean;
|
|
38
|
+
disableRenegotiation(): void;
|
|
39
|
+
enableTrace(): void;
|
|
40
|
+
getPeerX509Certificate(): X509Certificate | null;
|
|
41
|
+
getX509Certificate(): X509Certificate | null;
|
|
42
|
+
exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer;
|
|
43
|
+
protected setupEventForwarding(): void;
|
|
44
|
+
}
|
|
45
|
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kB,IAAI,eAAe,GAAG,IAAI,CAG3C;IAED,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3E;IAED,UAAmB,oBAAoB,IAAI,IAAI,CAkB9C;CACD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as tls from "node:tls";
|
|
2
|
+
import { isObject } from "@ac-kit/core";
|
|
3
|
+
import { StreamSocket } from "./stream-socket.js";
|
|
4
|
+
export class TlsSocket extends StreamSocket {
|
|
5
|
+
static from(stream, options) {
|
|
6
|
+
return new TlsSocket(new tls.TLSSocket(stream, options));
|
|
7
|
+
}
|
|
8
|
+
static connect(port, options) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const { signal, ...connectOptions } = options ?? {};
|
|
11
|
+
signal?.throwIfAborted();
|
|
12
|
+
const tlsSocket = new TlsSocket(tls.connect({ ...connectOptions, port }));
|
|
13
|
+
const handleError = (error) => {
|
|
14
|
+
tlsSocket.unsubscribe("secureConnect", handleSecureConnect);
|
|
15
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
16
|
+
reject(error);
|
|
17
|
+
};
|
|
18
|
+
tlsSocket.subscribe("error", handleError, { once: true });
|
|
19
|
+
const handleSecureConnect = () => {
|
|
20
|
+
tlsSocket.unsubscribe("error", handleError);
|
|
21
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
22
|
+
resolve(tlsSocket);
|
|
23
|
+
};
|
|
24
|
+
tlsSocket.subscribe("secureConnect", handleSecureConnect, { once: true });
|
|
25
|
+
const handleAbort = () => {
|
|
26
|
+
tlsSocket.unsubscribe("error", handleError);
|
|
27
|
+
tlsSocket.unsubscribe("secureConnect", handleSecureConnect);
|
|
28
|
+
tlsSocket.destroy();
|
|
29
|
+
reject(signal?.reason);
|
|
30
|
+
};
|
|
31
|
+
signal?.addEventListener("abort", handleAbort, { once: true });
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
get encrypted() {
|
|
35
|
+
return this.sock.encrypted;
|
|
36
|
+
}
|
|
37
|
+
get authorized() {
|
|
38
|
+
return this.sock.authorized;
|
|
39
|
+
}
|
|
40
|
+
get authorizationError() {
|
|
41
|
+
return this.sock.authorizationError ?? null;
|
|
42
|
+
}
|
|
43
|
+
get alpnProtocol() {
|
|
44
|
+
const value = this.sock.alpnProtocol;
|
|
45
|
+
return value === false ? null : value;
|
|
46
|
+
}
|
|
47
|
+
getCertificate() {
|
|
48
|
+
const cert = this.sock.getCertificate();
|
|
49
|
+
// Connection established but no certificate presented
|
|
50
|
+
if (isObject(cert) && Object.keys(cert).length === 0) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (cert === null) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return cert;
|
|
57
|
+
}
|
|
58
|
+
getCipher() {
|
|
59
|
+
return this.sock.getCipher();
|
|
60
|
+
}
|
|
61
|
+
getEphemeralKeyInfo() {
|
|
62
|
+
return this.sock.getEphemeralKeyInfo();
|
|
63
|
+
}
|
|
64
|
+
getFinished() {
|
|
65
|
+
const value = this.sock.getFinished();
|
|
66
|
+
return value ?? null;
|
|
67
|
+
}
|
|
68
|
+
getPeerCertificate(detailed) {
|
|
69
|
+
return this.sock.getPeerCertificate(detailed);
|
|
70
|
+
}
|
|
71
|
+
getPeerFinished() {
|
|
72
|
+
const value = this.sock.getPeerFinished();
|
|
73
|
+
return value ?? null;
|
|
74
|
+
}
|
|
75
|
+
getProtocol() {
|
|
76
|
+
return this.sock.getProtocol();
|
|
77
|
+
}
|
|
78
|
+
getSession() {
|
|
79
|
+
const value = this.sock.getSession();
|
|
80
|
+
return value ?? null;
|
|
81
|
+
}
|
|
82
|
+
getSharedSigalgs() {
|
|
83
|
+
return this.sock.getSharedSigalgs();
|
|
84
|
+
}
|
|
85
|
+
getTicket() {
|
|
86
|
+
const value = this.sock.getTLSTicket();
|
|
87
|
+
return value ?? null;
|
|
88
|
+
}
|
|
89
|
+
isSessionReused() {
|
|
90
|
+
return this.sock.isSessionReused();
|
|
91
|
+
}
|
|
92
|
+
async renegotiate(options) {
|
|
93
|
+
// renegotiate callback is never called if socket is destroyed
|
|
94
|
+
if (this.sock.destroyed) {
|
|
95
|
+
throw new Error("Socket is destroyed");
|
|
96
|
+
}
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const callback = (err) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
reject(err);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
resolve();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
this.sock.renegotiate(options, callback);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
setKeyCert(context) {
|
|
110
|
+
this.sock.setKeyCert(context);
|
|
111
|
+
}
|
|
112
|
+
setMaxSendFragment(size) {
|
|
113
|
+
return this.sock.setMaxSendFragment(size);
|
|
114
|
+
}
|
|
115
|
+
disableRenegotiation() {
|
|
116
|
+
this.sock.disableRenegotiation();
|
|
117
|
+
}
|
|
118
|
+
enableTrace() {
|
|
119
|
+
this.sock.enableTrace();
|
|
120
|
+
}
|
|
121
|
+
getPeerX509Certificate() {
|
|
122
|
+
const cert = this.sock.getPeerX509Certificate();
|
|
123
|
+
return cert ?? null;
|
|
124
|
+
}
|
|
125
|
+
getX509Certificate() {
|
|
126
|
+
const cert = this.sock.getX509Certificate();
|
|
127
|
+
return cert ?? null;
|
|
128
|
+
}
|
|
129
|
+
exportKeyingMaterial(length, label, context) {
|
|
130
|
+
return this.sock.exportKeyingMaterial(length, label, context);
|
|
131
|
+
}
|
|
132
|
+
setupEventForwarding() {
|
|
133
|
+
super.setupEventForwarding();
|
|
134
|
+
this.sock.on("secureConnect", () => {
|
|
135
|
+
this.dispatch("secureConnect", []);
|
|
136
|
+
});
|
|
137
|
+
this.sock.on("OCSPResponse", (response) => {
|
|
138
|
+
this.dispatch("ocspResponse", [response]);
|
|
139
|
+
});
|
|
140
|
+
this.sock.on("keylog", (line) => {
|
|
141
|
+
this.dispatch("keylog", [line]);
|
|
142
|
+
});
|
|
143
|
+
this.sock.on("session", (session) => {
|
|
144
|
+
this.dispatch("session", [session]);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=tls-socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tls-socket.js","sourceRoot":"","sources":["../../src/net/tls-socket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAkBlD,MAAM,OAAO,SAAU,SAAQ,YAA4C;IAC1E,MAAM,CAAU,IAAI,CAAC,MAAc,EAAE,OAA0B;QAC9D,OAAO,IAAI,SAAS,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,OAAO,CACb,IAAY,EACZ,OAAiC;QAEjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;YAEpD,MAAM,EAAE,cAAc,EAAE,CAAC;YAEzB,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAE1E,MAAM,WAAW,GAAG,CAAC,KAAY,EAAE,EAAE;gBACpC,SAAS,CAAC,WAAW,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;gBAC5D,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;gBAClD,MAAM,CAAC,KAAK,CAAC,CAAC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,EAAE,CAAC;QAC5C,OAAO,IAAI,IAAI,IAAI,CAAC;IACrB,CAAC;IAED,oBAAoB,CAAC,MAAc,EAAE,KAAa,EAAE,OAAe;QAClE,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAEkB,oBAAoB;QACtC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAE7B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;YAClC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,EAAE;YACzC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/B,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YACnC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ChildProcess, type Serializable } from "node:child_process";
|
|
2
|
+
import { Callable } from "@ac-kit/core";
|
|
3
|
+
import { type ProcessOutputStream, SpawnedProcess, type SpawnedProcessEvents, type SpawnedProcessOptions } from "./spawned-process.js";
|
|
4
|
+
import type { ProcessStdio } from "./start-process.js";
|
|
5
|
+
export type ForkedProcessEvents = SpawnedProcessEvents & {
|
|
6
|
+
/** A message the child sent over the IPC channel. */
|
|
7
|
+
message: [message: unknown];
|
|
8
|
+
};
|
|
9
|
+
export type ForkProcessOptions = {
|
|
10
|
+
readonly args?: readonly string[] | null;
|
|
11
|
+
readonly cwd?: string | null;
|
|
12
|
+
readonly env?: NodeJS.ProcessEnv | null;
|
|
13
|
+
readonly execArgv?: readonly string[] | null;
|
|
14
|
+
/** Default `"advanced"` — structured clone, so Uint8Array/BigInt survive. */
|
|
15
|
+
readonly serialization?: "json" | "advanced" | null;
|
|
16
|
+
/** Aborting terminates the child (SIGTERM, then SIGKILL after `graceMs`). */
|
|
17
|
+
readonly signal?: AbortSignal | null;
|
|
18
|
+
/**
|
|
19
|
+
* Default `"inherit"`, or `"pipe"` when `onOutput` is given. `output` events
|
|
20
|
+
* only ever carry a piped stream. IPC uses its own fd, so nothing the child
|
|
21
|
+
* prints can corrupt it.
|
|
22
|
+
*/
|
|
23
|
+
readonly stdout?: ProcessStdio | null;
|
|
24
|
+
/** Default `"inherit"`, or `"pipe"` when `onOutput` is given. */
|
|
25
|
+
readonly stderr?: ProcessStdio | null;
|
|
26
|
+
/** Pre-subscribed before the child can write anything. */
|
|
27
|
+
readonly onOutput?: Callable<[
|
|
28
|
+
stream: ProcessOutputStream,
|
|
29
|
+
line: string
|
|
30
|
+
]> | null;
|
|
31
|
+
/** Pre-subscribed before the child can send anything. */
|
|
32
|
+
readonly onMessage?: Callable<[message: unknown]> | null;
|
|
33
|
+
/** Default 5000. */
|
|
34
|
+
readonly graceMs?: number | null;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A forked Node module: everything a {@link SpawnedProcess} offers, plus the IPC
|
|
38
|
+
* channel `fork` opens.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ForkedProcess extends SpawnedProcess<ForkedProcessEvents> {
|
|
41
|
+
constructor(child: ChildProcess, startedAt: number, options?: SpawnedProcessOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Sends a message to the child.
|
|
44
|
+
*
|
|
45
|
+
* @param message Anything the configured serialization can carry.
|
|
46
|
+
* @param signal Abandons the send.
|
|
47
|
+
* @returns A promise resolving once the message has been handed to the OS.
|
|
48
|
+
*/
|
|
49
|
+
send(message: Serializable, signal?: AbortSignal | null): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Forks a Node module with an IPC channel and resolves once it has spawned, so
|
|
53
|
+
* the returned handle always has a `pid` and a live channel. A spawn failure
|
|
54
|
+
* rejects here rather than surfacing later on the handle.
|
|
55
|
+
*
|
|
56
|
+
* @param modulePath The module to run as the child.
|
|
57
|
+
* @param options Streams, environment, cancellation. See
|
|
58
|
+
* {@link ForkProcessOptions}.
|
|
59
|
+
* @returns A handle over the running child.
|
|
60
|
+
* @throws When the module cannot be forked.
|
|
61
|
+
*/
|
|
62
|
+
export declare function forkProcess(modulePath: string, options?: ForkProcessOptions): Promise<ForkedProcess>;
|
|
63
|
+
//# sourceMappingURL=fork-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork-process.d.ts","sourceRoot":"","sources":["../../src/process/fork-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAQ,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EACN,KAAK,mBAAmB,EACxB,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,GAAG;IACxD,qDAAqD;IACrD,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,S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;;;;;;GAUG;AACH,wBAAsB,WAAW,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAoDxB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import { SpawnedProcess, } from "./spawned-process.js";
|
|
3
|
+
/**
|
|
4
|
+
* A forked Node module: everything a {@link SpawnedProcess} offers, plus the IPC
|
|
5
|
+
* channel `fork` opens.
|
|
6
|
+
*/
|
|
7
|
+
export class ForkedProcess extends SpawnedProcess {
|
|
8
|
+
constructor(child, startedAt, options) {
|
|
9
|
+
super(child, startedAt, options);
|
|
10
|
+
// Eager, unlike `output`: an unread IPC channel drops what arrives on it.
|
|
11
|
+
child.on("message", (message) => {
|
|
12
|
+
this.dispatch("message", [message]);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sends a message to the child.
|
|
17
|
+
*
|
|
18
|
+
* @param message Anything the configured serialization can carry.
|
|
19
|
+
* @param signal Abandons the send.
|
|
20
|
+
* @returns A promise resolving once the message has been handed to the OS.
|
|
21
|
+
*/
|
|
22
|
+
send(message, signal) {
|
|
23
|
+
if (signal?.aborted === true) {
|
|
24
|
+
return Promise.reject(signal.reason);
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const onAbort = () => reject(signal?.reason);
|
|
28
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
29
|
+
this.child.send(message, (error) => {
|
|
30
|
+
signal?.removeEventListener("abort", onAbort);
|
|
31
|
+
if (error) {
|
|
32
|
+
reject(error);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
resolve();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Forks a Node module with an IPC channel and resolves once it has spawned, so
|
|
42
|
+
* the returned handle always has a `pid` and a live channel. A spawn failure
|
|
43
|
+
* rejects here rather than surfacing later on the handle.
|
|
44
|
+
*
|
|
45
|
+
* @param modulePath The module to run as the child.
|
|
46
|
+
* @param options Streams, environment, cancellation. See
|
|
47
|
+
* {@link ForkProcessOptions}.
|
|
48
|
+
* @returns A handle over the running child.
|
|
49
|
+
* @throws When the module cannot be forked.
|
|
50
|
+
*/
|
|
51
|
+
export async function forkProcess(modulePath, options) {
|
|
52
|
+
const startedAt = performance.now();
|
|
53
|
+
const piped = options?.onOutput ? "pipe" : "inherit";
|
|
54
|
+
const child = fork(modulePath, options?.args ? [...options.args] : [], {
|
|
55
|
+
cwd: options?.cwd ?? undefined,
|
|
56
|
+
env: options?.env ?? undefined,
|
|
57
|
+
execArgv: options?.execArgv ? [...options.execArgv] : undefined,
|
|
58
|
+
serialization: options?.serialization ?? "advanced",
|
|
59
|
+
stdio: [
|
|
60
|
+
"inherit",
|
|
61
|
+
options?.stdout ?? piped,
|
|
62
|
+
options?.stderr ?? piped,
|
|
63
|
+
"ipc",
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
// Attached before anything can await: an abort signal fires 'error' on the
|
|
67
|
+
// next tick, which would go unhandled during the gap below.
|
|
68
|
+
child.on("error", () => { });
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
child.once("error", reject);
|
|
71
|
+
child.once("spawn", () => {
|
|
72
|
+
child.removeListener("error", reject);
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const forked = new ForkedProcess(child, startedAt, {
|
|
77
|
+
graceMs: options?.graceMs,
|
|
78
|
+
});
|
|
79
|
+
const onMessage = options?.onMessage;
|
|
80
|
+
if (onMessage) {
|
|
81
|
+
forked.subscribe("message", onMessage);
|
|
82
|
+
}
|
|
83
|
+
const onOutput = options?.onOutput;
|
|
84
|
+
if (onOutput) {
|
|
85
|
+
forked.subscribe("output", onOutput);
|
|
86
|
+
}
|
|
87
|
+
const signal = options?.signal;
|
|
88
|
+
if (signal?.aborted === true) {
|
|
89
|
+
void forked.terminate();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
signal?.addEventListener("abort", () => void forked.terminate(), {
|
|
93
|
+
once: true,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return forked;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=fork-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork-process.js","sourceRoot":"","sources":["../../src/process/fork-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,IAAI,EAAqB,MAAM,oBAAoB,CAAC;AAIhF,OAAO,EAEN,cAAc,GAGd,MAAM,sBAAsB,CAAC;AA6C9B;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAmC;IACrE,YACC,KAAmB,EACnB,SAAiB,EACjB,OAA+B;QAE/B,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAEjC,0EAA0E;QAC1E,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YAC/B,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,OAAqB,EAAE,MAA2B;QACtD,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC7C,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CA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any promise chain — a stray socket/timer callback, for instance) into a
|
|
5
|
+
* rejection of the returned promise instead of letting it kill the process.
|
|
6
|
+
*
|
|
7
|
+
* @param work The function to run.
|
|
8
|
+
* @returns A promise settling the same way `work` would have, had its crash
|
|
9
|
+
* been catchable normally.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rejectOnUncaught<T>(work: () => MaybePromiseLike<T>): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=guarded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guarded.d.ts","sourceRoot":"","sources":["../../src/process/guarded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,gBAAgB,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `work`, converting a process-level crash (a synchronous throw outside
|
|
3
|
+
* any promise chain — a stray socket/timer callback, for instance) into a
|
|
4
|
+
* rejection of the returned promise instead of letting it kill the process.
|
|
5
|
+
*
|
|
6
|
+
* @param work The function to run.
|
|
7
|
+
* @returns A promise settling the same way `work` would have, had its crash
|
|
8
|
+
* been catchable normally.
|
|
9
|
+
*/
|
|
10
|
+
export function rejectOnUncaught(work) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const onCrash = (error) => reject(error);
|
|
13
|
+
process.once("uncaughtException", onCrash);
|
|
14
|
+
Promise.resolve()
|
|
15
|
+
.then(work)
|
|
16
|
+
.then((value) => {
|
|
17
|
+
process.off("uncaughtException", onCrash);
|
|
18
|
+
resolve(value);
|
|
19
|
+
}, (error) => {
|
|
20
|
+
process.off("uncaughtException", onCrash);
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=guarded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guarded.js","sourceRoot":"","sources":["../../src/process/guarded.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC/B,IAA+B;IAE/B,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,OAAO,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,OAAO,EAAE;aACf,IAAI,CAAC,IAAI,CAAC;aACV,IAAI,CACJ,CAAC,KAAK,EAAE,EAAE;YACT,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;YAClB,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;YAC1C,MAAM,CAAC,KAAc,CAAC,CAAC;QACxB,CAAC,CACD,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type StartProcessOptions } from "./start-process.js";
|
|
2
|
+
/** Which of the child's streams are buffered into a {@link ProcessResult}. */
|
|
3
|
+
export type ProcessCapture = "both" | "stdout" | "stderr" | "none";
|
|
4
|
+
export type SpawnProcessOptions = StartProcessOptions & {
|
|
5
|
+
/** Default `"utf8"`. */
|
|
6
|
+
readonly encoding?: BufferEncoding | null;
|
|
7
|
+
/** Per-stream cap on what is buffered. Default 8 MiB. */
|
|
8
|
+
readonly maxBuffer?: number | null;
|
|
9
|
+
/** Default `"both"`. */
|
|
10
|
+
readonly capture?: ProcessCapture | null;
|
|
11
|
+
/** Throw on a non-zero exit code or a terminating signal. Default `true`. */
|
|
12
|
+
readonly throwOnNonZero?: boolean | null;
|
|
13
|
+
};
|
|
14
|
+
export type ProcessResult = {
|
|
15
|
+
code: number | null;
|
|
16
|
+
signal: NodeJS.Signals | null;
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Runs a command to completion and returns what it printed.
|
|
23
|
+
*
|
|
24
|
+
* The one-shot form of {@link startProcess}: no handle is exposed, so streaming
|
|
25
|
+
* consumers pass `onOutput` instead of subscribing.
|
|
26
|
+
*
|
|
27
|
+
* @param command The executable to run.
|
|
28
|
+
* @param args Arguments passed to it verbatim.
|
|
29
|
+
* @param options Capture limits and everything {@link StartProcessOptions}
|
|
30
|
+
* accepts.
|
|
31
|
+
* @returns The exit status and the captured streams.
|
|
32
|
+
* @throws {ProcessExitWithOutputError} On a non-zero exit, unless
|
|
33
|
+
* `throwOnNonZero` is `false`.
|
|
34
|
+
* @throws {RangeError} When either stream exceeds `maxBuffer`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function spawnProcess(command: string, args?: readonly string[], options?: SpawnProcessOptions): Promise<ProcessResult>;
|
|
37
|
+
//# sourceMappingURL=spawn-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-process.d.ts","sourceRoot":"","sources":["../../src/process/spawn-process.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,oBAAoB,CAAC;AAE5E,8EAA8E;AAC9E,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,GAAG;IACvD,wBAAwB;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAE1C,yDAAyD;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC,wBAAwB;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAEzC,6EAA6E;IAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CA4ExB"}
|