The following is in the docs:
> If you want to switch to a CLJS REPL this may require additional setup in the tool you used to start the server in. Since `lein` will default to using nREPL it will require configuring additional nREPL `:middleware`. When using `clj` you are good to go since it doesn’t use nREPL.
I'm trying to manually connect to the shadowcljs nrepl and run (shadow/repl :build-id)
to create a cljs repl, but I'm not getting it to work. I guess it's supposed to change the ns for me, but getting nothing. Works when running via lein repl :connect
, changes the ns properly and drops my into a cljs repl, but no dice when manually connecting via sockets. Any ideas what I'm missing?
@victorbjelkholm429 you are connecting to what? the shadow-cljs nrepl server? the lein
one?
and what are you connecting with? if you are coding this manually you need to properly manage the nrepl session stuff
@thheller yeah, connecting directly to the nrepl started by shadow-cljs. Using the lein nrepl client just as a test client, main usage is supposed to be via a Java Socket manually in Clojure code. Yeah, already using session + id, bencode and the whole rabble. Any information around what the command shadow/repl
expects my nrepl session to do? I'm assuming it'll return me a ns that I should switch to, while retaining the same session, or something like that but haven't quite figured it out yet
I can't remember either. I think clients usually clone and then shadow/repl
switches the current session to CLJS. don't know if thats supposed to return something.
CLJS over nrepl is horrible
hah, it's a bit messy at times I guess, but unsure if there is any alternatives?
I'll continue digging, thanks!
don't know what you intend to do exactly
want to run cljs code in the browser from a clojure process programmatically, and since shadow-cljs runs as a sub-process to the clojure process, I'm using nrepl to communicate. That's the summary I guess
shadow.remote stuff is the easiest (if you can do websocket and transit) in my opinion but I'm quite biased 😉
ah, very cool, didn't know about shadow.remote! Seems to be an alternative, will take a closer look
socket repl is easy too if you don't care much about the output
you already looked at the shadow.remote stuff. its the websocket endpoint you tried a couple days ago.
https://github.com/thheller/shadow-cljs/blob/master/doc/remote.md its a bit out of date but the idea is the same
yeah, didn't look to much at it the other day as I found I could get a nREPL connection up and running 😄 But, back to it we go.
basically all you need to send is the {:op :hello}
and then get the client id of the CLJS runtime you want to eval in
if you know it
{:op :cljs-eval
:to client-id
:input {:code "(+ 1 2)"
:ns 'cljs.user
:repl true}}
this gets you eval
:repl true
is optional. if you don't care about *1
*2
and so on you can leave it out
awesome, thanks!
if you want to emulate "RPC" you can send :call-id 123
with the request and the server will reply with that id in the message
@victorbjelkholm429 if you want to take a look, I wrote a client to connect to shadow.remote - I use it on Chlorine / Clover plug-ins: https://github.com/mauricioszabo/repl-tooling/blob/master/src/repl_tooling/repl_client/shadow_ws.cljs
It's a ClojureScript package, so you can even import on your CLJS code and run right away! It does a lot more than just connecting to Shadow, but you can ignore most parts if you want (I believe that CLJS's dead code removal will handle it). Please, ping me if you think it helps, because I'm also researching on a web-based evaluator 🙂
@mauricio.szabo thanks a lot! In the end I went the nREPL way, so I can interact with the shadowcljs nrepl the same way I interact with clojure and babashka nrepls, less code 🙂 Figured out the issues I was seeing was my fault, I was creating a new session in the wrong place, instead of reusing an existing one, got everything to work as expected now