(defn parse-js-ns
"Given the lines from a JavaScript source file, parse the provide
and require statements and return them in a map. Assumes that all
provide and require statements appear before the first function
definition."
[lines]
(letfn [(conj-in [m k v] (update-in m [k] (fn [old] (conj old v))))]
(->> (for [line lines x (string/split line #";")] x)
(map string/trim)
(take-while #(not (re-matches #".*=[\s]*function\(.*\)[\s]*[{].*" %)))
(map #(re-matches #".*goog\.(provide|require)\(['\"](.*)['\"]\)" %))
(remove nil?)
(map #(drop 1 %))
(reduce (fn [m ns]
(let [munged-ns (string/replace (last ns) "_" "-")]
(if (= (first ns) "require")
(conj-in m :requires munged-ns)
(conj-in m :provides munged-ns))))
{:requires [] :provides []}))))