Skip to content

Commit 0bf9b1b

Browse files
committed
add public read-analysis-cache
1 parent 2f8dd2e commit 0bf9b1b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/clojure/cljs/analyzer/api.cljc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
to the analyzer."
1212
(:refer-clojure :exclude [all-ns ns-interns ns-resolve resolve find-ns
1313
ns-publics remove-ns])
14-
(:require [cljs.env :as env]
15-
[cljs.analyzer :as ana]))
14+
(:require [cljs.analyzer :as ana]
15+
[cljs.env :as env]
16+
[cljs.util :as util]
17+
[clojure.edn :as edn]
18+
[clojure.java.io :as io]))
1619

1720
;; =============================================================================
1821
;; Useful Utilities
@@ -179,6 +182,15 @@
179182
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
180183
(ana/analyze-file f opts))))))
181184

185+
(defn read-analysis-cache
186+
"Read an analysis cache."
187+
[cache-file]
188+
(case (util/ext cache-file)
189+
"edn" (edn/read-string (slurp cache-file))
190+
"json" (let [{:keys [reader read]} @ana/transit]
191+
(with-open [is (io/input-stream cache-file)]
192+
(read (reader is :json ana/transit-read-opts))))))
193+
182194
;; =============================================================================
183195
;; Main API
184196

0 commit comments

Comments
 (0)