Fork me on GitHub
#shadow-cljs
<
2020-05-17
>
orestis09:05:57

I’m building a library that I want to be compatible with both stable and experimental React. So when testing I need to bounce back between the two versions. I can probably detect the presence of functions at runtime, or I could have two different namespaces (one for stable and one for experimental), letting the user decide which to use.

orestis10:05:39

But when I’m developing the library, is there a way to test things out without too much hassle? My current thinking is to put the testing/demo stuff in a different project and use the library as a local root dep. Then I’d fire up two shadow-cljs instances, each one with a different node_modules.

thheller10:05:15

no clue? seems like more of a npm question than a shadow-cljs question 😛

thheller10:05:50

I'd probably take your appraoch of 2 separate builds with two separate folders

orestis10:05:23

I’ll play around. I assume shadow looks for node_modules next to shadow-cljs.edn?

orestis11:05:26

Btw where is the source for this guide? Would be nice to submit PRs ( if welcome)

folcon11:05:51

When you’re performing a require in the namespace in shadow-cljs, you have to add it to the ns form right? Shadow doesn’t like you referring to a namespace alias you defined outside that?

folcon11:05:12

Using code in editor sent to clojure repl:

(require '[clojure.data :as data])
(data/diff [1 2 3] [4 5 6])
=> nil
=> [[1 2 3] [4 5 6] nil]
Using code in editor sent to shadow repl:

folcon11:05:12

(require '[clojure.data :as data])
------ REPL Error while processing ---------------------------------------------
(require '[clojure.data :as data])
no source by id: [:shadow.build.classpath/resource "terrain_cljs/core_test.cljs"]
{:id [:shadow.build.classpath/resource "terrain_cljs/core_test.cljs"]}
ExceptionInfo: no source by id: [:shadow.build.classpath/resource "terrain_cljs/core_test.cljs"]
	shadow.build.data/get-source-by-id (data.clj:171)
	shadow.build.data/get-source-by-id (data.clj:168)
	shadow.build.compiler/remove-dead-js-deps/remove-fn--13854/fn--13855 (compiler.clj:1164)
	clojure.core/complement/fn--5669 (core.clj:1441)
	clojure.core/filter/fn--5893 (core.clj:2817)
	clojure.lang.LazySeq.sval (LazySeq.java:42)
	clojure.lang.LazySeq.seq (LazySeq.java:51)
	clojure.lang.ChunkedCons.chunkedNext (ChunkedCons.java:59)
	clojure.core/chunk-next (core.clj:708)
	clojure.core.protocols/fn--8154 (protocols.clj:137)
	clojure.core.protocols/fn--8154 (protocols.clj:124)
	clojure.core.protocols/fn--8114/G--8109--8123 (protocols.clj:19)
	clojure.core.protocols/seq-reduce (protocols.clj:31)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8088/G--8083--8101 (protocols.clj:13)
	clojure.core/reduce (core.clj:6828)
	clojure.core/into (core.clj:6895)
	clojure.core/into (core.clj:6887)
	shadow.build.compiler/remove-dead-js-deps/remove-fn--13854 (compiler.clj:1166)
	clojure.core/update (core.clj:6196)
	clojure.core/update (core.clj:6188)
	shadow.build.compiler/remove-dead-js-deps/fn--13859/fn--13860 (compiler.clj:1172)
	clojure.core/map/fn--5866 (core.clj:2753)
	clojure.lang.LazySeq.sval (LazySeq.java:42)
	clojure.lang.LazySeq.seq (LazySeq.java:51)
	clojure.lang.RT.seq (RT.java:535)
	clojure.core/seq--5402 (core.clj:137)
	clojure.core.protocols/seq-reduce (protocols.clj:24)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8146 (protocols.clj:75)
	clojure.core.protocols/fn--8088/G--8083--8101 (protocols.clj:13)
	clojure.core/reduce (core.clj:6828)
	clojure.core/into (core.clj:6895)
	clojure.core/into (core.clj:6887)
	shadow.build.compiler/remove-dead-js-deps/fn--13859 (compiler.clj:1173)
	clojure.core/update (core.clj:6196)
	clojure.core/update (core.clj:6188)
	shadow.build.compiler/remove-dead-js-deps (compiler.clj:1170)
	shadow.build.compiler/remove-dead-js-deps (compiler.clj:1159)
	shadow.build.compiler/compile-all (compiler.clj:1422)
	shadow.build.compiler/compile-all (compiler.clj:1269)
	shadow.build.api/compile-sources (api.clj:258)
	shadow.build.api/compile-sources (api.clj:250)
	shadow.build.api/compile-sources (api.clj:262)
	shadow.build.api/compile-sources (api.clj:250)
	shadow.cljs.repl/repl-require (repl.clj:218)
	shadow.cljs.repl/repl-require (repl.clj:187)
	shadow.cljs.repl/process-read-result (repl.clj:522)
	shadow.cljs.repl/process-read-result (repl.clj:502)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:879)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:833)
	shadow.cljs.devtools.server.worker.impl/eval16051/fn--16052 (impl.clj:914)
	clojure.lang.MultiFn.invoke (MultiFn.java:234)
	shadow.cljs.devtools.server.util/server-thread/fn--15579/fn--15580/fn--15588 (util.clj:285)
	shadow.cljs.devtools.server.util/server-thread/fn--15579/fn--15580 (util.clj:284)
	shadow.cljs.devtools.server.util/server-thread/fn--15579 (util.clj:257)
	java.lang.Thread.run (Thread.java:830)
(data/diff [1 2 3] [4 5 6])
------ WARNING - :undeclared-ns ------------------------------------------------
 Resource: :1:2
 No such namespace: data, could not locate data.cljs, data.cljc, or JavaScript source providing "data"
--------------------------------------------------------------------------------
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: :1:2
 Use of undeclared Var data/diff
--------------------------------------------------------------------------------
ReferenceError: data is not defined
    at eval (eval at shadow$cljs$devtools$client$browser$global_eval (), <anonymous>:1:1)
    at eval (<anonymous>)
    at Object.shadow$cljs$devtools$client$browser$global_eval [as global_eval] ()
    at eval ()
    at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] ()
    at Object.shadow$cljs$devtools$client$browser$repl_invoke [as repl_invoke] ()
    at shadow$cljs$devtools$client$browser$handle_message ()
    at eval ()
    at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] ()
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] ()

