nbb

hifumi123 2023-04-17T03:27:54.188659Z

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 )

borkdude 2023-04-17T06:54:41.337199Z

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

👍 1
hifumi123 2023-04-17T07:29:23.918459Z

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

borkdude 2023-04-17T07:56:14.943409Z

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

hifumi123 2023-04-17T07:56:27.420799Z

I see. Thanks!

hifumi123 2023-04-17T10:10:54.290179Z

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

borkdude 2023-04-17T10:13:05.413519Z

@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

👍 1
borkdude 2023-04-17T10:13:49.787199Z

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

hifumi123 2023-04-17T10:19:08.971739Z

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.

hifumi123 2023-04-17T10:19:50.815469Z

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

borkdude 2023-04-17T10:22:29.280089Z

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

borkdude 2023-04-17T10:23:08.243729Z

note that nbb already comes with reagent

hifumi123 2023-04-17T10:28:32.848079Z

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

hifumi123 2023-04-17T11:37:42.783819Z

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”

hifumi123 2023-04-17T11:38:29.966869Z

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

borkdude 2023-04-17T11:39:39.586669Z

that's very cool :)

Chris McCormick 2023-04-18T03:42:08.812729Z

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