clojurescript

Jeff Snell 2024-10-18T12:21:04.887099Z

Hello! We're using babel to compile some portions of our code with typescript and tsx. Essentially we're doing https://www.youtube.com/watch?v=Bp2d0jQx8Gs, with a bit of config on the side:

"start": "npx shadow-cljs watch dev & npm run babel -- --watch", 
The babel output gets put into a directory src/gen/ that we can require into our namespace eg ["/components/IconButton" :refer [IconButton]] The question: Babel outputs source maps but shadow-cljs either doesn't see them or doesn't pass them through it's build. Does anyone know if I can get shadow-cljs to consume the source maps from the babel output or if there is a better way of doing this part of the build?

thheller 2024-10-18T16:42:27.564029Z

that entire code path is a bit sketchy and I no longer recommend using it. instead output all your babel output to packages/some-name and then consume it via (:require ["some-name/components/IconButton" ...])

thheller 2024-10-18T16:42:49.900099Z

then in your build config set :js-options {:js-package-dirs ["packages" "node_modules"]}

thheller 2024-10-18T16:43:13.144099Z

this effectively treats your babel output as its own npm package, found via the packages dir

thheller 2024-10-18T16:44:41.265769Z

input source maps are however still a bit of an issue and unlikely to work properly there too

Jeff Snell 2024-10-18T16:47:15.488689Z

Ok thank you, appreciate the response!

2024-10-18T16:08:53.298459Z

Should I expect clojure.edn/read-string to pull in numbers as #object[Number] as opposed to #number ? In release mode I was seeing some problems with these not being used as a plain number. I had to go to efforts to cause the proper conversion.

dpsutton 2024-10-18T16:11:53.384879Z

what behavior are you seeing?

❯ clj -A:cljs -m cljs.main -re node -r
WARNING: Implicit use of clojure.main with options is deprecated, use -M
ClojureScript 1.10.773
cljs.user=> (type 3)
#object[Number]
cljs.user=> (clj->js 3)
3
cljs.user=> (type *1)
#object[Number]
cljs.user=> (require 'clojure.edn)
nil
cljs.user=> (clojure.edn/read-string "3")
3
cljs.user=> (type *1)
#object[Number]

2024-10-18T16:20:05.099499Z

works as expected in non-release mode. In release mode, there is an extra call on a method that returns nil. So I see sat = l.xd() if I set a break point, I can see that l is #object[Number] but that the method .xd() returns nil. might not be exactly 'xd'...doing this from memory. It took me a bit to get it to work, and I don't precisely know why I ran into this.