Fork me on GitHub
#shadow-cljs
<
2019-12-03
>
cfleming08:12:18

Hi all, I’m trying out shadow for some CLJS projects I have, it looks great so far. I have one question: I’m building code to deploy to AWS Lambda. I’m using :optimizations :simple , and I’d expected that to produce a single JS file. But it’s producing my :output-to file in a way that references a ton of other files under .shadow-cljs/builds - is that normal? Can I make it produce a single file without going to advanced optimisations?

cfleming09:12:05

Actually @U0510KXTU gave me the solution here, use release instead of compile.

romdoq09:12:02

@thheller I was testing with 2.8.76, but 2.8.77 also has the same behaviour - defines are not being overridden, and devtools are not active (I'd guess because the define/s to enable the devtools aren't being overridden).

Eliraz09:12:56

hey, can shadow-cljs work with lumo ?

thheller09:12:13

no. why would it?

Eliraz09:12:36

Hmmm so you won't have to deal with Java?

thheller09:12:50

you mean install it once and never see it again?

Eliraz09:12:45

I know you don't really deal with Java, and still you need to configure it on every machine that you'd like to build your code..

thheller09:12:50

the answer is no. shadow-cljs is written in Clojure and uses the Google Closure Compiler (written in Java). The Java requirement will stay.

Eliraz09:12:34

got it. I thought that the Google Closure Compiler has a JavaScript variant.

thheller10:12:08

it does. but it is like 10x slower and also not extensible in the way the java version is

Eliraz10:12:50

okay. that's good to know.

Eliraz10:12:06

so lumo is not "there" yet.

thheller10:12:46

not sure where "there" is but lumo is an entirely different project with entirely different goals. dunno if it even supports "builds" nowadays, the focus was always scripting AFAICT

romdoq10:12:31

Oof okay, apparently I was wrong about devtools working in 2.8.68. In that version the websocket connects, but the browser doesn't appear to notice updates when shadow recompiles changed files. It appears that that stopped working for me in 2.8.56 . 😕

thheller10:12:47

@mel.collins I'm working on that currently. I only verified in release builds and that did work fine

thheller10:12:56

but dev builds do instead have issues with closure defines

romdoq10:12:34

okay cool, thanks!

thheller10:12:00

why do you use :npm-module? I'm likely going to remove it given that it causes the most issues out of any builds

thheller10:12:33

oh nvm. you already answered that 😛

romdoq11:12:05

@thheller that seems to fix the defines, and the websocket is back! However, the hot reloading that stopped working in 2.8.56 is still broken. I thought it might be how I used my react components, but I don't get console logs about subscriptions being replaced (by re-frame) either.

thheller11:12:34

do you get console logs about shadow-cljs doing stuff?

thheller11:12:40

I mean it should be logging something right?

romdoq11:12:08

I get "websocket connected!" and "repl session start successful"

romdoq11:12:33

and I can see a websocket message come through when a build completes 😕

romdoq11:12:03

I mean in the network tab, not the console

thheller11:12:39

you don't happen to have a reproducible example?

thheller11:12:51

I don't have a working webpack setup anymore ...

thheller11:12:52

maybe I can try setting one up later ... don't have any ideas about what might be happening right now

romdoq11:12:50

I don't have a simple example, no. 😞 The only project I have is our main app, which is huge!

sheluchin11:12:35

I'm new to Clojure(script) and I'm trying to get some clarity on how to run tests. I'm building a Fulcro application and I want the tests to be integrated with my editor, so I can run them from Vim and get the results right there. I have: • :deps {:aliases [:dev]} in shadow-cljs.edn • :paths ["src/app" "src/test"] in the top level of deps.edn • src/test/sheluchin/poker/core_test.cljs with these contents:

(ns sheluchin.poker.core-test
  (:require
    [cljs.test :refer-macros [deftest is testing run-tests]]))

(deftest test-numbers
  (is (= 1 1)))

(run-tests)
It's unclear to me which option I should be using for running the tests: node.js, browser, or karma. Is it absolutely necessary to define a build target specifically for testing, or can I forego that for the time being? What command should I be using to run the tests? If I just eval the (run-tests) form, it doesn't seem to pick up on updates to that file, so if I change the test to (is (= 2 1)) , save the file, and re-eval the (run-tests) form, all the test still shows as passing.

