                   Defaults to true.
   static-dir:     List of directories to search for static content. Defaults to
                   [\".\" \"out/\"].
-  preloaded-libs: List of namespaces that should not be sent from the REPL server
-                  to the browser. This may be required if the browser is already
-                  loading code and reloading it would cause a problem.
   optimizations:  The level of optimization to use when compiling the client
                   end of the REPL. Defaults to :simple.
   src:            The source directory containing user-defined cljs files. Used to

  if any of the namespaces have not already been loaded from the
  ClojureScript REPL."
  [repl-env provides url]
  (let [missing (remove #(contains? @loaded-libs %) provides)]
    (when (seq missing)
      (browser-eval (slurp url))
      (swap! loaded-libs (partial apply conj) missing))))

(defn setup [repl-env opts]
  (server/start repl-env))

;; =============================================================================
;; Stracktrace parsing

;; =============================================================================
;; BrowserEnv

(defn compile-client-js [opts]
  (cljsc/build
    '[(ns clojure.browser.repl.client
        (:require [goog.events :as event]
                  [clojure.browser.repl :as repl]))
      (defn start [url]
        (event/listen js/window
          "load"
          (fn []
            (repl/start-evaluator url))))]
    {:optimizations (:optimizations opts)
     :output-dir (:working-dir opts)}))

(defn create-client-js-file [opts file-path]
  (let [file (io/file file-path)]
    (when (not (.exists file))
      (spit file (compile-client-js opts)))
    file))

(defn setup [{:keys [working-dir] :as repl-env} opts]
  (println "Compiling client js ...")
  (swap! browser-state
    (fn [old]
      (assoc old :client-js
        (create-client-js-file
          repl-env (io/file working-dir "client.js")))))
  (println "Waiting for browser to connect ...")
  opts
  (server/start repl-env))

(defrecord BrowserEnv []
  repl/IJavaScriptEnv
  (-setup [this opts]
