shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Fredrik Andersson 2021-04-29T09:18:56.069400Z

I am trying to understand how I could use nrepl in a node-script target. Any pointers to help/tutorial?

thheller 2021-04-29T09:22:14.070100Z

depends on what you mean by "nrepl in a node-script". do you mean starting your own nrepl server or using the shadow-cljs nrepl server to talk to the node-script?

Fredrik Andersson 2021-04-29T09:28:29.070900Z

using the shadow-cljs server

Fredrik Andersson 2021-04-29T09:29:19.071900Z

atleast that's what I thought to do. I'm still quite new to clojure/cljs

thheller 2021-04-29T09:29:21.072Z

then you use it like any other REPL?

Fredrik Andersson 2021-04-29T09:30:02.072500Z

i want to attach it to cursive

thheller 2021-04-29T09:30:26.073300Z

then you connect to the shadow-cljs server (using the .shadow-cljs/nrepl.port file)

thheller 2021-04-29T09:30:37.073700Z

and then (shadow/repl :the-build-id) to switch that connection to CLJS

Fredrik Andersson 2021-04-29T09:31:06.074100Z

ah ok

Fredrik Andersson 2021-04-29T09:32:24.074900Z

hm it seems i have another problem in cursive too

Fredrik Andersson 2021-04-29T09:32:32.075Z

Fredrik Andersson 2021-04-29T09:32:47.075500Z

maybe i need to figure that out first

thheller 2021-04-29T09:33:00.075700Z

just select the proper module

thheller 2021-04-29T09:33:27.076Z

you also want to remote connect, not run a local repl

Fredrik Andersson 2021-04-29T09:34:17.076400Z

ok

Fredrik Andersson 2021-04-29T09:35:26.076900Z

i dont understand where i would chose the proper module

Fredrik Andersson 2021-04-29T09:36:12.077Z

thheller 2021-04-29T09:41:19.077600Z

you don't need that. use the "Use port from nrepl file"

thheller 2021-04-29T09:41:51.077800Z

Fredrik Andersson 2021-04-29T09:42:32.078300Z

for some reason, when i do that i cant chose project

Fredrik Andersson 2021-04-29T09:42:46.078500Z

is there a step i missed_

Fredrik Andersson 2021-04-29T09:42:49.078800Z

?

thheller 2021-04-29T09:44:44.079100Z

I don't know? how did you create the project in cursive?

Fredrik Andersson 2021-04-29T09:44:54.079300Z

i created it with npx i believe

Fredrik Andersson 2021-04-29T09:45:02.079500Z

and just opened it in cursive

Fredrik Andersson 2021-04-29T09:45:32.079900Z

ahh

Fredrik Andersson 2021-04-29T09:46:03.080100Z

thanks!

Fredrik Andersson 2021-04-29T14:51:12.081300Z

okay, now I finally found time to test this @thheller and it works. however when i try to switch workspace in i get "No avvailable JS runtime"

Fredrik Andersson 2021-04-29T14:51:35.081700Z

so I guess i'm missing something?

thheller 2021-04-29T14:54:29.082100Z

yeah, you need to run your node-script output

Fredrik Andersson 2021-04-29T14:54:40.082300Z

ok so ill do that manually_

Fredrik Andersson 2021-04-29T14:54:41.082500Z

?

thheller 2021-04-29T14:54:56.082900Z

don't know what you are building but probably yes 😉

thheller 2021-04-29T14:55:11.083600Z

if you just want a node repl use (shadow/node-repl) instead

thheller 2021-04-29T14:55:25.083900Z

(from the initially connected Cursive REPL)

Fredrik Andersson 2021-04-29T14:56:03.084500Z

i would like to have the same concept that we have in the browser where i can reload code but keeping state

Fredrik Andersson 2021-04-29T14:56:16.084700Z

is that possible?

thheller 2021-04-29T15:01:11.085300Z

sure, but only via node-script and running the thing manually

thheller 2021-04-29T15:01:15.085500Z

node-repl doesn't do hot-reload

Fredrik Andersson 2021-04-29T15:02:10.086300Z

i have setup node-script and it's building

Fredrik Andersson 2021-04-29T15:02:26.086600Z

but it doesnt run the code

thheller 2021-04-29T15:02:50.087200Z

what do you mean by that? you are supposed to run it?

thheller 2021-04-29T15:03:02.087700Z

:node-script gives you the file in :output-to

Fredrik Andersson 2021-04-29T15:03:08.088100Z

yes

thheller 2021-04-29T15:03:12.088200Z

you then run node whatever.js

thheller 2021-04-29T15:03:28.088600Z

what this process does is completely under your control depending on what you do in main?

thheller 2021-04-29T15:03:56.088900Z

what are you trying to build?

Fredrik Andersson 2021-04-29T15:04:22.089400Z

a service that is monitoring crypto exchanges

Fredrik Andersson 2021-04-29T15:04:35.089700Z

basically a script

thheller 2021-04-29T15:04:48.090Z

ok something that is long running?

thheller 2021-04-29T15:05:08.090300Z

or just a script that runs once for a second or whatever and then exits?

Fredrik Andersson 2021-04-29T15:05:09.090500Z

yes

Fredrik Andersson 2021-04-29T15:05:12.090700Z

long running

thheller 2021-04-29T15:05:25.091Z

ok fine. then when you run that you can REPL into it

thheller 2021-04-29T15:05:41.091400Z

it should log a message on startup "shadow-cljs ready" or so

Fredrik Andersson 2021-04-29T15:05:46.091600Z

yep that works

Fredrik Andersson 2021-04-29T15:05:51.091800Z

and hot reload?

Fredrik Andersson 2021-04-29T15:05:55.092Z

just rebuilding?

Fredrik Andersson 2021-04-29T15:06:05.092200Z

while keeping the process alive

thheller 2021-04-29T15:06:15.092500Z

same way as the browser targets https://shadow-cljs.github.io/docs/UsersGuide.html#_hot_code_reload

thheller 2021-04-29T15:06:32.093200Z

no difference, same setup (just see the main fn as the init fn described in the post above)

Fredrik Andersson 2021-04-29T15:06:39.093500Z

okay thanks!

Fredrik Andersson 2021-04-29T15:06:47.093700Z

ill read through it

Fredrik Andersson 2021-04-29T15:17:32.094500Z

thanks for your patience, it works like i want it to now

👍 1
grounded_sage 2021-04-29T19:57:24.096200Z

I keep getting Stale Output! on this Chrome Extension I am working on. Even when I clear all the js , out, manifest.json, .shadow-cljs, node_modules etc

grounded_sage 2021-04-29T19:57:46.096700Z

I'm wondering if there is some weird Chrome caching bug happening here.

grounded_sage 2021-04-29T19:58:01.097100Z

Hard restart of the computer seems to fix it when this happens.

grounded_sage 2021-04-29T19:58:24.097500Z

Has happened to me several times over the course of a few days now.

thheller 2021-04-29T19:59:31.097900Z

if you restart the build for any reason you need to reload the extension in chrome

grounded_sage 2021-04-29T20:14:44.098700Z

hmm I am pretty sure I do this. Like hitting refresh everywhere.

thheller 2021-04-29T20:15:29.099700Z

in <chrome://extensions/> hit the reload thingy

grounded_sage 2021-04-29T20:15:51.100200Z

I even removed the unpacked extension and loaded it again. Maybe I'm missing something. Will go slower next time and write down all the steps I take to see if I do something silly.