romdoq11:12:41

I can work with 2.8.55 for the time being, so no rush. @thheller Let me know if you need more info or testing from my side. Thanks for your work

thheller11:12:35

@alex.sheluchin hot-reload in general only picks up changes from files used in the actual build (so no tests). you can use the :browser-test target for tests

thheller11:12:22

or I guess you could add the tests via :devtools {:preloads [your.foo.core-test]} in the regular build. that would make them hot-reload as well

sheluchin11:12:26

Ah, so even if I explicitly (require 'sheluchin.poker.core-test) after updating the file, it doesn't get picked up unless I shadow-cljs restart?

thheller11:12:07

to reload you'd do (require 'sheluchin.poker.core-test :reload) otherwise it'll not load anything if its already loaded

thheller11:12:40

or load-file is what I generally use (or rather my editor does)

thheller11:12:12

I don't think I have ever run a test as part of my regular build though

thheller11:12:26

no one has asked for that before either so support might not be great

thheller11:12:40

(if you expect hot-reload, everything else should be fine)

sheluchin11:12:23

Fair enough, I won't go against the grain on that; I'll just set up the separate build target for testing.

sheluchin11:12:48

With a :browser-test build target, what's the usual way to run the tests? I'm guessing it's like everything else and has CLI and REPL equivalents?

thheller11:12:20

you open the webpage. tests run on hot-reload

sheluchin11:12:51

If I want the results in my shell, is there a command I can call for that?

thheller11:12:09

karma or node-test

thheller11:12:22

you said fulcro application so I assumed webapp and that you need a browser

sheluchin11:12:03

Yep, it's a Fulcro webapp, but I want the results in my shell so I don't have to look at the browser. I understand that I need to have the builds active and need to have dev tools open to interact with the environment, but once that's done, I can receive the results in the shell as well as them being printed in the console?

thheller11:12:23

thats what karma would provide but you can't REPL into that at all

sheluchin11:12:16

Okay, thanks for the advice and info. This should be enough for me to try a few things and see if I can get something to work how I want it. Much appreciated.

thheller11:12:19

if you want to run the tests from the REPL as part of your main build then just try the :preloads thing I mentioned

thheller11:12:47

if you want other automated stuff you are limited to what is currently provided

sheluchin11:12:36

I'll provide some feedback after I figure out a setup that works for me. At this point I just want the testing to play nice with vim-fireplace and there's no definitive guide on that just yet. Thanks again.

sheluchin13:12:45

[1:1]~cljs.user=> (require 'sheluchin.poker.core-test :reload)

Testing sheluchin.poker.core-test

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
nil

[1:1]~cljs.user=> (load-file "sheluchin/poker/core_test.cljs")
[:result {:type :repl/error, :ex #error {
 :cause "file not on classpath"
 :data {:file-path "sheluchin/poker/core_test.cljs"}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "file not on classpath"
   :data {:file-path "sheluchin/poker/core_test.cljs"}
   :at [shadow.cljs.repl$repl_load_file_STAR_ invokeStatic "repl.clj" 254]}]
 :trace
 [[shadow.cljs.repl$repl_load_file_STAR_ invokeStatic "repl.clj" 254]
  [shadow.cljs.repl$repl_load_file_STAR_ invoke "repl.clj" 227]
  [shadow.cljs.repl$repl_load_file invokeStatic "repl.clj" 301]
  [shadow.cljs.repl$repl_load_file invoke "repl.clj" 299]
  [shadow.cljs.repl$process_read_result invokeStatic "repl.clj" 426]
  [shadow.cljs.repl$process_read_result invoke "repl.clj" 406]
  [shadow.cljs.devtools.server.worker.impl$do_repl_rpc invokeStatic "impl.clj" 797]
  [shadow.cljs.devtools.server.worker.impl$do_repl_rpc invoke "impl.clj" 751]
  [shadow.cljs.devtools.server.worker.impl$eval15200$fn__15201 invoke "impl.clj" 828]
  [clojure.lang.MultiFn invoke "MultiFn.java" 234]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772$fn__14773$fn__14781 invoke "util.clj" 285]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772$fn__14773 invoke "util.clj" 284]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772 invoke "util.clj" 257]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 834]]}}]
