Skip to content

Commit

Permalink
CLJS-3237: compiling with --target node errors at runtime with docume…
Browse files Browse the repository at this point in the history
…nt 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
  • Loading branch information
swannodette committed Apr 26, 2020
1 parent 6a6e4e3 commit 6c3276e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/clojure/cljs/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ is trying load some arbitrary ns."
(not (:repl-verbose options))
(contains? #{"node"} (repl-name repl-env)))))

(defn target->repl-env [target default]
(if (= :nodejs target)
(do
(require 'cljs.repl.node)
(resolve 'cljs.repl.node/repl-env))
default))

(defn- repl-opt
"Start a repl with args and inits. Print greeting if no eval options were
present"
Expand All @@ -320,7 +327,7 @@ present"
reopts (merge repl-env-options (select-keys opts [:output-dir]))
_ (when (or ana/*verbose* (:verbose opts))
(util/debug-prn "REPL env options:" (pr-str reopts)))
renv (apply repl-env (mapcat identity reopts))]
renv (apply (target->repl-env (:target options) repl-env) (mapcat identity reopts))]
(repl/repl* renv
(assoc (dissoc-entry-point-opts opts)
::repl/fast-initial-prompt?
Expand Down Expand Up @@ -350,7 +357,7 @@ present"
(select-keys opts [:output-to :output-dir]))
_ (when (or ana/*verbose* (:verbose opts))
(util/debug-prn "REPL env options:" (pr-str reopts)))
renv (apply repl-env (mapcat identity reopts))
renv (apply (target->repl-env (:target options) repl-env) (mapcat identity reopts))
coptsf (when-let [od (:output-dir opts)]
(io/file od "cljsc_opts.edn"))
copts (when (and coptsf (.exists coptsf))
Expand Down Expand Up @@ -487,7 +494,7 @@ present"
[repl-env {:keys [ns args options post-compile-fn] :as cfg}]
(let [rfs #{"-r" "--repl"}
sfs #{"-s" "--serve"}
env-opts (repl/repl-options (repl-env))
env-opts (repl/repl-options ((target->repl-env (:target options) repl-env)))
repl? (boolean (or (rfs ns) (rfs (first args))))
serve? (boolean (or (sfs ns) (sfs (first args))))
main-ns (get-main-ns cfg)
Expand Down

0 comments on commit 6c3276e

Please sign in to comment.