 (defn add-dep-string
   "Return a goog.addDependency string for an input."
   [opts input]
-  (letfn [(ns-list [coll] (when (seq coll) (apply str (interpose ", " (map #(str "'" % "'") coll)))))]
+  (letfn [(ns-list [coll] (when (seq coll) (apply str (interpose ", " (map #(str "'" (munge %) "'") coll)))))]
     (str "goog.addDependency(\""
          (path-relative-to (io/file (output-directory opts) "goog/base.js") input)
          "\", ["

  order. The returned list will not only include the explicitly
  required files but any transative depedencies as well. JavaScript
  files will be compiled to the working directory if they do not
  already exist."
  [opts requires]
  (let [index (js-dependency-index opts)]
    (letfn [(cljs-deps [coll] (remove #(contains? index %) coll))]
     (loop [requires (cljs-deps requires)
            deps {}]
       (if (seq requires)
         (let [next-ns (first requires)
               js (get-compiled-cljs opts next-ns)
               new-requires (remove #(or (contains? deps %)
                                         (contains? (set requires) %))
                                    (cljs-deps (-requires js)))]
           (recur (into (rest requires) new-requires) (assoc deps next-ns js)))
         (dependency-order (vals deps)))))))

(comment
  ;; only get cljs deps

(def compiled-cljs (atom {}))

(defn get-compiled-cljs
  "If not already compiled, compile the given cljs file. Return
  an IJavaScript for this file. Compiled output will be written to the
  working directory."
  [opts {:keys [relative-path uri]}]
  (let [js-file (comp/rename-to-js relative-path)
        out-file (io/file (output-directory opts) js-file)
        javascript (cond (and (.exists out-file) (get @compiled-cljs relative-path))
                         (get @compiled-cljs relative-path)
                         (.exists out-file) (let [ns-info (parse-js-ns
                                                           (string/split-lines (slurp out-file)))]
                                              (javascript-file (to-url out-file)
                                                               (:provides ns-info)
                                                               (:requires ns-info)))
                         :else (-compile uri (merge opts {:output-file js-file})))]
    (do (swap! compiled-cljs (fn [old] (assoc old relative-path javascript)))
        javascript)))

(defn ns->file-name [s]
  (let [ns (name s)
        path (string/replace (munge ns) \. java.io.File/separatorChar)]
    (str path ".cljs")))

(defn cljs-dependencies
  "Given a list of all required namespaces, return a list of
