Skip to content

Commit

Permalink
Graceful exit on lumo compilation failure (lumo >= 1.8.0)
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. This feature is only available in the latest lumo (>=
1.8.0) so the README now makes clear that other versions won't be
supported.
  • Loading branch information
arichiardi committed Sep 19, 2017
1 parent 135fae0 commit f044d29
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ 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)
[compiler](https://anmonteiro.com/2017/02/compiling-clojurescript-projects-without-the-jvm/).
Alternatively, you can use the [Lumo](https://github.com/anmonteiro/lumo)
[compiler](https://anmonteiro.com/2017/09/the-state-of-clojurescript-compilation-in-lumo).

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

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

Expand Down
2 changes: 1 addition & 1 deletion lumo-example/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# lumo-example

Assuming a local installation of `lumo`, run `serverless package` or `serverless deploy`.
Assuming a local installation of `lumo` (>= `1.8.0`), run `serverless package` or `serverless deploy`.
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 f044d29

Please sign in to comment.