From c75836fdb04b8e7c4827f95f1354882f465a07fa Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Thu, 2 Feb 2017 15:43:29 +1300 Subject: [PATCH] Add support for lein checkouts - Add checkouts source directories to the classpath - Add checkouts source directories to :source-paths This follows roughly the same pattern as cljsbuild in https://github.com/emezeske/lein-cljsbuild/pull/374 Fixes #9 --- plugin/src/leiningen/figwheel.clj | 53 +++++++++++++++++++------ plugin/test/leiningen/figwheel_test.clj | 10 +++++ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/plugin/src/leiningen/figwheel.clj b/plugin/src/leiningen/figwheel.clj index b9d39b89..c2fc371c 100644 --- a/plugin/src/leiningen/figwheel.clj +++ b/plugin/src/leiningen/figwheel.clj @@ -3,12 +3,15 @@ (:require #_[clojure.pprint :as pp] [leiningen.core.eval :as leval] + [leiningen.core.project :as lproject] [leiningen.clean :as clean] [leiningen.core.main :as main] [clojure.java.io :as io] [clojure.set :refer [intersection]] [leiningen.figwheel.fuzzy :as fuz] - [simple-lein-profile-merge.core :as lm])) + [simple-lein-profile-merge.core :as lm]) + (:import (java.io File) + (java.nio.file Path))) (def _figwheel-version_ "0.5.15-SNAPSHOT") @@ -284,6 +287,17 @@ (when (every? not-empty args) (not-empty (apply intersection (map set args))))) +(defn checkout-source-paths + "Get source paths for all of the lein projects that are in the checkouts directory." + [project] + (let [checkout-projects (lproject/read-checkouts project) + checkout-sources (for [co-project checkout-projects + build (conj (get-in co-project [:cljsbuild :builds]) co-project) ;; Use the :source-paths of the project too. + source-path (:source-paths build)] + (str (.relativize (.toPath (io/file (:root project))) + (.toPath (io/file source-path)))))] + (distinct checkout-sources))) + (defn source-paths-for-classpath [{:keys [figwheel-options all-builds build-ids] :as data}] (if-not (and all-builds (not-empty all-builds)) [] @@ -396,23 +410,36 @@ (fuzzy-config-from-project project) {:no-start-option true})) +(defn add-checkouts [project] + (let [checkout-paths (checkout-source-paths project)] + (update-in + project + [:cljsbuild :builds] + (fn [builds] + (into {} + (map (fn [[k build]] + [k (update build :source-paths concat checkout-paths)]) + builds)))))) + (defn build-once [project build-ids] (when-not (report-if-bad-build-ids project build-ids) - (run-build-once - project - (fuzzy-config-from-project project) - (source-paths-for-classpath - (normalize-data project build-ids)) - (vec build-ids)))) + (let [project (add-checkouts project)] + (run-build-once + project + (fuzzy-config-from-project project) + (source-paths-for-classpath + (normalize-data project build-ids)) + (vec build-ids))))) (defn figwheel-main [project build-ids] (when-not (report-if-bad-build-ids project build-ids) - (run-figwheel - project - (fuzzy-config-from-project project) - (source-paths-for-classpath - (normalize-data project build-ids)) - (vec build-ids)))) + (let [project (add-checkouts project)] + (run-figwheel + project + (-> project fuzzy-config-from-project) + (source-paths-for-classpath + (normalize-data project build-ids)) + (vec build-ids))))) (defmulti fig-dispatch (fn [command _ _] command)) diff --git a/plugin/test/leiningen/figwheel_test.clj b/plugin/test/leiningen/figwheel_test.clj index b8a6f261..14ef50d5 100644 --- a/plugin/test/leiningen/figwheel_test.clj +++ b/plugin/test/leiningen/figwheel_test.clj @@ -136,3 +136,13 @@ + +(deftest add-checkouts-test + (is (= ["src" "../../src" "checkouts/abc/src"] + (get-in + (f/add-checkouts + {:client {:source-paths ["src" "../../src"], :compiler {:output-dir "resources/public/js", :output-to "resources/public/js/client.js", :asset-path "js", :optimizations :none, :source-map true, :source-map-timestamp true, :main "todomvc.core", :closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}, :preloads ['day8.re-frame.trace.preload]}, :figwheel {:on-jsload "todomvc.core/main"}} + :dev {:source-paths ["src" "../../src"], :compiler {:output-dir "resources/public/js1", :output-to "resources/public/js1/client.js"}}} + ["checkouts/abc/src"]) + [:client :source-paths]) + )))