shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
aratare 2021-01-14T02:06:36.000100Z

You can have a run configuration to run npm run. It's what I'm using at the moment.

jkent 2021-01-14T02:25:10.004100Z

After adding :repl-init-ns option to my shadow-cljs.edn, I’ve been encountering the following error after leaving my browser repl idle:

[2021-01-05 13:26:03.677 - WARNING] :shadow.cljs.devtools.server.worker.impl/cljs-compile-ex - {:input {:code "(test-client)", :ns client, :repl true}}
ExceptionInfo Failed to process REPL command {:eof? false, :ns client, :form (test-client), :source "(test-client)", :tag :shadow.cljs.repl/process-ex}
        shadow.cljs.repl/process-read-result (repl.clj:524)
        shadow.cljs.repl/process-read-result (repl.clj:498)
        shadow.cljs.repl/process-input (repl.clj:682)
        shadow.cljs.repl/process-input (repl.clj:660)
        shadow.cljs.devtools.server.worker.impl/fn--15170 (impl.clj:755)
        shadow.cljs.devtools.server.worker.impl/fn--15170 (impl.clj:745)
        clojure.lang.MultiFn.invoke (MultiFn.java:234)
        shadow.cljs.devtools.server.util/server-thread/fn--14833/fn--14834/fn--14842 (util.clj:285)
        shadow.cljs.devtools.server.util/server-thread/fn--14833/fn--14834 (util.clj:284)
        shadow.cljs.devtools.server.util/server-thread/fn--14833 (util.clj:257)
        java.lang.Thread.run (Thread.java:834)
Caused by:
ExceptionInfo no source by provide: client {:provide client}
        shadow.build.data/get-source-id-by-provide (data.clj:187)
        shadow.build.data/get-source-id-by-provide (data.clj:184)
        shadow.build.data/get-source-by-provide (data.clj:190)
        shadow.build.data/get-source-by-provide (data.clj:189)
        shadow.cljs.repl/repl-compile/fn--14400/fn--14401 (repl.clj:460)
my client.cljs file looks as follows:
(ns client
  (:require [cljs.repl :refer [doc find-doc source apropos pst dir]]
            [re-frame.core :as rf]
            [re-frame.db :as rfdb]))

(defn test-client []
  {:status "alive"})

(defn db []
  @rfdb/app-db)
what does “no source by provide: xxx {:provide xxx}” mean? is there a way to to recover from this besides restarting my shadow-clj watch and my repl?

thheller 2021-01-14T10:55:56.015800Z

which version do you use? I fixed a bug related to this in the last version

jkent 2021-01-14T14:06:16.020500Z

@thheller I’m using the latest shadow-cljs version 2.11.13

thheller 2021-01-14T15:36:20.025Z

I suppose client is not part of your usual build? try adding :preloads [client] :repl-init-ns client

jkent 2021-01-14T15:37:35.026Z

thats correct. client.cljs is mostly used a scratch file for development

jkent 2021-01-14T15:38:02.026700Z

I’ll try adding :preloads [client] to my shadow-cljs.edn file

jkent 2021-01-14T15:40:59.027600Z

I’m giving this a go:

:devtools         {:repl-init-ns client
                   :http-root    "resources/public"
                   :http-port    8280
                   :proxy-url    "<http://localhost:8080>"
                   :preloads     [client
                                  sphere.cstools
                                  devtools.preload
                                  day8.re-frame-10x.preload]}}}}

thheller 2021-01-14T15:41:38.027900Z

that should be fine

grav 2021-01-14T08:42:18.005300Z

Can I get Shadow to reload and re-run tests (`:target :node-test`) when a non-clojure file changes (in this case an edn file with expected results)?

Karol Wójcik 2021-01-14T10:43:46.012500Z

@thheller I'm sorry for notifying you directly, but I think that you're the only who can answer this question. In the project I'm working on we're using following strategy to resolve lazy modules:

