             [cljs.repl :as repl]
             [cljs.compiler :as comp]
             [cljs.closure :as closure])
-  (:import [javax.script ScriptEngine ScriptEngineManager ScriptException]
+  (:import [javax.script ScriptEngine ScriptEngineManager ScriptException ScriptEngineFactory]
            [jdk.nashorn.api.scripting NashornException]))
 
 ;; Nashorn Clojurescript repl binding.


;; Implementation

(defn create-engine []
  (if-let [engine (.getEngineByName (ScriptEngineManager.) "nashorn")]
    (let [context (.getContext engine)]
      (.setWriter context *out*)
      (.setErrorWriter context *err*)
      engine)
    (throw (IllegalArgumentException.
            "Cannot find the Nashorn script engine, use a JDK version 8 or higher."))))

(defn eval-str [^ScriptEngine engine ^String s]
  (.eval engine s))

   :output-dir  the directory of the compiled files, e.g. \"resources/public/my-app\" (mandatory).
   :output-to   load this file initially into Nashorn, relative to output-dir.
                Use a minimal bootstrapped cljs.core environment if not specified."
  [& {:as opts}]
  (repl-env* opts))
