shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
mkarp 2020-08-27T09:19:19.289900Z

Hey there! Would it be possible to somehow run :browser-test and :node-test targets within the same shadow watch process? If I do this at the moment, shadow looks up for namespaces with "-test$" regexp and node-specific tests land in the browser-test target. So the options would be either to run separate shadow processes with different classpaths, or to have more precise namespace naming convention for the regexps (like "$browser([\w-\.]+)test$" and "$node([\w-\.]+)test$")?

thheller 2020-08-27T09:47:49.291Z

@me1676 if you structure your namespaces just right that might be enough too? your.app.frontend.foo-test vs your.app.backend.foo-test or your.app.whatever.foo-test?

thheller 2020-08-27T09:48:13.291600Z

happy to add more filtering options if needed too. you also have the option to specify namespaces directly instead of just a regexp

thheller 2020-08-27T09:48:30.292100Z

just :namespaces [foo.bar-test ...] and :exclude #{foo.dummy-test} also exists

mkarp 2020-08-27T09:51:02.292500Z

Ahh that’s nice, didn’t know about :namespaces and :exclude 🙂

thheller 2020-08-27T09:51:34.293100Z

if :namespaces is used :ns-regexp has no effect though

mkarp 2020-08-27T09:52:19.294Z

Do you think it would be possible to add something like :filepath-regexp to filter based on the file paths?

thheller 2020-08-27T09:55:02.294200Z

sure but what would that do?

thheller 2020-08-27T09:55:56.294800Z

I mean it doesn't make sense in how I organize my tests so I first need to understand how you organize your tests to make a useful impl 😛

mkarp 2020-08-27T13:22:56.298800Z

Alright, I’ll try explain. Source directories: src/browser — Namespaces pitch.app., pitch.components., pitch.integrations., pitch.something-else. src/node — Namespaces pitch.node., pitch.something-else. Test directories: test/browser — Namespaces pitch.app.-test, pitch.components.-test, pitch.integrations.-test, pitch.something-else.-test test/node — Namespaces pitch.node.-test, pitch.something-else.-test Unfortunately just by looking at the namespace it’s not possible to understand to if it belongs to browser or node bundle, that’s why ns-regexp can’t work in our case. However, if we can apply a regexp to the filepath of a cljs file, then it becomes easy

Elso 2020-08-27T15:38:27.307600Z

I guess this is only superficially a shadow question, but maybe someone could give me a hint I'm setting up devcards to give them a try and that works fine mostly, but shadow for some reason can't connect a REPL to the UI because it claims there is no watch running - so, I'm working with this shadow-cljs.edn

{:nrepl    {:port 7002},
 :dev-http {8082 ["env/dev/frontend" "resources/public"]}
 :builds   {:app      {:target          :browser
                       :output-dir      "resources/public/js"
                       :asset-path      "/js"
                       :modules         {:asdf
                                         {:base    {:entries [asdf.core]}
                                          :init-fn asdf.core/main}}
                       :devtools        {:watch-dir "resources/public"}}
            :devcards {:target           :browser
                       :output-dir       "resources/public/js"
                       :asset-path       "/js"
                       :modules          {:devcards {:base    {:entries [devcards.core]}
                                                     :init-fn devcards.core/main}}
                       :devtools         {:watch-dir "resources/public"}
                       :compiler-options {:devcards :true}}}
 :lein     true}
