shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
emccue 2021-03-18T03:27:21.040Z

Best I can tell shadow is able to send dev builds in a single bundle to the browser

emccue 2021-03-18T03:27:54.040700Z

is there any part of the techno wizardry that went in to that which can be used with a deps.edn project?

emccue 2021-03-18T03:28:44.041700Z

right now I am working on a project that is using figwheel.main to launch the dev environment, but compared to shadow it is taking forever on refreshes just due to the number of files

emccue 2021-03-18T03:29:12.042200Z

and I can't seem to find an option anywhere that would concat those

laurent 2021-03-18T04:36:56.043300Z

Hi! I’m using Ubuntu 20.10

thheller 2021-03-18T09:04:44.044100Z

@emccue figwheel or cljs.main do not support this feature no. you can just use shadow-cljs with deps.edn if you want.

thheller 2021-03-18T09:25:59.044200Z

hmm doh

thheller 2021-03-18T09:26:15.044400Z

seems like the maximum filename length is 255 bytes for ext4

thheller 2021-03-18T09:26:36.044600Z

which this ridiculous packages manages to use up

thheller 2021-03-18T09:26:55.044800Z

unfortunately I don't have an easy fix for you. this is the first time I see such a long name

pez 2021-03-18T10:24:22.052Z

Hello. I’m writing a library containing just two macros. It’s supposed to work in both CLJS and CLJ (I am having troubles making it work, but that’s a separate issue). It’s a tools/deps project and I have added a shadow-cljs.edn file to it with a :test build that runs my (failing) tests. Now I want to connect my REPL to it. I get No JS runtime if I try to eveluate anything towards the :test build. Is there a way I could make that work? Guessing not, so next question is how do I create a build that I can connect to and use for REPL-ing? I could make a small webapp, I guess, but it still seems a bit heavier than what I really need. Anyone know of a library project out there I could have a look at?

thheller 2021-03-18T10:32:50.052400Z

@pez use shadow-cljs node-repl or shadow-cljs browser-repl

thheller 2021-03-18T10:33:12.052800Z

:test builds (assuming that is actually :browser-test or :node-test) do not support REPLs

pez 2021-03-18T10:40:04.056300Z

It’s a :node-test. I’m trying to make it using CLJC, so same tests for Clojure as for ClojureScript. They run, but all fail utterly. I want to be able to load the test file and the tested file in the repl. Tried node-repl which also gave me No JS runtime, but I am testing it via Calva, which I haven’t done in a while, so that might be broken. Will try from the prompt now and see what that gives me.

thheller 2021-03-18T10:43:32.056700Z

I guess you are launching the REPL wrong

thheller 2021-03-18T10:43:48.057100Z

launching node-repl and then connecting to the test build instead of the node-repl?

thheller 2021-03-18T10:44:18.057500Z

don't have a clue of calva has a specific option for node-repl

thheller 2021-03-18T10:44:52.058Z

node-repl will ALWAYS have a JS runtime so if you get the no JS runtime error you likely are not actually using that

pez 2021-03-18T10:53:00.061200Z

Yes, Calva has a specific option. But it runs shadow-cljs using npx so my mistake was that I didn’t hava package.json with shadow dev deps. Now it works. I can load my files and my library (that let> macro stuff you helped me with over at ClojureVerse) also works. That’s great. But the tests are not passing in the :test build. I’ll see if I can figure that out.

pez 2021-03-18T10:53:58.061800Z

Calva also has a browser-repl option, btw.

thheller 2021-03-18T10:54:10.062Z

good to know

pez 2021-03-18T11:00:51.064900Z

So running the tests taps what I expect them to tap in the shadow-cljs inspector. But the tests add a tap of their own that are then inspected. Works for CLJ, but for CLJS the atom is not updated. The tests all look like this:

