|
32 | 32 | [cljs.tools.reader :as reader] |
33 | 33 | [cljs.tools.reader.reader-types :as readers] |
34 | 34 | [cljs.reader :as edn])) |
35 | | - #?(:clj (:import [java.io File Reader PushbackReader] |
| 35 | + #?(:clj (:import [java.io File Reader PushbackReader FileOutputStream] |
36 | 36 | [java.net URL] |
37 | 37 | [java.lang Throwable] |
38 | 38 | [clojure.lang Namespace Var LazySeq ArityException] |
|
2818 | 2818 | (and version (not= version version')))))))))) |
2819 | 2819 |
|
2820 | 2820 | #?(:clj |
2821 | | - (def transit-writer |
| 2821 | + (def transit |
2822 | 2822 | (delay |
2823 | 2823 | (try |
2824 | 2824 | (require '[cognitect.transit]) |
2825 | | - (some-> |
2826 | | - (find-ns 'cognitect.transit) |
2827 | | - (ns-resolve 'writer) |
2828 | | - deref) |
2829 | | - (catch Throwable t |
2830 | | - nil))))) |
2831 | | - |
2832 | | -#?(:clj |
2833 | | - (def transit-reader |
2834 | | - (delay |
2835 | | - (try |
2836 | | - (require '[cognitect.transit]) |
2837 | | - (some-> |
2838 | | - (find-ns 'cognitect.transit) |
2839 | | - (ns-resolve 'reader) |
2840 | | - deref) |
| 2825 | + (let [ns (find-ns 'cognitect.transit)] |
| 2826 | + (when ns |
| 2827 | + {:writer @(ns-resolve ns 'writer) |
| 2828 | + :reader @(ns-resolve ns 'reader) |
| 2829 | + :write @(ns-resolve ns 'write) |
| 2830 | + :read @(ns-resolve ns 'read)})) |
2841 | 2831 | (catch Throwable t |
2842 | 2832 | nil))))) |
2843 | 2833 |
|
2844 | 2834 | #?(:clj |
2845 | 2835 | (defn write-analysis-cache |
2846 | 2836 | ([ns cache-file] |
2847 | 2837 | (write-analysis-cache ns cache-file nil)) |
2848 | | - ([ns cache-file src] |
| 2838 | + ([ns ^File cache-file src] |
2849 | 2839 | (util/mkdirs cache-file) |
2850 | | - (spit cache-file |
2851 | | - (str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n" |
2852 | | - (pr-str |
2853 | | - (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)))) |
| 2840 | + (let [ext (util/ext cache-file) |
| 2841 | + analysis (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)] |
| 2842 | + (case ext |
| 2843 | + "edn" (spit cache-file |
| 2844 | + (str (when |
| 2845 | + (str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n")) |
| 2846 | + (pr-str analysis))) |
| 2847 | + "json" (when-let [{:keys [writer write]} @transit] |
| 2848 | + (write |
| 2849 | + (writer (FileOutputStream. cache-file) :json) |
| 2850 | + analysis)))) |
2854 | 2851 | (when src |
2855 | 2852 | (.setLastModified ^File cache-file (util/last-modified src)))))) |
2856 | 2853 |
|
|
0 commit comments