posipaki 0.44.0 → 0.45.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/dist/{hooks-Dpbe39oa.d.ts → hooks-DO-efRM_.d.ts} +2 -2
- package/dist/{hooks-Dpbe39oa.d.ts.map → hooks-DO-efRM_.d.ts.map} +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/plugins/debug-logger.d.ts +2 -2
- package/dist/plugins/tree-introspection.d.ts +2 -2
- package/dist/{process-CoEKoY5f.d.ts → process-eCAv2tIS.d.ts} +2 -2
- package/dist/{process-CoEKoY5f.d.ts.map → process-eCAv2tIS.d.ts.map} +1 -1
- package/dist/remote/gateway-cli.js +1157 -50
- package/dist/remote/gateway-cli.js.map +1 -1
- package/dist/remote/index.d.ts +4 -232
- package/dist/remote/index.d.ts.map +1 -1
- package/dist/remote/index.js +2 -2
- package/dist/remote/index.js.map +1 -1
- package/dist/remote/node.d.ts +29 -54
- package/dist/remote/node.d.ts.map +1 -1
- package/dist/remote/node.js +128 -128
- package/dist/remote/node.js.map +1 -1
- package/dist/testing/index.d.ts +4 -4
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/{types-CuabnerI.d.ts → types-U3NvKgpg.d.ts} +10 -1
- package/dist/{types-CuabnerI.d.ts.map → types-U3NvKgpg.d.ts.map} +1 -1
- package/dist/{version-B6eNJRZD.js → version-yonmO5bG.js} +2 -2
- package/dist/{version-B6eNJRZD.js.map → version-yonmO5bG.js.map} +1 -1
- package/dist/websocket-DT8zKD34.d.ts +836 -0
- package/dist/websocket-DT8zKD34.d.ts.map +1 -0
- package/dist/{websocket-DecgMfb3.js → websocket-DkDAHMFm.js} +1102 -85
- package/dist/websocket-DkDAHMFm.js.map +1 -0
- package/dist/xfetch.d.ts +2 -2
- package/package.json +1 -1
- package/dist/websocket-DecgMfb3.js.map +0 -1
- package/dist/websocket-sGQcEDbm.d.ts +0 -310
- package/dist/websocket-sGQcEDbm.d.ts.map +0 -1
package/dist/remote/node.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as LIB_VERSION } from "../version-
|
|
2
|
-
import {
|
|
1
|
+
import { t as LIB_VERSION } from "../version-yonmO5bG.js";
|
|
2
|
+
import { A as errorReason$1, C as json1Channel, G as lowBand, O as channelThrough, R as isProto, a as remoteClient, b as VERSION, k as errorFrame$1, m as StreamStore, n as WebSocketTransport, o as pumpOutput, r as readParts, s as stderrSink, u as serveRemoteActor } from "../websocket-DkDAHMFm.js";
|
|
3
3
|
import { chmod, mkdir, mkdtemp, open, readFile, rm, stat, unlink } from "node:fs/promises";
|
|
4
|
-
import * as readline from "node:readline";
|
|
5
4
|
import { execFile, spawn } from "node:child_process";
|
|
6
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
6
|
import { tmpdir } from "node:os";
|
|
@@ -9,12 +8,13 @@ import { basename, dirname, join } from "node:path";
|
|
|
9
8
|
import { promisify } from "node:util";
|
|
10
9
|
import { fileURLToPath } from "node:url";
|
|
11
10
|
import { createReadStream, createWriteStream } from "node:fs";
|
|
12
|
-
import {
|
|
11
|
+
import { Writable } from "node:stream";
|
|
13
12
|
import { connect, createServer } from "node:net";
|
|
14
13
|
//#region src/remote/transports/fifo.ts
|
|
15
14
|
var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
16
15
|
constructor(opts) {
|
|
17
16
|
this.pvtOnMessage = null;
|
|
17
|
+
this.pvtOnBytes = null;
|
|
18
18
|
this.pvtOnClose = null;
|
|
19
19
|
this.closed = false;
|
|
20
20
|
this.closingPromise = null;
|
|
@@ -22,12 +22,10 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
22
22
|
this.readFd = opts.readFd ?? null;
|
|
23
23
|
this.writeFd = opts.writeFd ?? null;
|
|
24
24
|
if (this.readFd) {
|
|
25
|
-
this.rs = this.readFd.createReadStream(
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
this.rl.on("close", () => {
|
|
25
|
+
this.rs = this.readFd.createReadStream();
|
|
26
|
+
this.reader = readParts(this.rs, (line) => this.closed ? void 0 : this.pvtOnMessage?.(line), (bytes) => {
|
|
27
|
+
if (!this.closed) this.pvtOnBytes?.(bytes);
|
|
28
|
+
}, () => {
|
|
31
29
|
this.pvtOnClose?.();
|
|
32
30
|
this.close();
|
|
33
31
|
});
|
|
@@ -37,10 +35,10 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
37
35
|
});
|
|
38
36
|
} else {
|
|
39
37
|
this.rs = null;
|
|
40
|
-
this.
|
|
38
|
+
this.reader = null;
|
|
41
39
|
}
|
|
42
40
|
if (this.writeFd) {
|
|
43
|
-
this.ws = this.writeFd.createWriteStream({
|
|
41
|
+
this.ws = this.writeFd.createWriteStream({});
|
|
44
42
|
this.ws.on("error", (err) => {
|
|
45
43
|
this.pvtError = err;
|
|
46
44
|
this.close();
|
|
@@ -95,6 +93,11 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
95
93
|
get canSend() {
|
|
96
94
|
return this.writeFd !== null && !this.closed;
|
|
97
95
|
}
|
|
96
|
+
onBytes(handler) {
|
|
97
|
+
if (this.closed) throw new Error("FifoUtf8NlineTransport: closed");
|
|
98
|
+
if (this.readFd === null) throw new Error("FifoUtf8NlineTransport: not a reader");
|
|
99
|
+
this.pvtOnBytes = handler;
|
|
100
|
+
}
|
|
98
101
|
onMessage(handler) {
|
|
99
102
|
if (this.closed) throw new Error("FifoUtf8NlineTransport: closed");
|
|
100
103
|
if (this.readFd === null) throw new Error("FifoUtf8NlineTransport: not a reader");
|
|
@@ -121,6 +124,11 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
121
124
|
if (!line.endsWith("\n")) line += "\n";
|
|
122
125
|
await this.ws?.write(line);
|
|
123
126
|
}
|
|
127
|
+
async sendBytes(bytes) {
|
|
128
|
+
if (this.closed) throw new Error("FifoUtf8NlineTransport: closed");
|
|
129
|
+
if (this.writeFd === null) throw new Error("FifoUtf8NlineTransport: not a writer");
|
|
130
|
+
await this.ws?.write(bytes);
|
|
131
|
+
}
|
|
124
132
|
async close() {
|
|
125
133
|
this.closingPromise = this.closingPromise || this.pvtClose();
|
|
126
134
|
await this.closingPromise;
|
|
@@ -128,9 +136,9 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
128
136
|
}
|
|
129
137
|
async pvtClose() {
|
|
130
138
|
await Promise.resolve();
|
|
131
|
-
if (this.
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
139
|
+
if (this.reader) {
|
|
140
|
+
this.reader.stop();
|
|
141
|
+
this.reader = null;
|
|
134
142
|
}
|
|
135
143
|
if (this.rs) {
|
|
136
144
|
this.rs.destroy();
|
|
@@ -621,15 +629,14 @@ function errorText$2(err) {
|
|
|
621
629
|
var LineTransport = class {
|
|
622
630
|
constructor(streams) {
|
|
623
631
|
this.pvtOnMessage = null;
|
|
632
|
+
this.pvtOnBytes = null;
|
|
624
633
|
this.pvtOnClose = null;
|
|
625
634
|
this.pvtClosed = false;
|
|
626
635
|
this.pvtClosing = null;
|
|
627
636
|
this.streams = streams;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
});
|
|
632
|
-
lines.on("close", () => {
|
|
637
|
+
readParts(streams.read, (line) => this.pvtClosed ? void 0 : this.pvtOnMessage?.(line), (bytes) => {
|
|
638
|
+
if (!this.pvtClosed) this.pvtOnBytes?.(bytes);
|
|
639
|
+
}, () => {
|
|
633
640
|
this.pvtOnClose?.();
|
|
634
641
|
this.close();
|
|
635
642
|
});
|
|
@@ -651,6 +658,10 @@ var LineTransport = class {
|
|
|
651
658
|
if (this.pvtOnMessage !== null) throw new StdioWireError("stdio transport: handler already set — call removeHandler()");
|
|
652
659
|
this.pvtOnMessage = handler;
|
|
653
660
|
}
|
|
661
|
+
onBytes(handler) {
|
|
662
|
+
if (this.pvtClosed) throw new StdioWireError("stdio transport: closed");
|
|
663
|
+
this.pvtOnBytes = handler;
|
|
664
|
+
}
|
|
654
665
|
removeHandler() {
|
|
655
666
|
const previous = this.pvtOnMessage;
|
|
656
667
|
this.pvtOnMessage = null;
|
|
@@ -660,11 +671,17 @@ var LineTransport = class {
|
|
|
660
671
|
this.pvtOnClose = handler;
|
|
661
672
|
}
|
|
662
673
|
send(frame) {
|
|
663
|
-
if (this.pvtClosed) return Promise.resolve();
|
|
664
674
|
const line = frame.endsWith("\n") ? frame : `${frame}\n`;
|
|
675
|
+
return this.pvtWrite(line);
|
|
676
|
+
}
|
|
677
|
+
sendBytes(bytes) {
|
|
678
|
+
return this.pvtWrite(bytes);
|
|
679
|
+
}
|
|
680
|
+
pvtWrite(data) {
|
|
681
|
+
if (this.pvtClosed) return Promise.resolve();
|
|
665
682
|
return new Promise((resolve, reject) => {
|
|
666
683
|
try {
|
|
667
|
-
this.streams.write.write(
|
|
684
|
+
this.streams.write.write(data, (err) => {
|
|
668
685
|
if (!err) return resolve();
|
|
669
686
|
const code = err.code;
|
|
670
687
|
if (peerGone(code)) return resolve();
|
|
@@ -695,28 +712,20 @@ function fdStreams(readFd, writeFd) {
|
|
|
695
712
|
return {
|
|
696
713
|
read: createReadStream("", {
|
|
697
714
|
fd: readFd,
|
|
698
|
-
encoding: "utf-8",
|
|
699
715
|
autoClose: false
|
|
700
716
|
}),
|
|
701
717
|
write: createWriteStream("", {
|
|
702
718
|
fd: writeFd,
|
|
703
|
-
encoding: "utf-8",
|
|
704
719
|
autoClose: false
|
|
705
720
|
})
|
|
706
721
|
};
|
|
707
722
|
}
|
|
708
|
-
/** The next frame that is the protocol's, or a timeout.
|
|
709
|
-
|
|
710
|
-
async function nextFrame(channel, timeoutMs, sink) {
|
|
723
|
+
/** The next frame that is the protocol's, or a timeout. */
|
|
724
|
+
async function nextFrame(channel, timeoutMs) {
|
|
711
725
|
return await new Promise((resolve, reject) => {
|
|
712
726
|
const timer = setTimeout(() => reject(new StdioWireError(`no protocol frame within ${timeoutMs}ms`)), timeoutMs);
|
|
713
727
|
timer.unref?.();
|
|
714
728
|
const off = channel.onMessage((frame) => {
|
|
715
|
-
const output = outputOf(frame);
|
|
716
|
-
if (output) {
|
|
717
|
-
sink(output.fd, output.data);
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
729
|
off();
|
|
721
730
|
clearTimeout(timer);
|
|
722
731
|
resolve(frame);
|
|
@@ -724,19 +733,20 @@ async function nextFrame(channel, timeoutMs, sink) {
|
|
|
724
733
|
});
|
|
725
734
|
}
|
|
726
735
|
/**
|
|
727
|
-
* The client end of the connection: hand the streams to the seam and wait for the peer's `$proto
|
|
728
|
-
*
|
|
729
|
-
*
|
|
736
|
+
* The client end of the connection: hand the streams to the seam and wait for the peer's `$proto`.
|
|
737
|
+
* A first stage reports a failed start as an `$error` frame instead.
|
|
738
|
+
*
|
|
739
|
+
* What the far end prints is not here: it arrives as a stream the far end announces under a name,
|
|
740
|
+
* and whoever wants it reads it by that name.
|
|
730
741
|
*/
|
|
731
742
|
async function clientChannel(streams, opts = {}) {
|
|
732
743
|
const channel = json1Channel(new LineTransport(streams));
|
|
733
|
-
const
|
|
734
|
-
const frame = await nextFrame(channel, opts.timeoutMs ?? 15e3, sink);
|
|
744
|
+
const frame = await nextFrame(channel, opts.timeoutMs ?? 15e3);
|
|
735
745
|
const reason = errorReason(frame);
|
|
736
746
|
if (reason) throw new StdioWireError(reason);
|
|
737
747
|
if (!isProto(frame)) throw new StdioWireError(`unexpected first frame: ${JSON.stringify(frame).slice(0, 120)}`);
|
|
738
748
|
if (frame.$proto !== "json.v1") throw new StdioWireError(`unsupported protocol ${String(frame.$proto)}, expected ${VERSION}`);
|
|
739
|
-
return
|
|
749
|
+
return channel;
|
|
740
750
|
}
|
|
741
751
|
/** The server end of the wire — a payload speaking stdio itself. */
|
|
742
752
|
async function serverChannel(streams) {
|
|
@@ -747,64 +757,12 @@ async function serverChannel(streams) {
|
|
|
747
757
|
//#endregion
|
|
748
758
|
//#region src/remote/streams.ts
|
|
749
759
|
/**
|
|
750
|
-
* A writable that
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
* own output and holds no channel — and a send that fails is the stream's error, not a lost line.
|
|
754
|
-
*/
|
|
755
|
-
function fdWriter(send, fd) {
|
|
756
|
-
return new Writable({ write(chunk, _encoding, done) {
|
|
757
|
-
Promise.resolve(send(outputFrame(fd, String(chunk)))).then(() => done(), (error) => done(error));
|
|
758
|
-
} });
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* The byte streams of a connection: what each end's root prints, and what it reads.
|
|
762
|
-
*
|
|
763
|
-
* The frames are the connection's, so anyone may also read them directly (`Channel.onMessage`); what
|
|
764
|
-
* this adds is the shape a program outside the seam already speaks.
|
|
765
|
-
*/
|
|
766
|
-
function connectionFds(channel) {
|
|
767
|
-
const sides = /* @__PURE__ */ new Map();
|
|
768
|
-
const side = (fd) => {
|
|
769
|
-
const read = new PassThrough();
|
|
770
|
-
const stream = {
|
|
771
|
-
read,
|
|
772
|
-
write: fdWriter((frame) => channel.send(frame), fd)
|
|
773
|
-
};
|
|
774
|
-
sides.set(fd, {
|
|
775
|
-
stream,
|
|
776
|
-
read
|
|
777
|
-
});
|
|
778
|
-
return stream;
|
|
779
|
-
};
|
|
780
|
-
const stdin = side(0);
|
|
781
|
-
const stdout = side(1);
|
|
782
|
-
const stderr = side(2);
|
|
783
|
-
const off = channel.onMessage((frame) => {
|
|
784
|
-
const output = outputOf(frame);
|
|
785
|
-
if (!output) return;
|
|
786
|
-
sides.get(output.fd)?.read.push(output.data);
|
|
787
|
-
});
|
|
788
|
-
return {
|
|
789
|
-
stdin,
|
|
790
|
-
stdout,
|
|
791
|
-
stderr,
|
|
792
|
-
close() {
|
|
793
|
-
off();
|
|
794
|
-
for (const { stream, read } of sides.values()) {
|
|
795
|
-
read.end();
|
|
796
|
-
stream.write.end();
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* A writable that turns what is written to it into log lines: fd 1 arrives as `info` and fd 2 as
|
|
803
|
-
* `warn`, and the tail is held until a newline (or the end) so a chunk boundary is not a line
|
|
804
|
-
* boundary.
|
|
760
|
+
* A writable that turns what is written to it into log lines: `stderr` arrives as `warn` and every
|
|
761
|
+
* other name as `info`, and the tail is held until a newline (or the end) so a chunk boundary is not
|
|
762
|
+
* a line boundary.
|
|
805
763
|
*/
|
|
806
764
|
function logStream(log, opts = {}) {
|
|
807
|
-
const warn = opts.
|
|
765
|
+
const warn = opts.name === "stderr";
|
|
808
766
|
const say = (line) => {
|
|
809
767
|
if (warn) log.warn(line);
|
|
810
768
|
else log.info(line);
|
|
@@ -880,13 +838,13 @@ async function fail(wire, reason) {
|
|
|
880
838
|
await wire.send(errorFrame(reason));
|
|
881
839
|
} catch {}
|
|
882
840
|
}
|
|
883
|
-
/**
|
|
884
|
-
function
|
|
885
|
-
|
|
886
|
-
const
|
|
887
|
-
out.on("error", () => {});
|
|
888
|
-
stream.pipe(out, { end: false });
|
|
841
|
+
/** The payload's own prints, as a stream: the pipe's chunks as they arrive. */
|
|
842
|
+
async function* chunksOf(stream, prefix = "") {
|
|
843
|
+
if (prefix.length > 0) yield new TextEncoder().encode(prefix);
|
|
844
|
+
for await (const chunk of stream) yield typeof chunk === "string" ? new TextEncoder().encode(chunk) : new Uint8Array(chunk);
|
|
889
845
|
}
|
|
846
|
+
/** Everything a payload printed into its pipes, up to the point they end: what a start that dies
|
|
847
|
+
* before its channel says about itself. A stream cannot carry it — there is no connection yet. */
|
|
890
848
|
/**
|
|
891
849
|
* Serve one environment over stdin/stdout. Returns the exit code; the caller
|
|
892
850
|
* turns it into `process.exitCode`.
|
|
@@ -896,6 +854,11 @@ async function runGateway(argv = process.argv.slice(2)) {
|
|
|
896
854
|
read: process.stdin,
|
|
897
855
|
write: process.stdout
|
|
898
856
|
});
|
|
857
|
+
const client = json1Channel(wire);
|
|
858
|
+
const output = new StreamStore(client, "even", {
|
|
859
|
+
ids: lowBand("even"),
|
|
860
|
+
attach: false
|
|
861
|
+
});
|
|
899
862
|
let booted;
|
|
900
863
|
try {
|
|
901
864
|
booted = gatewayBoot(argv);
|
|
@@ -960,8 +923,39 @@ async function runGateway(argv = process.argv.slice(2)) {
|
|
|
960
923
|
"pipe"
|
|
961
924
|
] });
|
|
962
925
|
child = workerProc;
|
|
963
|
-
|
|
964
|
-
|
|
926
|
+
/** What the payload printed before the client spoke: a start that dies that early has no connection
|
|
927
|
+
* to announce a stream on, and its words are the only way to say why it went. Kept per stream, so
|
|
928
|
+
* the output that comes after is still attributed to the right one. */
|
|
929
|
+
const early = {
|
|
930
|
+
stdout: "",
|
|
931
|
+
stderr: ""
|
|
932
|
+
};
|
|
933
|
+
const keep = (name) => (chunk) => {
|
|
934
|
+
early[name] = (early[name] + String(chunk)).slice(-4096);
|
|
935
|
+
};
|
|
936
|
+
const keepOut = keep("stdout");
|
|
937
|
+
const keepErr = keep("stderr");
|
|
938
|
+
workerProc.stdout?.on("data", keepOut);
|
|
939
|
+
workerProc.stderr?.on("data", keepErr);
|
|
940
|
+
/** Announce the payload's own output as the two streams a program's prints belong on, with whatever
|
|
941
|
+
* it said before the connection could carry it replayed as the first chunk. */
|
|
942
|
+
const offerOutput = () => {
|
|
943
|
+
const sides = [{
|
|
944
|
+
stream: workerProc.stdout,
|
|
945
|
+
name: "stdout",
|
|
946
|
+
keep: keepOut
|
|
947
|
+
}, {
|
|
948
|
+
stream: workerProc.stderr,
|
|
949
|
+
name: "stderr",
|
|
950
|
+
keep: keepErr
|
|
951
|
+
}];
|
|
952
|
+
for (const { stream, name, keep: drop } of sides) {
|
|
953
|
+
if (!stream) continue;
|
|
954
|
+
stream.off("data", drop);
|
|
955
|
+
stream.pause();
|
|
956
|
+
output.offer(chunksOf(stream, early[name]), name);
|
|
957
|
+
}
|
|
958
|
+
};
|
|
965
959
|
const exited = new Promise((settle) => {
|
|
966
960
|
workerProc.once("exit", (code) => settle(code ?? 0));
|
|
967
961
|
});
|
|
@@ -970,18 +964,34 @@ async function runGateway(argv = process.argv.slice(2)) {
|
|
|
970
964
|
throw new Error(`the payload exited with code ${code} before it opened its channel`);
|
|
971
965
|
})]);
|
|
972
966
|
} catch (err) {
|
|
973
|
-
|
|
967
|
+
const said = `${early.stdout}${early.stderr}`.trim();
|
|
968
|
+
await fail(wire, `${errorText$1(err)}${said ? `: ${said}` : ""}`);
|
|
974
969
|
await teardown();
|
|
975
970
|
abandon();
|
|
976
971
|
}
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
972
|
+
const payload = json1Channel(fifo);
|
|
973
|
+
const fromClient = channelThrough(client, (frame) => output.handle(frame));
|
|
974
|
+
const forward = (send, frame) => {
|
|
975
|
+
Promise.resolve(send(frame)).catch(() => {});
|
|
976
|
+
};
|
|
977
|
+
let offered = false;
|
|
978
|
+
fromClient.onMessage((frame) => {
|
|
979
|
+
if (!offered) {
|
|
980
|
+
offered = true;
|
|
981
|
+
offerOutput();
|
|
982
|
+
}
|
|
983
|
+
forward((next) => payload.send(next), frame);
|
|
984
|
+
});
|
|
985
|
+
fromClient.onSegment?.((head, bytes) => {
|
|
986
|
+
payload.sendSegment?.(head, bytes);
|
|
980
987
|
});
|
|
981
|
-
|
|
982
|
-
|
|
988
|
+
payload.onMessage((frame) => {
|
|
989
|
+
forward((next) => client.send(next), frame);
|
|
983
990
|
});
|
|
984
|
-
|
|
991
|
+
payload.onSegment?.((head, bytes) => {
|
|
992
|
+
client.sendSegment?.(head, bytes);
|
|
993
|
+
});
|
|
994
|
+
client.onClose(() => {
|
|
985
995
|
child?.kill();
|
|
986
996
|
});
|
|
987
997
|
const code = await exited;
|
|
@@ -1123,12 +1133,6 @@ async function stageKit(spec, kit, run) {
|
|
|
1123
1133
|
* answers.
|
|
1124
1134
|
*/
|
|
1125
1135
|
async function openChannel(spec, command, spawn) {
|
|
1126
|
-
const sink = spec.onOutput ?? stderrSink(spec.name);
|
|
1127
|
-
let tail = "";
|
|
1128
|
-
const output = (fd, data) => {
|
|
1129
|
-
if (fd === 2) tail = (tail + data).slice(-400);
|
|
1130
|
-
sink(fd, data);
|
|
1131
|
-
};
|
|
1132
1136
|
const child = spawn(command, [
|
|
1133
1137
|
"pipe",
|
|
1134
1138
|
"pipe",
|
|
@@ -1139,7 +1143,12 @@ async function openChannel(spec, command, spawn) {
|
|
|
1139
1143
|
write: child.stdin
|
|
1140
1144
|
};
|
|
1141
1145
|
child.stderr?.setEncoding("utf-8");
|
|
1142
|
-
child.stderr?.on("data", (chunk) =>
|
|
1146
|
+
child.stderr?.on("data", (chunk) => {
|
|
1147
|
+
tail = (tail + chunk).slice(-400);
|
|
1148
|
+
sink("stderr", chunk);
|
|
1149
|
+
});
|
|
1150
|
+
const sink = spec.onOutput ?? stderrSink(spec.name);
|
|
1151
|
+
let tail = "";
|
|
1143
1152
|
const exited = new Promise((_, reject) => {
|
|
1144
1153
|
child.once("close", (code, signal) => {
|
|
1145
1154
|
const how = signal === null ? `code ${code}` : `signal ${signal}`;
|
|
@@ -1151,10 +1160,7 @@ async function openChannel(spec, command, spawn) {
|
|
|
1151
1160
|
exited.catch(() => {});
|
|
1152
1161
|
let channel;
|
|
1153
1162
|
try {
|
|
1154
|
-
channel = await Promise.race([clientChannel(streams, {
|
|
1155
|
-
onOutput: output,
|
|
1156
|
-
...spec.handshakeTimeoutMs === void 0 ? {} : { timeoutMs: spec.handshakeTimeoutMs }
|
|
1157
|
-
}), exited]);
|
|
1163
|
+
channel = await Promise.race([clientChannel(streams, { ...spec.handshakeTimeoutMs === void 0 ? {} : { timeoutMs: spec.handshakeTimeoutMs } }), exited]);
|
|
1158
1164
|
} catch (err) {
|
|
1159
1165
|
child.kill();
|
|
1160
1166
|
throw new RemoteSpecError(`${spec.name} is not available: ${errorText(err)}`);
|
|
@@ -1333,20 +1339,14 @@ function socketClientSpawner(path, options = {}) {
|
|
|
1333
1339
|
return async (args) => {
|
|
1334
1340
|
const transport = await connectUnixSocket(typeof path === "function" ? path(args) : path, options);
|
|
1335
1341
|
const channel = json1Channel(transport);
|
|
1336
|
-
const sink = options.onOutput ?? stderrSink();
|
|
1337
1342
|
const first = await new Promise((resolve) => {
|
|
1338
1343
|
const off = channel.onMessage((frame) => {
|
|
1339
|
-
const output = outputOf(frame);
|
|
1340
|
-
if (output) {
|
|
1341
|
-
sink(output.fd, output.data);
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
1344
|
off();
|
|
1345
1345
|
resolve(frame);
|
|
1346
1346
|
});
|
|
1347
1347
|
});
|
|
1348
1348
|
if (!isProto(first) || first.$proto !== "json.v1") throw new Error(`unsupported protocol: ${JSON.stringify(first)}`);
|
|
1349
|
-
return
|
|
1349
|
+
return channel;
|
|
1350
1350
|
};
|
|
1351
1351
|
}
|
|
1352
1352
|
//#endregion
|
|
@@ -1455,6 +1455,6 @@ function webSocketListener(options) {
|
|
|
1455
1455
|
};
|
|
1456
1456
|
}
|
|
1457
1457
|
//#endregion
|
|
1458
|
-
export { DEFAULT_KIT_PARENT, DEFAULT_RUNTIMES, FifoUtf8NlineTransport, GATEWAY_ARTIFACT, GATEWAY_ENTRY, GATEWAY_FAILED, HANDSHAKE_TIMEOUT_MS, HostVersionError, KIT_LAYOUT, LineTransport, PAYLOAD_ARTIFACT, PAYLOAD_REFUSED, RemoteSpecError, StdioWireError, bootstrapScript, clientChannel, commandSpawner, connectUnixSocket,
|
|
1458
|
+
export { DEFAULT_KIT_PARENT, DEFAULT_RUNTIMES, FifoUtf8NlineTransport, GATEWAY_ARTIFACT, GATEWAY_ENTRY, GATEWAY_FAILED, HANDSHAKE_TIMEOUT_MS, HostVersionError, KIT_LAYOUT, LineTransport, PAYLOAD_ARTIFACT, PAYLOAD_REFUSED, RemoteSpecError, StdioWireError, bootstrapScript, clientChannel, commandSpawner, connectUnixSocket, defineSubprocessActor, errorFrame, errorReason, fdStreams, fifoArgvSpawner, fifoClientSpawner, fifoListener, gatewayArgs, gatewayBoot, gatewayClient, hostRemote, hostVersion, hostVersionAccepts, kitVersion, logStream, makeFifoPair, makeKit, parseBootstrapReport, parseHostVersion, pumpOutput, runGateway, runHost, sameHostVersion, serverChannel, sha256Hex, socketClientSpawner, spawnChild, stderrSink, unixSocketListener, webSocketListener };
|
|
1459
1459
|
|
|
1460
1460
|
//# sourceMappingURL=node.js.map
|