|
20 | 20 | ) |
21 | 21 | from deno_sandbox.api_types_generated import ( |
22 | 22 | DenoReplOptions, |
| 23 | + DenoRunOptions, |
23 | 24 | SandboxListOptions, |
24 | 25 | SandboxCreateOptions, |
25 | 26 | SandboxConnectOptions, |
|
35 | 36 | from deno_sandbox.utils import to_camel_case, to_snake_case |
36 | 37 | from deno_sandbox.wrappers import ( |
37 | 38 | AsyncChildProcess, |
| 39 | + AsyncDenoProcess, |
38 | 40 | AsyncDenoRepl, |
39 | 41 | ChildProcess, |
| 42 | + DenoProcess, |
| 43 | + DenoRepl, |
40 | 44 | ProcessSpawnResult, |
41 | 45 | RemoteProcessOptions, |
42 | 46 | ) |
@@ -212,9 +216,41 @@ class VsCodeOptions(TypedDict): |
212 | 216 |
|
213 | 217 |
|
214 | 218 | class AsyncSandboxDeno(AsyncSandboxDenoGenerated): |
| 219 | + async def run(self, options: DenoRunOptions) -> AsyncDenoProcess: |
| 220 | + """Create a new Deno process from the specified entrypoint file or code. The runtime will execute the given code to completion, and then exit.""" |
| 221 | + |
| 222 | + params = { |
| 223 | + "stdout": "inherit", |
| 224 | + "stderr": "inherit", |
| 225 | + } |
| 226 | + |
| 227 | + if options is not None: |
| 228 | + for key, value in options.items(): |
| 229 | + if value is not None: |
| 230 | + params[to_snake_case(key)] = value |
| 231 | + |
| 232 | + if "code" in params and "extension" not in params: |
| 233 | + params["extension"] = "ts" |
| 234 | + |
| 235 | + opts = RemoteProcessOptions( |
| 236 | + stdout_inherit=params["stdout"] == "inherit", |
| 237 | + stderr_inherit=params["stderr"] == "inherit", |
| 238 | + ) |
| 239 | + |
| 240 | + if params["stdout"] == "inherit": |
| 241 | + params["stdout"] = "piped" |
| 242 | + if params["stderr"] == "inherit": |
| 243 | + params["stderr"] = "piped" |
| 244 | + |
| 245 | + result = await self._rpc.call("spawnDeno", params) |
| 246 | + |
| 247 | + return await AsyncDenoProcess.create(result, self._rpc, opts) |
| 248 | + |
215 | 249 | async def eval(self, code: str) -> Any: |
216 | 250 | repl = await self.repl() |
217 | | - return await repl.eval(code) |
| 251 | + result = await repl.eval(code) |
| 252 | + await repl.close() |
| 253 | + return result |
218 | 254 |
|
219 | 255 | async def repl(self, options: Optional[DenoReplOptions] = None) -> AsyncDenoRepl: |
220 | 256 | params = {"stdout": "piped", "stderr": "piped"} |
@@ -243,9 +279,17 @@ def __init__(self, client: ConsoleClient, rpc: RpcClient): |
243 | 279 |
|
244 | 280 | self._async = AsyncSandboxDeno(self._client._async, rpc._async_client) |
245 | 281 |
|
| 282 | + def run(self, options: DenoRunOptions) -> DenoProcess: |
| 283 | + async_deno = self._client._bridge.run(self._async.run(options)) |
| 284 | + return DenoProcess(self._rpc, async_deno) |
| 285 | + |
246 | 286 | def eval(self, code: str) -> Any: |
247 | 287 | return self._client._bridge.run(self._async.eval(code)) |
248 | 288 |
|
| 289 | + def repl(self, options: Optional[DenoReplOptions] = None) -> DenoRepl: |
| 290 | + async_repl = self._client._bridge.run(self._async.repl(options)) |
| 291 | + return DenoRepl(self._rpc, async_repl) |
| 292 | + |
249 | 293 |
|
250 | 294 | class AsyncSandbox: |
251 | 295 | def __init__( |
|
0 commit comments