nbb

2023-07-26T20:03:40.158309Z

Using nbb to explore an API. I'm getting response data, converting it from json to edn via js->clj, and pprint'ing it. However, unlike js/console.log the output is all in one line in the repl. Guessing in some part due to my editor of choice, but is there a way to get the formatted output to show in the nrepl server process like js/console.log?

borkdude 2023-07-26T20:07:46.290999Z

perhaps you can try (set! *print-fn* js/console.log) or so?

2023-07-26T20:07:58.457659Z

Ooh will try

borkdude 2023-07-26T20:08:47.897439Z

doesn't seem to work

2023-07-26T20:08:52.780129Z

Same

borkdude 2023-07-26T20:09:42.372199Z

user=> (alter-var-root #'prn (constantly js/console.log))
#object[log]
user=> (prn 1)
1
nil
user=> (prn #js [1 2 3]))
[ 1, 2, 3 ]
nil

2023-07-26T20:12:01.392599Z

Oh... wait I was using clj->js instead of js->clj 😵

borkdude 2023-07-26T20:12:10.177879Z

oh :)

2023-07-26T20:13:02.614269Z

It would still be helpful if println, prn, pprint, etc... could output to the main nrepl server proc like js/console.log does but this is a big improvement at least 😅

2023-07-26T20:24:19.644149Z

Ooh actually, I can write a userland function for that. Would just call with-out-str to pprint my data, then console.log the str output

2023-07-26T20:24:52.137269Z

Thinking it would be nice for keeping particular data visible on my terminal that doesn't update frequently

2023-07-26T20:26:47.662609Z

It works!

🎉 1
hifumi123 2023-07-26T22:42:20.624989Z

Is it possible to invoke nbb scripts from a parent directory and possibly tools like Shadow CLJS without having to run shell commands? I am investigating using nbb to unify some build tasks in a pure CLJS project, and I would like to avoid makefiles and shell scripts if I can.

borkdude 2023-07-27T08:45:56.319699Z

Sure, you can use load-file in nbb and also you can use the Node libraries for spawning programs

hifumi123 2023-07-27T09:08:52.774719Z

Awesome! nbb.core/load-file is exactly what I wanted