|
2043 | 2043 | :entries '#{cljs.reader hello.core}}}})
|
2044 | 2044 | )
|
2045 | 2045 |
|
| 2046 | +(defn ^File target-file-for-cljs-ns |
| 2047 | + [ns-sym output-dir] |
| 2048 | + (util/to-target-file |
| 2049 | + (util/output-directory {:output-dir output-dir}) |
| 2050 | + {:ns ns-sym})) |
| 2051 | + |
| 2052 | +(defn mark-cljs-ns-for-recompile! |
| 2053 | + [ns-sym output-dir] |
| 2054 | + (let [s (target-file-for-cljs-ns ns-sym output-dir)] |
| 2055 | + (when (.exists s) |
| 2056 | + (.setLastModified s 5000)))) |
| 2057 | + |
| 2058 | +(defn cljs-dependents-for-macro-namespaces |
| 2059 | + [state namespaces] |
| 2060 | + (map :name |
| 2061 | + (let [namespaces-set (set namespaces)] |
| 2062 | + (filter (fn [x] (not-empty |
| 2063 | + (set/intersection namespaces-set (-> x :require-macros vals set)))) |
| 2064 | + (vals (:cljs.analyzer/namespaces @state)))))) |
| 2065 | + |
2046 | 2066 | (defn watch
|
2047 | 2067 | "Given a source directory, produce runnable JavaScript. Watch the source
|
2048 | 2068 | directory for changes rebuliding when necessary. Takes the same arguments as
|
|
2103 | 2123 | (loop [key nil]
|
2104 | 2124 | (when (and (or (nil? quit) (not @quit))
|
2105 | 2125 | (or (nil? key) (. ^WatchKey key reset)))
|
2106 |
| - (let [key (. srvc (poll 300 TimeUnit/MILLISECONDS))] |
| 2126 | + (let [key (. srvc (poll 300 TimeUnit/MILLISECONDS)) |
| 2127 | + poll-events-seq (when key (seq (.pollEvents key)))] |
2107 | 2128 | (when (and key
|
2108 | 2129 | (some
|
2109 | 2130 | (fn [^WatchEvent e]
|
2110 | 2131 | (let [fstr (.. e context toString)]
|
2111 | 2132 | (and (or (. fstr (endsWith "cljc"))
|
2112 | 2133 | (. fstr (endsWith "cljs"))
|
| 2134 | + (. fstr (endsWith "clj")) |
2113 | 2135 | (. fstr (endsWith "js")))
|
2114 | 2136 | (not (. fstr (startsWith ".#"))))))
|
2115 |
| - (seq (.pollEvents key)))) |
| 2137 | + poll-events-seq)) |
| 2138 | + (when-let [clj-files (seq (keep (fn [^WatchEvent e] |
| 2139 | + (let [ctx (.context e) |
| 2140 | + fstr (.toString ctx)] |
| 2141 | + (when (and (or (. fstr (endsWith "cljc")) |
| 2142 | + (. fstr (endsWith "clj"))) |
| 2143 | + (not (. fstr (startsWith ".#")))) |
| 2144 | + ctx))) |
| 2145 | + poll-events-seq))] |
| 2146 | + (let [^Path dir (.watchable key) |
| 2147 | + file-seq (map #(.toFile (.resolve dir %)) clj-files) |
| 2148 | + nses (map (comp :ns ana/parse-ns) file-seq)] |
| 2149 | + (doseq [ns nses] |
| 2150 | + (require ns :reload)) |
| 2151 | + (doseq [ns (cljs-dependents-for-macro-namespaces compiler-env nses)] |
| 2152 | + (mark-cljs-ns-for-recompile! ns (:output-dir opts))))) |
2116 | 2153 | (println "Change detected, recompiling ...")
|
2117 | 2154 | (flush)
|
2118 | 2155 | (buildf))
|
|
0 commit comments