shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
MatD 2020-10-13T01:40:37.411500Z

Hi. Is there a way for the test results to output the complete path of a failing test file? For example, suppose I have the following structure src + main ++ module1 +++ file.cljs + test ++ module1 +++ file_test.cljs when I have a failure, I get

FAIL in (my-test) (module1/file_test.cljs:31:13)
The problem is that I cannot click on the file path in the terminal and open the file directly, since it's missing the "src/test/" at the beginning

thheller 2020-10-13T08:40:36.412Z

not built-in no

πŸ‘ 1
jcf 2020-10-13T12:59:44.417600Z

Hello again folks! Hope you're having a great day wherever you are. πŸ™‚ I've pushed things as far as I can without a working cljs REPL so have carved out sometime to get a Emacs/Cider-based nREPL connection working with shadow-cljs. The blocker right now is Cider trying to require cider.piggieback, which I've read shadow-cljs doesn't use at all. I'm using cider-jack-in-cljs with both :deps and :nrepl in my shadow-cljs.edn:

{:deps  {:aliases [:client]}
 :nrepl {:port 8777}
 ,,,}
I've tried adding Cider deps to my deps.edn even though Cider injects its deps/middleware for me:
/usr/bin/clojure -A:dev:test -Sdeps '{:deps {me.raynes/fs {:mvn/version "1.4.6"} compliment {:mvn/version "0.3.6"} com.cemerick/pomegranate {:mvn/version "0.4.0"} org.tcrawley/dynapath {:mvn/version "0.2.5"} nrepl {:mvn/version "0.8.0"} cider/piggieback {:mvn/version "0.5.1"} refactor-nrepl {:mvn/version "2.5.0"} cider/cider-nrepl {:mvn/version "0.25.3"}}}' -m nrepl.cmdline --middleware '["refactor-nrepl.middleware/wrap-refactor", "cider.nrepl/cider-middleware", "cider.piggieback/wrap-cljs-repl"]'
I haven't tried adding my client alias to my global CLI opts because I don't want browser-based dependencies being loaded in a server REPL but if that's the problem I can probably juggle things around. I've also read in a GitHub issue that use of :dependencies is recommended over use of :deps but that's on an old issue and I can't find any mention of such a recommendation in the shadow-cljs user guide. I keep reading that it's a simple as running cider-jack-in-cljs so I'm feeling a little dumb I guess. 🀷

jcf 2020-10-13T13:00:34.417700Z

My .dir-locals.el contains this:

((nil
  (cider-clojure-cli-global-options . "-A:dev:test")
  (cider-default-cljs-repl . shadow-select)
  (cider-known-endpoints . (("localhost" "8777")))
  (cider-shadow-default-options . ":REDACTED")
  (cider-preferred-build-tool . clojure-cli)))

jcf 2020-10-13T13:01:16.417900Z

{:clojure.main/message
 "Execution error at nrepl.cmdline/require-and-resolve (cmdline.clj:195).\nNo namespace: cider.piggieback found\n",
 :clojure.main/triage
 {:clojure.error/class java.lang.Exception,
  :clojure.error/line 195,
  :clojure.error/cause "No namespace: cider.piggieback found",
  :clojure.error/symbol nrepl.cmdline/require-and-resolve,
  :clojure.error/source "cmdline.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.lang.Exception,
    :message "No namespace: cider.piggieback found",
    :at [clojure.core$the_ns invokeStatic "core.clj" 4162]}],
  :trace
  [[clojure.core$the_ns invokeStatic "core.clj" 4162]
   [clojure.core$ns_resolve invokeStatic "core.clj" 4369]
   [clojure.core$ns_resolve invokeStatic "core.clj" 4359]
   [clojure.core$ns_resolve invoke "core.clj" 4359]
   [nrepl.cmdline$require_and_resolve invokeStatic "cmdline.clj" 195]
   [nrepl.cmdline$require_and_resolve invoke "cmdline.clj" 185]
   [nrepl.cmdline$fn__3236 invokeStatic "cmdline.clj" 199]
   [nrepl.cmdline$fn__3236 invoke "cmdline.clj" 199]
   [clojure.core$map$fn__5862$fn__5863 invoke "core.clj" 2742]
   [clojure.core$map$fn__5862$fn__5863 invoke "core.clj" 2742]
   [clojure.lang.PersistentVector reduce "PersistentVector.java" 343]
   [clojure.core$transduce invokeStatic "core.clj" 6883]
   [clojure.core$into invokeStatic "core.clj" 6899]
   [clojure.core$into invoke "core.clj" 6887]
   [nrepl.cmdline$__GT_mw_list invokeStatic "cmdline.clj" 226]
   [nrepl.cmdline$__GT_mw_list invoke "cmdline.clj" 224]
   [nrepl.cmdline$build_handler invokeStatic "cmdline.clj" 235]
   [nrepl.cmdline$build_handler invoke "cmdline.clj" 228]
   [nrepl.cmdline$options__GT_handler invokeStatic "cmdline.clj" 304]
   [nrepl.cmdline$options__GT_handler invoke "cmdline.clj" 295]
   [nrepl.cmdline$server_opts invokeStatic "cmdline.clj" 352]
   [nrepl.cmdline$server_opts invoke "cmdline.clj" 340]
   [nrepl.cmdline$dispatch_commands invokeStatic "cmdline.clj" 443]
   [nrepl.cmdline$dispatch_commands invoke "cmdline.clj" 436]
   [nrepl.cmdline$_main invokeStatic "cmdline.clj" 459]
   [nrepl.cmdline$_main doInvoke "cmdline.clj" 454]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 665]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause "No namespace: cider.piggieback found"}}
