Fork me on GitHub
#shadow-cljs
<
2022-01-27
>
thheller06:01:22

@ben.hammond shadow-cljs clj-repl and then (shadow/repl :foo {:runtime-id 123}) where the runtime id is either listed here http://localhost:9630/runtimes or in the browser console on start shadow-cljs: #3 ready!

👀 1
thheller08:01:50

:cljs/quit drops you back down to the clj repl. so you can switch between the runtimes if needed

👍 1
Nom Nom Mousse17:01:25

What might the error messages above indicate? I've tried googling.

Nom Nom Mousse17:01:02

Easier to read.

Nom Nom Mousse17:01:40

These errors happened after I did git clean -fdx and reinstalled d3 through npm.

thheller17:01:56

from your messages in #clojurescript I assume you figured it out?

Nom Nom Mousse17:01:07

I was able to lein shadow watch app but I still get errors in the console. Anyways, if this is unrelated to shadow-cljs I'll try to google more myself 🙂

thheller17:01:56

the regenerator thing is a npm problem. you basically need to (:require ["regenerator-runtime/runtime"]) somewhere before you require the npm lib causing the problem

thheller17:01:07

or upgrade shadow-cljs in case you are on a really old version

Nom Nom Mousse17:01:51

I guess it was really old 😄

Nom Nom Mousse17:01:00

Thanks for your help

Nom Nom Mousse17:01:51

My version 2.12.1 seems to be from April last year. I'll try upgrading.

neilyio17:01:37

I’m trying to run shadow-cljs in embedded mode from a build.clj. Here’s what I’m running, I arrived at this by digging around the https://shadow-cljs.github.io/docs/UsersGuide.html#embedded of the docs, as well as https://github.com/thheller/shadow-cljs/issues/490.

(shadow.cljs.devtools.server/start!)

(shadow.cljs.devtools.api/compile*
 {:target     :browser
  :output-dir "public/js"
  :output-to  "public/js/main.js"
  :asset-path "js"
  :main       "hello-world.core"}
 {})
…Running clj -M build.clj, I get a error:
Jan 27, 2022 9:45:35 AM io.undertow.Undertow start
INFO: starting server: Undertow - 2.2.4.Final
Jan 27, 2022 9:45:35 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.8.0.Final
Jan 27, 2022 9:45:35 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.8.0.Final
Jan 27, 2022 9:45:35 AM org.jboss.threads.Version <clinit>
INFO: JBoss Threads version 3.1.0.Final
shadow-cljs - server version: 2.16.12 running at 
shadow-cljs - nREPL server started on port 54818
[null] Compiling ...
Syntax error (AssertionError) compiling at (build.clj:28:1).
Assert failed: (keyword? build-id)
I’d really like to be able to pass the build configuration right in my build.clj. Does anyone see what I’m doing wrong?

thheller17:01:27

:build-id :app or something needs to be in that map

thheller17:01:03

note that this is an invalid build config for :target :browser. :main does not apply there.

thheller17:01:43

you maybe want to configure your logging so that the undertow/xnio stuff goes away

neilyio17:01:10

Agreed that’s a little too verbose

neilyio17:01:23

I switched the call to this:

(shadow.cljs.devtools.api/compile*
 {:build-id   :app
  :target     :browser
  :output-dir "public/js"
  :output-to  "public/js/main.js"
  :asset-path "js"}
 {})

thheller17:01:36

still invalid. missing :modules

thheller17:01:28

:output-to also does nothing. :modules {:main {:entries [hello-world.core]}} will create a main.js in :output-dir

thheller17:01:11

I strongly recommend keeping the build config in shadow-cljs.edn though. you lose a bunch of features if you don't

neilyio17:01:05

Thanks for working through this with me, it’s compiling now! I’m noticing that it outputs a main.js in my :ouput-dir. Is that default/fixed behavior?

neilyio17:01:35

(As I’ve omiitted the :output-to, as you mentioned)

thheller17:01:45

you should probably refer to the docs for questions as that https://shadow-cljs.github.io/docs/UsersGuide.html

thheller17:01:58

the :main module produces main.js in :output-dir

neilyio17:01:08

Yep I see that now

thheller17:01:15

rename it and you get a different file. all coming from your config, no default 😛

neilyio17:01:32

That’s great, really appreciate your quick response @thheller, as usual.

thheller18:01:40

why compile though? watch and release are the common ones, compile is kinda rare?

neilyio18:01:49

I’m kind of just messing around now, compile caught my eye first. What’s the different from release?

thheller18:01:42

