(defn build-index
"Index a list of dependencies by namespace and file name. There can
be zero or more namespaces provided per file. Upstream foreign libraies
will have their options merged with local foreign libraries to support
fine-grained overriding."
[deps]
(reduce
(fn [index dep]
(let [provides (:provides dep)
index' (if (seq provides)
(reduce
(fn [index' provide]
(if (:foreign dep)
(update-in index' [provide] lib-spec-merge dep)
;; when building the dependency index, we need to
;; avoid overwriting a CLJS dep with a CLJC dep of
;; the same namespace - António Monteiro
(let [file (when-let [f (or (:source-file dep) (:file dep))]
(str f))
ext (when file
(subs file (inc (string/last-index-of file "."))))]
(update-in index' [provide]
(fn [d]
(if (and (= ext "cljc") (some? d))
d
dep))))))
index provides)
index)]
(if (:foreign dep)
(if-let [file (get-file dep index')]
(update-in index' [file] lib-spec-merge dep)
(throw
(Exception.
(str "No :file provided for :foreign-libs spec " (pr-str dep)))))
(assoc index' (:file dep) dep))))
{} deps))