Skip to content

Commit

Permalink
Handle exit by promisifying lumo compilation
Browse files Browse the repository at this point in the history
This patch fixes the fact that serverless could not display the failures of
compilation in lumo. It also needs the very latest lumo for it to work.
  • Loading branch information
arichiardi committed Sep 19, 2017
1 parent 135fae0 commit a99a65f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ In the example above, there needn't be a corresponding entry for `echo` in

## Lumo

Alternatively you can use the [Lumo](https://github.com/anmonteiro/lumo)
Alternatively, you can use the [Lumo](https://github.com/anmonteiro/lumo)
[compiler](https://anmonteiro.com/2017/02/compiling-clojurescript-projects-without-the-jvm/).

Note that `serverless-cljs-plugin` needs _Lumo >= 1.8.0_.

In order to enable it, pass the `--lumo` switch to either `deploy` or `package`:

```shell
Expand Down
30 changes: 19 additions & 11 deletions serverless-cljs-plugin/serverless_lumo/build.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[cljs.reader :as reader]
[lumo.build.api]
[lumo.classpath :as classpath]
[lumo.core]
[lumo.core :as lumo]
[lumo.io :as io]
[serverless-lumo.index :as index]))

Expand Down Expand Up @@ -51,9 +51,16 @@
"Invoking the Lumo compiler w/ inputs"
(.stringify js/JSON (clj->js inputs)))
(run! classpath/add! inputs)
(lumo.build.api/build
(apply lumo.build.api/inputs inputs)
compiler-opts))

(js/Promise.
(fn [resolve reject]
(lumo.build.api/build
(apply lumo.build.api/inputs inputs)
compiler-opts
(fn [result]
(if (:error result)
(reject result)
(resolve result)))))))

(defn read-conf!
"Read and return the configuration map."
Expand All @@ -69,7 +76,6 @@
{:source-paths ["src"]
:compiler {:output-to (.format path #js {:dir "out" :base "lambda.js"})
:output-dir "out"
:source-map false ;; lumo bug
:target :nodejs
:optimizations :none}})

Expand All @@ -94,11 +100,11 @@
(dump-index! (.resolve path output-dir "../index.js")
(:functions opts)
compiler))
(compile! (:source-paths cljs-lambda-opts) compiler)
(zip! (:zip-path opts)
{:dirs #{output-dir "node_modules"}
:files #{[index {:name "index.js"}]}}
compiler)))
(.then (compile! (:source-paths cljs-lambda-opts) compiler)
#(zip! (:zip-path opts)
{:dirs #{output-dir "node_modules"}
:files #{[index {:name "index.js"}]}}
compiler))))

(def cli-option-map
{:z :zip-path
Expand Down Expand Up @@ -134,6 +140,8 @@

(defn ^:export -main [& args]
(let [opts (cli-options (cmd-line-args))]
(build! opts (merge-maps default-config (read-conf!)))))
(.then (build! opts (merge-maps default-config (read-conf!)))
lumo/exit
#(lumo/exit 2))))

(set! *main-cli-fn* -main)

0 comments on commit a99a65f

Please sign in to comment.