| 21 | } |
| 22 | |
| 23 | export class WorkspaceRuntime { |
| 24 | readonly #options: WorkspaceRuntimeRouterOptions; |
| 25 | |
| 26 | constructor(options: WorkspaceRuntimeRouterOptions) { |
| 27 | this.#options = options; |
| 28 | } |
| 29 | |
| 30 | exec(source: string): Promise<WorkspaceRuntimeExecHandle<undefined>>; |
| 31 | exec( |
| 32 | source: string, |
| 33 | options: WorkspaceRuntimeExecOptions<"utf8">, |
| 34 | ): Promise<WorkspaceRuntimeExecHandle<"utf8">>; |
| 35 | exec( |
| 36 | source: string, |
| 37 | options: WorkspaceRuntimeExecOptions<undefined>, |
| 38 | ): Promise<WorkspaceRuntimeExecHandle<undefined>>; |
| 39 | async exec<E extends ExecEncoding>( |
| 40 | source: string, |
| 41 | options: WorkspaceRuntimeExecOptions<E> = {}, |
| 42 | ): Promise<WorkspaceRuntimeExecHandle<E>> { |
| 43 | if (options.id !== undefined) assertExecutionId(options.id); |
| 44 | const backend = this.#backend(options.backend); |
| 45 | if (options.input !== undefined && !this.#options.callableBackendIds.has(backend)) { |
| 46 | throw new Error( |
| 47 | `Backend ${JSON.stringify(backend)} is not callable; it does not accept structured input.`, |
| 48 | ); |
| 49 | } |
| 50 | if (this.#options.commandBackendIds.has(backend)) { |
| 51 | if (options.input !== undefined) { |
| 52 | throw new Error( |
| 53 | `Backend ${JSON.stringify(backend)} is not callable; it does not accept structured input.`, |
| 54 | ); |
| 55 | } |
| 56 | const shell = this.#options.shell(); |
| 57 | const handle = await ( |
| 58 | shell.exec as unknown as ( |
| 59 | command: string, |
| 60 | options: Record<string, unknown>, |
| 61 | ) => Promise<ExecHandle<E>> |
| 62 | )(source, { |
| 63 | backend, |
| 64 | cwd: options.cwd, |
| 65 | encoding: options.encoding, |
| 66 | id: options.id, |
| 67 | timeoutMs: options.timeoutMs, |
| 68 | env: options.env, |
| 69 | stdin: options.stdin, |
| 70 | }); |
| 71 | return wrapCommandHandle(handle, backend); |
| 72 | } |
| 73 | |
| 74 | const runtime = await this.#options.moduleHandle(backend); |
| 75 | const envelope = await runtime.exec({ |
| 76 | id: options.id, |
| 77 | source, |
| 78 | cwd: options.cwd, |
| 79 | input: options.input, |
| 80 | env: options.env, |
nothing calls this directly
no outgoing calls
no test coverage detected