Fork me on GitHub
#shadow-cljs
<
2021-02-24
>
pez12:02:37

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.

thheller12:02:58

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?

pez12:02:42

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

thheller12:02:57

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

pez12:02:27

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.

pez13:02:26

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)

pez13:02:56

This in the build conf:

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

thheller13:02:04

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

😂 3
thheller13:02:26

use tap> and look at it in the UI

thheller13:02:51

also the metadata is misplaced

thheller13:02:57

before the args vector, not after.

pez13:02:56

That inspector. ❤️

pez13:02:45

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

pez13:02:00

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.

👍 3
pez13:02:34

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?

thheller14:02:10

@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

thheller14:02:14

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)

pez14:02:15

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

😎 3
thheller14:02:19

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

thheller14:02:16

rc will also contain all the other info. :file will have the .File instance if you need the full path. :resource-name is just the name on the classpath

thheller14:02:01

(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)

pez14:02:51

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
        (->> 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 Miller16:02:57

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?

thheller16:02:38

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

Jimmy Miller16:02:20

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)

thheller16:02:39

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

thheller16:02:17

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

Jimmy Miller16:02:29

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 Miller16:02:17

Maybe it is a lack of piggieback?

Jimmy Miller16:02:18

Wait that was the wrong one sorry

Jimmy Miller16:02:43

;;  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))        

dpsutton16:02:38

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 Miller16:02:07

Yep, I can eval perfectly fine

dpsutton16:02:09

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 Miller16:02:08

(-->
  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"
)
(<--
  id         "51"
  session    "50e453a5-e9b4-4b65-8572-923074485504"
  time-stamp "2021-02-24 11:35:14.717698000"
  status     ("done" "no-eldoc")

Jimmy Miller16:02:04

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

dpsutton16:02:06

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"

dpsutton16:02:09

(-->
  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"
)
(<--
  id           "23"
  session      "dcdd12ab-8b2e-4411-8096-66c5e103943c"
  time-stamp   "2021-02-24 10:40:49.113750000"
  added        "1.1"
  arglists-str "[string & 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 Miller17:02:38

Yeah, info does the same sort of thing.

(-->
  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"
)
(<--
  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

dpsutton17:02:06

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 Miller17:02:23

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)