shadow-cljs

Schmoho 2025-03-24T10:17:47.851559Z

I've mentioned this problem some days ago: https://clojurians.slack.com/archives/C6N245JGG/p1742253581707129 I just wondered, is there a way to extract this code into a separate project, build an artifact from this that I can include in other projects to circumvent this? Sorry that this is such an open-ended question, my understanding of CLJS builds is still very limited. Basically, the entire interop I need with the vega libraries is just for building this single component. Alternatively, is there a way to disable/circumvent google closure compilation for just a single dependency?

thheller 2025-03-24T10:30:03.833009Z

I believe they provide a CDN variant, which you can just use and just not have vega in the build at all

thheller 2025-03-24T10:30:21.510839Z

https://vega.github.io/vega-lite/usage/embed.html

thheller 2025-03-24T10:30:42.753539Z

following that you'd just use (js/vegaEmbed ..) in your code

thheller 2025-03-24T10:31:13.676109Z

so, basically yes, they already provide this for you ๐Ÿ˜›

thheller 2025-03-24T10:31:36.533759Z

if you don't want the CDN you probably can just use the files directly from npm

Schmoho 2025-03-24T10:32:16.479639Z

and include them via separate src tags?

thheller 2025-03-24T10:32:21.291259Z

yes

Schmoho 2025-03-24T10:32:44.075329Z

well now I just feel stupid

Schmoho 2025-03-24T11:14:43.317869Z

Can I refer to this then? Or am I dependent on global objects defined by a library? Having this in index.html :


    
    
and this require:
["react-vega" :refer [VegaLite]]
unsurprisingly gives me
[:app] Build failure:
The required JS dependency "react-vega" is not available

thheller 2025-03-24T13:04:08.851289Z

you can configure shadow-cljs to redirect the react-vega to the global https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve

thheller 2025-03-24T13:04:55.507329Z

but that still means you are dependent on the globals provided by the lib, so might as well just use the globals via js/whatever

Schmoho 2025-03-24T13:43:23.242919Z

Thanks so much! I ended up triangulating an older version that doesn't give me all that headache (i.e. works with google closure and seems to support all the features I am interested in). It was not obvious to me what globals are exported by the respective packages anyway, whether those would "work" as expected etc.

thheller 2025-03-24T14:47:07.203689Z

yeah I hope the new closure compiler version fixes this, but it isn't available via maven. gotta wait a bit to find out I guess.

2025-03-24T18:15:17.368689Z

I take it if you have a test suite and run npx shadow-cljs watch :test` there is no way to pass CLI args to the test runner to only run a single namespace?

thheller 2025-03-24T18:19:19.280229Z

not currently no, but you can just not use :autorun and instead use something else that just runs the node command with some kind of trigger, e.g. watching the output file

2025-03-24T18:20:12.182039Z

Got it, I can just use nodemon for that, just wanted to make sure I wasn't missing something. Thanks!

2025-03-24T20:16:16.589809Z

Hi, I get a strange issue with react-scan npm package. I managed to reproduce on a bare reagent project create with lein new. ๐Ÿงต

2025-03-24T20:17:19.951479Z

It works great adding react-scan like this in the core namespace :

(ns reagent-scan.core
  (:require
   ["react-scan" :refer [scan]]
   [reagent.core :as r]
   [reagent.dom :as d]))

;; -------------------------
;; Views

(defn home-page []
  [:div
   [:h2 "Welcome to Reagent"]])

;; -------------------------
;; Initialize app

(defn mount-root []
  (d/render [home-page] (.getElementById js/document "app")))

(defn ^:export init! []
  (scan #js {:enabled true})
  (mount-root))

2025-03-24T20:19:08.669909Z

But when using Shadow options :deps true , scan return undefined and I get this error in the browser console :

Uncaught TypeError: module$node_modules$react_scan$dist$auto_global.scan is not a function

2025-03-24T20:27:47.496239Z

At first, I was thinking it's caused by a different Shadow-CLJS version and indirectly a different Closure version but both deps.edn and package.json had the same shadow-cljs version. ๐Ÿค”

2025-03-24T20:41:05.183369Z

OK, using yarn shadow-cljs info , I see the project using the last version of Shadow-cljs ignoring the package.json version.

thheller 2025-03-24T20:41:06.648629Z

unsure how this would affect anything in the code? it certainly won't affect the JS generated if you are indeed getting the exact same versions

thheller 2025-03-24T20:41:30.185149Z

its not ignoring anything unless you tell it to ๐Ÿ˜›

thheller 2025-03-24T20:41:49.922759Z

remember that changing the verison in package.json does nothing unless you actually run yarn install

2025-03-24T20:44:26.694529Z

I pretty sure, that I run rm -r node_modules && yarn install haha ! Maybe it's too late for my brain ๐Ÿ˜„

2025-03-24T20:49:26.268839Z

Maybe I missed something. On a fresh new project lein new reagent-frontend foobar , I have this version in package.json :

"shadow-cljs": "^2.19.2"

2025-03-24T20:50:46.411489Z

But running, yarn shadow-cljs info , I get :

=== shadow-cljs version (via npm)
shadow-cljs version:  2.28.21

2025-03-24T20:51:49.410989Z

It's why I said "ignoring".

thheller 2025-03-24T20:52:01.948659Z

"^2.19.2" that is a node version range, basically anything higher goes, as long as its 2.x

thheller 2025-03-24T20:52:35.986949Z

so that gives you the latest version whenever you install it and once installed it uses whatever is on the lock file

2025-03-24T20:55:11.576029Z

Indeed, Shadow-cljs is still version 2. ๐Ÿ‘ As usual, thank you @thheller for this reminder and you reactivity !

thheller 2025-03-24T20:55:14.448789Z

(same goes for the react-scan lib btw, so make sure you are actually working on the same version you have issues with)

๐Ÿ‘ 1
thheller 2025-03-24T20:55:45.257229Z

version ranges can really mess with you expectations here ๐Ÿ˜›

2025-03-24T21:02:43.526059Z

Yeah, the JS little pleasures. ๐Ÿ˜›