From 51561751d80bc9d9cbcb4e00019922aa99b26349 Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Tue, 20 Sep 2022 12:39:46 +0200 Subject: [PATCH] Improve shadow-cljs integration - use node_modules from nested project - filter build-ids to those that exist - merge sets like :cache-blockers --- src/lambdaisland/launchpad.clj | 67 ++++++++++++++++++--------- src/lambdaisland/launchpad/shadow.clj | 10 +++- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/lambdaisland/launchpad.clj b/src/lambdaisland/launchpad.clj index ae03e5b..82154ea 100644 --- a/src/lambdaisland/launchpad.clj +++ b/src/lambdaisland/launchpad.clj @@ -7,6 +7,7 @@ [clojure.edn :as edn] [clojure.java.io :as io] [clojure.java.shell :as shell] + [clojure.pprint :as pprint] [clojure.string :as str] [clojure.tools.cli :as tools-cli] [lambdaisland.dotenv :as dotenv]) @@ -258,8 +259,10 @@ (register-watch-handlers '(lambdaisland.launchpad.env/watch-handlers)))) (defn start-shadow-build [{:keys [deps-edn aliases] :as ctx}] - (let [build-ids (concat (:launchpad/shadow-build-ids deps-edn) - (mapcat #(get-in deps-edn [:aliases % :launchpad/shadow-build-ids]) aliases))] + (let [build-ids (->> aliases + (mapcat #(get-in deps-edn [:aliases % :launchpad/shadow-build-ids])) + (concat (:launchpad/shadow-build-ids deps-edn)) + distinct)] ;; FIXME filter this down to builds that exist in the combined shadow config (when (seq build-ids) (debug "Starting shadow-cljs builds" build-ids)) @@ -269,8 +272,10 @@ (assoc :shadow-cljs/build-ids build-ids) (update :eval-forms (fnil conj []) '(require 'lambdaisland.launchpad.shadow) - `(lambdaisland.launchpad.shadow/start-builds! - ~@build-ids))) + `(apply + lambdaisland.launchpad.shadow/start-builds! + (filter (set (keys (:builds (lambdaisland.launchpad.shadow/merged-config)))) + ~(vec build-ids))))) ctx))) (defn find-launchpad-coords [] @@ -313,25 +318,41 @@ :project-dir ~project-root))))))) ctx) -(def default-steps [find-free-nrepl-port - read-deps-edn - handle-cli-args - compute-middleware - ;; inject dependencies and enable behavior - compute-extra-deps - include-hot-reload-deps - include-launchpad-deps - watch-dotenv - ;; extra java flags - disable-stack-trace-elision - inject-aliases-as-property - ;; start the actual process - include-watcher - run-nrepl-server - start-process - wait-for-nrepl - ;; stuff that happens after the server is up - maybe-connect-emacs]) +(defn print-summary [ctx] + (apply println "Aliases: " (:aliases ctx)) + (apply println "Java flags: " (:java-args ctx)) + (apply println "Middleware: " (:middleware ctx)) + (println "Deps:") + (pprint/pprint (:extra-deps ctx)) + (println "Eval:") + (pprint/pprint (:eval-forms ctx)) + ctx) + +(def before-steps [find-free-nrepl-port + read-deps-edn + handle-cli-args + compute-middleware + ;; inject dependencies and enable behavior + compute-extra-deps + include-hot-reload-deps + include-launchpad-deps + watch-dotenv + start-shadow-build + ;; extra java flags + disable-stack-trace-elision + inject-aliases-as-property + ;; start the actual process + include-watcher + run-nrepl-server + print-summary]) + +(def after-steps [wait-for-nrepl + ;; stuff that happens after the server is up + maybe-connect-emacs]) + +(def default-steps (concat before-steps + [start-process] + after-steps)) (defn find-project-root [] (loop [dir (.getParent (io/file *file*))] diff --git a/src/lambdaisland/launchpad/shadow.clj b/src/lambdaisland/launchpad/shadow.clj index 26272d2..1476a49 100644 --- a/src/lambdaisland/launchpad/shadow.clj +++ b/src/lambdaisland/launchpad/shadow.clj @@ -53,8 +53,12 @@ (-> (apply merge-with (fn [a b] - (if (and (map? a) (map? b)) + (cond + (and (map? a) (map? b)) (merge a b) + (and (set? a) (set? b)) + (into a b) + :else b)) (for [module-path module-paths :let [module-root (.toAbsolutePath (Path/of module-path (into-array String []))) @@ -74,7 +78,9 @@ (keyword module-name (name k)))] [build-id (assoc (update-build-keys process-root module-root v) - :build-id build-id)]))) + :build-id build-id + :js-options {:js-package-dirs [(str module-path "/node_modules")]})]))) + builds)))))) (assoc :deps {}) (dissoc :source-paths :dependencies)))