I moved to selmer instead for templating...it's amazingly quick with bb! 40 files in 150ms https://github.com/typedclojure/typedclojure/blob/fd7e00a134425e0ee6b13adbc418c0991dd97608/dev/src/typed/dev/selmer.clj#L77-L117 Totally changed my workflow, thanks @borkdude!
Is it possible to use a different encoding in slurp
than utf-8
?
(slurp "/path/to/file" :encoding "ISO-8859-1")
which means that my encoding is not included
what are you trying with?
Not sure if I mentioned it here already, but: Maybe you need just a little bit of CLJS in your babashka httpkit app and you don't want to set up a whole new CLJS project for it. Performance and bundle size may not be that important. Then scittle may be suited for you: https://borkdude.github.io/scittle/
"cp1250"
Yeah can confirm bb raises the java.io.UnsupportedEncodingException with both cp1250 and Windows-1250 @borkdude any ideas?
Seems we need to add -H:+AddAllCharsets
, https://github.com/oracle/graal/issues/1370
PR welcome in a branch. First let's see what it does to the binary size :)
Is there any way to introspect the classes that are available to bb?
@cfleming I can give you a full list as JSON, if that is useful?
It's basically this list: https://github.com/babashka/babashka/releases/download/v0.4.3/babashka-0.4.3-reflection.json which is published at every release
Can that be obtained at runtime, or is that hardcoded somehow? I assume that classes are added to that from time to time?
I'm not sure how to do this at runtime, how would you do that in Clojure?
The churn in classes isn't that high though, so it would probably be ok if you updated this every so often
Ok, or I’ll download it from github based on the version of the bb runtime. Thanks!
Having looked at it, it looks like all the namespaces available to the bb runtime are available immediately, i.e. I can see them being returned by all-ns
. Is that correct?
correct
except for libraries from the "classpath"
so all-ns
does return all the built-in ones
Great. I’m trying to figure out how to best support bb in Cursive, and the problem is the built-in libs. But if I can introspect those that will probably work well.
Users will still have to mark specific files as being bb rather than normal Clojure in some way, but I think that’s ok.
@huxley please have a look at the PR above, let us know of your use case, we can consider adding it 🙂
yeah. babashka does have a bb.edn
now which is similar to deps.edn
but this isn't mandatory, so it's still useful to have an option to flag a file as "bb"
for Clojure-LSP we have a similar problem: https://github.com/babashka/babashka/issues/733#issue-811939787
so there currently we have a script to obtain the latest deps in babashka and lsp does analysis on those deps
Ok so there you’re actually getting the deps.edn from github for the built-in deps, correct?
Interesting, that might work well for Cursive too.
correct. not sure how well it works, it hasn't seen a lot of usage yet I think, but that's the idea
thx!
Is the deps.edn published as part of a release?
I will check as soon as I have some time
Hmm, looks like not.
no, but we tag every release, so maybe that helps somehow
Unfortunately https://raw.githubusercontent.com/babashka/babashka/blob/v0.4.3/deps.edn doesn’t work.
I think for tags you have to know the sha
This does work :) https://raw.githubusercontent.com/babashka/babashka/v0.4.3/deps.edn
Yes, I just tried clicking the link 🙂
Ok, great, that will help.
I’ll try that and see how far I get, thanks.
I suggested to ericdallo that bb could spit out a deps.edn-like structure with its built-in deps and also the deps and paths from bb.edn combined. Maybe that would help too, but he would rather see a complete classpath with all deps downloaded, which is basically what that script does. Feel free to post in that issue as well, if you have some new insights.
I’ll read through it all after breakfast.
Is there only one bb.edn in the root of a project, normally?
typically yes. but it's relatively new and not mandatory for say, single one-off scripts
I'm afk now as it's almost midnight here, have a great day
Thanks for the help!
Is there an xpath like thing for babashka? I'm trying to read the version of a pom file... I want to say something like short and sweet like
(xpath "...pom.xml" "/version[0]" )
but instead, I'm doing
(def pom-file ".../pom.xml")
(def pom (xml/parse (io/input-stream pom-file)))
(def element-type (class pom)) ;; instanceof didnt like class literal
(def children-of-toplevel-pom (filter #(instance? element-type %) (:content pom)))
(def version-element (first (filter #(= "version" (name (:tag %))) children-of-toplevel-pom)))
(def current-version (first (:content version-element)))
Maybe this example helps? https://github.com/babashka/babashka/blob/master/examples/pom_version_get.clj
That is way better.
I think zippers could also help: https://ravi.pckl.me/short/functional-xml-editing-using-zippers-in-clojure/
I think I had this problem before and solved it in like 5 lines of specter. Haven't tried it with babashka, though.
https://www.reddit.com/r/Clojure/comments/6tod7e/xmlin_your_friendly_xml_navigator/ See the first comment here (not mine)