Fork me on GitHub
#nbb
<
2022-11-21
>
milelo09:11:30

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

borkdude09:11:42

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

borkdude09:11:58

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

borkdude09:11:29

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

milelo09:11:16

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.

borkdude09:11:53

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

borkdude09:11:56

but for nbb it makes sense

borkdude09:11:18

we can additionally support:

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

borkdude09:11:29

similar to how it works in js

borkdude15:11:04

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

hoppy19:11:09

kicking the tires on nbb nrepl-server connected via calva

hoppy19:11:38

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

borkdude19:11:48

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

hoppy19:11:29

that behaves

hoppy19:11:34

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.

hoppy19:11:10

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

borkdude19:11:10

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

pez19:11:17

Calva no longer adds or removes any newlines. FYI.

borkdude20:11:55

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