Fork me on GitHub
#shadow-cljs
<
2019-12-04
>
ashnur00:12:37

Hi. I am reading this https://shadow-cljs.github.io/docs/UsersGuide.html#_build_tool_integration and there is this caution which I don't understand. It says use standalone version. Standalone what? Is it telling me to NOT use deps.edn to manage dependencies?

thheller00:12:45

standalone as in dependencies managed by shadow-cljs.edn

thheller00:12:04

you can use deps.edn but you have been warned when you run into dependency conflict issues and so on

thheller00:12:23

deps.edn is a bit better dealing with those than project.clj but they can still happen

ashnur00:12:50

I don't know enough to understand these tradeoffs, so I am inclined to take this as gospel : ). But it feels weird, I thought deps.edn is good.

dpsutton01:12:47

Ha I originally read this as you saying β€œit is... the gospel”

ashnur00:12:44

so, what kind of dependency conflict issues can there be? I mean, if I would use only deps.edn for it? Is this something inherent to clojure/clojurescript ecosystem or just shadowcljs vs the other tools? Sorry if it's the wrong kind of question to ask.

thheller01:12:42

shadow-cljs tries to ensure that you get clojurescript, closure-compiler, closure-library versions that are actually compatible

thheller01:12:56

if you use deps.edn you have to manage that yourself and keep it matched

thheller01:12:18

usually that works out .. sometimes it doesnt ...

ashnur01:12:12

I see, I didn't realize there could be incompatibilities like that. Thanks for the explanation, I think I will use the built in for now : )

pavel.klavik06:12:56

I am testing version 78 and my WebWorkers got broken:

;; for /browser-repl in case the page is reloaded
  ;; otherwise the browser seems to still have the websocket open
  ;; when doing the reload
  (js/window.addEventListener "beforeunload"
    (fn []
      (when-let [s @socket-ref]
        (.close s))))

pavel.klavik06:12:11

browser.cljs:406 Uncaught ReferenceError: window is not defined
    at browser.cljs:406
    at layout.js:2110
    at Array.forEach (<anonymous>)
    at Object.env.load (layout.js:2106)
    at layout.js:2142

pavel.klavik06:12:10

It should probably be js/self instead of js/window in WebWorker.

eliraz.kedmi07:12:01

@thheller Is it possible to make figwheel work with shadow-cljs

pavel.klavik07:12:00

Not really needed, shadow-cljs has something like figwheel build in, everything works for free.

orestis08:12:55

Is there a way to get the build size report as data, instead of as HTML? Would like to keep a history of build sizes etc somehow.

thheller10:12:35

@pavel.klavik sorry I forgot to document since the feature is kinda unfinished. you can set :devtools {:browser-inject :name-of-the-main-browser-module}

thheller10:12:58

otherwise the browser devtools get injected into the shared module but they don't work in the workers

thheller10:12:14

workers now have their own devtools inject so hotreload and REPL work

thheller10:12:12

@orestis there is a .shadow-cljs/release-snapshot/the-build/latest/bundle-info.edn

thheller10:12:01

the build-report stuff sort has its own versioning already built-in its just not accessible from the command line

pavel.klavik10:12:08

How does the repl for web workers work?

thheller10:12:08

just like any other REPL ... but your editor might not support selecting it

thheller10:12:17

which editor do you use?

thheller10:12:19

you can disable the worker inject (to disable hot-reload/REPL) via :worker-inject false

deas11:12:46

Appears shadow-cljs does not support require outside ns, right?

thheller11:12:41

yes. curious why you'd want to use it? as it doesn't allow you to do anything you can't already do in the ns

deas11:12:32

Got a conditional macro (depending on :compiler-options {:custom-stuff {...}}) choosing what goes into a build.

