Skip to content

Commit 501a922

Browse files
author
dnolen
committed
CLJS-1155: REPL :watch support does not play nicely with :cljs/quit
1 parent 6e2c817 commit 501a922

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/clj/cljs/closure.clj

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
[java.net URL]
4848
[java.util.logging Level]
4949
[java.util List Random]
50+
[java.util.concurrent TimeUnit]
5051
[com.google.javascript.jscomp CompilerOptions CompilationLevel
5152
CompilerOptions$LanguageMode SourceMap$Format
5253
SourceMap$DetailLevel ClosureCodingConvention SourceFile
@@ -1486,6 +1487,8 @@ should contain the source for the given namespace name."
14861487
env/*compiler*
14871488
(env/default-compiler-env opts))))
14881489
([source opts compiler-env]
1490+
(watch source opts compiler-env nil))
1491+
([source opts compiler-env quit]
14891492
(let [opts (cond-> opts
14901493
(= (:verbose opts :not-found) :not-found)
14911494
(assoc :verbose true))
@@ -1529,14 +1532,17 @@ should contain the source for the given namespace name."
15291532
(println "Watching path:" source)
15301533
(watch-all path)
15311534
(loop [key nil]
1532-
(when (or (nil? key) (. ^WatchKey key reset))
1533-
(let [key (. service take)]
1534-
(when (some (fn [^WatchEvent e]
1535-
(let [fstr (.. e context toString)]
1536-
(and (or (. fstr (endsWith "cljs"))
1537-
(. fstr (endsWith "js")))
1538-
(not (. fstr (startsWith ".#"))))))
1539-
(seq (.pollEvents key)))
1535+
(when (and (or (nil? quit) (not @quit))
1536+
(or (nil? key) (. ^WatchKey key reset)))
1537+
(let [key (. service (poll 300 TimeUnit/MILLISECONDS))]
1538+
(when (and key
1539+
(some
1540+
(fn [^WatchEvent e]
1541+
(let [fstr (.. e context toString)]
1542+
(and (or (. fstr (endsWith "cljs"))
1543+
(. fstr (endsWith "js")))
1544+
(not (. fstr (startsWith ".#"))))))
1545+
(seq (.pollEvents key))))
15401546
(println "Change detected, recompiling ...")
15411547
(flush)
15421548
(buildf))

src/clj/cljs/repl.clj

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@
691691
:caught caught
692692
:reader reader
693693
:print-no-newline print-no-newline
694-
:source-map-inline source-map-inline})))]
694+
:source-map-inline source-map-inline})))
695+
done? (atom false)]
695696
(env/with-compiler-env (or compiler-env (env/default-compiler-env opts))
696697
(binding [*err* (if bind-err *out* *err*)
697698
ana/*cljs-ns* 'cljs.user
@@ -755,17 +756,21 @@
755756
(catch Throwable e
756757
(caught e repl-env opts)))
757758
(when-let [src (:watch opts)]
758-
(future
759-
(let [log-file (io/file (util/output-directory opts) "watch.log")]
760-
(err-out (print "Watch compilation log available at:" (str log-file)))
761-
(flush)
762-
(try
763-
(let [log-out (FileWriter. log-file)]
764-
(binding [*err* log-out
765-
*out* log-out]
766-
(cljsc/watch src (dissoc opts :watch))))
767-
(catch Throwable e
768-
(caught e repl-env opts))))))
759+
(.start
760+
(Thread.
761+
((ns-resolve 'clojure.core 'binding-conveyor-fn)
762+
(fn []
763+
(let [log-file (io/file (util/output-directory opts) "watch.log")]
764+
(err-out (print "Watch compilation log available at:" (str log-file)))
765+
(flush)
766+
(try
767+
(let [log-out (FileWriter. log-file)]
768+
(binding [*err* log-out
769+
*out* log-out]
770+
(cljsc/watch src (dissoc opts :watch)
771+
env/*compiler* done?)))
772+
(catch Throwable e
773+
(caught e repl-env opts)))))))))
769774
;; let any setup async messages flush
770775
(Thread/sleep 50)
771776
(binding [*in* (if (true? (:source-map-inline opts))
@@ -785,7 +790,8 @@
785790
(prompt)
786791
(flush))
787792
(recur))))))))
788-
(-tear-down repl-env)))))
793+
(reset! done? true)
794+
(-tear-down repl-env)))))
789795

790796
(defn repl
791797
"Generic, reusable, read-eval-print loop. By default, reads from *in* using

0 commit comments

Comments
 (0)