Fork me on GitHub
#nbb
<
2023-04-17
>
hifumi12303:04:54

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 )

borkdude06:04:41

Currently not unless you clone them locally yourself and add them to the classpath yourself

👍 2
hifumi12307:04:23

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

borkdude07:04:14

babashka doesn't use clj but deps.clj to download deps

hifumi12307:04:27

I see. Thanks!

hifumi12310:04:54

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

borkdude10:04:05

@U0479UCF48H 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

👍 2
borkdude10:04:49

And here are some docs for publishing to npm: https://github.com/babashka/nbb/tree/main/doc/publish

hifumi12310:04:08

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.

hifumi12310:04:50

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");

borkdude10:04:29

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 so

borkdude10:04:08

note that nbb already comes with reagent

hifumi12310:04:32

Yeah, it looks like importing closure modules won’t be possible; I’ll use reagent I guess.

hifumi12311:04:42

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”

hifumi12311:04:29

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))

borkdude11:04:39

that's very cool :)

Chris McCormick03:04:08

Wow bundle is amazing! I didn't know about this, thanks. 🙏