@polyengine/wasi 0.6.3 → 0.6.5

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/esm/cli.js CHANGED
@@ -45,14 +45,19 @@ function concat(chunks) {
45
45
  export function cli(options = {}) {
46
46
  const stdoutChunks = [];
47
47
  const stderrChunks = [];
48
+ const passthrough = options.passthrough ?? false;
48
49
  let exited = false;
49
50
  let exitOk;
50
51
  let exitCode;
51
52
  const stdout = new OutputStream((chunk) => {
52
53
  stdoutChunks.push(chunk);
54
+ if (passthrough)
55
+ console.log(new TextDecoder().decode(chunk));
53
56
  });
54
57
  const stderr = new OutputStream((chunk) => {
55
58
  stderrChunks.push(chunk);
59
+ if (passthrough)
60
+ console.error(new TextDecoder().decode(chunk));
56
61
  });
57
62
  const captured = {
58
63
  stdout: () => concat(stdoutChunks),
@@ -64,10 +69,11 @@ export function cli(options = {}) {
64
69
  exitCode: () => exitCode,
65
70
  };
66
71
  /** 0.3 write-via-stream into a capture buffer (the promise IS the future — embedder-api.md §"Streams and futures"). */
67
- const captureViaStream = (chunks) => async (data) => {
72
+ const captureViaStream = (chunks, mirror) => async (data) => {
68
73
  for await (const chunk of data) {
69
74
  const bytes = chunk instanceof Uint8Array ? chunk : Uint8Array.from(chunk);
70
75
  chunks.push(bytes);
76
+ mirror?.(new TextDecoder().decode(bytes));
71
77
  }
72
78
  return { kind: "ok" };
73
79
  };
@@ -134,10 +140,10 @@ export function cli(options = {}) {
134
140
  ],
135
141
  },
136
142
  "wasi:cli/stdout@0.3": {
137
- writeViaStream: captureViaStream(stdoutChunks),
143
+ writeViaStream: captureViaStream(stdoutChunks, passthrough ? (t) => console.log(t) : undefined),
138
144
  },
139
145
  "wasi:cli/stderr@0.3": {
140
- writeViaStream: captureViaStream(stderrChunks),
146
+ writeViaStream: captureViaStream(stderrChunks, passthrough ? (t) => console.error(t) : undefined),
141
147
  },
142
148
  "wasi:cli/terminal-input@0.3": { TerminalInput },
143
149
  "wasi:cli/terminal-output@0.3": { TerminalOutput },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyengine/wasi",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "WASI providers for polyengine hosts: the p2 baseline and p3 clocks, one module per semver track.",
5
5
  "homepage": "https://github.com/polymorph-components/polyengine#readme",
6
6
  "repository": {
package/types/cli.d.ts CHANGED
@@ -8,6 +8,13 @@ export interface CliOptions {
8
8
  cwd?: string;
9
9
  /** `get-stdin`'s buffer contents; default empty (matches contract: "stdin (empty)"). */
10
10
  stdinBuffer?: Uint8Array;
11
+ /**
12
+ * Also `console.log`/`console.error` captured stdout/stderr writes as
13
+ * they happen. Default false. For embedders whose guest's stderr is its
14
+ * only diagnostic channel (lann/wosh): a buffer nobody reads is a black
15
+ * box exactly when something is going wrong.
16
+ */
17
+ passthrough?: boolean;
11
18
  /** `exit()` throws `ExitError` instead of merely recording. Default false. */
12
19
  throwOnExit?: boolean;
13
20
  }