This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-11
Channels
- # announcements (3)
- # asami (4)
- # babashka (79)
- # babashka-sci-dev (47)
- # beginners (97)
- # biff (12)
- # calva (7)
- # clj-commons (3)
- # clj-kondo (22)
- # clj-on-windows (13)
- # cljdoc (31)
- # cljfx (2)
- # cljs-dev (1)
- # clojure (85)
- # clojure-austin (4)
- # clojure-dev (12)
- # clojure-europe (15)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-uk (4)
- # community-development (19)
- # conjure (3)
- # core-typed (40)
- # cursive (9)
- # datahike (21)
- # datomic (1)
- # emacs (7)
- # exercism (2)
- # graalvm (20)
- # graphql (1)
- # honeysql (16)
- # jobs (1)
- # malli (2)
- # off-topic (3)
- # pathom (28)
- # pedestal (3)
- # polylith (7)
- # reitit (14)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (4)
- # shadow-cljs (21)
- # sql (21)
- # testing (8)
- # tools-deps (23)
- # vscode (8)
- # xtdb (38)
@borkdude Heyo. Following up on the requires suggestion, how about we introduce a nbb/register-feature!
that gets placed in an init
similar to nbb/register-plugin!
e.g. (nbb/register-feature ::datascript {:requires {'datascript.core "./nbb_datascript.js"}})
?
We could also make it a part of register-plugin!
but didn't know if you wanted to mix impl and feature concerns
This is a chicken and egg problem: since you need to load the JS first, which calls register-plugin
I think it doesn't hurt if we just add the datascript namespaces into the case statement. If the JS isn't there, then you will get an error, but you would get an error when requiring those nss anyway
Ah ok. I hadn't tried this yet but happy to keep with it as is if register-feature!
isn't possible
Ah. Now I understand the chicken and egg reference. It's not possible. We could also have a map in nbb.features
if it helps to not have new features modify nbb.core
We could solve this maybe using a macro which using "JVM" time looks at some env variables or find all features.edn
files on the classpath and merges them or so
Maybe something like:
nbb_features.edn
[{:name logseq/datascript
:namespaces [datascript.core]
:js "./nbb_datascript.js"}
...
]
The macro will find all nbb_features.edn
files on the classpath, and then store this in a CLJS runtime map.
This map can be queried in nbb.core for feature namespaces and then call load_modules with the right stuff.
@cldwalker Does that make sense to you?
It makes sense but doing this through macros seems more complex than it has to be. We could do this within the bb task itself, generate an edn map and then slurp it in with shadow's https://github.com/thheller/shadow-cljs/blob/650d78f2a7d81f33cb2590e142ddcbcbd756d781/src/main/shadow/resource.clj#L53 during compilation
Here is an example of how you can detect the nbb_features.edn
maps in a macro at compile time:
(enumeration-seq (.getResources (.getContextClassLoader (Thread/currentThread)) "META-INF"))
(replace META-INF
with nbb_features.edn
).
How does moving that to the bb task make it less complex?There are no macros or classpath thinking involved. The bb task just focuses on reading edn and generating data to an edn file
Cool. With any approach, there's still an entry in handle-libspecs
that looks in a features map. That's fine, right?
@cldwalker One of the reasons why I was thinking about the classpath is that you could have several libraries floating around which contain extra features for nbb, without adding them to the central repo (for whatever reason, perhaps corporate code for example).
Then the datascript feature could live in its own dep. Adding it to your classpath would then automatically activate it. Along with a piece of shadow-cljs config which we could add via the shadow clojure API and a clojure function to build nbb
@cldwalker About the new commits: ⢠you will still have a git difference when you're building with features ⢠it seems this will discover all features, not just the ones you've selected in your CI via env vars or so?
Yes there would be a git diff during build but it doesn't effect a fork using the original source. I could clean the modified file after release if you'd like
Hmm. I'm not seeing any way to do that shadow's API - https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/resource.clj . Any ideas?
Just don't use shadow's API for this, just use a macro ;). See e.g. nbb.core/version
I think we could still do the classpath thing in there too, imo it'd be a lot cleaner
The thing you're doing in the bb task you could move to the macro, read the feature files from the classpath, merge and present the EDN to the CLJS runtime
Hehe. I'll check out the macro. Not keen on moving at all to the macro but I'll timebox it
So shall I just merge and give the macro thing a go later? Then you won't be blocked by anything you want to do
Welcome to nbb v0.3.4!
user=> (require '[datascript.core :as d])
nil
user=> (let [schema {:aka {:db/cardinality :db.cardinality/many}}
conn (d/create-conn schema)]
(d/transact! conn [ { :db/id -1
:name "Maksim"
:age 45
:aka ["Max Otto von Stierlitz", "Jack Ryan"] } ])
(d/q '[ :find ?n ?a
:where [?e :aka "Max Otto von Stierlitz"]
[?e :name ?n]
[?e :age ?a] ]
@conn))
#{["Maksim" 45]}
:-D> So shall I just merge and give the macro thing a go later? Then you won't be blocked by anything you want to do Sure! > Have you tested building the features in a CI with the features enabled? That's the next thing I wanted to do. A number of test namespaces run great for me locally
@cldwalker done: https://github.com/babashka/nbb/commit/3ba808483bf2ab537cb75378618ca51667ff0697?w=1
Nice! Was easier than I imagined. Pushed up a branch with datascript tests - https://github.com/logseq-cldwalker/nbb/tree/add-datascript-tests . Passing at https://app.circleci.com/pipelines/github/logseq-cldwalker/nbb/2/workflows/78c34c22-59cf-4445-830c-c12867804c8c/jobs/2?invite=true#step-105-505 . Happy to PR it if you'd like. It optionally runs tests if $NBB_FEATURES
is enabled. Eventually I'd like to make it more data driven like we have for library tests in bb but this works for now