Stacktrace hidden in a file by Clojure. πŸ‘†

thheller 2020-10-13T13:01:25.418300Z

All I can point you to is https://shadow-cljs.github.io/docs/UsersGuide.html#cider

jcf 2020-10-13T13:01:36.418600Z

I wish Clojure would write to stdout/stderr so I could redirect output myself. πŸ™‚

thheller 2020-10-13T13:01:36.418700Z

I don't use emacs/cider so I don't have a clue how it works

thheller 2020-10-13T13:02:56.419200Z

might be simpler to just connect to the REPL instead of jacking in

thheller 2020-10-13T13:03:24.419700Z

ie. just run shadow-cljs server or so and then connect remotely to 8777 (however you do that I don't know though)

thheller 2020-10-13T13:04:05.421Z

the clojure call above doesn't seem to be using shadow-cljs

jcf 2020-10-13T13:07:14.422900Z

Thanks for the pointers, @thheller. I tried connecting to the nREPL server running inside my shadow-cljs watch process but I get errors about middleware being missing. I've added the middleware to my deps.edn and get the same errors.

jcf 2020-10-13T13:07:36.423300Z

;; Connected to nREPL server - <nrepl://localhost:8777>
;; CIDER 0.26.1 (Nesebar), nREPL 0.7.0
;; Clojure 1.10.1, Java 14.0.2
;;     Docs: (doc function-name)
;;           (find-doc part-of-name)
;;   Source: (source function-name)
;;  Javadoc: (javadoc java-object-or-class)
;;     Exit: &lt;C-c C-q&gt;
;;  Results: Stored in vars *1, *2, *3, an exception in *e;
;;
;; ClojureScript REPL type: shadow-select
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/nrepl-select :REDACTED))
;;
WARNING: CIDER 0.26.1 requires cider-nrepl 0.25.3, but you're currently using cider-nrepl 0.23.0-SNAPSHOT. The version mismatch might break some functionality! (More information)
To quit, type: :cljs/quit
;; =&gt; [:selected :REDACTED]WARNING: clj-refactor and refactor-nrepl are out of sync.
Their versions are 2.5.0 and n/a, respectively.
You can mute this warning by changing cljr-suppress-middleware-warnings.shadow.user&gt; 
cljs.user&gt; 

thheller 2020-10-13T13:08:10.423800Z

seems fine? just adjust the versions in deps.edn?

jcf 2020-10-13T13:08:29.424100Z

Uno momento. I'll get the error from that. πŸ™‚

jcf 2020-10-13T13:11:13.425200Z

I've added these deps to my :client alias:

cider/cider-nrepl             {:mvn/version "0.25.4"}
    refactor-nrepl/refactor-nrepl {:mvn/version "2.5.0"}
And now Cider tells me this:
WARNING: CIDER 0.26.1 requires cider-nrepl 0.25.3, but you're currently using cider-nrepl 0.23.0-SNAPSHOT. The version mismatch might break some functionality! (More information)

