|
93 | 93 | (assoc ret module-name module'))) |
94 | 94 | {} modules)) |
95 | 95 |
|
| 96 | +(defn normalize-input [input] |
| 97 | + (-> input |
| 98 | + (update :provides #(into [] (map (comp str comp/munge)) %)) |
| 99 | + (update :requires #(into [] (map (comp str comp/munge)) %)))) |
| 100 | + |
96 | 101 | (defn index-inputs |
97 | 102 | "Index compiler inputs by :provides. If an input has multiple entries |
98 | 103 | in :provides will result in multiple entries in the map. The keys will be munged |
|
105 | 110 | (fn [provide] |
106 | 111 | (vector |
107 | 112 | (-> provide comp/munge str) |
108 | | - (-> input |
109 | | - (update :provides #(into [] (map (comp str comp/munge)) %)) |
110 | | - (update :requires #(into [] (map (comp str comp/munge)) %)))))) |
| 113 | + (-> input normalize-input)))) |
111 | 114 | provides)) |
112 | 115 | {} inputs)) |
113 | 116 |
|
114 | | -(defn ^:dynamic validate-inputs* |
115 | | - [indexed path seen] |
| 117 | +(defn validate-inputs* |
| 118 | + [indexed path seen validated] |
116 | 119 | (let [ns (peek path) |
117 | 120 | {:keys [requires]} (get indexed ns)] |
118 | 121 | (doseq [ns' requires] |
|
122 | 125 | (str "Circular dependency detected " |
123 | 126 | (apply str (interpose " -> " (conj path ns')))) |
124 | 127 | {:cljs.closure/error :invalid-inputs})) |
125 | | - (validate-inputs* indexed (conj path ns') (conj seen ns')))))) |
| 128 | + (when-not (contains? @validated ns) |
| 129 | + (validate-inputs* indexed (conj path ns') (conj seen ns') validated)))) |
| 130 | + (swap! validated conj ns))) |
126 | 131 |
|
127 | 132 | (defn validate-inputs |
128 | 133 | "Throws on the presence of circular dependencies" |
129 | 134 | ([inputs] |
130 | 135 | (validate-inputs inputs [] #{})) |
131 | 136 | ([inputs path seen] |
132 | | - (let [indexed (index-inputs inputs)] |
133 | | - (binding [validate-inputs* (memoize validate-inputs*)] |
134 | | - (doseq [[ns] (seq indexed)] |
135 | | - (validate-inputs* indexed (conj path ns) (conj seen ns))))))) |
| 137 | + (let [indexed (index-inputs inputs) |
| 138 | + validated (atom #{})] |
| 139 | + (binding [] |
| 140 | + (doseq [{:keys [provides]} (map normalize-input inputs)] |
| 141 | + (let [ns (first provides)] |
| 142 | + (validate-inputs* indexed (conj path ns) (conj seen ns) validated) |
| 143 | + (swap! validated conj ns))))))) |
136 | 144 |
|
137 | 145 | (defn ^:dynamic deps-for |
138 | 146 | "Return all dependencies for x in a graph using deps-key." |
|
0 commit comments