folcon11:05:12

Manually pasting the form:

(require '[clojure.data :as data])
=> nil
1
=> 1
(data/diff [1 2 3] [4 5 6])
=> [[1 2 3] [4 5 6] nil]

thheller11:05:27

@folcon you can't define a namespace alias outside the ns

folcon11:05:28

In shadow? It works in the normal repl, just tested it…

thheller11:05:55

REPL is a special case

thheller11:05:58

it does not work in regular files

folcon11:05:12

Ah, sure =)…

folcon11:05:32

Sorry, just to be clear, In both cases I’m performing send form to repl in a file, not pasting straight into the repl?

folcon11:05:02

Let me check in a clj file (as opposed to user.clj), you’re almost certainly right however =)…

folcon11:05:09

No, that seems to work as well? To be honest, I’m not really bothered, it’s an easy thing to just add the form to the file. I’m more surprised that this requires special handling, I would have thought this sort of functionality would have been part of the reader?

thheller11:05:15

CLJ is different ...

folcon11:05:25

That’s fair =)…

thheller11:05:45

it is simply a limitation of the JS platform. we cannot do sync IO, which require would need.

folcon11:05:06

Good to know

thheller21:05:13

in case someone is interested in WASM related things https://www.reddit.com/r/Clojure/comments/gloazr/using_wasm_in_cljs/

👀 4
👏 8
🎉 8