nbb 2022-11-21

nbb classpath issue? I have an issue with the nbb classpath; I need to explicitly add my nbb script folders absolute path to the nbb classpath to enable nbb to find a local dependent library. My nbb executable scripts are together in the root of my nbb project along with package.json etc. I've added this to my Linux PATH so they can be called from other locations. The scripts use #! but I have found I also need to set the classpath: #!/usr/bin/env -S nbb -cp <path to script project root>. It doesn't mater if the library is in the root (:require [utils]) or a folder (:require [lib.utils]), the classpath is still required. nbb finds the dependent packages ok. Similarly I expected nbb to find local cljs libraries without the explicit classpath. Is this an nbb issue or am I missing something? Message: Could not find namespace: lib.utils nbb v1.1.146

It uses the JS API to add to the classpath that takes into account the directory of the wrapper script

Maybe we could fix this as follows: when you invoke a script outside of the current working directory, nbb should add the script parent directory to the classpath instead. But if you have libraries (nbb.edn), it should act the same way - but it currently doesn't work this way: it always just picks the current working directory and only respects nbb in the current directory. Feel free to make an issue + example project

Also PR welcome to solve the issue, if you're in for it

Ok thanks I'll take a look. I was just about to ask why nbb couldn't infer the project root from the namespace of the invoked script and add it to the classpath, it must do this to find the node_modules.

The reason is that node kind of works like that, but classpath things don't work like that for clojure-like things

but for nbb it makes sense

we can additionally support:

(ns foo.bar (:require ["./baz.cljs"])
maybe to load foo/baz.cljs

similar to how it works in js

There was a small problem with 1.1.146 in package.json which is now fixed in 1.1.147

kicking the tires on nbb nrepl-server connected via calva

is it expected that (println ...) comes back via nrepl, but doesn't print in the shell window running nbb?

don't know :) you can also use js/console.log if that works better

also newlines are missing in the println coming back via nrepl. @pez and I just yapped about that week or two ago and I think he pulled appending an extra newline out of calva.

but I spoke too soon, some work some don't

feel free to post some issues and if you feel like it, you can hack on the nrepl server as well

Calva no longer adds or removes any newlines. FYI.

I'm not aware that any nrepl server ever added or removed newlines, so if that's the case, make issues ;)