[1:1]~cljs.user=>

+08:07 $ npx shadow-cljs classpath | tr ':' '\n'
shadow-cljs - config: /home/alex/repos/clojure-stuff/fulcrologic/poker/shadow-cljs.edn  cli version: 2.8.64  node: v8.11.1
src/app
src/test
...


+08:08 $ tree src/test/
src/test/
└── sheluchin
    └── poker
        └── core_test.cljs
I can require the namespace and it works fine, but load-file complains that the file is not in the classpath, although it clearly is.

thheller13:12:34

what happens if you load-file first?

thheller13:12:49

oh wait ...

thheller13:12:55

load-file takes an actual file path

thheller13:12:58

not a resource path

thheller13:12:09

(load-file "src/test/sheluchin/poker/core_test.cljs")

sheluchin13:12:12

[2:1]~cljs.user=> (load-file "src/test/sheluchin/poker/core_test.cljs")
[:result {:type :repl/error, :ex #error {
 :cause "file not on classpath"
 :data {:file-path "src/test/sheluchin/poker/core_test.cljs"}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "file not on classpath"
   :data {:file-path "src/test/sheluchin/poker/core_test.cljs"}
   :at [shadow.cljs.repl$repl_load_file_STAR_ invokeStatic "repl.clj" 254]}]
 :trace
 [[shadow.cljs.repl$repl_load_file_STAR_ invokeStatic "repl.clj" 254]
  [shadow.cljs.repl$repl_load_file_STAR_ invoke "repl.clj" 227]
  [shadow.cljs.repl$repl_load_file invokeStatic "repl.clj" 301]
  [shadow.cljs.repl$repl_load_file invoke "repl.clj" 299]
  [shadow.cljs.repl$process_read_result invokeStatic "repl.clj" 426]
  [shadow.cljs.repl$process_read_result invoke "repl.clj" 406]
  [shadow.cljs.devtools.server.worker.impl$do_repl_rpc invokeStatic "impl.clj" 797]
  [shadow.cljs.devtools.server.worker.impl$do_repl_rpc invoke "impl.clj" 751]
  [shadow.cljs.devtools.server.worker.impl$eval15200$fn__15201 invoke "impl.clj" 828]
  [clojure.lang.MultiFn invoke "MultiFn.java" 234]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772$fn__14773$fn__14781 invoke "util.clj" 285]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772$fn__14773 invoke "util.clj" 284]
  [shadow.cljs.devtools.server.util$server_thread$fn__14772 invoke "util.clj" 257]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 834]]}}]
[2:1]~cljs.user=>

thheller13:12:25

which version are you on?

sheluchin13:12:38

thheller/shadow-cljs {:mvn/version "2.8.52"}

thheller13:12:42

I only added support for relative paths recently

thheller13:12:47

yeah that version still required absolute paths

sheluchin13:12:59

Ah, I was thinking about upgrading shadow-cljs but I wasn't too confident if it would continue to be compatible with the Fulcro version I'm on.

thheller13:12:31

that works fine (I'm using fulcro myself)

thheller13:12:18

the only thing you need to watch out for is dependency conflicts when using deps.edn but generally it should be fine

thheller13:12:42

or just (load-file "/Users/whoever/projects/that-project/src/test/sheluchin/poker/core_test.cljs")

thheller13:12:47

or wherever the file lives 😛

thheller13:12:04

but I fixed a bunch of REPL stuff since .52 so probably worth upgrading

sheluchin13:12:37

Okay, guess that's homework for tonight or tomorrow. Looking forward to upgrading. Thanks! Off to work now.

deas14:12:57

Just getting started with shadow-cljs, so please forgive me in case I am missing something.

deas14:12:07

Migrating to shadow-cljs requires getting rid of all foreign-deps and hence, cljsjs deps, right?

deas14:12:08

Ok, appears I want thheller/shadow-cljsjs- sorry for the noise.

Eliraz16:12:54

Hey, I was just wondering, is shadow-cljs using figwheel under the hood?

thheller16:12:13

@deas shadow-cljsjs includes a number of pre-made shims yes. it is included by default you don't need to depend on it

👍 4