From 0bbb0c9effc5757bd1e422dbab774fe5377f6beb Mon Sep 17 00:00:00 2001 From: Dominic Monroe Date: Mon, 20 May 2019 10:41:05 +0100 Subject: [PATCH] Fix missing include behavior in cljs Fix #57 Related to #54 --- src/aero/core.cljc | 30 ++++++++++++++++++++++-------- test/aero/core_test.cljc | 4 ++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/aero/core.cljc b/src/aero/core.cljc index c843837..7f8894b 100644 --- a/src/aero/core.cljc +++ b/src/aero/core.cljc @@ -6,7 +6,9 @@ #?@(:clj [[clojure.edn :as edn]] :cljs [[cljs.tools.reader.edn :as edn] [cljs.tools.reader :refer [default-data-readers *data-readers*]] - [cljs.tools.reader.reader-types :refer [source-logging-push-back-reader]]]) + [cljs.tools.reader.reader-types + :refer [source-logging-push-back-reader] + :as tools.reader.reader-types]]) #?@(:clj [[clojure.java.io :as io]] :cljs [[goog.string :as gstring] goog.string.format @@ -121,9 +123,13 @@ include))) :cljs (defn adaptive-resolver [source include] - (if (path/isAbsolute include) - include - (path/join source ".." include)))) + (let [fl (if (path/isAbsolute include) + include + (path/join source ".." include))] + (if (fs/existsSync fl) + fl + (source-logging-push-back-reader + (pr-str {:aero/missing-include include})))))) (def default-opts @@ -187,10 +193,18 @@ (throw (ex-info (#?(:clj format :cljs gstring/format) "Config error on line %s" line) {:line line} e)))))) :cljs (read-pr-into-tagged-literal - (source-logging-push-back-reader - (fs/readFileSync source "utf-8") - 1 - source)))) + (cond + (tools.reader.reader-types/source-logging-reader? source) + source + + (implements? tools.reader.reader-types/Reader source) + (source-logging-push-back-reader source) + + :else + (source-logging-push-back-reader + (fs/readFileSync source "utf-8") + 1 + source))))) ;; Queue utilities (defn- queue diff --git a/test/aero/core_test.cljc b/test/aero/core_test.cljc index e87f365..653bcb3 100644 --- a/test/aero/core_test.cljc +++ b/test/aero/core_test.cljc @@ -157,6 +157,10 @@ :valid-file (io/resource "aero/valid.edn")}})) (is (:aero/missing-include (read-config source {:profile :file-does-not-exist})))))) +(deftest missing-include-test + (let [source "test/aero/includes.edn"] + (is (:aero/missing-include (read-config source {:profile :file-does-not-exist}))))) + #?(:clj (deftest dangling-ref-test (is