Skip to content

Commit

Permalink
Fix missing include behavior in cljs
Browse files Browse the repository at this point in the history
Fix #57

Related to #54
  • Loading branch information
SevereOverfl0w committed Jun 2, 2019
1 parent 405ac47 commit bf1de01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/aero/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/aero/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf1de01

Please sign in to comment.