@seanhogg/builderforce-webcontainers-core 2026.10.11 → 2026.10.13

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 (199) hide show
  1. package/dist/archive.d.ts +25 -2
  2. package/dist/archive.d.ts.map +1 -1
  3. package/dist/archive.js +45 -6
  4. package/dist/archive.js.map +1 -1
  5. package/dist/attribution.js.map +1 -1
  6. package/dist/check/acquire.js.map +1 -1
  7. package/dist/check/typeStore.d.ts.map +1 -1
  8. package/dist/compileScript.js.map +1 -1
  9. package/dist/devServer.d.ts +2 -0
  10. package/dist/devServer.d.ts.map +1 -1
  11. package/dist/devServer.js +2 -2
  12. package/dist/devServer.js.map +1 -1
  13. package/dist/hot/moduleGraph.d.ts.map +1 -1
  14. package/dist/html.d.ts +5 -2
  15. package/dist/html.d.ts.map +1 -1
  16. package/dist/html.js +9 -7
  17. package/dist/html.js.map +1 -1
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +2 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/installer/npmrc.js.map +1 -1
  23. package/dist/installer/registry.d.ts.map +1 -1
  24. package/dist/installer/registry.js.map +1 -1
  25. package/dist/installer/semver.js.map +1 -1
  26. package/dist/installer/tree.d.ts +2 -2
  27. package/dist/installer/tree.d.ts.map +1 -1
  28. package/dist/node/assert.d.ts.map +1 -1
  29. package/dist/node/buffer.d.ts.map +1 -1
  30. package/dist/node/buffer.js.map +1 -1
  31. package/dist/node/callable.js.map +1 -1
  32. package/dist/node/crypto.d.ts.map +1 -1
  33. package/dist/node/crypto.js +6 -2
  34. package/dist/node/crypto.js.map +1 -1
  35. package/dist/node/events.d.ts.map +1 -1
  36. package/dist/node/events.js.map +1 -1
  37. package/dist/node/fs/index.js.map +1 -1
  38. package/dist/node/fs/stats.d.ts.map +1 -1
  39. package/dist/node/fs/stats.js.map +1 -1
  40. package/dist/node/fs/sync.d.ts +1 -1
  41. package/dist/node/fs/sync.d.ts.map +1 -1
  42. package/dist/node/fs/sync.js.map +1 -1
  43. package/dist/node/hostClock.d.ts +14 -0
  44. package/dist/node/hostClock.d.ts.map +1 -0
  45. package/dist/node/hostClock.js +15 -0
  46. package/dist/node/hostClock.js.map +1 -0
  47. package/dist/node/http/client.d.ts.map +1 -1
  48. package/dist/node/http/client.js.map +1 -1
  49. package/dist/node/http/index.js.map +1 -1
  50. package/dist/node/http/messages.d.ts.map +1 -1
  51. package/dist/node/http/messages.js.map +1 -1
  52. package/dist/node/http/server.d.ts.map +1 -1
  53. package/dist/node/http/server.js +10 -1
  54. package/dist/node/http/server.js.map +1 -1
  55. package/dist/node/http/serverResponse.d.ts +2 -1
  56. package/dist/node/http/serverResponse.d.ts.map +1 -1
  57. package/dist/node/http/serverResponse.js +4 -2
  58. package/dist/node/http/serverResponse.js.map +1 -1
  59. package/dist/node/http/upgradeSocket.d.ts.map +1 -1
  60. package/dist/node/http/upgradeSocket.js.map +1 -1
  61. package/dist/node/inspect.d.ts +2 -2
  62. package/dist/node/inspect.d.ts.map +1 -1
  63. package/dist/node/inspect.js.map +1 -1
  64. package/dist/node/loader.d.ts.map +1 -1
  65. package/dist/node/loader.js.map +1 -1
  66. package/dist/node/loop.d.ts.map +1 -1
  67. package/dist/node/loop.js.map +1 -1
  68. package/dist/node/misc.d.ts.map +1 -1
  69. package/dist/node/misc.js +3 -2
  70. package/dist/node/misc.js.map +1 -1
  71. package/dist/node/process.d.ts.map +1 -1
  72. package/dist/node/process.js +9 -8
  73. package/dist/node/process.js.map +1 -1
  74. package/dist/node/processExit.d.ts.map +1 -1
  75. package/dist/node/processExit.js.map +1 -1
  76. package/dist/node/readline.js.map +1 -1
  77. package/dist/node/resolve.d.ts +2 -2
  78. package/dist/node/resolve.d.ts.map +1 -1
  79. package/dist/node/runtime.d.ts.map +1 -1
  80. package/dist/node/runtime.js +2 -2
  81. package/dist/node/runtime.js.map +1 -1
  82. package/dist/node/stream/index.d.ts.map +1 -1
  83. package/dist/node/stream/index.js.map +1 -1
  84. package/dist/node/stream/readable.d.ts.map +1 -1
  85. package/dist/node/stream/readable.js.map +1 -1
  86. package/dist/node/stream/writable.d.ts.map +1 -1
  87. package/dist/node/stream/writable.js.map +1 -1
  88. package/dist/node/util.d.ts +2 -2
  89. package/dist/node/util.d.ts.map +1 -1
  90. package/dist/node/util.js.map +1 -1
  91. package/dist/node/wasi/abi.d.ts.map +1 -1
  92. package/dist/node/wasi/abi.js.map +1 -1
  93. package/dist/node/wasi/files.d.ts.map +1 -1
  94. package/dist/node/wasi/index.d.ts.map +1 -1
  95. package/dist/node/wasi/index.js +2 -1
  96. package/dist/node/wasi/index.js.map +1 -1
  97. package/dist/node/workerThreads.js.map +1 -1
  98. package/dist/packageCdn.js.map +1 -1
  99. package/dist/previewBridge.d.ts +15 -3
  100. package/dist/previewBridge.d.ts.map +1 -1
  101. package/dist/previewBridge.js +30 -8
  102. package/dist/previewBridge.js.map +1 -1
  103. package/dist/projectConfig.d.ts +1 -1
  104. package/dist/projectConfig.d.ts.map +1 -1
  105. package/dist/projectConfig.js.map +1 -1
  106. package/dist/resolve.d.ts +1 -1
  107. package/dist/resolve.d.ts.map +1 -1
  108. package/dist/rootedFs.d.ts +7 -0
  109. package/dist/rootedFs.d.ts.map +1 -1
  110. package/dist/rootedFs.js +22 -2
  111. package/dist/rootedFs.js.map +1 -1
  112. package/dist/shell/builtins.d.ts +3 -0
  113. package/dist/shell/builtins.d.ts.map +1 -1
  114. package/dist/shell/builtins.js +4 -4
  115. package/dist/shell/builtins.js.map +1 -1
  116. package/dist/shell/compound.js.map +1 -1
  117. package/dist/shell/context.js.map +1 -1
  118. package/dist/shell/exec.d.ts +15 -3
  119. package/dist/shell/exec.d.ts.map +1 -1
  120. package/dist/shell/exec.js +47 -7
  121. package/dist/shell/exec.js.map +1 -1
  122. package/dist/shell/expand.js.map +1 -1
  123. package/dist/shell/lineEditor.d.ts.map +1 -1
  124. package/dist/shell/lineEditor.js.map +1 -1
  125. package/dist/shell/npm.d.ts.map +1 -1
  126. package/dist/shell/npm.js +6 -2
  127. package/dist/shell/npm.js.map +1 -1
  128. package/dist/shell/options.d.ts +37 -0
  129. package/dist/shell/options.d.ts.map +1 -0
  130. package/dist/shell/options.js +86 -0
  131. package/dist/shell/options.js.map +1 -0
  132. package/dist/shell/packageManagers.d.ts +2 -2
  133. package/dist/shell/packageManagers.d.ts.map +1 -1
  134. package/dist/shell/parse.js.map +1 -1
  135. package/dist/shell/program.d.ts +4 -0
  136. package/dist/shell/program.d.ts.map +1 -1
  137. package/dist/shell/program.js +20 -8
  138. package/dist/shell/program.js.map +1 -1
  139. package/dist/shell/testCommand.js.map +1 -1
  140. package/dist/shell/textCommands.d.ts.map +1 -1
  141. package/dist/shell/textCommands.js +3 -1
  142. package/dist/shell/textCommands.js.map +1 -1
  143. package/dist/shell/tokenize.d.ts.map +1 -1
  144. package/dist/shell/tokenize.js.map +1 -1
  145. package/dist/styles/imports.d.ts.map +1 -1
  146. package/dist/system/commands.d.ts +1 -1
  147. package/dist/system/commands.d.ts.map +1 -1
  148. package/dist/system/cookieJar.d.ts.map +1 -1
  149. package/dist/system/httpStream.d.ts +16 -4
  150. package/dist/system/httpStream.d.ts.map +1 -1
  151. package/dist/system/httpStream.js +25 -3
  152. package/dist/system/httpStream.js.map +1 -1
  153. package/dist/system/index.d.ts +1 -0
  154. package/dist/system/index.d.ts.map +1 -1
  155. package/dist/system/index.js +1 -0
  156. package/dist/system/index.js.map +1 -1
  157. package/dist/system/ipc.js.map +1 -1
  158. package/dist/system/kernel.d.ts.map +1 -1
  159. package/dist/system/kernel.js.map +1 -1
  160. package/dist/system/ports.d.ts.map +1 -1
  161. package/dist/system/process.js.map +1 -1
  162. package/dist/system/serverEvents.d.ts.map +1 -1
  163. package/dist/system/signals.d.ts +26 -0
  164. package/dist/system/signals.d.ts.map +1 -0
  165. package/dist/system/signals.js +36 -0
  166. package/dist/system/signals.js.map +1 -0
  167. package/dist/system/terminal.d.ts +13 -1
  168. package/dist/system/terminal.d.ts.map +1 -1
  169. package/dist/system/terminal.js +49 -0
  170. package/dist/system/terminal.js.map +1 -1
  171. package/dist/system/webSocketFrames.d.ts.map +1 -1
  172. package/dist/system/webSocketFrames.js.map +1 -1
  173. package/dist/vfs.d.ts.map +1 -1
  174. package/dist/vfs.js.map +1 -1
  175. package/package.json +6 -5
  176. package/src/archive.ts +46 -6
  177. package/src/devServer.ts +4 -2
  178. package/src/html.ts +11 -7
  179. package/src/index.ts +3 -3
  180. package/src/node/crypto.ts +6 -1
  181. package/src/node/hostClock.ts +16 -0
  182. package/src/node/http/server.ts +9 -1
  183. package/src/node/http/serverResponse.ts +5 -3
  184. package/src/node/misc.ts +3 -2
  185. package/src/node/process.ts +9 -8
  186. package/src/node/runtime.ts +2 -3
  187. package/src/node/wasi/index.ts +2 -1
  188. package/src/previewBridge.ts +31 -9
  189. package/src/rootedFs.ts +21 -2
  190. package/src/shell/builtins.ts +6 -4
  191. package/src/shell/exec.ts +52 -10
  192. package/src/shell/npm.ts +5 -2
  193. package/src/shell/options.ts +104 -0
  194. package/src/shell/program.ts +20 -8
  195. package/src/shell/textCommands.ts +3 -1
  196. package/src/system/httpStream.ts +42 -11
  197. package/src/system/index.ts +1 -0
  198. package/src/system/signals.ts +39 -0
  199. package/src/system/terminal.ts +51 -1
