mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
JSRuntime: remove WebContainer type dependency
This commit is contained in:
2 files changed
+43
-22
No files matched your search
+40
-19
@@ -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 {
|
export interface JSRuntime {
|
||||||
name: string;
|
/**
|
||||||
isDirectory(): boolean;
|
* Filesystem access
|
||||||
isFile(): boolean;
|
*/
|
||||||
|
fs(): Promise<JSRuntimeFS>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<string, unknown>): Promise<JSRuntimeChildProcess>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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 {
|
export interface DirectoryEntry {
|
||||||
/**
|
name: string;
|
||||||
* Filesystem access
|
isDirectory(): boolean;
|
||||||
*/
|
isFile(): boolean;
|
||||||
fs(): Promise<JSRuntimeFS>;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unified child process interface
|
||||||
|
*/
|
||||||
|
export interface JSRuntimeChildProcess {
|
||||||
/**
|
/**
|
||||||
* Spawn a process in the runtime environment
|
* A promise for the exit code of the process.
|
||||||
* @param command Command to execute
|
|
||||||
* @param args Command arguments
|
|
||||||
* @param options Spawn options
|
|
||||||
* @returns Process handle
|
|
||||||
*/
|
*/
|
||||||
spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<WebContainerProcess>;
|
exit: Promise<number>;
|
||||||
|
/**
|
||||||
|
* An input stream for the attached pseudoterminal device.
|
||||||
|
*/
|
||||||
|
input: WritableStream<string>;
|
||||||
|
/**
|
||||||
|
* A stream that receives all terminal output, including the stdout and stderr emitted by the spawned process
|
||||||
|
* _and_ its descendants.
|
||||||
|
*/
|
||||||
|
output: ReadableStream<string>;
|
||||||
|
/**
|
||||||
|
* Kills the process.
|
||||||
|
*/
|
||||||
|
kill(): void;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { WebContainer, type WebContainerProcess } from '@webcontainer/api';
|
import { WebContainer } from '@webcontainer/api';
|
||||||
import type { JSRuntime, JSRuntimeFS, DirectoryEntry } from './JSRuntime';
|
import type { JSRuntime, JSRuntimeFS, JSRuntimeChildProcess, DirectoryEntry } from './JSRuntime';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebContainer adapter that implements the JSRuntime interface
|
* WebContainer adapter that implements the JSRuntime interface
|
||||||
@@ -36,7 +36,7 @@ export class WebContainerAdapter implements JSRuntime {
|
|||||||
* Spawn a process in the WebContainer
|
* Spawn a process in the WebContainer
|
||||||
* Automatically boots the container on first call
|
* Automatically boots the container on first call
|
||||||
*/
|
*/
|
||||||
async spawn(command: string, args: string[] = [], options: Record<string, unknown> = {}): Promise<WebContainerProcess> {
|
async spawn(command: string, args: string[] = [], options: Record<string, unknown> = {}): Promise<JSRuntimeChildProcess> {
|
||||||
const webcontainer = await this.ensureBooted();
|
const webcontainer = await this.ensureBooted();
|
||||||
return webcontainer.spawn(command, args, options);
|
return webcontainer.spawn(command, args, options);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user