Skip to content

Commit ecdbdcc

Browse files
committed
refactor handle-js-modules
remove only-required? param, not used in Node.js context we still need to build :node-module-index which is just the entire Node.js top level. This is necessary in REPL contexts where compilation is always incremental. We may for example need to analyze dependencies without compiling them - but in this case we won't know have information about deps from node_modules up front (in a build this would not occur since we process files in dep order). The REPL strategy could probably be refactored to remove these issues but that is out of scope for the coming release.
1 parent 1f5e795 commit ecdbdcc

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,36 +2397,35 @@
23972397
- index all the node node modules
23982398
- process the JS modules (preprocess + convert to Closure JS)
23992399
- save js-dependency-index for compilation"
2400-
([opts js-sources compiler-env]
2401-
(handle-js-modules opts js-sources compiler-env true))
2402-
([{:keys [npm-deps target] :as opts} js-sources compiler-env only-required?]
2403-
(let [;; Find all the top-level Node packages and their files
2404-
top-level (reduce
2405-
(fn [acc m]
2406-
(reduce (fn [acc p] (assoc acc p m)) acc (:provides m)))
2407-
{} (index-node-modules-dir))
2408-
requires (set (mapcat deps/-requires js-sources))
2409-
;; Select Node files that are required by Cljs code,
2410-
;; and create list of all their dependencies
2411-
node-required (if only-required?
2412-
(set/intersection (set (keys top-level)) requires)
2413-
(keys top-level))]
2414-
(if-not (= target :nodejs)
2415-
(let [opts (-> opts
2416-
(update :foreign-libs
2417-
(fn [libs]
2418-
(into (if-not (empty? npm-deps)
2419-
(index-node-modules node-required)
2420-
[])
2421-
(expand-libs libs))))
2422-
process-js-modules)]
2423-
(swap! compiler-env assoc :js-dependency-index
2424-
(deps/js-dependency-index opts))
2425-
opts)
2426-
(do
2427-
(swap! compiler-env update-in [:node-module-index]
2428-
(fnil into #{}) (map str node-required))
2429-
opts)))))
2400+
[{:keys [npm-deps target] :as opts} js-sources compiler-env]
2401+
(let [;; Find all the top-level Node packages and their files
2402+
top-level (reduce
2403+
(fn [acc m]
2404+
(reduce (fn [acc p] (assoc acc p m)) acc (:provides m)))
2405+
{} (index-node-modules-dir))
2406+
requires (set (mapcat deps/-requires js-sources))
2407+
;; Select Node files that are required by Cljs code,
2408+
;; and create list of all their dependencies
2409+
node-required (set/intersection (set (keys top-level)) requires)]
2410+
(if-not (= target :nodejs)
2411+
(let [opts (-> opts
2412+
(update :foreign-libs
2413+
(fn [libs]
2414+
(into (if-not (empty? npm-deps)
2415+
(index-node-modules node-required)
2416+
[])
2417+
(expand-libs libs))))
2418+
process-js-modules)]
2419+
(swap! compiler-env merge
2420+
;; we need to also track the whole top level - this is to support
2421+
;; cljs.analyze/analyze-deps, particularly in REPL contexts - David
2422+
{:js-dependency-index (deps/js-dependency-index opts)
2423+
:node-module-index (into #{} (map str (keys top-level)))})
2424+
opts)
2425+
(do
2426+
(swap! compiler-env update-in [:node-module-index]
2427+
(fnil into #{}) (map str node-required))
2428+
opts))))
24302429

24312430
(defn build
24322431
"Given a source which can be compiled, produce runnable JavaScript."

0 commit comments

Comments
 (0)