@rogatio/cli 6.6.2 → 6.6.3

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.
Files changed (2) hide show
  1. package/dist/node/index.js +65 -27
  2. package/package.json +1 -1
@@ -25210,8 +25210,68 @@ async function runNativeHost(options) {
25210
25210
  }
25211
25211
  await host.start();
25212
25212
  const stdin = options.stdin ?? process.stdin;
25213
- if (options.onReady) options.onReady();
25213
+ stdout.on("error", (error) => {
25214
+ if (error.code === "EPIPE") return;
25215
+ console.error("[rogatio-host] stdout error:", error.message);
25216
+ });
25214
25217
  let buffer = Buffer2.alloc(0);
25218
+ let commandChain = Promise.resolve();
25219
+ let pumping = false;
25220
+ function writeResponse2(response) {
25221
+ if (response && stdout.writable) {
25222
+ console.error(
25223
+ "[rogatio-host] writing response:",
25224
+ response.length,
25225
+ "bytes"
25226
+ );
25227
+ stdout.write(Buffer2.from(response));
25228
+ return;
25229
+ }
25230
+ console.error("[rogatio-host] no response to write");
25231
+ }
25232
+ function isHostReply(frame) {
25233
+ try {
25234
+ const envelope = decodeEnvelopeFrame(frame);
25235
+ return typeof envelope.requestId === "string" && envelope.requestId.startsWith("host-");
25236
+ } catch {
25237
+ return false;
25238
+ }
25239
+ }
25240
+ function dispatch(frame) {
25241
+ if (isHostReply(frame)) {
25242
+ void host.processFrame(frame).then(writeResponse2);
25243
+ return;
25244
+ }
25245
+ commandChain = commandChain.then(async () => {
25246
+ console.error(
25247
+ "[rogatio-host] processing frame:",
25248
+ frame.byteLength,
25249
+ "bytes"
25250
+ );
25251
+ writeResponse2(await host.processFrame(frame));
25252
+ }).catch((error) => {
25253
+ console.error(
25254
+ "[rogatio-host] frame failed:",
25255
+ error instanceof Error ? error.message : String(error)
25256
+ );
25257
+ });
25258
+ }
25259
+ function pump() {
25260
+ if (pumping) return;
25261
+ pumping = true;
25262
+ try {
25263
+ for (; ; ) {
25264
+ if (buffer.length < 4) break;
25265
+ const length = buffer.readUInt32LE(0);
25266
+ if (buffer.length < 4 + length) break;
25267
+ const frame = Buffer2.from(buffer.subarray(0, 4 + length));
25268
+ buffer = buffer.subarray(4 + length);
25269
+ dispatch(frame);
25270
+ }
25271
+ } finally {
25272
+ pumping = false;
25273
+ }
25274
+ }
25215
25275
  stdin.on("data", (chunk) => {
25216
25276
  const buf = Buffer2.isBuffer(chunk) ? Buffer2.from(chunk) : Buffer2.from(chunk);
25217
25277
  console.error(
@@ -25221,36 +25281,14 @@ async function runNativeHost(options) {
25221
25281
  buffer.length
25222
25282
  );
25223
25283
  buffer = Buffer2.concat([buffer, buf]);
25224
- void (async () => {
25225
- for (; ; ) {
25226
- if (buffer.length < 4) break;
25227
- const length = buffer.readUInt32LE(0);
25228
- if (buffer.length < 4 + length) break;
25229
- const frame = new Uint8Array(
25230
- buffer.buffer,
25231
- buffer.byteOffset,
25232
- 4 + length
25233
- );
25234
- console.error("[rogatio-host] processing frame:", 4 + length, "bytes");
25235
- const response = await host.processFrame(frame);
25236
- buffer = buffer.subarray(4 + length);
25237
- if (response && stdout.writable) {
25238
- console.error(
25239
- "[rogatio-host] writing response:",
25240
- response.length,
25241
- "bytes"
25242
- );
25243
- stdout.write(Buffer2.from(response));
25244
- } else {
25245
- console.error("[rogatio-host] no response to write");
25246
- }
25247
- }
25248
- })();
25284
+ pump();
25249
25285
  });
25250
25286
  await new Promise((resolve22) => {
25251
25287
  stdin.on("end", () => {
25252
- void host.stop().then(resolve22);
25288
+ void commandChain.finally(() => host.stop()).then(() => resolve22());
25253
25289
  });
25290
+ if (options.onReady) options.onReady();
25291
+ pump();
25254
25292
  });
25255
25293
  }
25256
25294
  var NATIVE_FRAME_MAX_BYTES = 64 * 1024;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogatio/cli",
3
- "version": "6.6.2",
3
+ "version": "6.6.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Local-first browser request and response rules — editor host, file verification, test runner, and runtime dispatch.",