shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
pez 2021-02-24T12:39:37.083200Z

Is there a way to configure the compilation progress output to include the files being compiled? So I have things like this in the log

[:dev] Build completed. (451 files, 3 compiled, 0 warnings, 5.12s)
And would like to have the file paths of the 3 compiled files.

thheller 2021-02-24T12:41:58.083400Z

the UI might be a better option for that? as far as the CLI is concerned there is only --verbose which is likely too verbose?

pez 2021-02-24T12:50:42.084400Z

Looks like I can grep a bit on the verbose output and get what I want.

thheller 2021-02-24T12:51:57.085100Z

what do you want? if you actually want to do something with the "data" a build hook might help? https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks

pez 2021-02-24T12:57:27.088300Z

A build hook might do it too. I have the output from the CLI in a terminal pane in VS Code. When I save a file or unstash something and such I like to see when the compilation is done, and also which files have been recompiled. It’s more “for my information” than anything else.

pez 2021-02-24T13:21:26.089100Z

Tried with this hook now, but don’t see anything in the CLI output.

(defn print-compilation-info [build-state & args]
  {:shadow.build/stages #{:compile-finish :flush}}
  (prn [:build-state build-state
        :args args])
  build-state)

pez 2021-02-24T13:22:56.089600Z

This in the build conf:

:build-hooks [(env.hooks/print-compilation-info 1 2 3)]

thheller 2021-02-24T13:26:04.090400Z

ehm yeah printing the build-state is not a good idea. it will be several hunderd megabytes 😛

😂 1
thheller 2021-02-24T13:26:26.090600Z

use tap> and look at it in the UI

thheller 2021-02-24T13:26:51.090800Z

also the metadata is misplaced

thheller 2021-02-24T13:26:57.091Z

before the args vector, not after.

pez 2021-02-24T13:28:56.091400Z

That inspector. ❤️

pez 2021-02-24T13:29:45.092Z

With the metadata map at the right place things started to work of course.

pez 2021-02-24T13:31:00.093400Z

We have just (yesterday) switched to shadow at work for our react native app. I am going to have so much use for the inspector I now realize. Totally wonderful.

👍 1
pez 2021-02-24T13:51:34.095800Z

Not sure I can hook myself to the output I want. Using verbose output it looks like I would want the -> Cache write: foo.cljs rows in addition to the non-verbose output. But i don’t find the info I need in the build-state. You think it is there in any of the stages, @thheller?

thheller 2021-02-24T14:07:10.096300Z

@pez well you could replace the logger but I think it is enough if you just get the data you need and print what you want

thheller 2021-02-24T14:07:14.096500Z

for example

(defn pez-print
  {:shadow.build/state :flush}
  [{:keys [build-sources] :as build-state}]
  
  (let [compiled (get-in build-state [:shadow.build/build-info :compiled])]
    (doseq [src-id build-sources
            :when (contains? compiled src-id)
            :let [rc (get-in build-state [:sources src-id])]]
      (prn [:compiled (:resource-name rc)])))

  build-state)

pez 2021-02-24T14:11:15.097900Z

:shadow-build/build-info :compiled! Thanks. I’m tempted to name the hook like that. 😃

😎 1
thheller 2021-02-24T14:12:19.098500Z

yeah I need to document the build-state data at some point. kind of a lot of stuff in there 🙂

thheller 2021-02-24T14:15:16.099300Z

rc will also contain all the other info. :file will have the <http://java.io|java.io>.File instance if you need the full path. :resource-name is just the name on the classpath

thheller 2021-02-24T14:18:01.100100Z

(not all sources fill have :file though so make sure you are only accessing it if it exist. won't exist for classpath .jar resources for example)

pez 2021-02-24T14:48:51.101200Z

I’ll run with this for now. Many thanks for the help!

(defn print-compiled-files
  {:shadow.build/stages #{:flush}}
  [{:keys [build-sources] :as build-state}]
  (let [compiled
        (get-in build-state
                [:shadow.build/build-info
                 :compiled])
        output
        (-&gt;&gt; rc
             :resource-name
             (for [src-id build-sources
                   :when (contains? compiled src-id)
                   :let [rc (get-in build-state
                                    [:sources src-id])]])
             (sort)
             (into [:compiled]))]
    (binding [clojure.pprint/*print-right-margin* 20]
      (clojure.pprint/pprint output)))
  build-state)

jimmy 2021-02-24T16:15:57.101800Z

Posted in #cider and got no bites. Figured I’d repost here: Anyone else have any issues with cider-doc in a shadow-cljs? It is working fine in my clojure repl and in a different project that uses weasel. It isn’t even working for built-in clojure functions.  Toggled messages and just see a (“done” “no-eldoc”). Any ideas?

thheller 2021-02-24T16:16:38.102200Z

shadow-cljs doesn't handle eldoc. the cider-nrepl middleware does. did you install that?

jimmy 2021-02-24T16:18:20.103300Z

Yep, got cider nrepl. Works for all the other projects I’m working on. But for some reason not working in my shadow-cljs project. (Posted in cider first because I know it isn’t shadow-cljs’s fault)

thheller 2021-02-24T16:21:39.104100Z

if you have the cider-nrepl listed as a proper dependency and a new enough shadow-cljs version it should work

thheller 2021-02-24T16:22:17.105300Z

but I don't use emacs or cider so I cannot help much with debugging

jimmy 2021-02-24T16:24:29.106200Z

No worries. Like I said, not it isn’t shadow’s fault. Just want to see if anyone has run into it. I’m doing a jack-in. (Pasted the wrong one here see comment in thread for correct one) Using shadow version 2.11.17

jimmy 2021-02-24T16:25:17.106300Z

Maybe it is a lack of piggieback?

jimmy 2021-02-24T16:26:18.106800Z

Wait that was the wrong one sorry

jimmy 2021-02-24T16:26:43.107100Z

;;  Startup: /Users/jimmy/.npm-packages/bin/npx shadow-cljs -d nrepl:0.8.2 -d cider/piggieback:0.5.2 -d cider/cider-nrepl:0.25.4 server                                                                                                     
43 ;;                                                                                                                                                                                                                                          
44 ;; ClojureScript REPL type: shadow                                                                                                                                                                                                          
45 ;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :frontend) (shadow/nrepl-select :frontend))        

thheller 2021-02-24T16:28:08.107500Z

looks fine

dpsutton 2021-02-24T16:28:38.107700Z

and you've connected to the runtime? something like (js/alert "hi") will work? (making sure you're not still in a clojure repl or have connected to the js engine)

jimmy 2021-02-24T16:34:07.107900Z

Yep, I can eval perfectly fine

dpsutton 2021-02-24T16:36:09.108100Z

m-x nrepl-toggle-message-logging and then try again. you can inspect the nrepl messages to see if there are any clues there

jimmy 2021-02-24T16:37:08.108300Z

(--&gt;
  id         "51"
  op         "eldoc"
  session    "50e453a5-e9b4-4b65-8572-923074485504"
  time-stamp "2021-02-24 11:35:14.713680000"
  ns         #("[my-namespace]" 0 40 (fontified t help-echo cider--help-echo cider-locals nil cider-block-dynamic-font-lock t face font-lock-type-face))
  sym        "helix/defnc"
)
(&lt;--
  id         "51"
  session    "50e453a5-e9b4-4b65-8572-923074485504"
  time-stamp "2021-02-24 11:35:14.717698000"
  status     ("done" "no-eldoc")

jimmy 2021-02-24T16:38:04.108600Z

Doesn’t matter what symbol. That is what I always get.

dpsutton 2021-02-24T16:41:06.108800Z

m-x cider-describe-session and choose either of the two connections listed (if you only have the one connection at the moment. one is tooling, one is regular interaction). It should open up a buffer with Supported ops: and list what the connection can do. you can see if eldoc and info are supported. also, eldoc is something that happens on hover i think. I think you want to find an op of "info"

dpsutton 2021-02-24T16:41:09.109Z

(--&gt;
  id         "23"
  op         "info"
  session    "dcdd12ab-8b2e-4411-8096-66c5e103943c"
  time-stamp "2021-02-24 10:40:49.108554000"
  ns         #("metabase.sync.sync-metadata.tables-test" 0 39 (fontified t help-echo cider--help-echo cider-locals nil cider-block-dynamic-font-lock t face font-lock-type-face))
  sym        "testing"
)
(&lt;--
  id           "23"
  session      "dcdd12ab-8b2e-4411-8096-66c5e103943c"
  time-stamp   "2021-02-24 10:40:49.113750000"
  added        "1.1"
  arglists-str "[string &amp; body]"
  column       1
  doc          "Adds a new string to the list of testing contexts.  May be n..."
  file         "jar:file:/Users/dan/.m2/repository/org/clojure/clojure/1.10...."
  line         597
  macro        "true"
  name         "testing"
  ns           "clojure.test"
  resource     "clojure/test.clj"
  see-also     ("clojure.test/is" "clojure.test/deftest")
  status       ("done")
)

jimmy 2021-02-24T17:26:38.109200Z

Yeah, info does the same sort of thing.

(--&gt;
  id         "66"
  op         "info"
  session    "50e453a5-e9b4-4b65-8572-923074485504"
  time-stamp "2021-02-24 12:24:05.124286000"
  ns         #("[my-ns]" 0 40 (fontified t help-echo cider--help-echo cider-locals nil cider-block-dynamic-font-lock t face font-lock-type-face))
  sym        "helix/defnc"
)
(&lt;--
  id         "66"
  session    "50e453a5-e9b4-4b65-8572-923074485504"
  time-stamp "2021-02-24 12:24:05.127422000"
  status     ("done" "no-info")
)
I do have two sessions. One shows me a big long list including eldoc and info. But the session listed above “50e453a5-e9b4-4b65-8572-923074485504” literally doesn’t open up anything when I do a cider-describe-nrepl-session

dpsutton 2021-02-24T17:31:06.109400Z

hmm. i can look into this tonight to see if i can reproduce. don't have time until then. sorry about this issue though

jimmy 2021-02-24T17:37:23.109600Z

I think I figured out a commonality. Most of them that aren’t working are macros. There are non-macros that are working. (At first I thought none were working, I just kept accidentally trying macros)