Skip to content

Commit 52b4bb7

Browse files
committed
fix cljs.util/debug-prn so it works like println. update compiler
activity logging. when :watch supplied to cljs.repl/repl bind *err* to the log writer as well. sleep 50ms before starting the REPL look to allow futures to flush. don't start printing until we enter the REPL loop block
1 parent e752b94 commit 52b4bb7

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ argument, which the reader will use in any emitted errors."
20572057
*cljs-file* path
20582058
reader/*alias-map* (or reader/*alias-map* {})]
20592059
(when (or *verbose* (:verbose opts))
2060-
(util/debug-prn "Analyzing " res))
2060+
(util/debug-prn "Analyzing" (str res)))
20612061
(let [env (assoc (empty-env) :build-options opts)
20622062
ns (loop [ns nil forms (seq (forms-seq res))]
20632063
(if forms
@@ -2079,7 +2079,7 @@ argument, which the reader will use in any emitted errors."
20792079
:analyze-deps true
20802080
:load-macros true}))]
20812081
(when (or *verbose* (:verbose opts))
2082-
(util/debug-prn "Reading analysis cache for " res))
2082+
(util/debug-prn "Reading analysis cache for" (str res)))
20832083
(swap! env/*compiler*
20842084
(fn [cenv]
20852085
(let [cached-ns (edn/read-string (slurp cache))]

src/clj/cljs/compiler.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,15 +978,15 @@
978978
(with-core-cljs opts
979979
(fn []
980980
(when (or ana/*verbose* (:verbose opts))
981-
(util/debug-prn "Compiling " src))
981+
(util/debug-prn "Compiling" (str src)))
982982
(if-let [cached (and (= (:optimizations opts) :none)
983983
(= (:ns (ana/parse-ns src)) 'cljs.core)
984984
(io/resource "cljs/core.aot.js"))]
985985
;; no need to bother with analysis cache reading, handled by
986986
;; with-core-cljs
987987
(do
988988
(when (or ana/*verbose* (:verbose opts))
989-
(util/debug-prn "Using cached cljs.core " src))
989+
(util/debug-prn "Using cached cljs.core" (str src)))
990990
(spit dest (slurp cached))
991991
(when (true? (:source-map opts))
992992
(spit (io/file (str dest ".map"))

src/clj/cljs/repl.clj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@
654654
print-no-newline print
655655
source-map-inline true}
656656
:as opts}]
657-
(print "To quit, type:" :cljs/quit)
658657
(let [{:keys [analyze-path repl-verbose warn-on-undeclared special-fns static-fns] :as opts
659658
:or {warn-on-undeclared true}}
660659
(merge
@@ -733,18 +732,24 @@
733732
(future
734733
(let [log-file (io/file (util/output-directory opts) "watch.log")]
735734
(print "Watch compilation log available at:" (str log-file))
735+
(flush)
736736
(try
737-
(binding [*out* (FileWriter. log-file)]
738-
(cljsc/watch src (dissoc opts :watch)))
737+
(let [log-out (FileWriter. log-file)]
738+
(binding [*err* log-out
739+
*out* log-out]
740+
(cljsc/watch src (dissoc opts :watch))))
739741
(catch Throwable e
740742
(caught e repl-env opts))))))
743+
;; let any setup async messages flush
744+
(Thread/sleep 50)
741745
(binding [*in* (if (true? (:source-map-inline opts))
742746
*in*
743747
(reader))]
744748
(try
745749
(init)
746750
(catch Throwable e
747751
(caught e repl-env opts)))
752+
(print "To quit, type:" :cljs/quit)
748753
(prompt)
749754
(flush)
750755
(loop []

src/clj/cljs/util.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@
128128

129129
(defn debug-prn
130130
[& args]
131-
(.println System/err (apply str args)))
131+
(binding [*out* *err*]
132+
(apply println args)))
132133

133134
(defmacro measure
134135
"Like cljs.core/time but toggleable and takes a message string."
@@ -138,6 +139,6 @@
138139
`(if ~enable
139140
(let [start# (. System (nanoTime))
140141
ret# ~expr]
141-
(debug-prn (str ~msg ", elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))
142+
(debug-prn ~msg ", elapsed time:" (/ (double (- (. System (nanoTime)) start#)) 1000000.0) "msecs")
142143
ret#)
143144
~expr)))

0 commit comments

Comments
 (0)