cljs.repl.rhino/goog-require

functionremoved v0.0-2985added v0.0-927Edit
(goog-require repl-env opts rule)

Source code @ clojurescript:src/clj/cljs/repl/rhino.clj
(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)
        ;; TODO: only take this path if analysis cache is available
        ;; - David
        (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"))))))))))