Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
fixup! Update compiler with latest upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arichiardi committed Apr 26, 2018
1 parent bb1245b commit c408d4c
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions src/cljs/bundled/lumo/closure.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@
(defn maybe-install-node-deps!
[{:keys [npm-deps verbose] :as opts}]
(let [npm-deps (merge npm-deps (compute-upstream-npm-deps opts))]
(if-not (empty? npm-deps)
(when-not (empty? npm-deps)
(let [pkg-json "package.json"]
(when (or ana/*verbose* verbose)
(util/debug-prn "Installing Node.js dependencies"))
Expand All @@ -1841,10 +1841,9 @@
(string/join " ")
child_process/execSync)
(catch js/Error _))]
(when-not (nil? proc)
(util/debug-prn (.toString proc "utf8")))
opts))
opts)))
(when (nil? proc)
(util/debug-prn (.toString proc "utf8")))))
true)))

(defn node-module-deps
"EXPERIMENTAL: return the foreign libs entries as computed by running
Expand All @@ -1859,10 +1858,12 @@
(let [main-entries (str "[" (->> (package-json-entries opts)
(map #(str "\"" % "\""))
(string/join ",")) "]")
escape-backslashes #(string/replace % "\\" "\\\\")
code (-> (slurp (io/resource "cljs/module_deps.js"))
(string/replace "JS_FILE" (string/replace file "\\" "\\\\"))
(string/replace "CLJS_TARGET" (str "" (when target (name target))))
(string/replace "MAIN_ENTRIES" main-entries))
(string/replace "MAIN_ENTRIES" main-entries)
(string/replace "FILE_SEPARATOR" (escape-backslashes path/sep)))
proc (child_process/spawnSync "node" #js ["--eval" code])]
(if (zero? (.-status proc))
(into []
Expand Down Expand Up @@ -1982,6 +1983,8 @@
(when env/*compiler*
(:options @env/*compiler*))))
([opts]
(when (or ana/*verbose* (:verbose opts))
(util/debug-prn "Indexing node modules"))
(let [module-fseq (util/module-file-seq)]
(node-file-seq->libs-spec module-fseq))))

Expand Down Expand Up @@ -2168,28 +2171,52 @@
- process the JS modules (preprocess + convert to Closure JS)
- save js-dependency-index for compilation"
[{:keys [npm-deps target] :as opts} js-sources compiler-env]
(let [requires (set (mapcat deps/-requires js-sources))
(let [top-level (reduce
(fn [acc m]
(reduce (fn [acc p] (assoc acc p m)) acc (:provides m)))
{}
;; if :npm-deps option is false, node_modules/ dir shouldn't be indexed
(if (not (false? npm-deps))
(index-node-modules-dir)))
requires (set (mapcat deps/-requires js-sources))
;; Select Node files that are required by Cljs code,
;; and create list of all their dependencies
node-required (into []
(filter ana/node-module-dep?)
requires)
expanded-libs (expand-libs (:foreign-libs opts))
opts (-> opts
(update :foreign-libs
(fn [libs]
(into (if (= target :nodejs)
[]
(index-node-modules node-required))
(into expanded-libs
(node-inputs (filter (fn [{:keys [module-type]}]
(and (some? module-type)
(not= module-type :amd)))
expanded-libs))))))
process-js-modules)]
;; we need to also track the whole top level - this is to support
;; cljs.analyze/analyze-deps, particularly in REPL contexts - David
(swap! compiler-env assoc :js-dependency-index (deps/js-dependency-index opts))
output-dir (util/output-directory opts)
opts (update opts :foreign-libs
(fn [libs]
(into (if (= target :nodejs)
[]
(index-node-modules node-required))
(into expanded-libs
(node-inputs (filter (fn [{:keys [module-type]}]
(some? module-type))
expanded-libs))))))
;; If compiler-env doesn't contain JS module info we need to process
;; modules even if files haven't changed since last compile.
opts (if (or (nil? (:js-namespaces @compiler-env))
(nil? (:js-module-index @compiler-env))
(some
(fn [ijs]
(let [dest (path/join output-dir (rel-output-path (assoc ijs :foreign true) opts))]
(util/changed? (deps/-url ijs opts) dest)))
(: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 [:options] merge opts)
(update-in [:node-module-index] (fnil into #{})
(if (= target :nodejs)
(map str node-required)
(map str (keys top-level)))))))
opts))

(defn build
Expand All @@ -2208,6 +2235,10 @@
;; we want to warn about NPM dep conflicts before installing the modules
(when (:install-deps opts)
(check-npm-deps opts)
(swap! compiler-env update-in [:npm-deps-installed?]
(fn [installed?]
(when-not installed?
(maybe-install-node-deps! opts)))))
(maybe-install-node-deps! opts))
(let [runtime-loaded @cljs/*loaded*
compiler-stats (:compiler-stats opts)
Expand Down

0 comments on commit c408d4c

Please sign in to comment.