@@ -6,10 +6,19 @@
6
6
  */
7
7
  import type { ByteChannel, HttpResponseData, HttpResponseHead, HttpStreamResponse } from './types.js';
8
8
 
9
+ /** Bytes a body stream queues for a reader that is not keeping up before `push` reports it full. */
10
+ export const BODY_HIGH_WATER_MARK = 1024 * 1024;
11
+
9
12
  export interface PushStream {
10
13
  readonly stream: ReadableStream<Uint8Array>;
11
- /** Queue a chunk; ignored once the stream is closed or cancelled. */
12
- push(chunk: Uint8Array): void;
14
+ /**
15
+ * Queue a chunk; ignored once the stream is closed or cancelled. Returns false
16
+ * when the queue is at its high-water mark (or the reader is gone): a producer
17
+ * that can wait should, until `ready()` resolves.
18
+ */
19
+ push(chunk: Uint8Array): boolean;
20
+ /** Resolves when the reader wants more (pulls below the high-water mark), or the stream is done. */
21
+ ready(): Promise<void>;
13
22
  end(): void;
14
23
  /** End with an error: the reader sees a failed read (a truncated response). */
15
24
  fail(error: unknown): void;
@@ -17,32 +26,54 @@ export interface PushStream {
17
26
  readonly done: boolean;
18
27
  }
19
28
 
20
- /** A body stream fed from outside. `onCancel` runs when the reader hangs up before the end. */
21
- export function pushStream(onCancel?: (reason: unknown) => void): PushStream {
29
+ /**
30
+ * A body stream fed from outside, pull-based: it queues up to `highWaterMark`
31
+ * bytes for a slow reader, and `push`/`ready` tell the producer when to wait.
32
+ * `onCancel` runs when the reader hangs up before the end.
33
+ */
34
+ export function pushStream(onCancel?: (reason: unknown) => void, highWaterMark = BODY_HIGH_WATER_MARK): PushStream {
22
35
  let controller!: ReadableStreamDefaultController<Uint8Array>;
23
36
  let done = false;
24
- const stream = new ReadableStream<Uint8Array>({
25
- start: (c) => void (controller = c),
26
- cancel: (reason) => {
27
- if (done) return;
28
- done = true;
29
- onCancel?.(reason);
37
+ let waiting: Array<() => void> = [];
38
+ const wake = () => {
39
+ const resume = waiting;
40
+ waiting = [];
41
+ for (const go of resume) go();
42
+ };
43
+ const hasRoom = () => !done && (controller.desiredSize ?? 0) > 0;
44
+ const stream = new ReadableStream<Uint8Array>(
45
+ {
46
+ start: (c) => void (controller = c),
47
+ pull: wake, // the reader drained below the mark: producers may go on
48
+ cancel: (reason) => {
49
+ if (done) return;
50
+ done = true;
51
+ wake();
52
+ onCancel?.(reason);
53
+ },
30
54
  },
31
- });
55
+ new ByteLengthQueuingStrategy({ highWaterMark }),
56
+ );
32
57
  return {
33
58
  stream,
34
59
  push(chunk) {
35
60
  if (!done && chunk.byteLength) controller.enqueue(chunk);
61
+ return hasRoom();
62
+ },
63
+ ready() {
64
+ return done || hasRoom() ? Promise.resolve() : new Promise((resolve) => waiting.push(resolve));
36
65
  },
37
66
  end() {
38
67
  if (done) return;
39
68
  done = true;
40
69
  controller.close();
70
+ wake();
41
71
  },
42
72
  fail(error) {
43
73
  if (done) return;
44
74
  done = true;
45
75
  controller.error(error);
76
+ wake();
46
77
  },
47
78
  get done() {
48
79
  return done;
@@ -37,6 +37,7 @@ export type { ServerAddress, PortChange } from './serverEvents.js';
37
37
  export { resolveCommand, findExecutable, binDirectories, interpreterFor, commandNotFound } from './commands.js';
38
38
  export type { ResolvedCommand } from './commands.js';
39
39
  export { InputQueue, LineDiscipline, toTerminal } from './terminal.js';
40
+ export { SIGNAL_EXIT_CODES, SIGPIPE_STATUS, signalExitCode, BrokenPipeError, isBrokenPipe, brokePipe } from './signals.js';
40
41
  export { defaultPrograms } from './programs.js';
41
42
  export { startNode } from '../node/runtime.js';
42
43
  export type { NodeInstance, NodeOptions } from '../node/runtime.js';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Signals as exit statuses (128 + the signal number, as a shell reports a
3
+ * process a signal ended), and the broken-pipe error a write to a pipe whose
4
+ * reader is gone raises — the in-memory stand-in for SIGPIPE.
5
+ */
6
+
7
+ export const SIGNAL_EXIT_CODES: Readonly<Record<string, number>> = { SIGHUP: 129, SIGINT: 130, SIGKILL: 137, SIGPIPE: 141, SIGTERM: 143 };
8
+
9
+ /** The status of a pipeline stage stopped by writing to a closed pipe. */
10
+ export const SIGPIPE_STATUS = SIGNAL_EXIT_CODES.SIGPIPE!;
11
+
12
+ /** The exit status `signal` ends a process with (1 for a signal with no number here). */
13
+ export function signalExitCode(signal: string): number {
14
+ return SIGNAL_EXIT_CODES[signal] ?? 1;
15
+ }
16
+
17
+ /**
18
+ * A write to a pipe nobody reads any more (`yes | head -1` once head exits).
19
+ * `pipe` is the pipe that broke, so the pipeline stage writing into it — and only
20
+ * that stage — turns it into SIGPIPE's status: a loop or group inside the stage
21
+ * (`while true; do echo y; done | head -1`) must stop with it, as SIGPIPE ends the
22
+ * whole subshell in a real shell, not swallow it and go round again.
23
+ */
24
+ export class BrokenPipeError extends Error {
25
+ readonly code = 'EPIPE';
26
+ constructor(readonly pipe?: object) {
27
+ super('EPIPE: broken pipe, write');
28
+ this.name = 'BrokenPipeError';
29
+ }
30
+ }
31
+
32
+ export function isBrokenPipe(error: unknown): boolean {
33
+ return error instanceof BrokenPipeError || (error as { code?: unknown } | null)?.code === 'EPIPE';
34
+ }
35
+
36
+ /** Did writing into `pipe` (and not some other pipe) raise `error`? */
37
+ export function brokePipe(error: unknown, pipe: object): boolean {
38
+ return error instanceof BrokenPipeError && error.pipe === pipe;
39
+ }
@@ -2,7 +2,9 @@
2
2
  * What a kernel's TTY layer does between xterm.js and a program:
3
3
  *
4
4
  * - InputQueue: stdin as a buffered stream of chunks — text, or bytes (data that arrives
5
- * before the program subscribes is kept, not dropped).
5
+ * before the program subscribes is kept, not dropped). As a pipe, its reader
6
+ * closes it on exit (`closeReader`): what was buffered is dropped and later
7
+ * writes throw EPIPE, so the writer stops instead of buffering forever.
6
8
  * - LineDiscipline: "cooked" mode — echo, backspace, Ctrl-U, Enter delivers the
7
9
  * line, Ctrl-C raises SIGINT, Ctrl-D is end-of-file. A program that calls
8
10
  * `setRawMode(true)` (the shell, prompts libraries) gets keystrokes untouched.
@@ -10,6 +12,7 @@
10
12
  * only moves to column 0 on `\r`.
11
13
  */
12
14
  import type { StdioChunk } from './types.js';
15
+ import { BrokenPipeError } from './signals.js';
13
16
 
14
17
 
15
18
  export class InputQueue<T extends StdioChunk = string> {
@@ -18,8 +21,14 @@ export class InputQueue<T extends StdioChunk = string> {
18
21
  private ended = false;
19
22
 
20
23
  private draining = false;
24
+ private readerClosed = false;
21
25
 
26
+ /** Queue a chunk (`null`: end-of-file). Throws {@link BrokenPipeError} once the reader has closed; ending is always allowed. */
22
27
  push(chunk: T | null): void {
28
+ if (this.readerClosed) {
29
+ if (chunk === null) return;
30
+ throw new BrokenPipeError(this);
31
+ }
23
32
  if (this.ended) return;
24
33
  if (chunk === null) this.ended = true;
25
34
  this.buffered.push(chunk);
@@ -64,9 +73,50 @@ export class InputQueue<T extends StdioChunk = string> {
64
73
  });
65
74
  }
66
75
 
76
+ /**
77
+ * The first `count` lines (each with its `\n`; fewer at end-of-file), then stop
78
+ * reading — what `head` needs to exit early, so the writer upstream gets EPIPE.
79
+ */
80
+ readLines(count: number): Promise<string> {
81
+ return new Promise((resolve) => {
82
+ if (count <= 0) return resolve('');
83
+ let text = '';
84
+ let found = 0;
85
+ let done = false;
86
+ const finish = () => {
87
+ done = true;
88
+ stop();
89
+ resolve(text);
90
+ };
91
+ const stop = this.subscribe(
92
+ textChunks((chunk) => {
93
+ if (done) return;
94
+ if (chunk === null) return finish();
95
+ for (let from = 0; ; ) {
96
+ const newline = chunk.indexOf('\n', from);
97
+ if (newline < 0) return void (text += chunk.slice(from));
98
+ text += chunk.slice(from, newline + 1);
99
+ from = newline + 1;
100
+ if (++found === count) return finish();
101
+ }
102
+ }),
103
+ );
104
+ });
105
+ }
106
+
107
+ /** The reader is gone (a pipeline stage exited): drop what it never read; later writes fail with EPIPE. */
108
+ closeReader(): void {
109
+ this.readerClosed = true;
110
+ this.buffered.length = 0;
111
+ }
112
+
67
113
  get isEnded(): boolean {
68
114
  return this.ended;
69
115
  }
116
+
117
+ get isReaderClosed(): boolean {
118
+ return this.readerClosed;
119
+ }
70
120
  }
71
121
 
72
122
  /**