Skip to content

Commit 195b254

Browse files
author
dnolen
committed
clean up all REPL entry points
1 parent a649fc5 commit 195b254

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

src/clj/cljs/repl/browser.clj

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,12 @@
253253
(cljsc/js-dependencies opts cljs))]
254254
(disj (set (concat cljs goog)) nil)))
255255

256-
(defn repl-env
257-
"Create a browser-connected REPL environment.
258-
259-
Options:
256+
;; NOTE: REPL evaluation environment designers do not replicate the behavior
257+
;; of the browser REPL. The design is outdated, refer to the Node.js, Rhino or
258+
;; Nashorn REPLs.
260259

261-
port: The port on which the REPL server will run. Defaults to 9000.
262-
working-dir: The directory where the compiled REPL client JavaScript will
263-
be stored. Defaults to \".repl\" with a ClojureScript version
264-
suffix, eg. \".repl-0.0-2138\".
265-
serve-static: Should the REPL server attempt to serve static content?
266-
Defaults to true.
267-
static-dir: List of directories to search for static content. Defaults to
268-
[\".\" \"out/\"].
269-
preloaded-libs: List of namespaces that should not be sent from the REPL server
270-
to the browser. This may be required if the browser is already
271-
loading code and reloading it would cause a problem.
272-
optimizations: The level of optimization to use when compiling the client
273-
end of the REPL. Defaults to :simple.
274-
src: The source directory containing user-defined cljs files. Used to
275-
support reflection. Defaults to \"src/\".
276-
"
277-
[& {:as opts}]
278-
(let [ups-deps (cljsc/get-upstream-deps (java.lang.ClassLoader/getSystemClassLoader))
260+
(defn repl-env* [opts]
261+
(let [ups-deps (cljsc/get-upstream-deps)
279262
opts (assoc opts
280263
:ups-libs (:libs ups-deps)
281264
:ups-foreign-libs (:foreign-libs ups-deps))
@@ -284,8 +267,8 @@
284267
{:port 9000
285268
:optimizations :simple
286269
:working-dir (or (:output-dir opts)
287-
(->> [".repl" (util/clojurescript-version)]
288-
(remove empty?) (string/join "-")))
270+
(->> [".repl" (util/clojurescript-version)]
271+
(remove empty?) (string/join "-")))
289272
:serve-static true
290273
:static-dir (cond-> ["." "out/"]
291274
(:output-dir opts) (conj (:output-dir opts)))
@@ -304,12 +287,37 @@
304287
(swap! browser-state
305288
(fn [old]
306289
(assoc old :client-js
307-
(create-client-js-file
308-
opts
309-
(io/file (:working-dir opts) "client.js")))))
290+
(create-client-js-file
291+
opts
292+
(io/file (:working-dir opts) "client.js")))))
310293
(println "Waiting for browser to connect ...")
311294
opts)))
312295

296+
(defn repl-env
297+
"Create a browser-connected REPL environment.
298+
299+
Options:
300+
301+
port: The port on which the REPL server will run. Defaults to 9000.
302+
working-dir: The directory where the compiled REPL client JavaScript will
303+
be stored. Defaults to \".repl\" with a ClojureScript version
304+
suffix, eg. \".repl-0.0-2138\".
305+
serve-static: Should the REPL server attempt to serve static content?
306+
Defaults to true.
307+
static-dir: List of directories to search for static content. Defaults to
308+
[\".\" \"out/\"].
309+
preloaded-libs: List of namespaces that should not be sent from the REPL server
310+
to the browser. This may be required if the browser is already
311+
loading code and reloading it would cause a problem.
312+
optimizations: The level of optimization to use when compiling the client
313+
end of the REPL. Defaults to :simple.
314+
src: The source directory containing user-defined cljs files. Used to
315+
support reflection. Defaults to \"src/\".
316+
"
317+
[& {:as opts}]
318+
(assert (even? (count opts)) "Arguments must be interleaved key value pairs")
319+
(repl-env* opts))
320+
313321
(comment
314322

315323
(require '[cljs.repl :as repl])

src/clj/cljs/repl/nashorn.clj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,7 @@
211211
opts)))
212212

213213
(defn repl-env
214-
"Create a Nashorn repl-env for use with the repl/repl* method in Clojurescript and as the
215-
:repl-env argument to piggieback/cljs-repl. Besides the usual repl options (e.g. :source-map),
216-
opts has the following extra parameters:
217-
218-
:output-dir the directory of the compiled files, e.g. \"resources/public/my-app\" (mandatory).
219-
:output-to load this file initially into Nashorn, relative to output-dir.
220-
Use a minimal bootstrapped cljs.core environment if not specified."
214+
"Create a Nashorn repl-env for use with the repl/repl* method in Clojurescript."
221215
[& {:as opts}]
216+
(assert (even? (count opts)) "Arguments must be interleaved key value pairs")
222217
(repl-env* opts))

src/clj/cljs/repl/node.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@
195195
(NodeEnv. host port (atom nil) (atom nil))))
196196

197197
(defn repl-env
198+
"Construct a Node.js evalution environment. Can supply :host and :port."
198199
[& {:as options}]
200+
(assert (even? (count options)) "Arguments must be interleaved key value pairs")
199201
(repl-env* options))
200202

src/clj/cljs/repl/rhino.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@
198198
(load-javascript this ns url))
199199
(-tear-down [_] (Context/exit)))
200200

201-
(defn repl-env
202-
"Returns a fresh JS environment, suitable for passing to repl.
203-
Hang on to return for use across repl calls."
204-
[]
201+
(defn repl-env*
202+
[opts]
205203
(let [cx (Context/enter)]
206204
;; just avoid the 64K method limit
207205
;; Rhino is slow even with optimizations enabled
@@ -210,6 +208,12 @@
210208
{:cx cx
211209
:scope (.initStandardObjects cx)})))
212210

211+
(defn repl-env
212+
"Returns a fresh JS environment, suitable for passing to repl.
213+
Hang on to return for use across repl calls."
214+
[& {:as opts}]
215+
(repl-env* opts))
216+
213217
(comment
214218

215219
(repl/-parse-stacktrace (repl-env)

0 commit comments

Comments
 (0)