I'm currently serving the app via a ring server and not using the dev-http, I've set that up specifically for the devcards bit (which servces the env/dev/frontend folder because that's where I put the index.html for devcards for now. Now I'm trying to connect a CLJS REPL to 7002 with IntelliJ which weirdly enough works fine for the app build, but not for the devcards build - in both cases I'm running lein shadow watch appresp lein shadow watch devcards
(shadow/repl :devcards)
Execution error (ExceptionInfo) at shadow.cljs.devtools.server.nrepl-impl/repl-init (nrepl_impl.clj:28).
watch for build not running
Point is, I don't see any difference between the two cases that would factor in here

thheller 2020-08-27T15:40:52.308200Z

@d.eltzner012 I'm guessing that you are running the (shadow/repl :devcards) from the REPL started by lein repl?

thheller 2020-08-27T15:43:55.310100Z

oh wait you are running two separate lein shadow commands so that means you'll have two separate JVMs and the one you connected do only has app

thheller 2020-08-27T15:44:07.310400Z

lein shadow watch app devcards should work and only give you one JVM

Elso 2020-08-27T15:46:01.310500Z

that's actually quite awesome to know (does it matter in that case that watch-dirs overlap?)

thheller 2020-08-27T15:46:25.310700Z

no

Elso 2020-08-27T15:46:40.310900Z

The problem was rather more stupid than I'm comfortable admitting - I had a terminal window burrowed somewhere that still had a watch job only on app running

Elso 2020-08-27T15:47:54.311100Z

but your hint made me look for it so thank you very much 🙂

Sam Ritchie 2020-08-27T17:20:49.312Z

@thheller, do you have any advice on how to enable data_readers.cljc for a self hosted build? here is the shadow-cljs.edn: https://github.com/sritchie/maria/blob/sritchie/last_attempt/editor/shadow-cljs.edn

Sam Ritchie 2020-08-27T17:22:01.313Z

I found a reference on the site about the compiler option to enable this (and your footgun warning 🙂 ), but it seems to not work when I add :compiler-options {:data-readers true} to the bootstrap build

Sam Ritchie 2020-08-27T17:22:21.313300Z

"not work" means, grabbing the error...

Sam Ritchie 2020-08-27T17:24:03.313400Z

Sam Ritchie 2020-08-27T17:25:13.314300Z

this does indeed work at a repl with data_readers.cljc loaded, and I can see that it did make it into the jar

thheller 2020-08-27T19:01:35.314900Z

@sritchie09 for self-hosted that you are compiling you need to handle data-readers in the compiler yourself. nothing shadow-cljs can do to help that.

thheller 2020-08-27T19:02:26.315200Z

at least I don't think so. no clue really.

Sam Ritchie 2020-08-27T19:13:40.315500Z

here be dragons!

Sam Ritchie 2020-08-27T19:14:03.316Z

thanks for the note, @thheller, I'll see if I can figure out how to get it working down the road

Sam Ritchie 2020-08-27T19:14:09.316200Z

and write down my lessons from the mines

neilyio 2020-08-27T19:58:49.317Z

Sorry to double-post, but I think I asked this after-hours last night and missed everyone. I'm rather stuck on it, so fingers crossed there's an easy answer:

neilyio 2020-08-27T19:58:50.317200Z

How should I use a CommonJS/ES6 namespace in a ClojureScript macro? I'm following @thheller's https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html, which suggests that `defmacro` within a .`clj` file should use a fully-qualified namespace.  But going by the shadow-cljs User Guide's https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages, I don't see how to use a fully-qualified namespace with CommonJS/ES6 imports, because they are referred to with strings as in `(:require ["module-name"])`.

thheller 2020-08-27T20:00:05.318Z

@neil.hansen.31 I recommend that you don't access npm packages directly but instead create a helper fn that does so and call that from the macro

neilyio 2020-08-27T20:01:07.318800Z

Thanks @thheller, I'll try that right now.

neilyio 2020-08-27T20:08:18.319200Z

That totally worked, I should have thought of that. Thanks!

Sam Ritchie 2020-08-27T20:58:51.319400Z

(set!
 cljs.tagged-literals/*cljs-data-readers*
 (merge cljs.tagged-literals/*cljs-data-readers*
        {'sicm/complex sicmutils.complex/parse-complex
         'sicm/bigint sicmutils.util/parse-bigint
         'sicm/ratio sicmutils.ratio/parse-ratio}))

Sam Ritchie 2020-08-27T20:59:04.319600Z

as a hack, @thheller this does it, if I type this in on the page itself!

thheller 2020-08-27T22:24:24.321400Z

@me1676 in 2.11.1 you can specify :test-paths ["test/node"] in the test build configs which will only make it use namespaces matching ns-regexp from those paths. they need to be classpath roots and already on the classpath though. maybe that works.