jcf 2020-10-13T13:11:49.426Z

I've checked my ~/.config/clojure/deps.edn and made sure there's no ~/.clojure/deps.edn. Where this snapshot version of Cider is coming from, I'm unsure.

jcf 2020-10-13T13:12:05.426400Z

And why the explicit artefacts in my deps.edn are ignored…

jcf 2020-10-13T13:12:22.426800Z

:aliases
 :client
  :extra-deps
   applied-science/js-interop    {:mvn/version "0.2.7"}
    cider/cider-nrepl             {:mvn/version "0.25.4"}

thheller 2020-10-13T13:12:28.427100Z

might be a better question for #cider

jcf 2020-10-13T13:12:45.427200Z

Slack ditched a curly brace there. It's definitely in my deps.edn file. πŸ˜„

jcf 2020-10-13T13:13:35.428100Z

Hmm. Cider doesn't manage my dependencies when I connect a REPL but I guess they might have some vendored snapshot or some dependency resolution thing they're doing somewhere.

thheller 2020-10-13T13:14:19.428600Z

I would expect it to respect deps.edn but I don't have a clue

thheller 2020-10-13T13:15:22.429200Z

either way it is saying it requires 0.25.3 and you have 0.25.4 so that might be the problem too

thheller 2020-10-13T13:19:36.430Z

maybe try clojure -A:client -Stree or whatever the command was to list the tree. maybe that explains wheres its coming from

jcf 2020-10-13T13:22:33.431500Z

I've asked the question over here too: https://clojurians.slack.com/archives/C0617A8PQ/p1602595230188700 Hopefully some of the lovely people over there are using my dream combo of Cider and shadow-cljs! πŸ™‚

thheller 2020-10-13T13:24:49.432300Z

@jcf I just noticed from the command above it had /usr/bin/clojure -A:dev:test

thheller 2020-10-13T13:25:00.432800Z

so that doesn't use the :client alias you setup?

jcf 2020-10-13T13:25:59.434200Z

That's correct. In my shadow-cljs.edn file I have :deps {:aliases [:client]} … Do I need the initial invocation of Clojure to include :client too?

jcf 2020-10-13T13:26:34.435500Z

That might get a little tricky as I don't always want to load up all my browser-based deps when I jack in. Maybe I can add those options to just the cljs opts.

thheller 2020-10-13T13:26:41.435700Z

I cannot answer cider/emacs questions sorry. From the command above it did not invoke shadow-cljs at all so whatever is in shadow-cljs.edn also has no effect.

jcf 2020-10-13T13:28:53.436400Z

Progress! πŸ’₯

Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
DEPRECATED: Libs must be qualified, change compliment =&gt; compliment/compliment 
DEPRECATED: Libs must be qualified, change nrepl =&gt; nrepl/nrepl 
DEPRECATED: Libs must be qualified, change refactor-nrepl =&gt; refactor-nrepl/refactor-nrepl 
WARNING: When invoking clojure.main, use -M
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
nREPL server started on port 33897 on host localhost.localdomain - <nrepl://localhost.localdomain:33897>
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by dynapath.defaults$eval29666$fn__29667 to method java.net.URLClassLoader.addURL(java.net.URL)
WARNING: Please consider reporting this to the maintainers of dynapath.defaults$eval29666$fn__29667
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
;; Connected to nREPL server - <nrepl://localhost:33897>
;; CIDER 0.26.1 (Nesebar), nREPL 0.8.0
;; Clojure 1.10.1, Java 14.0.2
;;     Docs: (doc function-name)
;;           (find-doc part-of-name)
;;   Source: (source function-name)
;;  Javadoc: (javadoc java-object-or-class)
;;     Exit: &lt;C-c C-q&gt;
;;  Results: Stored in vars *1, *2, *3, an exception in *e;
;;  Startup: /usr/bin/clojure -A:client:dev:test -Sdeps '{:deps {me.raynes/fs {:mvn/version "1.4.6"} compliment {:mvn/version "0.3.6"} com.cemerick/pomegranate {:mvn/version "0.4.0"} org.tcrawley/dynapath {:mvn/version "0.2.5"} nrepl {:mvn/version "0.8.0"} cider/piggieback {:mvn/version "0.5.1"} refactor-nrepl {:mvn/version "2.5.0"} cider/cider-nrepl {:mvn/version "0.25.3"}}}' -m nrepl.cmdline --middleware '["refactor-nrepl.middleware/wrap-refactor", "cider.nrepl/cider-middleware", "cider.piggieback/wrap-cljs-repl"]'
;;
;; ClojureScript REPL type: shadow-select
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/nrepl-select :grocer))
;;
;; =&gt; :missing-nrepl-middlewareuser&gt; 
user&gt; 

