Nbb a.k.a. Node-Babashka

Hi! I don’t think I’ve announced nbb here yet, so here it goes.

Nbb is a babashka-like tool but instead of based on the JVM and GraalVM native-image it targets Node.js. The main goal is to make ad-hoc scripting with CLJS (syntax) on Node.js easy to get started with. You can use any Node.js library from nbb (unlike bb where Java libraries have to be built into the image). Additionally, like bb, you might be able to use CLJS libraries using the --classpath argument, if those libraries are written in the subset that SCI supports. I’ve tested HoneySQL and it worked well. Like with babashka, when your project outgrows nbb, you can then migrate to a fully compiled CLJS project.

More info in the README here:

It’s still early days and nbb probably has some rough edges (please do report those), but Chris McCormick already managed to build a cool Twitter bot project with it!

Oh yes, nbb bundles Reagent, so you can build TUI apps with for example Ink.

14 Likes

It requires bb, and bb requires graalvm. Have you been able to build graalvm from source?

I believe GraalVM is implemented in Java, so it doesn’t get built from source, what you need is to build from source another JVM with JVMCI support, which is then used to byte-compile the GraalVM java source into java bytecode, and then you use that other JVM to run GraalVM.

Basically GraalVM is a Java application.

Though I think you can then use GraalVM running in another JVM to native-image compile GraalVM itself.

OpenJDK 9 and above support JVMCI.

What are you folks referring to? You don’t need bb to run nbb, but it’s convenient to build nbb with bb due to the task runner. But you can do without it by just looking up the commands it uses in the bb.edn file.

2 Likes

I’m on gentoo linux. I want to build everything including graalvm from source if possible.

For nbb, it doesn’t really make sense to build bb from source as this is way too much overhead. Just look in the bb.edn for the shell commands you have to execute to build. You need the command for bb release followed by npm install -g (if you want to have nbb globally available on your system).

Just pushed a couple of fixes, so if you cloned it locally, please pull the latest commits.

Concerning macros: in the docs for SCI it says a macro is defined via a normal function having ^:sci/macro metadata (I am using this in Scittle). In nbb there is defmacro. Is there a fundamental difference between macros in Scittle vs. macros in nbb?

In code executed by SCI the only API is defmacro. The ^:sci/macro metadata is for SCI configuration if you use it as a library (and perhaps creating functions with that metadata inside scripts act like macros, but this is more a leaky abstraction than a feature). Nbb is a scripting environment like Babashka where SCI is already configured for you and not exposed to the person who is writing the scripts.

The idea is to turn npm packages, java jars, clojure jars, bb, and nbb into gentoo packages.
Once it’s done, gentoo users can just install it with gentoo’s package manager.

Technically, gentoo is capable of binary packages, but I prefer source packages.