shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Franklin 2021-06-16T09:33:02.092300Z

is it possible to do something like the following in shadow-cljs?

import './App.css';

thheller 2021-06-16T09:34:59.092500Z

no

Franklin 2021-06-16T09:35:47.093200Z

mmmh... I wonder if there are any constraints/reasons why?

thheller 2021-06-16T09:37:05.094400Z

well the constraint is that shadow-cljs knows how to build JS and CLJS files. adding support for CSS files would be a non-trivial amount of work.

thheller 2021-06-16T09:37:17.094700Z

the reason I haven't done it is because I don't think it is useful

thheller 2021-06-16T09:38:22.095700Z

I usually have a secondary build system for my CSS anyways and I can just put the import there. I think its silly to use JS constructs for that.

thheller 2021-06-16T09:39:04.096Z

for example you can use the setup described here

thheller 2021-06-16T09:39:05.096200Z

https://github.com/jacekschae/shadow-cljs-tailwindcss

thheller 2021-06-16T09:39:39.096800Z

and then either put your css in this file directly https://github.com/jacekschae/shadow-cljs-tailwindcss/blob/main/src/css/tailwind.css or have that import the other files

thheller 2021-06-16T09:40:48.098300Z

I know that it would be more convenient if shadow-cljs handled all that automatically but I currently don't have the time/energy to work on that

Franklin 2021-06-16T09:41:37.098800Z

alright

Jakub Holý 2021-06-16T10:56:26.103Z

Hello! I struggle with REPL-driven development with shadow. The problem is that when I define some troubleshooting / dev vars (such as (defn f [& args] (def *debug args) (...)) ), they tend to disappear. I suppose that is because I do most of my coding inside a (comment ...) and when IntelliJ saves the file after any changes, Shadow reloads the code. I thought that vars would survive that (as they do in clj) but it seems they do not, at least sometimes. Any tips? 🙏

thheller 2021-06-16T11:09:31.103400Z

well yeah hot-reload and REPL are sort of at odds with each other

thheller 2021-06-16T11:09:58.104Z

hot-reload is not additive so it'll remove definitions that you only defined in the REPL

thheller 2021-06-16T11:10:15.104400Z

so one option is to disable the hot-reload and just use the REPL like you would in CLJ

thheller 2021-06-16T11:10:30.104800Z

or you keep the hot-reload but accept that stuff sometimes gets undefined

thheller 2021-06-16T11:10:43.105200Z

technically it is all still there on the JS side, just the compiler doesn't know about it anymore

thheller 2021-06-16T11:16:39.107Z

things aren't additive with hot-reload since I want warnings to show up ASAP. say I changed (defn foo []) to (defn bar []). I want to see warnings for all places still using foo ASAP. In Clojure I often only notice such things when I restart my process a couple hours/days later since foo will still be around and valid until then.

thheller 2021-06-16T11:19:21.107700Z

I guess I could compromise somehow and track which def was defined from a REPL and keep those instead of resetting the entire ns

Jakub Holý 2021-06-16T12:12:10.108300Z

Thanks a lot! Is there a quick way to switch hot-reload on/off?

Jakub Holý 2021-06-16T12:13:51.109300Z

(I agree that being non-additive to show such warnings ASAP is in general the better choice. I just need to find out an effective way of doing experiments/troubleshooting in the REPL - which may be telling intellij not to save files automatically.)

thheller 2021-06-16T12:24:03.109900Z

from the CLJ REPL you can call (shadow/watch-set-autobuild! :app false)

❤️ 1
raspasov 2021-06-16T12:31:16.110900Z

Not sure if that’s relevant for you/shadow, but figwheel will actually refuse to load namespaces with warnings and namespaces that depend on them. That feels like a good default to me.

thheller 2021-06-16T12:32:30.111100Z

same in shadow

raspasov 2021-06-16T12:32:44.111300Z

Cool 👍

2021-06-16T13:10:50.113Z

Hello.. I am relatively new to ShadowCLJS and using Clojure_Script_… and was wondering if you all might be able to point me in the general direction on JS libraries that use Node dependencies

2021-06-16T13:12:27.114300Z

there might be two issues going on: 1st - we are trying to use the Redlock library, and when we do as part of the require:

~   9             ["ioredis" :as Redis]
~  10             ["redlock" :as Redlock]

2021-06-16T13:12:56.114800Z

I get the following compilation error:

[:employee_record] Compiling ...
The required JS dependency "async_hooks" is not available, it was required by "node_modules/bluebird/js/release/util.js".

Dependency Trace:
        shadow/umd_helper.cljs
        user_auth_profile/employee_record/update.cljs
        user_auth_profile/system_config.cljs
        node_modules/redlock/redlock.js
        node_modules/bluebird/js/release/bluebird.js
        node_modules/bluebird/js/release/promise.js
        node_modules/bluebird/js/release/util.js

Searched for npm packages in:
        /Users/sproctor/guaranteed-rate/user-auth-profile/node_modules

See: <https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install>

2021-06-16T13:13:46.115600Z

