Fork me on GitHub
#shadow-cljs
<
2023-03-13
>
oxalorg (Mitesh)13:03:26

How do I run 2 shadow-cljs processes / servers together? • I am trying to run a shadow server for my code repl (let’s say build-id :dev ) • and another instance for kaocha bin/kaocha tests with shadow build-id :test Up until shadow-cljs 2.19.X this was possible. Turns out in 2.20.0 this additional check was introduced https://github.com/thheller/shadow-cljs/commit/47c3824634118f27a8276a70d6bf2da8752905bc check-for-other-instance! which won’t let me start another instance. Any idea for a work around for this? Or how do I check for an existing shadow process and connect to it? think_beret

thheller15:03:04

just run both builds in one instance? npx shadow-cljs watch dev test?

thheller15:03:46

it checks automatically whether an instance is running

thheller15:03:06

just may not detect it in time they are started too fast concurrently

oxalorg (Mitesh)16:03:49

> just run both builds in one instance? npx shadow-cljs watch dev test? I’ll try doing this but I think this would cause a bit of a mismatch in our tooling. I have the project setup with kaocha + kaocha-cljs2 + funnel, all of which are bundled together using kaocha hooks. Then to enable proper hot reloading with kaocha-cljs2 I manually hook into the shadow-api/watch-compile!. By running both shadow dev and test builds together, I’ll also have to run Kaocha and funnel everytime I run the dev repl which may not be required. Also won’t get terminal logs separately. Also when the dev repl is running we can no longer run kaochas --focus tests or any other runs from the CLI. Everything related to koacha will need a repl interface -or- dev repl will need to be closed. Any thoughts here? Also would a PR be accepted adding an extra option in config and making this check overridable?

thheller16:03:41

run npx shadow-cljs server first

thheller16:03:50

then you can run all other commands separately

think_beret 2
oxalorg (Mitesh)16:03:03

We’re running the shadow server from clj (embedded). Any way for the kaocha process running in a separate process to connect to that embedded shadow server?

thheller16:03:04

the check will not be overridable, the check was added for good reasons. basically shadow-cljs is not intended to run two instances per project. they WILL interfere with each other.

😮 2
👍 2
thheller16:03:21

if you want to create a repo with that setup I can take a look. so far I don't quite understand what you are doing

oxalorg (Mitesh)16:03:38

Thanks I can do that.

oxalorg (Mitesh)16:03:46

Would super appreciate it 🙌 🙏

thheller16:03:56

embedded server is fine. the npx command will also connect to that one

oxalorg (Mitesh)16:03:20

Process A: cider-jack-in-clj&cljs or clj -A:dev launches a server using shadow-server/start!and then does shadow-api/watch :dev Process B: Then I have another process for tests clj -A:tests -m kaocha.runner which also is trying to shadow-api/watch :test but it can’t find the shadow server running in process A

thheller16:03:19

the CLJ API never looks for a new server, only the npx shadow-cljs command does

😢 2
thheller16:03:04

why are these using different aliases?

oxalorg (Mitesh)16:03:49

The clj commands? The :dev repl has some dev specific paths and debugging libraries. The :test repl has kaocha and other libraries + test paths. > the CLJ API never looks for a new server, only the npx shadow-cljs command does This is the issue because we need to use the shadow-api/watch-compile! trigger on kaocha pre-load. So we have to use the clj api.

thheller16:03:19

can you explain the last bit? I have never used kaocha, why does it need to trigger this?

thheller17:03:28

I guess I can add an option to remove this check in case of two embedded servers. the reason it exists is that a server writes several "state" files (nrepl.port, http.port, etc) to .shadow-cljs. if you start two the second will overwrite the files from the first

thheller17:03:47

so in essence the first becomes a "ghost" that nothing external (ie. your editor) can find

thheller17:03:26

so in case of your setup I guess thats fine since probably both test and dev are self contained with no "network access" required from external processes?

thheller17:03:35

maybe I could add a special for that, that doesn't even attempt to write those files

skylize15:03:29

> the CLJ API never looks for a new server, only the npx shadow-cljs command does 💡 Maybe that ^ could be changed instead of disabling the check?

Patrick Brown13:03:39

I’m running into some issues bringing shadow into an existing project. The error I am getting is

