workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

Cloudflare Workers REPL

Open threepointone opened this issue 3 years ago • 5 comments

Describe the solution

While it’s nice to use stackblitz etc for making a quick worker, it’s not great to have to define an http interface for input and out put. It would be nice to have a repl style interface for quickly running code.

threepointone avatar Jun 14 '22 21:06 threepointone

How's this? 🙂

miniflare --repl
> await new HTMLRewriter().on("p", { element(e) { e.setInnerContent("new") } }).transform(new Response("<p>old</p>")).text()
'<p>new</p>'
> const id = env.COUNTER.newUniqueId()
undefined
> const stub = env.COUNTER.get(id)
undefined
> await (await stub.fetch("/")).text()
'1'
> await (await stub.fetch("/")).text()
'2'
> 

Automatically loads scripts/bindings from wrangler.toml files too, so your Durable Objects/KV namespaces work out-of-the-box.

mrbbot avatar Jun 15 '22 12:06 mrbbot

amazing!!! is this available as an api? we can then do all our custom build stuff that we do

threepointone avatar Jun 15 '22 12:06 threepointone

Yep!

import { Miniflare } from "miniflare";
const mf = new Miniflare(...);
mf.startREPL();

mrbbot avatar Jun 15 '22 12:06 mrbbot

you're so awesome

threepointone avatar Jun 15 '22 12:06 threepointone

Potentially can have a rethink in the future once we know more clearly the repl story with the open source runtime.

cameron-robey avatar Sep 15 '22 11:09 cameron-robey

was this completed, or is this not going to be done?

threepointone avatar Jan 09 '23 20:01 threepointone

@threepointone sorry about that, I should've clarified before closing. This is something we're not going to do for now. We can definitely reevaluate that once miniflare is the default for local dev.

admah avatar Jan 09 '23 21:01 admah