jcf 2020-10-13T13:29:15.436900Z

I've added :client to my CLI opts.

thheller 2020-10-13T13:33:13.437100Z

ok now you are missing the shadow-cljs nrepl middleware

thheller 2020-10-13T13:33:47.437700Z

dunno how you add that

jcf 2020-10-13T13:35:31.438100Z

There's a cider-jack-in-cljs-nrepl-middlewares var that takes a list of strings from the looks of it.

jcf 2020-10-13T13:35:43.438400Z

cider-jack-in-cljs-nrepl-middlewares is a variable defined in
cider.el.

Value
("cider.piggieback/wrap-cljs-repl")

Set

Documentation
List of Clojure variable names.

jcf 2020-10-13T13:36:44.439100Z

I'm not sure if I need wrap-cljs-repl with shadow-cljs, right? I thought I read that shadow provides its own middleware.

thheller 2020-10-13T13:37:06.439300Z

you can keep it but you don't need it yes

jcf 2020-10-13T13:37:38.439600Z

Cool. Jacking in now. 🀞

jcf 2020-10-13T13:42:58.440100Z

I think this exception is shadow-cljs letting me know that I'm not building anything?

Execution error (ExceptionInfo) at shadow.cljs.devtools.server.runtime/get-instance! (runtime.clj:11).
missing instance

jcf 2020-10-13T13:43:32.440800Z

Not sure why an exception is thrown as that doesn't seem like an exceptional circumstance but maybe it's the way Cider's firing up the REPL internally.

thheller 2020-10-13T13:44:11.441300Z

you are running in embedded mode so shadow-cljs isn't even started yet

thheller 2020-10-13T13:44:15.441500Z

you need to start it

thheller 2020-10-13T13:45:14.442100Z

it is an exception because the jack in likely wants to switch you to the shadow-cljs REPL which obviously can't work when shadow-cljs isn't even running

thheller 2020-10-13T13:46:02.443Z

I recommend connecting remotely ... doing all of this yourself is a lot of effort for basically no gain

jcf 2020-10-13T13:49:44.443900Z

Okay, I'll stick with connecting Cider to shadow-cljs and forget about jacking in.

jcf 2020-10-13T13:52:01.444500Z

I'll be starting from here:

WARNING: CIDER 0.26.1 requires cider-nrepl 0.25.3, but you're currently using cider-nrepl 0.23.0-SNAPSHOT. The version mismatch might break some functionality! (More information)
To quit, type: :cljs/quit
;; =&gt; [:selected :grocer]No available JS runtime.
See <https://shadow-cljs.github.io/docs/UsersGuide.html#repl-troubleshootingshadow.user>&gt; 
πŸ™‚

thheller 2020-10-13T13:53:09.445600Z

looks like you got it. just open the browser with your code loaded. (assuming this is a browser build of course)

jcf 2020-10-13T13:54:14.446200Z

That's awesome! I can connect to the browser and eval stuff like (js/alert "Hi, there!").

jcf 2020-10-13T13:54:29.446600Z

Completion blows up quite spectacularly. πŸ˜„

thheller 2020-10-13T13:54:48.447Z

thats likely https://github.com/rksm/clj-suitable/issues/15

jcf 2020-10-13T13:55:10.447900Z

Yeah, I've stumbled across that issue today.

thheller 2020-10-13T13:55:10.448Z

you can turn that off to just get regular completion

jcf 2020-10-13T13:57:38.448500Z

@thheller do you know how I turn that off to get regular completion?

jcf 2020-10-13T13:57:54.449Z

I can eval code but completion and eldoc are broken.

jcf 2020-10-13T13:58:09.449400Z

Eldoc gives you the function signature in the bottom of the editor window, which is super handy.

jcf 2020-10-13T13:59:15.449700Z

Found something here: https://github.com/clojure-emacs/cider/issues/2808#issuecomment-620382450