From ec18af7bd3af3f329f54d4868325b9b3b8780c31 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Tue, 12 Sep 2017 16:08:35 -0700 Subject: [PATCH] Handle exit by promisifying lumo compilation 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. --- .../serverless_lumo/build.cljs | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/serverless-cljs-plugin/serverless_lumo/build.cljs b/serverless-cljs-plugin/serverless_lumo/build.cljs index 5cb6b94..cb9e187 100644 --- a/serverless-cljs-plugin/serverless_lumo/build.cljs +++ b/serverless-cljs-plugin/serverless_lumo/build.cljs @@ -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])) @@ -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." @@ -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 @@ -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)