cljs.repl.rhino/goog-require
function | removed v0.0-2985 | added v0.0-927 | Edit |
(goog-require repl-env opts rule)
(defn goog-require [repl-env opts rule]
(let [path (string/replace (comp/munge rule) \. File/separatorChar)
output-dir (util/output-directory opts)
cljsc-path (str output-dir File/separator (str path ".js"))
cljs-path (str path ".cljs")
gpath (-eval (str "goog.dependencies_.nameToPath['" rule "']")
repl-env "" 1)
js-path (str "goog/" gpath)
js-out-path (io/file output-dir "goog"
(string/replace gpath \/ File/separatorChar))]
(let [compiled (io/file cljsc-path)]
(if (.exists compiled)
(do
(with-open [reader (io/reader compiled)]
(-eval reader repl-env cljsc-path 1)))
(if-let [res (io/resource cljs-path)]
(binding [ana/*cljs-ns* 'cljs.user]
(repl/load-stream repl-env cljs-path res))
(if-let [res (io/resource js-path)]
(with-open [reader (io/reader res)]
(-eval reader repl-env js-path 1))
(if (.exists js-out-path)
(with-open [reader (io/reader js-out-path)]
(-eval reader repl-env js-path 1))
(throw
(Exception.
(str "Cannot find "
cljs-path " or "
js-path " or "
(.getName js-out-path) " in classpath"))))))))))