Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix dependency-order to work with JavaScript strings

This allows running dependency-order once on all sources even when
some of the sources are JavaScript strings.
  • Loading branch information...
commit 7472ab9013ad5d2b3468daabe20ba3479546f287 1 parent 69e8f4f
Brenton Ashworth authored March 31, 2012

Showing 1 changed file with 25 additions and 12 deletions. Show diff stats Hide diff stats

  1. 37  src/clj/cljs/closure.clj
37  src/clj/cljs/closure.clj
@@ -292,11 +292,24 @@
292 292
             state (reduce dependency-order-visit state deps)]
293 293
         (assoc state :order (conj (:order state) file))))))
294 294
 
  295
+(defn- pack-string [s]
  296
+  (if (string? s)
  297
+    {:provides (-provides s)
  298
+     :requires (-requires s)
  299
+     :file (str "from_source_" (gensym) ".clj")
  300
+     ::original s}
  301
+    s))
  302
+
  303
+(defn- unpack-string [m]
  304
+  (or (::original m) m))
  305
+
295 306
 (defn dependency-order
296 307
   "Topologically sort a collection of dependencies."
297 308
   [coll]
298  
-  (let [state (build-index coll)]
299  
-    (distinct (:order (reduce dependency-order-visit (assoc state :order []) (keys state))))))
  309
+  (let [state (build-index (map pack-string coll))]
  310
+    (map unpack-string
  311
+         (distinct
  312
+          (:order (reduce dependency-order-visit (assoc state :order []) (keys state)))))))
300 313
 
301 314
 ;; Compile
302 315
 ;; =======
@@ -591,13 +604,15 @@
591 604
   (let [requires (mapcat -requires inputs)
592 605
         required-cljs (remove (set inputs) (cljs-dependencies opts requires))
593 606
         required-js (js-dependencies opts (set (concat (mapcat -requires required-cljs) requires)))]
594  
-    (concat (map #(-> (javascript-file (:foreign %)
595  
-                                       (or (:url %) (io/resource (:file %)))
596  
-                                       (:provides %)
597  
-                                       (:requires %))
598  
-                      (assoc :group (:group %))) required-js)
599  
-            required-cljs
600  
-            inputs)))
  607
+    (cons (javascript-file nil (io/resource "goog/base.js") ["goog"] nil)
  608
+          (dependency-order
  609
+           (concat (map #(-> (javascript-file (:foreign %)
  610
+                                              (or (:url %) (io/resource (:file %)))
  611
+                                              (:provides %)
  612
+                                              (:requires %))
  613
+                             (assoc :group (:group %))) required-js)
  614
+                   required-cljs
  615
+                   inputs)))))
601 616
 
602 617
 (comment
603 618
   ;; add dependencies to literal js
@@ -861,9 +876,7 @@
861 876
                      [(-compile (io/resource "cljs/nodejscli.cljs") all-opts)]))
862 877
         js-sources (if (coll? compiled)
863 878
                      (apply add-dependencies all-opts compiled)
864  
-                     (add-dependencies all-opts compiled))
865  
-        js-sources (cons (javascript-file nil (io/resource "goog/base.js") ["goog"] nil)
866  
-                         (dependency-order js-sources))]
  879
+                     (add-dependencies all-opts compiled))]
867 880
     (if (:optimizations all-opts)
868 881
       (->> js-sources
869 882
            (apply optimize all-opts)

0 notes on commit 7472ab9

Please sign in to comment.
Something went wrong with that request. Please try again.