Skip to content

Commit 9eae9ca

Browse files
author
dnolen
committed
CLJS-2595: cljs.main: Mixture of out and directory specified by -d
Change browser REPL so "easy" mode is not hardcoded to out.
1 parent 1d98bdb commit 9eae9ca

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ is trying load some arbitrary ns."
240240
"Start a repl with args and inits. Print greeting if no eval options were
241241
present"
242242
[repl-env [_ & args] {:keys [repl-env-options options inits] :as cfg}]
243-
(let [renv (apply repl-env (mapcat identity repl-env-options))]
243+
(let [reopts (merge repl-env-options
244+
(select-keys options [:output-to :output-dir]))
245+
_ (when (or ana/*verbose* (:verbose options))
246+
(util/debug-prn "REPL env options:" (pr-str reopts)))
247+
renv (apply repl-env (mapcat identity reopts))]
244248
(repl/repl* renv
245249
(assoc (dissoc-entry-point-opts options)
246250
:inits
@@ -251,20 +255,25 @@ present"
251255
inits)))))
252256

253257
(defn default-main
254-
[repl-env {:keys [main script args options inits] :as cfg}]
258+
[repl-env {:keys [main script args repl-env-options options inits] :as cfg}]
255259
(env/ensure
256-
(let [renv (repl-env)
260+
(let [reopts (merge repl-env-options
261+
(select-keys options [:output-to :output-dir]))
262+
_ (when (or ana/*verbose* (:verbose options))
263+
(util/debug-prn "REPL env options:" (pr-str reopts)))
264+
renv (apply repl-env (mapcat identity reopts))
257265
coptsf (when-let [od (:output-dir options)]
258266
(io/file od "cljsc_opts.edn"))
259267
copts (when (and coptsf (.exists coptsf))
260268
(-> (edn/read-string (slurp coptsf))
261269
(dissoc-entry-point-opts)))
262-
opts (merge copts (build/add-implicit-options
263-
(merge (repl/repl-options renv) options)))]
270+
opts (merge copts
271+
(build/add-implicit-options
272+
(merge (repl/repl-options renv) options)))]
264273
(binding [ana/*cljs-ns* 'cljs.user
265274
repl/*repl-opts* opts
266275
ana/*verbose* (:verbose opts)
267-
repl/*repl-env* renv]
276+
repl/*repl-env* renv]
268277
(when ana/*verbose*
269278
(util/debug-prn "Compiler options:" (pr-str repl/*repl-opts*)))
270279
(comp/with-core-cljs repl/*repl-opts*

src/main/clojure/cljs/repl/browser.clj

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@
132132
"<script src=\"" output-to "\"></script>"
133133
"</body></html>"))
134134

135-
(defn send-static [{path :path :as request} conn {:keys [static-dir host port gzip?] :as opts}]
135+
(defn send-static
136+
[{path :path :as request} conn
137+
{:keys [static-dir output-to output-dir host port gzip?] :or {output-dir "out"} :as opts}]
136138
(if (and static-dir (not= "/favicon.ico" path))
137139
(let [path (if (= "/" path) "/index.html" path)
138140
local-path
@@ -151,8 +153,7 @@
151153
(#{"/cljs-logo-icon-32.png" "/cljs-logo.svg"} path)
152154
(io/resource (subs path 1))
153155
:else nil)
154-
local-path)
155-
copts (when env/*compiler* (get @env/*compiler* :options))]
156+
local-path)]
156157
(cond
157158
local-path
158159
(if-let [ext (some #(if (.endsWith path %) %) (keys ext->mime-type))]
@@ -163,21 +164,21 @@
163164
(server/send-and-close conn 200 (slurp local-path) "text/plain"))
164165
;; "/index.html" doesn't exist, provide our own
165166
(= path "/index.html")
166-
(let [{:keys [output-to] :or {output-to "out/main.js"}} copts]
167-
(server/send-and-close conn 200 (default-index output-to) "text/html" "UTF-8"))
168-
(= path "/out/main.js")
167+
(server/send-and-close conn 200
168+
(default-index (or output-to (str output-dir "/main.js"))) "text/html" "UTF-8")
169+
(= path (str "/" output-dir "/main.js") )
169170
(let [closure-defines (-> `{clojure.browser.repl/HOST ~host
170171
clojure.browser.repl/PORT ~port}
171172
cljsc/normalize-closure-defines
172173
json/write-str)]
173174
(server/send-and-close conn 200
174175
(str "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n"
175176
"var CLOSURE_NO_DEPS = true;\n"
176-
"document.write('<script src=\"out/goog/base.js\"></script>');\n"
177-
"document.write('<script src=\"out/goog/deps.js\"></script>');\n"
178-
(when (.exists (io/file "out" "cljs_deps.js"))
179-
"document.write('<script src=\"out/cljs_deps.js\"></script>');\n")
180-
"document.write('<script src=\"out/brepl_deps.js\"></script>');\n"
177+
"document.write('<script src=\"" output-dir "/goog/base.js\"></script>');\n"
178+
"document.write('<script src=\"" output-dir "/goog/deps.js\"></script>');\n"
179+
(when (.exists (io/file output-dir "cljs_deps.js"))
180+
"document.write('<script src=\"" output-dir "/cljs_deps.js\"></script>');\n")
181+
"document.write('<script src=\"" output-dir "/brepl_deps.js\"></script>');\n"
181182
"document.write('<script>goog.require(\"clojure.browser.repl.preload\");</script>');\n")
182183
"text/javascript" "UTF-8"))
183184
:else (server/send-404 conn path)))
@@ -300,11 +301,14 @@
300301
;; TODO: this could be cleaner if compiling forms resulted in a
301302
;; :output-to file with the result of compiling those forms - David
302303
(when (and output-dir (not (.exists (io/file output-dir "clojure" "browser" "repl" "preload.js"))))
303-
(spit (io/file "out/brepl_deps.js")
304-
(build/build
305-
'[(require '[clojure.browser.repl.preload])]
306-
{:optimizations :none
307-
:opts-cache "brepl_opts.edn"})))
304+
(let [target (io/file output-dir "brepl_deps.js")]
305+
(util/mkdirs target)
306+
(spit target
307+
(build/build
308+
'[(require '[clojure.browser.repl.preload])]
309+
{:optimizations :none
310+
:output-dir output-dir
311+
:opts-cache "brepl_opts.edn"}))))
308312
(repl/err-out
309313
(println "Serving HTTP on" (:host repl-env) "port" (:port repl-env))
310314
(println "Listening for browser REPL connect ..."))

0 commit comments

Comments
 (0)