@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.
- package/dist/archive.d.ts +25 -2
- package/dist/archive.d.ts.map +1 -1
- package/dist/archive.js +45 -6
- package/dist/archive.js.map +1 -1
- package/dist/attribution.js.map +1 -1
- package/dist/check/acquire.js.map +1 -1
- package/dist/check/typeStore.d.ts.map +1 -1
- package/dist/compileScript.js.map +1 -1
- package/dist/devServer.d.ts +2 -0
- package/dist/devServer.d.ts.map +1 -1
- package/dist/devServer.js +2 -2
- package/dist/devServer.js.map +1 -1
- package/dist/hot/moduleGraph.d.ts.map +1 -1
- package/dist/html.d.ts +5 -2
- package/dist/html.d.ts.map +1 -1
- package/dist/html.js +9 -7
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/installer/npmrc.js.map +1 -1
- package/dist/installer/registry.d.ts.map +1 -1
- package/dist/installer/registry.js.map +1 -1
- package/dist/installer/semver.js.map +1 -1
- package/dist/installer/tree.d.ts +2 -2
- package/dist/installer/tree.d.ts.map +1 -1
- package/dist/node/assert.d.ts.map +1 -1
- package/dist/node/buffer.d.ts.map +1 -1
- package/dist/node/buffer.js.map +1 -1
- package/dist/node/callable.js.map +1 -1
- package/dist/node/crypto.d.ts.map +1 -1
- package/dist/node/crypto.js +6 -2
- package/dist/node/crypto.js.map +1 -1
- package/dist/node/events.d.ts.map +1 -1
- package/dist/node/events.js.map +1 -1
- package/dist/node/fs/index.js.map +1 -1
- package/dist/node/fs/stats.d.ts.map +1 -1
- package/dist/node/fs/stats.js.map +1 -1
- package/dist/node/fs/sync.d.ts +1 -1
- package/dist/node/fs/sync.d.ts.map +1 -1
- package/dist/node/fs/sync.js.map +1 -1
- package/dist/node/hostClock.d.ts +14 -0
- package/dist/node/hostClock.d.ts.map +1 -0
- package/dist/node/hostClock.js +15 -0
- package/dist/node/hostClock.js.map +1 -0
- package/dist/node/http/client.d.ts.map +1 -1
- package/dist/node/http/client.js.map +1 -1
- package/dist/node/http/index.js.map +1 -1
- package/dist/node/http/messages.d.ts.map +1 -1
- package/dist/node/http/messages.js.map +1 -1
- package/dist/node/http/server.d.ts.map +1 -1
- package/dist/node/http/server.js +10 -1
- package/dist/node/http/server.js.map +1 -1
- package/dist/node/http/serverResponse.d.ts +2 -1
- package/dist/node/http/serverResponse.d.ts.map +1 -1
- package/dist/node/http/serverResponse.js +4 -2
- package/dist/node/http/serverResponse.js.map +1 -1
- package/dist/node/http/upgradeSocket.d.ts.map +1 -1
- package/dist/node/http/upgradeSocket.js.map +1 -1
- package/dist/node/inspect.d.ts +2 -2
- package/dist/node/inspect.d.ts.map +1 -1
- package/dist/node/inspect.js.map +1 -1
- package/dist/node/loader.d.ts.map +1 -1
- package/dist/node/loader.js.map +1 -1
- package/dist/node/loop.d.ts.map +1 -1
- package/dist/node/loop.js.map +1 -1
- package/dist/node/misc.d.ts.map +1 -1
- package/dist/node/misc.js +3 -2
- package/dist/node/misc.js.map +1 -1
- package/dist/node/process.d.ts.map +1 -1
- package/dist/node/process.js +9 -8
- package/dist/node/process.js.map +1 -1
- package/dist/node/processExit.d.ts.map +1 -1
- package/dist/node/processExit.js.map +1 -1
- package/dist/node/readline.js.map +1 -1
- package/dist/node/resolve.d.ts +2 -2
- package/dist/node/resolve.d.ts.map +1 -1
- package/dist/node/runtime.d.ts.map +1 -1
- package/dist/node/runtime.js +2 -2
- package/dist/node/runtime.js.map +1 -1
- package/dist/node/stream/index.d.ts.map +1 -1
- package/dist/node/stream/index.js.map +1 -1
- package/dist/node/stream/readable.d.ts.map +1 -1
- package/dist/node/stream/readable.js.map +1 -1
- package/dist/node/stream/writable.d.ts.map +1 -1
- package/dist/node/stream/writable.js.map +1 -1
- package/dist/node/util.d.ts +2 -2
- package/dist/node/util.d.ts.map +1 -1
- package/dist/node/util.js.map +1 -1
- package/dist/node/wasi/abi.d.ts.map +1 -1
- package/dist/node/wasi/abi.js.map +1 -1
- package/dist/node/wasi/files.d.ts.map +1 -1
- package/dist/node/wasi/index.d.ts.map +1 -1
- package/dist/node/wasi/index.js +2 -1
- package/dist/node/wasi/index.js.map +1 -1
- package/dist/node/workerThreads.js.map +1 -1
- package/dist/packageCdn.js.map +1 -1
- package/dist/previewBridge.d.ts +15 -3
- package/dist/previewBridge.d.ts.map +1 -1
- package/dist/previewBridge.js +30 -8
- package/dist/previewBridge.js.map +1 -1
- package/dist/projectConfig.d.ts +1 -1
- package/dist/projectConfig.d.ts.map +1 -1
- package/dist/projectConfig.js.map +1 -1
- package/dist/resolve.d.ts +1 -1
- package/dist/resolve.d.ts.map +1 -1
- package/dist/rootedFs.d.ts +7 -0
- package/dist/rootedFs.d.ts.map +1 -1
- package/dist/rootedFs.js +22 -2
- package/dist/rootedFs.js.map +1 -1
- package/dist/shell/builtins.d.ts +3 -0
- package/dist/shell/builtins.d.ts.map +1 -1
- package/dist/shell/builtins.js +4 -4
- package/dist/shell/builtins.js.map +1 -1
- package/dist/shell/compound.js.map +1 -1
- package/dist/shell/context.js.map +1 -1
- package/dist/shell/exec.d.ts +15 -3
- package/dist/shell/exec.d.ts.map +1 -1
- package/dist/shell/exec.js +47 -7
- package/dist/shell/exec.js.map +1 -1
- package/dist/shell/expand.js.map +1 -1
- package/dist/shell/lineEditor.d.ts.map +1 -1
- package/dist/shell/lineEditor.js.map +1 -1
- package/dist/shell/npm.d.ts.map +1 -1
- package/dist/shell/npm.js +6 -2
- package/dist/shell/npm.js.map +1 -1
- package/dist/shell/options.d.ts +37 -0
- package/dist/shell/options.d.ts.map +1 -0
- package/dist/shell/options.js +86 -0
- package/dist/shell/options.js.map +1 -0
- package/dist/shell/packageManagers.d.ts +2 -2
- package/dist/shell/packageManagers.d.ts.map +1 -1
- package/dist/shell/parse.js.map +1 -1
- package/dist/shell/program.d.ts +4 -0
- package/dist/shell/program.d.ts.map +1 -1
- package/dist/shell/program.js +20 -8
- package/dist/shell/program.js.map +1 -1
- package/dist/shell/testCommand.js.map +1 -1
- package/dist/shell/textCommands.d.ts.map +1 -1
- package/dist/shell/textCommands.js +3 -1
- package/dist/shell/textCommands.js.map +1 -1
- package/dist/shell/tokenize.d.ts.map +1 -1
- package/dist/shell/tokenize.js.map +1 -1
- package/dist/styles/imports.d.ts.map +1 -1
- package/dist/system/commands.d.ts +1 -1
- package/dist/system/commands.d.ts.map +1 -1
- package/dist/system/cookieJar.d.ts.map +1 -1
- package/dist/system/httpStream.d.ts +16 -4
- package/dist/system/httpStream.d.ts.map +1 -1
- package/dist/system/httpStream.js +25 -3
- package/dist/system/httpStream.js.map +1 -1
- package/dist/system/index.d.ts +1 -0
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +1 -0
- package/dist/system/index.js.map +1 -1
- package/dist/system/ipc.js.map +1 -1
- package/dist/system/kernel.d.ts.map +1 -1
- package/dist/system/kernel.js.map +1 -1
- package/dist/system/ports.d.ts.map +1 -1
- package/dist/system/process.js.map +1 -1
- package/dist/system/serverEvents.d.ts.map +1 -1
- package/dist/system/signals.d.ts +26 -0
- package/dist/system/signals.d.ts.map +1 -0
- package/dist/system/signals.js +36 -0
- package/dist/system/signals.js.map +1 -0
- package/dist/system/terminal.d.ts +13 -1
- package/dist/system/terminal.d.ts.map +1 -1
- package/dist/system/terminal.js +49 -0
- package/dist/system/terminal.js.map +1 -1
- package/dist/system/webSocketFrames.d.ts.map +1 -1
- package/dist/system/webSocketFrames.js.map +1 -1
- package/dist/vfs.d.ts.map +1 -1
- package/dist/vfs.js.map +1 -1
- package/package.json +6 -5
- package/src/archive.ts +46 -6
- package/src/devServer.ts +4 -2
- package/src/html.ts +11 -7
- package/src/index.ts +3 -3
- package/src/node/crypto.ts +6 -1
- package/src/node/hostClock.ts +16 -0
- package/src/node/http/server.ts +9 -1
- package/src/node/http/serverResponse.ts +5 -3
- package/src/node/misc.ts +3 -2
- package/src/node/process.ts +9 -8
- package/src/node/runtime.ts +2 -3
- package/src/node/wasi/index.ts +2 -1
- package/src/previewBridge.ts +31 -9
- package/src/rootedFs.ts +21 -2
- package/src/shell/builtins.ts +6 -4
- package/src/shell/exec.ts +52 -10
- package/src/shell/npm.ts +5 -2
- package/src/shell/options.ts +104 -0
- package/src/shell/program.ts +20 -8
- package/src/shell/textCommands.ts +3 -1
- package/src/system/httpStream.ts +42 -11
- package/src/system/index.ts +1 -0
- package/src/system/signals.ts +39 -0
- package/src/system/terminal.ts +51 -1
package/src/system/httpStream.ts
CHANGED
|
@@ -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
|
-
/**
|
|
12
|
-
|
|
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
|
-
/**
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
package/src/system/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/system/terminal.ts
CHANGED
|
@@ -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
|
/**
|