(prefs/if-cljs-kernel
 (require '[pinkgorilla.kernel.shadowcljs :as cljs-kernel])
 (require '[pinkgorilla.kernel.mock :as cljs-kernel]))

thheller11:12:44

that doesn't work. I mean it doesn't work in CLJS either. you can't make require conditional. CLJS stops parsing at the prefs/if-cljs-kernel

deas11:12:54

Right in the middle of "migrate to shadow-cljs" work (new to it) so I might be missing something.

deas11:12:31

It worked before.

thheller11:12:02

hmm worked where? its not supposed to work?

deas11:12:29

Worked with figwheel and lein-cljsbuild.

thheller11:12:37

hmm strange. I thought it didn't run macros. guess I was wrong

deas11:12:00

I get an error complaining that requirecannot be used anywhere other than in the ns form which is generally not true.

thheller11:12:14

FWIW you can set :build-options {:ns-aliases {pinkgorilla.kernel.shadow-cljs pinkgorilla.kernel.mock}}

thheller11:12:31

that would make it use the mock ns whenever the shadow-cljs one was required

deas11:12:25

Never heard of :ns-aliases, but this looks like it could do the trick.

thheller11:12:47

its shadow-cljs only and not documented but meant to solve exactly this problem πŸ˜›

thheller11:12:23

I'll see about require. my assumption always was that it also didn't run macros but I guess it does?

thheller11:12:52

it definitely doesn't work if if-cljs-kernel was a function

thheller11:12:28

require outside ns was really meant for scripts that didn't have an ns (which shadow-cljs doesn't support either)

deas11:12:44

if-cljs-kernel is a macro which acts depending custom :compiler-options

thheller11:12:55

yeah I figured as much

deas12:12:51

πŸ™ ...

thheller12:12:26

it analyzes indeed ...

deas12:12:14

Appears there is an issue with 2.8.78 πŸ˜‰

[:app] Build failure:
IllegalArgumentException: Wrong number of args passed to keyword: :ns-aliases
        clojure.lang.Keyword.throwArity (Keyword.java:98)
        clojure.lang.Keyword.invoke (Keyword.java:149)
        clojure.core/update (core.clj:6200)
        clojure.core/update (core.clj:6188)
        shadow.build/copy-ns-aliases (build.clj:251)

thheller12:12:41

what the heck is that? πŸ˜›

thheller12:12:19

oh haha ... I'm dumb πŸ˜›

deas13:12:07

NP. Likely still good enough! πŸ˜‰

pavel.klavik12:12:50

@thheller I am running Cursive.

thheller12:12:50

fixed in 2.8.80

thheller12:12:12

@pavel.klavik do you use nrepl?

thheller12:12:41

unfortunately there is no easy way to select which runtime to talk to in nrepl

pavel.klavik12:12:46

What would be another option?

thheller12:12:49

you can run (shadow.cljs.devtools.api/repl-runtimes :todomvc-split) in the clojure REPL

thheller12:12:00

that'd give you something like

[{:runtime-info {:runtime-type :browser,
                 :lang :cljs,
                 :build-id :todomvc-split,
                 :user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.56 Safari/537.36",
                 :remote-addr "0:0:0:0:0:0:0:1"},
  :last-ping 1575462862870,
  :last-pong 1575462862872,
  :last-msg-received 1575462862872,
  :last-pong-runtime 1575462862871,
  :connected-since 1575462831938,
  :runtime-id "69b97643-1982-4922-b7cf-375bfa7496a8"}
 {:runtime-info {:runtime-type :worker,
                 :lang :cljs,
                 :build-id :todomvc-split,
                 :user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.56 Safari/537.36",
                 :remote-addr "0:0:0:0:0:0:0:1"},
  :last-ping 1575462863873,
  :last-pong 1575462863874,
  :last-msg-received 1575462863874,
  :last-pong-runtime 1575462863874,
  :connected-since 1575462832785,
  :runtime-id "ebd1298e-0201-430b-889b-30bc97eb0103"}]

thheller12:12:36

hmm nevermind

thheller12:12:39

it doesn't work in nrepl πŸ˜›

thheller12:12:20

in theory you should be able to use (shadow.cljs.devtools.api/repl :the-build {:runtime-id "that-runtime-id-from-above"})

pavel.klavik12:12:56

I will test it later. But i wouldnt mind to switch to some other repl, Cursive now supports SocketREPL as well.

pavel.klavik12:12:30

Not very familar with repls, yet

thheller12:12:47

I think it doesn't really work anywhere right now

thheller12:12:13

picking a runtime-id by hand is a bit annoying

thheller12:12:53

would be neat if the editor just supported selecting runtimes. I did some experiments with that in the shadow-cljs UI but its all unfinished

pavel.klavik12:12:26

I see, it is ok to do this when you dont do it that frequently.

pavel.klavik12:12:49

Is it possible to run multiple instances with different runtimes?

thheller12:12:03

"instances"? of what?

pavel.klavik12:12:01

Shadow is running nrepl on a port, and i open a window in Cursive which connect there. So the question is whether i can have multiple windows, one for each runtime?

thheller12:12:32

you can open as many nrepl connections as you want yes. and each can talk to a different runtime yes.

pavel.klavik12:12:12

I see. Than one could probably bind some keys to do the switching, I will take a look later.

thheller12:12:14

thats the idea behind runtimes as there can always be multiple in a browser env. ie. opening the page in chrome/firefox. or just using workers since they run in their own little world

pavel.klavik12:12:04

I see. Make sense, running a page in multiple tabs.

pavel.klavik12:12:42

Cornerning hot reloading, I can basically remove restarting the web workers now?

thheller12:12:26

maybe? I'm still testing this myself. in theory hot-reload should be fine now

pavel.klavik12:12:21

Ok, I will test it later and will let you know.

deas13:12:31

@thheller Would you mind rolling to 2.8.80? πŸ˜‚

thheller13:12:08

hmm? I release 2.8.80 45 minutes ago or so?

deas13:12:00

Just pulled and saw 2.8.79 came out today. Did not expect that I was already lagging. πŸ™‚

thheller13:12:51

yeah I just pushed the fix to the problem you ran into with :ns-aliases

deas13:12:15

Started working on a PR alfready. Did not expect you to react at that pace. Thanks Thomas!

scottlowe15:12:47

If I pass two target arguments to the shadow-cljs watch function, shadow-cljs shuts down once the targets are compiled. e.g.:

20:52 $ shadow-cljs watch dev test
shadow-cljs - config: /Users/scott/code/xxxx/shadow-cljs.edn  cli version: 2.8.52  node: v12.11.1
...
shadow-cljs - watching build :dev
shadow-cljs - watching build :test
[:dev] Configuring build.
[:test] Configuring build.
[:test] Compiling ...
[:dev] Compiling ...
[:dev] Build completed. (240 files, 1 compiled, 0 warnings, 3.65s)
[:test] Build completed. (240 files, 1 compiled, 0 warnings, 3.67s)
shutting down ...
Worker shutdown.
Worker shutdown.
Works fine and continues to watch when only one target argument is supplied. Am I doing this wrong?

thheller15:12:31

thats not normal. you may be getting killed by the system?

thheller15:12:44

do you use deps.edn/project.clj? you cut that bit of information out

scottlowe15:12:33

Thanks. We use deps.edn

scottlowe15:12:34

The section that I cut out in a failed attempt at helpful brevity was:

shadow-cljs - starting via "clojure"
[2019-12-04T10:13:14,521][INFO ][o.xnio                   ] XNIO version 3.7.3.Final
[2019-12-04T10:13:14,542][INFO ][o.x.nio                  ] XNIO NIO Implementation Version 3.7.3.Final
[2019-12-04T10:13:14,581][INFO ][o.j.threads              ] JBoss Threads version 2.3.2.Final
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.8.52 running at 
shadow-cljs - nREPL server started on port 8777

thheller15:12:10

alright so you'd set :jvm-opts in deps.edn then

thheller15:12:21

but try upgrading first

thheller15:12:16

also try upgrading since I did a bunch of fixes which reduced resource use a bunch. 2.8.80 is latest

thheller15:12:02

it looks like you use macOS which seems to kill the shadow-cljs process sometimes for consuming too much memory

thheller15:12:24

you can set :jvm-opts ["-Xmx1G"] in shadow-cljs.edn to constrain that

thheller15:12:38

but upgrading will most likely take care of that

scottlowe15:12:52

Thank you so much. That’s a good point about memory consumption. I will upgrade and if that doesn’t work, try tweaking the memory settings. Cheers for the incredibly fast response. shadow-cljs really is a fantastic project and a pleasure to use.

scottlowe15:12:41

confirmed: Upgrading to 2.8.80 worked. No memory constraints required. Thanks again πŸ™‚

thheller16:12:23

no idea whats up with that but it caused upstream in CLJS

nickmbailey17:12:54

i guess i can file a jira

hoertlehner17:12:41

I have a stupid question on how to use "deps.cljs" I have a project https://github.com/pink-gorilla/leaflet-shadow/blob/master/src/deps.cljs

hoertlehner17:12:14

In the project I use a few npm dependencies and then I publish the project to clojars

hoertlehner17:12:41

If now other projects require leaflet-shadow when I define a deps.cljs file

hoertlehner17:12:03

will then shadow cljs automatically get the transient npm dependencies ?

hoertlehner17:12:22

Provided the projects that use my project use shadow-cljs

hoertlehner17:12:57

Essentially my library is a slim wrapper around react-leaflet. So I think the right place to publish this lib to is clojars...

hoertlehner17:12:29

I want to avoid having to remember to require transient npm dependencies

hoertlehner17:12:11

Is this possible?

mauricio.szabo17:12:20

Hi there! I'm trying to rewrite a project that uses webpack+react to ClojureScript with Shadow-CLJS. The thing is, I don't want to do a "big rewrite", and instead I would like to start migrating existing react components to CLJS little by little.

mauricio.szabo17:12:20

I though that using :node-library's target would allow me to integrate with webpack and all other tools on the React side, but its not working (because it needs some of the Node code, like readFileSync and others). I could use :npm-module but then I loose the ClojureScript REPL. Is there any alternative?

aisamu17:12:12

We're doing something similar with :npm-module as a target, going outside-in (i.e. from the leaves). We still use the REPL

aisamu17:12:46

These had to be added on the js entrypoint: (`cljs/` ` is a webpack alias pointing to the cljs build folder)

window.CLOSURE_BASE_PATH = '/javascripts' // Should match your assets location
require('cljs/shadow.cljs.devtools.client.browser') // REPL
require('cljs/shadow.remote.runtime.cljs.browser') // Shadow's Inspect

mauricio.szabo17:12:54

Great, I'm gonna test right now πŸ™‚

mauricio.szabo18:12:08

Just for the record, if I add [shadow.cljs.devtools.client.browser] on one of the required namespaces, it works too πŸ™‚

thheller19:12:17

@hoertlehner yes that should work fine?

thheller19:12:08

@mauricio.szabo :node-library presumes node not webpack + browser.

hoertlehner19:12:08

@thheller just a file in the src path named deps.cljs ?

thheller19:12:31

but it only works in libraries

hoertlehner19:12:04

but I dont add a reference to that file anywhere?

thheller19:12:04

just has to be in the classpath root in a library

mauricio.szabo21:12:57

Is :npm-module able to run before/after load code?

mauricio.szabo21:12:06

I'm not seeing it working on my setup

mauricio.szabo21:12:47

(in fact, I'm not sure the hot reload is working either)

thheller21:12:10

@mauricio.szabo in general hot-reload and REPL are a bit constrained when running through webpack. it sometimes work if you require the REPL ns separately from JS

thheller21:12:44

something like if (process.env.NODE_ENV === "development") { require("./path-to-output/shadow.cljs.devtools.client.browser") }

hoertlehner22:12:38

@thheller cool - got transient dependencies going with deps.cljs -> very cool feature!!