clj/cljs best practice

132 views
Skip to first unread message

Mimmo Cosenza

unread,
Feb 19, 2013, 3:13:13 PM2/19/13
to clojur...@googlegroups.com, clo...@googlegroups.com
Hi all,
as someone perhaps remember, few days ago I asked about the state of feature expressions which appeared to be immutable ;-) from july 2012. David Nolen gave us a hope to have them in the 1.6 version.

I'm studying the javelin lib which has been recently release. I alway start from project.clj (yes from lein) to understand a library which is new to me (most of them actually)

In javelin lib it seems to me that there is a third way to bypass the CLJ/CLJS differences: the new :source-paths of lein-cljsbuild plugin. I'm getting confused.

If that impression is true, which is the best practice to bypass the CLJ/CLJS differences in the meantime we'll have the feature expression?

Hope to have understood correctely the javelin lib. If not, sorry about that.

Mimmo

Alan Dipert

unread,
Feb 20, 2013, 2:07:39 AM2/20/13
to clo...@googlegroups.com, clojur...@googlegroups.com
Hi Mimmo,
I can't speak to what practice is best, but I can explain the Javelin Leiningen and lein-cljsbuild configuration.

A ClojureScript library like Javelin usually has no compiled pieces to distribute the way a Clojure program that uses AOT or a Java program might.  The only example I can think of is a ClojureScript library with Clojure macros that AOT.  As such, it's possible (but silly, because you probably want to compile tests) to create and distribute a ClojureScript library that doesn't use lein-cljsbuild at all.  One must ensure only that the ClojureScript sources are included in the jar's resource manifest, which is what Javelin does [1].

Javelin, though it includes Clojure code for ClojureScript macros, also has no explicit Clojure dependency.  Javelin's macros depend on the presence of a Clojure provided by the lein-cljsbuild plugin that's used by the consumer to compile the program that depends on Javelin.  One of Javelin's dependencies, cljs-priority-map [2], is configured similarly.  As cljs-priority-map doesn't use any ClojureScript macros, its :source-paths specifies only "src/cljs".

lein-cljsbuild's :source-paths option is less about packaging and more about building - it specifies where in the current project to look for sources.  I don't know which, but either the ClojureScript compiler or lein-cljsbuild look also on the classpath for resources and resolve namespaces to files on it, which is how Javelin is able to depend on cljs-priority-map.

I hope this clarifies things.  Have fun with Javelin!

Alan

Reply all
Reply to author
Forward
0 new messages