(defn- lazy-resolve
  [symbol-k]
  (let [symbol' (symbol symbol-k)
        module' (-&gt; (str symbol')
                    (s/replace #"/.*" "")
                    (s/split #"\.")
                    ((partial s/join "-"))
                    keyword)]
    `(conj [] ~module' (cond-&gt; (fn [] (resolve (quote ~symbol')))
                         config.core/DEV?
                         (with-meta {:sym (quote ~symbol')})))))
.... From this we get [module-name, symbol] like ["core-reservation", "core.reservation/some-symbol"] . Then we combine that data with shadow.loader . Of course it works well. The only issue I have is how greatly this pattern increase the build size. Those invocations are spread across whole application adding like 200kb for main bundle. The question is whether it can be somehow optimized? If you could share some insights with me I would be more than grateful.

thheller 2021-01-14T10:53:30.013400Z

@karol.wojcik look at a build report to see where the size is coming from https://shadow-cljs.github.io/docs/UsersGuide.html#build-report

thheller 2021-01-14T10:54:26.014500Z

in general you should avoid resolve. there is also https://clojureverse.org/t/shadow-lazy-convenience-wrapper-for-shadow-loader-cljs-loader/3841

Karol Wójcik 2021-01-14T10:55:41.015700Z

@thheller I'm using code splitting and lazy modules. I'm trying to say that requiring lazy different modules to main bundle results in those long strings of resolves. I would like to make it smaller.

thheller 2021-01-14T10:55:56.015800Z

which version do you use? I fixed a bug related to this in the last version

Karol Wójcik 2021-01-14T10:58:14.016600Z

@thheller Ok got it. Will use loadable and the issue is resolved. 🙂 Thank you so much!

thheller 2021-01-14T11:00:22.017200Z

as I said ... look at the build report so you can figure out WHY you get the 200kb

thheller 2021-01-14T11:00:34.017600Z

my hunch would be that you are importing cljs.analyzer somewhere maybe

Karol Wójcik 2021-01-14T12:55:45.019600Z

@thheller i got a lot of lazy calls, and a lot of lazy modules. Anyway thanks for hint with cljs.analyzer. Will check this out

thheller 2021-01-14T12:56:28.020Z

that doesn't tell me anything. I do not know what a lazy call or lazy module is in your terms

thheller 2021-01-14T12:56:50.020400Z

I know what it is in the case of shadow.lazy but if you build your own I do not know what that does

jkent 2021-01-14T14:06:16.020500Z

@thheller I’m using the latest shadow-cljs version 2.11.13

Felipe Marques 2021-01-14T14:46:58.022900Z

I boiled down to two problems. • Referencing deprecated functions (and multi-method)

(defn ^:deprecated my-fn [a b] (+ a b))
• A namespace defining a value two times
(def a 1)
(def a 2)
@thheller Was there any change to Shadow from version 2.8.93 to verison 2.11.13 regarding this? I didn't find any in the notes of each release, but I may have not notice.

grounded_sage 2021-01-14T15:07:13.023400Z

How do I control what browser the browser-repl connects to?

mkvlr 2021-01-14T15:09:07.024100Z

@grounded_sage by default it’s the first one that connects, but you can change it to be the last with :repl {:runtime-select :latest} in shadow-cljs.edn

1👍
Karol Wójcik 2021-01-14T15:13:05.024200Z

I mean that I'm having 30-40 modules (you told me once that I should group those modules together (will do it as well)) in :modules section in shadow-cljs.edn configuration which I use quite extensively in main module. The strategy of requiring the module is combination of shadow.loader + resolve. Resolve is the function which adds that 200kb to main bundle. Checked whether cljs.analyzer is imported somewhere, but it's not 🙂

Karol Wójcik 2021-01-14T15:13:33.024400Z

Thank you very much for the respnse. Will use Loadable to get rid of resolve 🙂

thheller 2021-01-14T15:35:23.024800Z

resolve adds a bunch of boilerplate "noise" yes. didn't expect it to get to 200kb though.

thheller 2021-01-14T15:36:20.025Z

I suppose client is not part of your usual build? try adding :preloads [client] :repl-init-ns client

jkent 2021-01-14T15:37:35.026Z

thats correct. client.cljs is mostly used a scratch file for development

thheller 2021-01-14T15:37:48.026400Z

there is also now (shadow/repl :app {:runtime-id 123})

1👍
jkent 2021-01-14T15:38:02.026700Z

I’ll try adding :preloads [client] to my shadow-cljs.edn file

thheller 2021-01-14T15:39:03.027500Z

@marques.goncalves.fel your question is unclear. need more information about what you are doing. how do you "eval" the dev ns? (require 'dev) in the REPL? load-file from the editor? (ns dev)? if you just use (dev/whatever) without doing those first you'll get the dev is not defined error?

jkent 2021-01-14T15:40:59.027600Z

I’m giving this a go:

:devtools         {:repl-init-ns client
                   :http-root    "resources/public"
                   :http-port    8280
                   :proxy-url    "<http://localhost:8080>"
                   :preloads     [client
                                  sphere.cstools
                                  devtools.preload
                                  day8.re-frame-10x.preload]}}}}

thheller 2021-01-14T15:41:38.027900Z

that should be fine

Felipe Marques 2021-01-14T15:47:17.028100Z

I eval the file using cider-eval-buffer. The file in question is the dev.cljs which contains the dev namespace.

thheller 2021-01-14T15:59:36.028300Z

and what is in that file?

Felipe Marques 2021-01-14T16:30:39.028500Z

Lot of stuff! Hahahaha. But I found out that it didn't load when it referred another namespace that contained a deprecated function like this: (defn ^:deprecated ab [a b] (+ a b) Or when the namespace itself defined a value two times, like this:

(def company-id (random-uuid))
; Some other code
(def company-id #uuid "0acf9013-7c42-49fc-ae4b-221639bf9a34")

grounded_sage 2021-01-14T16:38:46.029300Z

Thanks @mkvlr that is exactly what I needed.

grounded_sage 2021-01-14T16:39:10.029400Z

Is this documented somewhere and how you use it?

thheller 2021-01-14T16:39:32.029600Z

ah so whenever there is a warning

thheller 2021-01-14T16:57:09.029800Z

what do you mean? thats all there is to it?

grounded_sage 2021-01-14T17:39:18.030Z

Sorry I am just unsure how :runtime-id works. Where is it generated? I don’t see anything that says runtime id when I run shadow-cljs watch app etc. I haven’t been that deep in shadow-cljs lately or doing any complex configurations.

thheller 2021-01-14T17:48:16.030200Z

ah sorry. it is visible in the ui http://localhost:9630/runtimes

thheller 2021-01-14T17:48:25.030400Z

or listed in most runtimes on connect

thheller 2021-01-14T17:48:38.030600Z

browser.cljs:20 shadow-cljs: #13 ready! or so

thheller 2021-01-14T17:48:43.030800Z

13 would be the runtime-id

grounded_sage 2021-01-14T18:24:24.031100Z

🙏

Felipe Marques 2021-01-14T18:27:48.031300Z

Yes, I think so.

thheller 2021-01-14T18:38:05.031500Z

right yeah I changed it that warnings in compiled code prevent the code from being loaded

thheller 2021-01-14T18:38:32.031700Z

still need to add an option to turn that off

Felipe Marques 2021-01-14T18:41:41.031900Z

Got it! Cool! Thanks for the information. Do you think that this is an issue that a new comer to the repo would be able to do? Maybe I can try to add this option.

thheller 2021-01-14T18:49:42.032100Z

fixed in 2.11.14 via :devtools {:ignore-warnings true} in your build config

Felipe Marques 2021-01-14T18:50:26.032300Z

cool! Thanks!