Replies: 4 comments 18 replies
-
|
Beta Was this translation helpful? Give feedback.
-
One possible solution without converting your entire project to Make one or more namespaces that only deal with importing your deps: (ns deps
(:require #?(:org.babashka/nbb
["puppeteer$default" :as p]
:cljs
["puppeteer" :as p])))
#?(:cljs
(def puppeteer p)) And then use those namespace(s) from your scripts: (ns script
(:require [deps :refer [puppeteer]]))
(.launch puppeteer #js {:headless false}) The above works with both lumo and nbb. |
Beta Was this translation helpful? Give feedback.
-
I'm inclined to add something to the metadata part of the namespace to make this easier: (ns example
{:nbb/auto-default #{"handlebars"}} ;; automatically selects $default for
;; these libs for compatibility
;; {:nbb/auto-default true} ;;=> does it for every lib that doesn't already have $property
(:require ["handlebars" :as handlebars]))
(def template (.compile handlebars "Hello {{name}}!"))
(prn (template #js {:name "world"})) /cc @thheller: perhaps shadow is also interested in a feature like this and we could come up with some standard? |
Beta Was this translation helpful? Give feedback.
-
I guess I misread this line from the documentation as always providing this "mirrored" object, but I guess thats not what they meant. So it is actually still relying on dynamic inspection of the code as mentioned in
So whenever an export cannot be discovered statically it won't work and you need to use the default export. I really wish they went with the default-only way but I guess we'll have to live with this mess much longer then when packages aren't forced to upgrade (or provide two variants). Since you are using dynamic |
Beta Was this translation helpful? Give feedback.
-
There are some users who want to write code (libraries) that should run both in shadow or vanilla CLJS (with target node) and nbb, but they run into the
$default
thing as the only difference. The$default
is necessary because nbb operates in an ES modules context whereas other compilation targets don't (the only CLJS option for target ESM is currently shadow).I recommend that they could use .cljc files and make a reader conditional branch for nbb, but to be honest this gets old quite fast.
What if nbb could support some way to facilitate this use case. E.g.:
Then again, if people would switch to
:target :esm
in shadow (or in the future CLJS) then they would add$default
and nbb would read$default.default
? This is probably asking for trouble...Beta Was this translation helpful? Give feedback.
All reactions