Fork me on GitHub
#shadow-cljs
<
2023-03-01
>
martinklepsch10:03:14

Sentry recently added @sentry/replay to their packages and then added https://github.com/getsentry/sentry-javascript/pull/6508to save people an extra require / streamline the API. Unfortunately this assumes tree shaking of npm code which shadow isn’t doing(?), which caused our build to grow by 130kb. Is there any way to manually exclude a package? Could this be imrpoved in shadow?

thheller10:03:24

what a stupid reason. removing an import and putting all the burden on tooling to figure out what you actually wanted.

martinklepsch12:03:57

yeah I also found that logic a bit rage-inducing… saved one line — bravo

thheller10:03:50

you can set :js-options {:resolve {"@sentry/replay" false}} in the build config, assuming its never actually used that should work

sirwobin12:03:48

Has anyone integrated koacha for running tests in a shadow-cljs project? Any tips to share if I give it a try?

sirwobin12:03:31

Ooh! Hadn't noticed the shadow-cljs.edn in the project root. Thanks for the pointer! And further down is a nice example..

hifumi12316:03:36

@martinklepsch for reference: npm packages are always passed through google closure's simple optimizations since the vast majority of code on npm breaks under advanced optimizations

hifumi12316:03:16

there is a setting in shadow cljs to pass npm dependencies through advanced optimizations anyway, but you'll see basically all of your npm dependencies break when you set it

dpsutton17:03:43

I’m running into an error when running (require 'ns :reload). Details in thread

dpsutton17:03:55

Running metabase and connecting to a socket repl

dpsutton17:03:06

❯ netcat localhost 51345
shadow-cljs - REPL - see (help)
To quit, type: :repl/quit
shadow.user=> (shadow/node-repl)
cljs.user=> shadow-cljs - #5 ready!
(require 'metabase.util.log-test :reload)
nil
cljs.user=> (require 'metabase.util.log-test :reload) ;; run twice no error
nil
cljs.user=> (in-ns 'metabase.util.log-test)
nil
metabase.util.log-test=> (logf-formatting-test)
[metabase.util.log-test] "input: 8, 3; output: ignored"
nil
metabase.util.log-test=> (require 'metabase.util.log-test :reload)
------ REPL Error while processing ---------------------------------------------
(require 'metabase.util.log-test :reload)
no source by provide: metabase.util.log-test
{:provide metabase.util.log-test}
ExceptionInfo: no source by provide: metabase.util.log-test
	shadow.build.data/get-source-id-by-provide (data.clj:192)
	shadow.build.data/get-source-id-by-provide (data.clj:187)
	shadow.build.data/get-source-by-provide (data.clj:195)
	shadow.build.data/get-source-by-provide (data.clj:194)
	shadow.build.resolve/resolve-repl (resolve.clj:725)
	shadow.build.resolve/resolve-repl (resolve.clj:719)
	shadow.cljs.repl/repl-require (repl.clj:223)
	shadow.cljs.repl/repl-require (repl.clj:187)
	shadow.cljs.repl/process-read-result (repl.clj:530)
	shadow.cljs.repl/process-read-result (repl.clj:510)
	shadow.cljs.repl/process-input (repl.clj:673)
	shadow.cljs.repl/process-input (repl.clj:651)
	shadow.cljs.devtools.server.worker.impl/eval17570/fn--17573 (impl.clj:698)
	clojure.lang.MultiFn.invoke (MultiFn.java:234)
	shadow.cljs.devtools.server.util/server-thread/fn--17210/fn--17211/fn--17219 (util.clj:283)
	shadow.cljs.devtools.server.util/server-thread/fn--17210/fn--17211 (util.clj:282)
	shadow.cljs.devtools.server.util/server-thread/fn--17210 (util.clj:255)
	java.lang.Thread.run (Thread.java:833)

dpsutton17:03:39

i can require the namespace several times, then switch to the namespace, run a test. But if i require :reload from the namespace itself I get an error

dpsutton17:03:52

I’m running shadow with :deps {:aliases [:cljs]}, and that alias is

:cljs
  {:extra-paths ["test" "shared/test"]
   :extra-deps
   {binaryage/devtools                 {:mvn/version "1.0.6"}
    cider/cider-nrepl                  {:mvn/version "0.30.0"}
    cider/piggieback                   {:mvn/version "0.5.3"}
    cljs-bean/cljs-bean                {:mvn/version "1.9.0"}
    com.lambdaisland/glogi             {:mvn/version "1.2.164"}
    io.github.metabase/hawk            {:sha "45ed36008014f9ac1ea66beb56fb1c4c39f8342b"}
    ;; Forcibly targeting a newer release than ships by default with shadow-cljs 2.20.20.
    ;; It fixes an issue where TypeScript can't parse the `cljs_env.js` output file.
    org.clojure/google-closure-library {:mvn/version "0.0-20230227-c7c0a541"}
    refactor-nrepl/refactor-nrepl      {:mvn/version "3.6.0"}
    thheller/shadow-cljs               {:mvn/version "2.21.0"}}}

dpsutton18:03:40

digging into the compiler state, the error says it is not finding the provide (the namespace symbol) in the :sym->id map Looking at the contents of that, that seems to omit the current namespace. So i can require :reload other namespace, and if i require another namespace then the current namespace shows back up

dpsutton18:03:00

I also think that it’s using my require forms in the repl and adding those to a dependency graph. It thinks that I’m adding a require to the other namespace and then switching around makes it warn about circularity

thheller18:03:03

hmm could be wiping too much or not enough from the compiler-env due to the :reload

thheller18:03:23

I never use require re-load, load-file is much more reliable

thheller18:03:52

but should work regardless

dpsutton18:03:24

why do you say that? I use :reload in clojure repls. And that ensures that all of the metadata is set correctly on vars (line numbers and such) so doc and friends work. So I prefer that route. But wondering why you prefer load-file

thheller18:03:42

the require creating a circular require is known, currently there is no separation of requires added by the REPL or code

dpsutton18:03:10

ok. is that a feature request i can add or just a known limitation of the internals?

thheller18:03:35

this should work fine. I cannot immediately tell you why it doesn't

thheller18:03:44

just saying that load-file might not have that issue 😛

thheller18:03:13

(which is what cursive uses, so I guess that why I never end up with require)

dpsutton18:03:27

(i meant about the circular require issue). I’ll switch to load-file 🙂 . Happy to create any issues that you are interested in tackling (making require work correctly at the repl, the circularity bug, etc)

thheller18:03:55

yes, feel free to open an issue. there is already one for the circular dependency though

thheller18:03:59

so keep it to the reload thing

dpsutton18:03:08

thanks much

dpsutton19:03:36

thanks for your help