nREPL middleware: shadow.cljs.devtools.cli has no namespace
My thoughts are that my middleware config is causing the conflict. I both including and not including shadow-cljs and the middleware in my deps.edn. Here is a very minimal config that is causing the error. Can anyone place give it a look and see what I’m missing? DEV PROFILE IN DEPS.EDN
:aliases {:dev {:exta-paths ["src/clojure/dev"]
                 :extra-deps {nrepl/nrepl {:mvn/version "1.1.0-alpha1"}
                              cider/cider-nrepl {:mvn/version "0.30.0"}
                              refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}
                              mx.cider/tools.deps.enrich-classpath {:mvn/version "1.9.0"}
                              com.github.jpmonettas/flow-storm-dbg {:mvn/version "3.3.320"}
                              djblue/portal {:mvn/version "0.35.1"}
                              com.lambdaisland/classpath {:mvn/version "0.4.44"}
                              com.datomic/dev-local       {:mvn/version "1.0.243"}
                              org.clojure/tools.namespace {:mvn/version "1.2.0"}

                              ; clojurescript
                              org.clojure/clojurescript {:mvn/version "1.11.60"}
                              #_#_thheller/shadow-cljs {:mvn/version "2.22.0"}
                              binaryage/devtools {:mvn/version "1.0.6"}
                              com.google.javascript/closure-compiler-unshaded {:mvn/version "v20230228"}}

                 :main-opts  ["-m" "nrepl.cmdline" "-b" "0.0.0.0" "-p" "8675" "--middleware"
                                  "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}
SHADOW-CLJS.EDN
{:deps {:aliases [:dev]}
 :dev-http {4040 "classpath:public"}
 :builds   {:main {:target     :browser
                   :output-dir "resources/public/js/main"
                   :asset-path "/js/main"
                   :modules    {:main {:init-fn troubleshoot.client/init
                                       :entries [troubleshoot.client]}}}}}
If anyone can set me straight I’d greatly appreciate it. Lost here.

Patrick Brown14:03:20

I am currently working in a separate profile that just has;

:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.60"}
                                   thheller/shadow-cljs {:mvn/version "2.22.0"}
                                   binaryage/devtools {:mvn/version "1.0.6"}
                                   com.google.javascript/closure-compiler-unshaded {:mvn/version "v20230228"}}}
Everything is all good there. Is there any added benefit to having my cljs deps combined with my other dev dependencies? Or is heading forward with a cljs only profile actually a better move?

oxalorg (Mitesh)14:03:39

Why do you have shadow-cljs dep commented out in the :dev profile? #_#_thheller/shadow-cljs {:mvn/version "2.22.0"}

thheller15:03:12

yeah, the shadow-cljs dependency needs to be active

Patrick Brown17:03:07

I was troubleshooting. It was giving me the same error with and without ignoring the shadow-cljs in the deps profile. I was a bit confused with a recommendation to run shadow standalone in the docs. The whole thing gives me a bit of confusion for a moment every time. Imagine it’s a me thing. At any rate, I’m quite pleased with putting all my cljs deps in it’s own profile and my clj dev deps separate. Everything is working as I expect and workflow is quite enjoyable. Good times. CHEERS!

fabrao16:03:28

Hello, I just updated from 2.21.0 to 2.22.2 and I got this The required namespace ".cookies" is not available in my code. So, is there some lib removed from shadow-cljs?

scarytom16:03:57

yes, and no. This version of shadow-cljs bumps the underlying version of the google-closure-lib, which provides http://goog.net.cookies. goog.net.cookies got deprecated (and then removed) in favour of http://goog.net.Cookies.

fabrao16:03:12

Ohhh, I have both there, I'll remove the lower case

scarytom16:03:34

it is a bit more involved than just changing the cookies to Cookies... you need to use http://goog.net.Cookies/getInstance now

hifumi12317:03:33

I'm a bit confused on how externs inference and shadow-cljs work together. If I import a constructor from JS code and use it in a lexical binding, does the binding get the ^js meta? If so, do we still need goog.object.set or can we safely use set!

thheller17:03:27

example code?

thheller17:03:05

the gist is if you get a warning, add a hint. if you get no warning you should be safe.

hifumi12317:03:28

No warning. Here is an example:

(ns demo
  (:require ["js-code" :refer [SomeObject]]))

(defn example []
  (let [obj (SomeObject.)]
    (set! (.-property obj) val)))

thheller17:03:35

and it gets renamed?

hifumi12317:03:59

I haven't checked that. The code seemingly works under both development and production builds

thheller17:03:21

as I said .. no warning means you should be safe.

hifumi12317:03:22

I was just wondering if what I'm doing is a bad idea and whether I should prefer goog.object/set here

hifumi12317:03:31

Ok good to know

thheller17:03:58

set! is correct there

Tyler Nisonoff17:03:24

Has anyone run into an issue where running

npx shadow-cljs stop 
Does not actually shut down the server? I get:
shadow-cljs - server not running
But i have to manually determine whats running on port 9630 and kill it, and then
npx shadow-cljs start
will start it back up on the correct port I tried hardcoding the port in my config, etc. but cant get it to stop the service automatically :thinking_face:

thheller17:03:36

do you delete the .shadow-cljs directory in some sort of clean task maybe? it determines the state of the server from the files in that dir.

thheller17:03:38

otherwise not sure. I generally do not recommend running the background server. npx shadow-cljs server and keeping that open lets you ctrl+c it anytime

Tyler Nisonoff17:03:26

i probably did delete it, but thought itd be fine after a fresh start command -- for some reason seeing this happen every time, even without a clean -- but good to know! I can probably look through that dir to see if state is incorrect somewhere good to know about the background server! will try that workflow instead, thanks

thheller17:03:56

btw never delete the .shadow-cljs dir. it also holds all caches, there should be no reason to ever delete it all.

Tyler Nisonoff18:03:53

noted! Yeah I had an issue sometime where i got into a crazy state, and wanted to rule out the shadow cache as the issue, but will avoid going forward