Open kungfooman opened 4 years ago
There's no way to do that currently.
I asked on Discord and @SyrupThinker shared his attempt (thanks a lot ❤️):
Usage like:
// Filename: test_repl.ts
import * as repl from "./repl.ts";
Object.assign(window, {
i: 42
});
await repl.replLoop();
Only problem so far seems to be that it crashes when objects are too "complex" (e.g. type in Deno
itself), then it requires:
deno run --allow-read test_repl.ts
Otherwise it will fail like this:
Deno 1.1.0
exit using ctrl+d or close()
> Deno
error: Uncaught PermissionDenied: read access to <main_module>, run again with the --allow-read flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
at Object.opMainModule [as mainModule] ($deno$/ops/runtime.ts:25:10)
at createRawObjectString ($deno$/web/console.ts:512:43)
at createObjectString ($deno$/web/console.ts:592:12)
at stringify ($deno$/web/console.ts:296:14)
at stringifyArgs ($deno$/web/console.ts:685:14)
at Object.Console.log ($deno$/web/console.ts:729:7)
at replLog (file:///D:/web/libwebgame_node/src/repl_deno.ts:57:11)
at evaluate (file:///D:/web/libwebgame_node/src/repl_deno.ts:109:7)
As noted when I shared this gist, this heavily relies on internal behaviour and might break at any release.
As noted when I shared this gist, this heavily relies on internal behaviour and might break at any release.
As of https://github.com/denoland/deno/commit/4c779b5e8ca427faf24c26443a8054004827d450 there are no repl ops and the runtime environment has no concept of a repl at all.
Node has: https://nodejs.org/api/repl.html#repl_repl_start_options
So I can simply start a webserver and spawn a REPL in the same context to manipulate the server object for example:
How can I do the same in deno?