(defn find-classpath-lib
"Given [lib], a string or symbol naming a goog-style JavaScript library
(i.e. one that uses goog.provide and goog.require), look for a resource on the
classpath corresponding to [lib] and return a map via `library-graph-node`
that contains its relevant metadata. The library found on the classpath
_must_ contain a `goog.provide` that matches [lib], or this fn will return nil
and print a warning."
[lib]
(when-let [lib-resource (some-> (name lib)
(.replace \. \/)
(.replace \- \_)
(str ".js")
io/resource)]
(let [{:keys [provides] :as lib-info} (library-graph-node lib-resource)]
(if (some #{(name lib)} provides)
(assoc lib-info :closure-lib true)
(binding [*out* *err*]
(println
(format
(str "WARNING: JavaScript file found on classpath for library `%s`, "
"but does not contain a corresponding `goog.provide` declaration: %s")
lib lib-resource)))))))