Skip to content

Commit 69cd63c

Browse files
author
dnolen
committed
in the REPL case, if :output-dir not supplied create a temporary
directory
1 parent b23c77e commit 69cd63c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[cljs.compiler.api :as comp]
1818
[cljs.build.api :as build]
1919
[cljs.repl :as repl])
20-
(:import [java.io StringReader FileWriter]
20+
(:import [java.io File StringReader FileWriter]
2121
[java.text BreakIterator]
2222
[java.util Locale]))
2323

@@ -236,17 +236,25 @@ is trying load some arbitrary ns."
236236
[opts]
237237
(dissoc opts :main :output-to))
238238

239+
(defn temp-out-dir []
240+
(let [f (File/createTempFile "out" (Long/toString (System/nanoTime)))]
241+
(.delete f)
242+
(util/mkdirs f)
243+
(util/path f)))
244+
239245
(defn- repl-opt
240246
"Start a repl with args and inits. Print greeting if no eval options were
241247
present"
242248
[repl-env [_ & args] {:keys [repl-env-options options inits] :as cfg}]
243-
(let [reopts (merge repl-env-options
244-
(select-keys options [:output-to :output-dir]))
245-
_ (when (or ana/*verbose* (:verbose options))
249+
(let [opts (cond-> options
250+
(not (:output-dir options))
251+
(assoc :output-dir (temp-out-dir)))
252+
reopts (merge repl-env-options (select-keys opts [:output-to :output-dir]))
253+
_ (when (or ana/*verbose* (:verbose opts))
246254
(util/debug-prn "REPL env options:" (pr-str reopts)))
247255
renv (apply repl-env (mapcat identity reopts))]
248256
(repl/repl* renv
249-
(assoc (dissoc-entry-point-opts options)
257+
(assoc (dissoc-entry-point-opts opts)
250258
:inits
251259
(into
252260
[{:type :init-forms

0 commit comments

Comments
 (0)