Fork me on GitHub
#shadow-cljs
<
2022-04-01
>
chromalchemy01:04:12

Can I run a cljs repl on target :npm-module ? Also, If I run shadow-cljs watch :code, get server + nrepl port, connect to it (in cursive, ,via port), run (shadow/repl :code) I get No available JS runtime. Any not sure how to procede. Here is my shadow-cljs.end

{:source-paths ["src"]
 :dependencies
   [[binaryage/devtools "1.0.5"]]

 :builds
   {:code
    {:target :npm-module
     :output-dir  "node_modules/shadow-cljs"
     :entries [gbo.mycljs]}}}

thheller05:04:57

:npm-module can in theory have a REPL but it depends on how and where you are including the code. if another tools processes it too much it won't work. eg. webpack can work but also can break horribly đŸ˜›

thheller05:04:14

for it to load you need to set a proper :runtime :browser or :runtime :node in the build config

thheller05:04:55

and then include the devtools client ns from JS so if (process.env.NODE_ENV === "development") { require("shadow-cljs/shadow.cljs.devtools.client.browser") } or so

mauricio.szabo02:04:13

@thheller any tips on hacking shadow-cljs? I'm feeling bad only asking/reporting issues and I want to know how could I try to fix them too đŸ™‚

thheller05:04:35

thats kind of too general. what do you intend to work on? its just a clojure project like any other clojure project đŸ˜›

thheller06:04:45

I usually add the shadow-cljs src/main path to a project I'm working on. ie. keep the regular dependency and then just override it with local sources. then just poke at it from the REPL.

thheller06:04:00

similar to working on shadow-cljs directly

mauricio.szabo21:04:52

Yes, I think the idea of adding src/main path could work đŸ™‚. My problem is with react-native builds, somehow I see no stacktrace at all (only the munged function name). I was thinking if I could debug it and at least know what's wrong

thheller21:04:00

define no stacktrace at all. like what is the error?

mauricio.szabo00:04:51

The stacktrace appears, but no file (not even the JS one) or line number

thheller06:04:49

this is not an error from shadow-cljs and nothing you do to shadow-cljs will change this error message?

mauricio.szabo17:04:23

It's not an error from shadow-cljs - it's just that when I use shadow-cljs with react native, and an error occurs on my code, I don't see the ClojureScript nor the Javascript (compiled) file, regardless of source-maps is disabled or enabled...

mauricio.szabo17:04:55

So I've been thinking if I could debug this issue somehow

thheller18:04:20

hmm yeah dunno what your plan is. so can't provide tips. but there is nothing in shadow-cljs producing this stacktrace format. that is all in react-native/metro

thheller18:04:44

maybe you can just try/catch this error in your code somewhere so you can get to it before metro mangles it?

mauricio.szabo15:04:50

Yeah, that's what I did: I did a (try (my-code) (catch :default e) (println (-stack e)), and indeed the filename and row are missing

thheller06:04:31

oh well I just remembered that metro didn't support merging input source maps a very long time ago. maybe it still doesn't? I don't really keep up to date with what react-native is doing. maybe something in that changed so that you now get no trace at all rather than a trace back to the JS?

Joshua Smock10:04:02

Is there a way to get the current build state from a channel or some other async mechanism when running a build using (devtools.api/watch target {:autobuild false}) and (devtools.api/watch-compile! target)? At the moment I’m using the build history coming from the server instance ref (`(get @(:state-ref (:build-history @devtools.server.runtime/instance-ref)) target)`) but if it’s possible to get it via a channel that would be nicer. I tried to use the :channels :output channel coming from the worker state ref but subscribing to that seemed to cause some issues

thheller15:04:22

what do you intend to do with this state? makes it easier to give suggestions on how to get it đŸ˜›

Joshua Smock13:04:16

I need to know what the latest status that isn’t :compiling is so I can see if the build succeeded or failed programmatically

Joshua Smock18:04:04

I want to know if a build has succeeded or failed when run in watch mode, and I need to query for the status programmatically. The way described at the start works but I saw there are also async channels, so I wonder if I should use the method described there or if there is another way

thheller18:04:08

it would really help to know WHERE you want to know it? like what kind of tool? the info is all available but without knowing a WHERE I cannot give a suggestions of which method to use

thheller18:04:46

do you want to know it on the client side? do you want to know it in the JVM running shadow-cljs? do you want to know it over nrepl?

Joshua Smock18:04:52

In the JVM, with a running server using the devtools server

thheller18:04:32

so you are running it in embedded mode? via a user.clj or so? or is that one started just via shadow-cljs server or shadow-cljs watch ..?

Joshua Smock18:04:52

I guess so, I'm running it by calling devtools.server/start! and then api/watch :target-name

thheller18:04:20

ok, (sys-bus/sub (:system-bus @shadow.cljs.devtools.server.runtime/instance-ref) :shadow.cljs.model/worker-broadcast your-channel)

thheller18:04:34

sys-bus being shadow.cljs.devtools.server.system-bus

thheller18:04:56

your-channel being a core.async channel you create and read from. or close when done

thheller18:04:10

:shadow.cljs.model/worker-broadcast listens to all build workers

thheller18:04:48

[:shadow.cljs.model/worker-output build-id] instead would just be the output for the specified build

thheller18:04:54

messages are the same

Joshua Smock18:04:31

Great, thanks!