nbb

2023-06-27T11:48:14.058929Z

I'm trying to call local javascript code from file f.js on nbb project. I tried (:require ["./f" :refer [someFunction]] and was expecting it to load from the nbb project root dir, where nbb.edn is located, but since there is a "src" folder configuration in nbb.edn it's loading the root from there. It's a little different from nodejs loading mechanism. (I've tested with : nbb (global) and pnpx nbb (local) both are loading from "src") What is the advised way to javascript code co-exist on a nbb project ?

borkdude 2023-06-27T11:57:36.567349Z

A relative path is loaded relative to the file you’re loading from

borkdude 2023-06-27T11:57:44.350279Z

Similar to JS

2023-06-27T12:02:46.523169Z

Embarassing. You're right.

2023-06-27T13:33:24.106899Z

(traverse ast #js {:FunctionDeclaration identity }) is generating the following error: :message "c.call is not a function", :data {:type :sci/error, :line 29, :column 5, :message "c.call is not a function", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 29, :column 5, :ns #object[Ur js-cljs.astutils-test], It's a babel function https://babeljs.io/docs/babel-traverse that is imported as ["@babel/traverse" :as traverse] It expects an object with methods. I've stripped the code and passed identity just for testing.

2023-06-27T13:46:12.179839Z

I did (js/console.log traverse) and it is a function. The code is executed with nbb --debug -cp test -m nextjournal.test-runner

borkdude 2023-06-27T13:49:23.611999Z

Try adding $default to the libname

2023-06-27T13:51:49.838909Z

"@babel/traverse$default" same result

2023-06-27T13:56:27.909579Z

["@babel/traverse" :refer [default]] invoking (default) instead of traverse gives same message c.call is not a function

2023-06-27T14:01:30.282149Z

Interesting, Now the import is as ["@babel/traverse$default" :as traverse] and I actually hit the function by doing ((j/get traverse :default ) )

2023-06-27T14:01:40.301099Z

So two defaults one from require one from calling

borkdude 2023-06-27T14:40:51.030289Z

user=> (require '["@babel/traverse" :as t])
nil
user=> t/
t/Hub         t/NodePath    t/Scope       t/__esModule  t/default     t/visitors

borkdude 2023-06-27T14:43:19.734199Z

I'll try to make the minimal traverse example from their README to work

2023-06-27T14:52:16.413149Z

It's working

2023-06-27T14:53:55.375059Z

https://gist.github.com/geraldodev/001b3dc5f8888cd9e8847d45d185c1fd it's from a test

borkdude 2023-06-27T14:56:44.069099Z

oh yikes, you needed to do a double default, ok

😄 1
2023-06-27T14:58:04.276389Z

safetyfull defaults

borkdude 2023-06-27T14:58:31.077399Z

what's that?

2023-06-27T15:09:37.094779Z

Joking, two defaults

borkdude 2023-06-27T15:13:10.449399Z

it has something to do with typescript weirdness

2023-06-27T22:27:05.433539Z

So beautiful. require type l/ tab expansion

🤩 4