From 616966ca9e94229af128eaf1ff4b54bcb9745c72 Mon Sep 17 00:00:00 2001 From: David Nolen Date: Fri, 16 Mar 2018 10:30:51 +0000 Subject: [PATCH] CLJS-2659: Unable to require namespaces that require node modules in node cljs repl Fixes the non-Node.js case. handle-js-modules *must* update compiler `:options`. If this isn't done, the future compilation runs will return different results. --- src/main/clojure/cljs/closure.clj | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/clojure/cljs/closure.clj b/src/main/clojure/cljs/closure.clj index 9683b14499..18b3190c5d 100644 --- a/src/main/clojure/cljs/closure.clj +++ b/src/main/clojure/cljs/closure.clj @@ -2636,15 +2636,17 @@ (:foreign-libs opts))) (process-js-modules opts) (:options @compiler-env))] - (swap! compiler-env (fn [cenv] - (-> cenv - ;; we need to also track the whole top level - this is to support - ;; cljs.analyze/analyze-deps, particularly in REPL contexts - David - (merge {:js-dependency-index (deps/js-dependency-index opts)}) - (update-in [:node-module-index] (fnil into #{}) - (if (= target :nodejs) - (map str node-required) - (map str (keys top-level))))))) + (swap! compiler-env + (fn [cenv] + (-> cenv + ;; we need to also track the whole top level - this is to support + ;; cljs.analyze/analyze-deps, particularly in REPL contexts - David + (merge {:js-dependency-index (deps/js-dependency-index opts)}) + (update-in [:options] merge opts) + (update-in [:node-module-index] (fnil into #{}) + (if (= target :nodejs) + (map str node-required) + (map str (keys top-level))))))) opts)) (defn output-bootstrap [{:keys [target] :as opts}] @@ -2667,8 +2669,6 @@ (#(map add-core-macros-if-cljs-js %)) (add-js-sources opts) deps/dependency-order (->> (map #(source-on-disk opts %)) doall))] - ;; this is an optimization for handle-js-modules - (swap! env/*compiler* update-in [:options] merge opts) sources))) (defn compile-ns @@ -2768,7 +2768,6 @@ (-> (-find-sources source opts) (add-dependency-sources compile-opts))) opts (handle-js-modules opts js-sources compiler-env) - _ (swap! env/*compiler* update-in [:options] merge opts) js-sources (-> js-sources deps/dependency-order (compile-sources compiler-stats compile-opts)