Skip to content

Commit 6c3276e

Browse files
committed
CLJS-3237: compiling with --target node errors at runtime with document undefined
The problem was uncovered by the change in default-compile to pull in all relevant compiler options from repl-options returned from the repl-env. The issue was that --target node would still use the browser-repl repl-env which sets :browser-repl true. Add a target->repl-env helper that looks at the target and returns the true repl-env in all cases. This also means you can start a node REPL now with `clj -m cljs.main -t node -r` Fixes the later half of the Quick Start
1 parent 6a6e4e3 commit 6c3276e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ is trying load some arbitrary ns."
308308
(not (:repl-verbose options))
309309
(contains? #{"node"} (repl-name repl-env)))))
310310

311+
(defn target->repl-env [target default]
312+
(if (= :nodejs target)
313+
(do
314+
(require 'cljs.repl.node)
315+
(resolve 'cljs.repl.node/repl-env))
316+
default))
317+
311318
(defn- repl-opt
312319
"Start a repl with args and inits. Print greeting if no eval options were
313320
present"
@@ -320,7 +327,7 @@ present"
320327
reopts (merge repl-env-options (select-keys opts [:output-dir]))
321328
_ (when (or ana/*verbose* (:verbose opts))
322329
(util/debug-prn "REPL env options:" (pr-str reopts)))
323-
renv (apply repl-env (mapcat identity reopts))]
330+
renv (apply (target->repl-env (:target options) repl-env) (mapcat identity reopts))]
324331
(repl/repl* renv
325332
(assoc (dissoc-entry-point-opts opts)
326333
::repl/fast-initial-prompt?
@@ -350,7 +357,7 @@ present"
350357
(select-keys opts [:output-to :output-dir]))
351358
_ (when (or ana/*verbose* (:verbose opts))
352359
(util/debug-prn "REPL env options:" (pr-str reopts)))
353-
renv (apply repl-env (mapcat identity reopts))
360+
renv (apply (target->repl-env (:target options) repl-env) (mapcat identity reopts))
354361
coptsf (when-let [od (:output-dir opts)]
355362
(io/file od "cljsc_opts.edn"))
356363
copts (when (and coptsf (.exists coptsf))
@@ -487,7 +494,7 @@ present"
487494
[repl-env {:keys [ns args options post-compile-fn] :as cfg}]
488495
(let [rfs #{"-r" "--repl"}
489496
sfs #{"-s" "--serve"}
490-
env-opts (repl/repl-options (repl-env))
497+
env-opts (repl/repl-options ((target->repl-env (:target options) repl-env)))
491498
repl? (boolean (or (rfs ns) (rfs (first args))))
492499
serve? (boolean (or (sfs ns) (sfs (first args))))
493500
main-ns (get-main-ns cfg)

0 commit comments

Comments
 (0)