(testing "Taps the binding box"
  (let [tapped (atom nil)
        save-tap (fn [v] (reset! tapped v))]
    (add-tap save-tap)
    (is (= [:foo :bar]
           (sut/let> [foo :foo
                      bar :bar]
                     [foo bar])))
    (is (= '[[foo :foo]
             [bar :bar]]
           @tapped))
    (remove-tap save-tap)))
Failing like this:
FAIL in (let>) (pez/taplet_test.cljc:20:11)
Taps the binding box
expected: (= (quote [[foo :foo] [bar :bar]]) (clojure.core/deref tapped))
  actual: (not (= [[foo :foo] [bar :bar]] nil))

thheller 2021-03-18T11:58:08.065700Z

@pez in CLJS the tap is done via setTimeout so it is async

thheller 2021-03-18T11:59:00.066100Z

you can bind your own tap-fn so it stays sync https://github.com/clojure/clojurescript/blob/715cdc07dbb1d595af91ea12affb6faf0b615d4b/src/main/cljs/cljs/core.cljs#L79-L86

pez 2021-03-18T12:30:13.067600Z

Thanks. I know this is not the CLJS support, but anyway, does this look sane enough to your eyes?

(defn sync-fn [f] (f))
(def ^:dynamic *dummy* nil)

(deftest let>
  (testing "Evaluates as `let`"
    (is (= [:foo :bar] (sut/let> [foo :foo
                                  bar :bar]
                                 [foo bar]))))

  (testing "Taps the binding box"
    (let [tapped (atom nil)
          save-tap (fn [v] (reset! tapped v))]
      (add-tap save-tap)
      (is (= [:foo :bar]
             (binding [#?(:clj *dummy*
                          :cljs *exec-tap-fn*) sync-fn]
               (sut/let> [foo :foo
                          bar :bar]
                         [foo bar]))))
      (is (= '[[foo :foo]
               [bar :bar]]
             @tapped))
      (remove-tap save-tap)))
 ...
It works, but ¯\(ツ)

laurent 2021-03-18T12:37:54.067700Z

Thanks @thheller! I search replaced the file name with a shorter name across the project and it works.

thheller 2021-03-18T13:18:07.068600Z

well I'd probably swap the binding to just use do for CLJ but this is fine too

thheller 2021-03-18T13:22:15.069300Z

you can also do #?(:cljs (set! *exec-tap-fn* (fn [f] (f))) somewhere in that file

thheller 2021-03-18T13:22:29.069700Z

not exactly clean but saves having to mess with binding and stuff 😛

pez 2021-03-18T14:16:54.070300Z

Ah, makes sense. Thanks!

Schpaa 2021-03-18T14:34:58.071500Z

What is going on here? Getting this error/warning when starting an app of mine.

error when calling lifecycle function app.core/reload! #error {:message "Unexpected compile spec type", :data {:given nil, :type nil}}
eval @ env.cljs:198
shadow$cljs$devtools$client$env$do_js_reload_STAR_ @ env.cljs:204
G__73437 @ env.cljs:204
eval @ env.cljs:196
shadow$cljs$devtools$client$env$do_js_reload_STAR_ @ env.cljs:204
G__73437 @ env.cljs:204
eval @ env.cljs:233
shadow$cljs$devtools$client$env$do_js_reload_STAR_ @ env.cljs:204
eval @ env.cljs:240
shadow$cljs$devtools$client$browser$do_js_reload @ browser.cljs:49
eval @ browser.cljs:93
eval @ shared.cljs:32
shadow$remote$runtime$shared$process @ shared.cljc:164
eval @ shared.cljs:284
shadow$cljs$devtools$client$shared$remote_msg @ shared.cljs:16
eval @ websocket.cljs:16

Schpaa 2021-03-18T14:36:55.072100Z

Also getting this when dispatching any events (in re-frame), probably nothing to do with shadow, but hey…

thheller 2021-03-18T15:22:34.072600Z

yeah not shadow. something you do in the reload! method throws an exception. no clue what.