release creates a optimized release build. compile creates an unoptimized development build, same as watch just without the watch parts (no hot-reload, REPL, etc)

neilyio18:01:48

Ah okay, that was my guess. I’m toying around with my own REPL/reload setup for some custom pREPL tooling in Emacs. So I’m looking for a development build, but starting my own REPL server etc.

neilyio18:01:02

I’ll pass it along if I get something cool!

thheller18:01:26

shadow-cljs has built in prepl support in case you didn't know

thheller18:01:40

prepl sucks so I wouldn't recommend it though 😉

thheller18:01:13

but for any kind of repl tooling regardless you must use watch. compile is not designed for it and will not work.

neilyio18:01:35

This is such great info, thank you!

thheller18:01:03

"will not work" is not exactly right. with your own REPL server it might work, it'll just be rather slow. compile has to load all caches from disk with each compile

thheller18:01:17

watch just loads it once and keeps it in memory making incremental compiles rather fast

neilyio18:01:57

Hmm yeah I’ve got a error when I connect to my REPL and try to evaluate:

:type java.lang.AssertionError,
:message \"Assert failed: (set? ns-roots)\", :at [shadow.build.cljs_hacks$shadow_find_ns_starts_with invokeStatic \"cljs_hacks.cljc\" 645]}],

neilyio18:01:18

Here’s my whole setup if you’re curious. I know this is unconventional and all this functionality is in shadow-cljs… I’m just toying around and trying to replace the functionality with other standard Clojure tools for learning purposes.

(clojure.core.server/start-server
 {:accept        'cljs.core.server/io-prepl
  :address       "127.0.0.1"
  :port          6776
  :name          "build"
  :args          [:repl-env (weasel.repl.websocket/repl-env :ip "0.0.0.0" :port 9001)]
  :server-daemon false})

(org.httpkit.server/run-server
 (compojure.core/routes
  (compojure.route/files "/" {:root "public"}))
 {:port 8000})

(cljs.build.api/build ;; or watch with path
 {:output-dir   "public/js"
  :output-to    "public/js/main.js"
  :asset-path   "js"
  :main         "hello-world.core"})

(println "Now connect through inf-clojure to port 6776.")
(println "Then, refresh the web page.")

thheller18:01:46

uhm you are trying to use weasel with shadow-cljs? that'll not work

neilyio18:01:57

Yeah, unconventional, like I said! I was just trying to replicate a really minimal ClojureScript compilation setup. This was working well with the code below:

(clojure.core.server/start-server
 {:accept        'cljs.core.server/io-prepl
  :address       "127.0.0.1"
  :port          6776
  :name          "build"
  :args          [:repl-env (weasel.repl.websocket/repl-env :ip "0.0.0.0" :port 9001)]
  :server-daemon false})

(org.httpkit.server/run-server
 (compojure.core/routes
  (compojure.route/files "/" {:root "public"}))
 {:port 8000})

(cljs.build.api/build ;; or watch with path
 {:output-dir   "public/js"
  :output-to    "public/js/main.js"
  :asset-path   "js"
  :main         "hello-world.core"})

thheller18:01:28

what is your intended end goal here?

neilyio18:01:42

…but I can’t for the life of me properly get cljs.build.api/build to find my npm dependencies. shadow-cljs is so, so good at that, I was hoping there’d be an easy way to just “swap out” those compile calls.

thheller18:01:48

you can just set :prepl {12345 :app} and that will give a a prepl on port 12345 for build :app (all in shadow-cljs.edn of course)

neilyio18:01:52

Yeah, that’s a great feature. I’m really just experimenting, but I would say my goal is to see how I can leverage popular Clojure tools (httpkit, clojure.core.server, cljs.build.api) to “mix and match” the behavior of my development experience.

thheller18:01:24

well then shadow-cljs is probably not the right choice for you. it is a build tool already, not a toolkit to build a build tool.

thheller18:01:12

it replaces basically all of the default build tooling, so anything trying to use that won't work either

neilyio18:01:01

Yeah I understand, I appreciate you being straightforward with me. I really admire the experience you’ve built with shadow-cljs, and I’m sure I’ll end up using it as you’ve intended for a real project!

neilyio18:01:14

If only :npm-deps on the ClojureScript compiler would work properly…

thheller18:01:16

if you explain what you are trying to do I can maybe provide some pointers. shadow-cljs is pretty flexible, so it should be possible to just disable the parts you don't want to use but keep the rest

thheller18:01:33

but that being said it is built to do exactly what it does. everything else is asking for trouble 😉