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 15, 2017
1 parent 1dbcf50 commit ec18af7
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 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 @@ -44,13 +44,19 @@
(defn compile!
"Compile ClojureScript using the lumo api."
[inputs compiler-opts]
(js/console.info
"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]
(js/console.info
"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
(fn [result]
(if (:error result)
(reject result)
(resolve result)))))))

(defn read-conf!
"Read and return the configuration map."
Expand Down Expand Up @@ -91,11 +97,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 @@ -131,6 +137,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 1))))

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

0 comments on commit ec18af7

Please sign in to comment.