ClojureScript Compiler Service (poc)

If Muhammad will not go to the mountain, we must bring the mountain to Muhammad.

ClojureScript has a very specific goal set. This singular focus is refreshing and frees the project to progress rapidly on core goals, cutting unnecessary burdens. That leaves out features that are rarely needed in "production", like runtime evaluation.

While the "development" and "production" time dichotomy is pragmatic, it is more probability distribution than tautology. If your use case falls in the false end of the distribution, [1] we must bring the mountain to Muhammad. A ClojureScript Compiler-as-a-Service (CaaS) could add back some dynamism.

Happily, a CaaS has more uses than just enabling a poor-mans runtime eval.
CaaS can be embedded, be hosted, and simplify a dev environment.

More importantly, it's a step towards lowering barrier-to-entry to a complex system such as ClojureScript's: install JVM, clone source tree, know a shell, set environment vars, run bootstrap, cross fingers, and you still don't have immediate browser feedback without extra setup or specially modifying your app.
This in comparison to JavaScript: launch browser, open dev console, done. [2]



To support these goals, I pushed to clojars: custom ClojureScript [3], the Google Closure compiler, and Google Closure JavaScript library.

:dependencies [[org.clojars.pmbauer/clojurescript_svced "1.0.0-SNAPSHOT"]
               [org.clojars.pmbauer/goog.js "1.0.0-SNAPSHOT"]
               [org.clojars.pmbauer/goog.compiler "1.0.0-SNAPSHOT"]]


This is just a proof-of-concept and there are problems to solve:
  • multi-file compilation without a filesystem [4]
  • incremental/contextual compilation option (e.g. in-browser repl)
  • simple gui front-end a la Google Closure Compiler Service.


POST /compile
  • optimizations: advanced | simple | whitespace
  • pretty-print: true | false
  • cs-code: string of ClojureScript | file upload

example usage:

# compile a string of forms
CODE="(defn square [x] (* x x)) (def twenty-five (square 5))"
curl --data "optimizations=simple&cs-code=${CODE}&pretty-print=true" \

# compile a sourece file
curl --form optimizations=advanced \
     --form cs-code="@${CODE}" \
     --form pretty-print=true \

[1] Browsers are rapidly approaching first-class citizenship as a platform for system tools.
See Cloud9, exo, CQ5, Sencha, amber-lang (smalltalk).

[2] ClojureScript is a powerful tool by professionals for professionals. But easing access benefits everyone, adoption, and ecosystem.

[3] This is a custom ClojureScript build (not yet released) that isolates shared mutable state to thread-local vars.

[4] Envisioned primarily as a standalone tool, the ClojureScript compiler makes easy choices regarding state. For example, it complects compiling a set of source files with their structure on disk.