shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Volodymyr Huzar 2021-03-26T13:50:17.184200Z

We have :ssl in our configuration which enabling https for all builds. Is it possible to run :devtools for one of the build on http? To add more context: I am trying to run tests using https://github.com/lambdaisland/kaocha-cljs2 and having https there adding a lot of overhead to setup all the tools to have proper certificates provided everywhere. Also Chrome complains with registering custom ServiceWorkers when self signed certificates are used which seems to be configurable but again adds another overhead.

thheller 2021-03-26T17:02:41.185200Z

@vguzar in 2.11.26 I added an option to allow that. :dev-http {3000 {:root "public" :ssl false}}

haywood 2021-03-26T17:14:07.186Z

apologies… but has anyone run into this? I’m dusting off a project that hasn’t been touched in like a year

[:failed-to-compare "^16.13.1" "16.9.0" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]
 :trace
 [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]
  [shadow.cljs.devtools.server.npm_deps$make_engine invokeStatic "npm_deps.clj" 39]
  [shadow.cljs.devtools.server.npm_deps$make_engine invoke "npm_deps.clj" 32]
  [shadow.cljs.devtools.server.npm_deps$fn__17458$fn__17459 invoke "npm_deps.clj" 46]
  [clojure.lang.Delay deref "Delay.java" 42]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [shadow.cljs.devtools.server.npm_deps$fn__17458$fn__17461 invoke "npm_deps.clj" 52]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invokeStatic "npm_deps.clj" 207]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invoke "npm_deps.clj" 201]
  [shadow.cljs.devtools.server.npm_deps$main$fn__17546 invoke "npm_deps.clj" 223]
  [clojure.core$complement$fn__5669 invoke "core.clj" 1441]
  [clojure.core$filter$fn__5893 invoke "core.clj" 2821]
  [clojure.lang.LazySeq sval "LazySeq.java" 42]
  [clojure.lang.LazySeq seq "LazySeq.java" 51]
  [clojure.lang.RT seq "RT.java" 535]
  [clojure.core$seq__5402 invokeStatic "core.clj" 137]
  [clojure.core$seq__5402 invoke "core.clj" 137]
  [shadow.cljs.devtools.server.npm_deps$main invokeStatic "npm_deps.clj" 225]
  [shadow.cljs.devtools.server.npm_deps$main invoke "npm_deps.clj" 216]
  [shadow.cljs.devtools.cli$main invokeStatic "cli.clj" 143]
  [shadow.cljs.devtools.cli$main doInvoke "cli.clj" 134]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 669]
  [clojure.core$apply invoke "core.clj" 660]
  [shadow.cljs.devtools.cli$_main invokeStatic "cli.clj" 221]
  [shadow.cljs.devtools.cli$_main doInvoke "cli.clj" 219]
  [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]]}]

haywood 2021-03-26T17:14:35.186400Z

versions:

=== Version
jar:            2.11.25
cli:            2.11.25
deps:           1.3.2
config-version: 2.11.25

thheller 2021-03-26T17:16:17.187300Z

@haywood looks like you upgraded to java JDK 15+ in the meantime? that removed the Nashorn JS engine previously used. need to upgrade shadow-cljs.

thheller 2021-03-26T17:17:21.187900Z

the above versions would have the fix but you might be using deps.edn or project.clj to manage your dependencies so you'd need to upgrade shadow-cljs there

haywood 2021-03-26T17:18:00.188300Z

oof why do I have shadow in my deps.edn AND package.json

haywood 2021-03-26T17:20:25.188800Z

well, that fixed it, was only upgrading the version in the package.json…

Azzurite 2021-03-26T17:32:40.190800Z

whenever I get some kind of runtime error during reload while developing, there's a small error dialog fixed at the bottom of the page. This does not disappear until I completely reload the page. Is that a bug or supposed to be like that?

thheller 2021-03-26T17:33:33.191100Z

define runtime error?

Azzurite 2021-03-26T17:33:52.191200Z

Azzurite 2021-03-26T17:34:13.191800Z

I fix that, and the page reloads again and everything is fine, except that the error stays at the bottom

thheller 2021-03-26T17:35:00.192500Z

ok that looks like you are running code directly on load? (eg. directly calling (render)) in your file? you should not be doing that.

Azzurite 2021-03-26T17:35:42.192900Z

well yeah, when I load the page the js should execute, should it not?

thheller 2021-03-26T17:36:24.193300Z

no, you should be using the lifecycle hooks provided for that https://shadow-cljs.github.io/docs/UsersGuide.html#_hot_code_reload

Azzurite 2021-03-26T17:38:00.195Z

oh thanks so basically use one namespace on the production site that immediately executes and another with the lifecycle hooks while developing?

thheller 2021-03-26T17:38:16.195200Z

no, use :init-fn in your module to call the code you want to run on startup

Azzurite 2021-03-26T17:38:26.195500Z

hm

