shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Sam Ritchie 2021-06-07T14:46:51.405800Z

hey all, gut-check question here… I have a library I’d like to depend on that is currently managed with bower: https://gitgud.io/unconed/mathbox If I want to publish a clojurescript library that depends on this package… is the best option to re-publish this as an NPM dependency? I am getting my head around all of this, and it seems that bower is deprecated

Sam Ritchie 2021-06-07T14:47:18.406400Z

I guess the alternative that comes to mind is cljsjs, or including the js files directly (seems very un-pro)

thheller 2021-06-07T16:23:23.406700Z

for shadow-cljs you'd need to publish to npm since cljsjs is not supported. should be very simple since bower is very similar to npm as far as packages are concerned

thheller 2021-06-07T16:25:44.408400Z

in fact shadow-cljs can also use bower packages just fine, just needs a little extra configuration in :js-package-dirs

Sam Ritchie 2021-06-07T16:49:00.408700Z

interesting!

Sam Ritchie 2021-06-07T16:49:11.409100Z

is there any docs page that lays out what to do? otherwise I will go down the NPM road

thheller 2021-06-07T16:50:13.409700Z

well since you mentioned publishing a library that depends on mathbox I strongly recommend publishing to npm

thheller 2021-06-07T16:50:30.410200Z

otherwise everyone using that package would need to manually install bower and that package

thheller 2021-06-07T16:50:42.411Z

with npm it just works automatically if you list it in deps.cljs

Sam Ritchie 2021-06-07T16:50:47.411100Z

got it, that is clearly best

thheller 2021-06-07T16:51:04.411300Z

otherwise if you just want to try it https://shadow-cljs.github.io/docs/UsersGuide.html#alt-node-modules

thheller 2021-06-07T16:51:27.411800Z

:js-packages-dirs ["node_modules" "bower_modules"] IIRC bower used that dir?

thheller 2021-06-07T16:52:24.412700Z

but to publish the thing to npm you likely only need to change the name in package.json and npm publish

Sam Ritchie 2021-06-07T16:53:10.413200Z

thank you @thheller

Sam Ritchie 2021-06-07T16:53:11.413400Z

!

thheller 2021-06-07T16:55:27.414500Z

dunno if its a good idea to use a 5 year old JS package with version 0.0.5 though. It is not clojure after all 😛

Sam Ritchie 2021-06-07T17:07:07.414900Z

@thheller in most cases I would agree.. BUT!

Sam Ritchie 2021-06-07T17:08:34.415700Z

in this case, this library still seems to be the most world-class thing out there for mathematical visualization in the browser... it powers http://www.math3d.org/animate_camera as an example

Sam Ritchie 2021-06-07T17:09:19.416500Z

@unconed has this insane level of work in this project, but stalled because he'd developed something wonderful but "javascript as a language didn't seem to fit for the declarative XML-ish structures he'd based the library on" 😉 https://acko.net/blog/mathbox2/

Sam Ritchie 2021-06-07T17:09:40.417100Z

so I'm going to rehab this thing and get him interested again. Anyway, TMI for the main thread, but cool stuff!

Sam Ritchie 2021-06-07T18:09:04.418600Z

@thheller one Q for you related to cljsjs. I've published mathbox as https://www.npmjs.com/package/@sicmutils/mathbox2. I want to provide a :global-exports entry that will make this package compatible with shadow-cljs. but the boot task in cljsjs needs a map of sym=>sym for its :global-exports value. what should the value be here?

:global-exports '{"@sicmutils/mathbox2" MathBox
                  cljsjs.mathbox2 MathBox}

Sam Ritchie 2021-06-07T18:10:21.419400Z

I can always republish it without the @ symbol... but I don't want to stomp the global mathbox2 name, for when the original author pushes this out

thheller 2021-06-07T18:13:35.419900Z

I don't understand your question. shadow-cljs does NOT support foreign-libs, so whatever you add there will not be read by shadow-cljs at all?

thheller 2021-06-07T18:13:54.420200Z

does (:require ["@sicmutils/mathbox2" :as x]) not work?

Sam Ritchie 2021-06-07T18:16:44.421100Z

ah, I think I have this figured out. I wanted to make sure that the foreign-libs entry I added would let users write code that was compatible with foreign-libs and also with shadow-cljs, and cljsjs was rejecting my foreign-libs entry

Sam Ritchie 2021-06-07T18:18:25.421900Z

your line should absolutely work with shadow-cljs (duh), and I think I figured out how to get past my problem in cljsjs...

thheller 2021-06-07T18:20:09.422700Z

yeah you can just setup foreign-libs to that the above require works with regular CLJS. can't remember how though.