diff --git a/src/lib/JSRuntime.ts b/src/lib/JSRuntime.ts index 2173c4d4..ede545f8 100644 --- a/src/lib/JSRuntime.ts +++ b/src/lib/JSRuntime.ts @@ -1,12 +1,20 @@ -import type { WebContainerProcess } from '@webcontainer/api'; - /** - * Directory entry with file type information + * JavaScript runtime interface for executing code and managing files */ -export interface DirectoryEntry { - name: string; - isDirectory(): boolean; - isFile(): boolean; +export interface JSRuntime { + /** + * Filesystem access + */ + fs(): Promise; + + /** + * Spawn a process in the runtime environment + * @param command Command to execute + * @param args Command arguments + * @param options Spawn options + * @returns Process handle + */ + spawn(command: string, args?: string[], options?: Record): Promise; } /** @@ -50,20 +58,33 @@ export interface JSRuntimeFS { } /** - * JavaScript runtime interface for executing code and managing files + * Directory entry with file type information */ -export interface JSRuntime { - /** - * Filesystem access - */ - fs(): Promise; +export interface DirectoryEntry { + name: string; + isDirectory(): boolean; + isFile(): boolean; +} +/** + * Unified child process interface + */ +export interface JSRuntimeChildProcess { /** - * Spawn a process in the runtime environment - * @param command Command to execute - * @param args Command arguments - * @param options Spawn options - * @returns Process handle + * A promise for the exit code of the process. */ - spawn(command: string, args?: string[], options?: Record): Promise; + exit: Promise; + /** + * An input stream for the attached pseudoterminal device. + */ + input: WritableStream; + /** + * A stream that receives all terminal output, including the stdout and stderr emitted by the spawned process + * _and_ its descendants. + */ + output: ReadableStream; + /** + * Kills the process. + */ + kill(): void; } \ No newline at end of file diff --git a/src/lib/WebContainerAdapter.ts b/src/lib/WebContainerAdapter.ts index d6b1db9c..2a6d0fc0 100644 --- a/src/lib/WebContainerAdapter.ts +++ b/src/lib/WebContainerAdapter.ts @@ -1,5 +1,5 @@ -import { WebContainer, type WebContainerProcess } from '@webcontainer/api'; -import type { JSRuntime, JSRuntimeFS, DirectoryEntry } from './JSRuntime'; +import { WebContainer } from '@webcontainer/api'; +import type { JSRuntime, JSRuntimeFS, JSRuntimeChildProcess, DirectoryEntry } from './JSRuntime'; /** * WebContainer adapter that implements the JSRuntime interface @@ -36,7 +36,7 @@ export class WebContainerAdapter implements JSRuntime { * Spawn a process in the WebContainer * Automatically boots the container on first call */ - async spawn(command: string, args: string[] = [], options: Record = {}): Promise { + async spawn(command: string, args: string[] = [], options: Record = {}): Promise { const webcontainer = await this.ensureBooted(); return webcontainer.spawn(command, args, options); }