Azzurite 2021-03-26T17:38:32.195700Z

ok well I'll read some more

thheller 2021-03-26T17:38:49.196Z

as the blogpost explains

thheller 2021-03-26T17:39:15.196500Z

the pattern of swapping out namespaces in production is bad and absolutely advised against

Azzurite 2021-03-26T17:41:48.197Z

yeah I only read the user guide and maybe I didn't understand that perfectly

Azzurite 2021-03-26T17:42:08.197400Z

it seemed more like "you can do that if you want" not "you need to do that actually"

thheller 2021-03-26T17:42:37.197900Z

well the issue with running code directly on load is that it interrupts that reload cycle

thheller 2021-03-26T17:42:53.198400Z

shadow-cljs cannot know WHAT failed during load, it only knows that something failed and abort

thheller 2021-03-26T17:42:59.198900Z

leaving your code in an undefined state

Azzurite 2021-03-26T17:43:13.199400Z

makes a lot of sense, just didn't get that by myself 😄

Azzurite 2021-03-26T17:43:15.199600Z

thanks

thheller 2021-03-26T17:43:16.199700Z

thats why the error dialog doesn't go away

Azzurite 2021-03-26T17:43:57.200Z

so much shit to learn when you're teaching yourself

Azzurite 2021-03-26T17:44:02.200200Z

😄

Azzurite 2021-03-26T17:44:24.200500Z

really appreciate the help & quick reply ❤️

thheller 2021-03-26T17:45:50.202Z

yeah thats why shadow-cljs tries to keep everything as minimal as possible. unfortunately some older blogposts, tutorials, templates use more complex setups making things more complicated than they need to be. IMHO, YMMV 😛

Azzurite 2021-03-27T12:07:30.209800Z

@raspasov yeah over-engineering is very rampant where I'm from, took a bit to get to this path not easy when you're doing it alone and "only" trying to scour the interwebs for the "right things to do" - so much knowledge in people's heads but not written down I feel 😄

raspasov 2021-03-27T16:50:34.210Z

@azzurite “over-engineering” - what language/framework?

Azzurite 2021-03-27T19:40:32.210500Z

@raspasov I more meant geographically/where I've been working/studying so far, Germany but language is Java/C#/JS mostly

raspasov 2021-03-27T20:18:09.211200Z

👍 understood :)

Azzurite 2021-03-26T18:00:22.202700Z

yeah I'm not an inexperienced dev, only in clj/cljs... I so so love getting everything as simple as possible, which is basically what I've been doing so far. And shadow-cljs is a really nice piece of software in the simplicity area

👌 1
Volodymyr Huzar 2021-03-26T18:38:20.203100Z

@thheller seems it will not fix a problem I have. A :dev-http is a global configuration, isn’t? What I need to run one of the builds (test one) on http, but I want application build still to be run using https. Is it possible to solve somehow, maybe disable ssl using :devtools configuration?

thheller 2021-03-26T18:40:14.203300Z

the http servers are ALWAYS global, the :devtools :http-root and :http-port are old configuration and were replaced by :dev-http

thheller 2021-03-26T18:40:54.203500Z

so if you previously had :devtools {:http-port 3000 :http-root "public"} that should instead be :dev-http {3000 "public"} or the the example above with the disabled :ssl

Volodymyr Huzar 2021-03-26T18:41:45.203700Z

oh, good to know that, doesn’t it complicates the things? how to serve different roots for different builds now?

thheller 2021-03-26T18:42:50.204Z

no, it makes things much simpler. it was my mistake allowing the devtools http config in a config for the build. that was never how it worked and the dev-http matches more closely how it actually works

thheller 2021-03-26T18:43:01.204200Z

if you need multiple servers you just use multiple ports

thheller 2021-03-26T18:43:14.204400Z

:dev-http {3000 {:root "public" :ssl false} 3001 "something-else"}

Volodymyr Huzar 2021-03-26T18:43:19.204600Z

oh, got it

Volodymyr Huzar 2021-03-26T18:44:29.204900Z

by the way the latest release I see here https://github.com/thheller/shadow-cljs/releases is 2.11.13

thheller 2021-03-26T18:44:53.205100Z

https://clojars.org/thheller/shadow-cljs

Volodymyr Huzar 2021-03-26T18:50:17.205500Z

thanks a lot! everything, works as expected now

👍 1
2021-03-26T22:31:44.206500Z

Does anyone know of a good example of using a service worker with shadow-cljs?

2021-03-26T22:33:52.206900Z

(in terms of shadow-cljs.edn set up)

thheller 2021-03-27T08:37:29.209100Z

{:target :browser :modules {:sw {:init-fn my.sw/init :web-worker true}}} should be ok

thheller 2021-03-27T09:26:48.209300Z

FWIW I think its better to use a dedicated tool for this like https://developers.google.com/web/tools/workbox

2021-03-27T09:45:41.209600Z

🙏