The part that is confusing is that async_hooks is part of NodeJS

thheller 2021-06-16T13:14:12.116100Z

which :target is your build? when building for the browser the native node packages are not available

2021-06-16T13:14:21.116300Z

a :node-library

2021-06-16T13:14:37.116900Z

we are deploying to AWS Lambda

thheller 2021-06-16T13:14:44.117300Z

did you set :js-provider :shadow in your build config?

2021-06-16T13:14:55.117700Z

yes

2021-06-16T13:15:00.118Z

here is the build target:

:employee_record {:target :node-library
   43                             :exports {:update user-auth-profile.employee-record.update/-main}
   44                             :source-map false
   45                             :output-dir "target/employee-record"
   46                             :output-to "target/employee-record/lambda.js"
   47                             :compiler-options {:infer-externs :auto
   48                                                :externs ["externs/httpurr.js"]}
   49                             :js-options {:js-provider :shadow
   50                                          :keep-native-requires true}
~  51                             :release {:compiler-options {:optimizations :simple}}}

thheller 2021-06-16T13:15:32.118500Z

so you can either not do that at all or add :keep-as-require #{"async_hooks"}

thheller 2021-06-16T13:17:23.119700Z

note that I do NOT recommend using :js-provider :shadow for node builds

thheller 2021-06-16T13:17:57.120100Z

better to keep the default and post-process with https://github.com/vercel/ncc or so if you really need things to be standalone

2021-06-16T13:20:14.121500Z

Is there some detail in the UserGuide that outlines this? Wondering if I have missed it, or mis-understood this

thheller 2021-06-16T13:21:27.123200Z

:js-provider :shadow is built and optimized for browser builds. that is works for node was due to some experimental changes and I decided this wasn't worth doing so didn't continue working on it.

thheller 2021-06-16T13:22:05.124100Z

so you likely found out about it in the github issue about this in the first place? the docs don't mention it

2021-06-16T13:22:08.124200Z

I have been trying to ramp up on ShadowCLJS as new projects at work are starting to use it over Figwheel for our AWS Lambda deployments

rberger 2021-06-17T21:44:35.152700Z

I have a little playground example for getting cljs working with lambda. I think it still works https://github.com/omnyway-labs/lambda-play

rberger 2021-06-17T21:49:01.152900Z

This also looks interesting. Not (yet) supporting cljs but it makes it easy to use Java, GraalVM or Babashka for lambdas https://github.com/FieryCod/holy-lambda The biggest issue I found with using cljs in lambdas (or probably any standalone node style program) is you are trapped in single thread / Promise / Async hell that you don't really experience in a browser / reagent / re-frame app

2021-06-16T13:22:48.125100Z

I saw some, but might have mis-understood what that issue was referring to

thheller 2021-06-16T13:24:16.125800Z

I think its best to NOT post-process the files at all and just "deploy" your .js file together with the needed node_modules

thheller 2021-06-16T13:24:48.126300Z

but I don't use AWS lambda so I don't know the details of how deploys actually work

2021-06-16T13:25:13.126700Z

I did see this item yesterday: https://github.com/thheller/shadow-cljs/issues/290

2021-06-16T13:25:40.127400Z

got lost in the other references around MongoDB, and some other side threads on it… 😉

2021-06-16T13:26:04.127600Z

Thank you for your help!!!

2021-06-16T13:26:44.128300Z

need to take this back to the larger team and understand how we want to proceed

2021-06-16T13:26:49.128500Z

thanks again

kiranshila 2021-06-16T18:38:13.130500Z

Is the story for having a library play nice with figwheel is to just provide the CLJSJS fallbacks? If so, how do I provide the equivalent :require calls?

kiranshila 2021-06-16T18:38:54.131100Z

As much as I'd like to slap a "won't fix/use shadow" tag on the issue haha

Jonathan 2021-06-16T19:52:21.132100Z

@neo2551 did you ever figure out shadow-cljs with kamera?

2021-06-16T19:53:36.133800Z

Not really. What I did figure out though was to use Clojure dev tools protocols used in kamera to navigate to the page and make the screenshot and then use these screenshot with kamera.

2021-06-16T19:54:51.135600Z

Since I am using re-frame, I also had a list of events that cdp could use to go to the desired state.

Jonathan 2021-06-16T19:58:21.135900Z

Thanks 🙂 I'm in a similar situation

Jonathan 2021-06-16T19:58:56.136400Z

> use Clojure dev tools protocols used in kamera to navigate to the page Any chance you could elaborate on this?

thheller 2021-06-16T20:17:27.136500Z

for people using figwheel with :target :bundle :require is exactly identical and no CLJSJS is needed

thheller 2021-06-16T20:18:09.136700Z

for CLJSJS you need to setup that CLJSJS package and setup the proper :foreign-libs to emulate the :require

thheller 2021-06-16T20:18:16.136900Z

in the code nothing changes

Jonathan 2021-06-16T20:30:13.137800Z

Kamera library looks fairly hackable, gonna try forking it. Will post more if it works.