Would it be possible to download CLJS dependencies in nbb without needing babashka installed? (One of the reasons I use nbb is precisely so I don’t have to build or use bb )
Currently not unless you clone them locally yourself and add them to the classpath yourself
Is there a way to instruct babashka where clojure is installed? For some reason it wants to randomly download things into ~/.deps.clj, but doesn’t clojure itself already come with deps.edn? In fact I already have access to a clj command on my PATH and I can use -Sdeps and everything else. Not sure why bb is unable to find it
babashka doesn't use clj but deps.clj to download deps
I see. Thanks!
Is it possible to publish nbb scripts to npm if they have a CLJS dependency? I assume the JAR will have to be bundled somehow into what gets published
@hifumi123 This might help: https://github.com/babashka/nbb/tree/main/doc/bundle You can create a single file from your CLJS files and then publish that to npm
And here are some docs for publishing to npm: https://github.com/babashka/nbb/tree/main/doc/publish
Very nice. One more question: is nbb capable of importing JS files that are Google Closure modules? The CLJS library I’m dealing with has a JS file beginning with goog.provide("some.namespace"); it exists in some/namespace.js but (require '[some.namespace]) fails in nbb.
If you’d like to experiment, I am using {lilactown/helix {:mvn/version "0.1.10"}} . Running (require '[helix.core :as hx]) fails with Could not find namespace: helix.impl.classes, but there is a helix/impl/classes.js file and it begins with goog.provide("helix.impl.classes");
hmm this doesn't work, but maybe we can mock this with:
(j/assoc-in! js/globalThis [:goog :provide] (fn [s] (j/assoc-in! js/globalThis (vec (.split s ".")) #js {}))
or sonote that nbb already comes with reagent
Yeah, it looks like importing closure modules won’t be possible; I’ll use reagent I guess.
well, I am very stubborn … I have made a partial port of Helix to nbb. Not everything is supported, just enough for building TUIs with Ink. I stripped out class components, too, since people can simply import react-error-boundary . I have tenatively called this port “twirl”
Here’s a quick demo in case you’re wondering how it looks.
(ns demo.core
(:require ["ink" :as ink]
[twirl :refer [$ defnc]]
[twirl.hooks :as hooks]))
(defnc counter []
(let [[counter set-counter] (hooks/use-state 0)]
(hooks/use-effect :once
(let [timer (js/setInterval #(set-counter inc) 1000)]
(fn unmount []
(js/clearInterval timer))))
($ ink/Text {:color "green"}
(str counter " test passed"))))
(ink/render ($ counter))that's very cool :)
Wow bundle is amazing! I didn't know about this, thanks. 🙏