|
1754 | 1754 | ([classloader]
|
1755 | 1755 | (let [upstream-deps (map #(read-string (slurp %))
|
1756 | 1756 | (enumeration-seq (. classloader (getResources "deps.cljs"))))]
|
1757 |
| - (apply merge-with concat upstream-deps)))) |
| 1757 | + (apply merge-with |
| 1758 | + (fn [a b] |
| 1759 | + (if (map? a) |
| 1760 | + (merge-with #(into #{%1} #{%2}) a b) |
| 1761 | + (concat a b))) |
| 1762 | + upstream-deps)))) |
1758 | 1763 |
|
1759 | 1764 | (def get-upstream-deps (memoize get-upstream-deps*))
|
1760 | 1765 |
|
|
1879 | 1884 | (format ":cache-analysis format must be :edn or :transit but it is: %s"
|
1880 | 1885 | (pr-str cache-analysis-format))))
|
1881 | 1886 |
|
| 1887 | +(defn check-npm-deps [{:keys [npm-deps]}] |
| 1888 | + (let [{ups-npm-deps :npm-deps} (get-upstream-deps) |
| 1889 | + conflicts (filter (fn [[dep v]] |
| 1890 | + (and (coll? v) (not (contains? npm-deps dep)))) |
| 1891 | + ups-npm-deps)] |
| 1892 | + (binding [*out* *err*] |
| 1893 | + (doseq [[dep versions] conflicts] |
| 1894 | + (println (str "WARNING: NPM dependency " (name dep) |
| 1895 | + " conflicts between versions " |
| 1896 | + (util/conjunction-str versions) |
| 1897 | + ". Specify a version in :npm-deps or the latest will be installed.")))))) |
| 1898 | + |
1882 | 1899 | (defn foreign-source? [js]
|
1883 | 1900 | (and (satisfies? deps/IJavaScript js)
|
1884 | 1901 | (deps/-foreign? js)))
|
|
1917 | 1934 |
|
1918 | 1935 | (declare index-node-modules)
|
1919 | 1936 |
|
| 1937 | +(defn compute-upstream-npm-deps |
| 1938 | + ([] |
| 1939 | + (compute-upstream-npm-deps |
| 1940 | + (when env/*compiler* |
| 1941 | + (:options @env/*compiler*)))) |
| 1942 | + ([{:keys [npm-deps]}] |
| 1943 | + (let [{ups-npm-deps :npm-deps} (get-upstream-deps)] |
| 1944 | + (reduce |
| 1945 | + (fn [m [dep v]] |
| 1946 | + (cond-> m |
| 1947 | + (not (contains? npm-deps dep)) |
| 1948 | + (assoc dep (if (coll? v) |
| 1949 | + (last (sort v)) |
| 1950 | + v)))) |
| 1951 | + {} ups-npm-deps)))) |
| 1952 | + |
1920 | 1953 | (defn add-implicit-options
|
1921 |
| - [{:keys [optimizations output-dir] |
| 1954 | + [{:keys [optimizations output-dir npm-deps] |
1922 | 1955 | :or {optimizations :none
|
1923 | 1956 | output-dir "out"}
|
1924 | 1957 | :as opts}]
|
1925 | 1958 | (let [opts (cond-> (update opts :foreign-libs
|
1926 | 1959 | (fn [libs]
|
1927 | 1960 | (into []
|
1928 | 1961 | (util/distinct-merge-by :file
|
1929 |
| - (index-node-modules opts) |
| 1962 | + (index-node-modules npm-deps opts) |
1930 | 1963 | (expand-libs libs)))))
|
1931 | 1964 | (:closure-defines opts)
|
1932 | 1965 | (assoc :closure-defines
|
|
1946 | 1979 | :optimizations optimizations
|
1947 | 1980 | :output-dir output-dir
|
1948 | 1981 | :ups-libs libs
|
1949 |
| - :ups-foreign-libs foreign-libs |
| 1982 | + :ups-foreign-libs (into [] |
| 1983 | + (util/distinct-merge-by :file |
| 1984 | + (index-node-modules (compute-upstream-npm-deps opts) opts) |
| 1985 | + (expand-libs foreign-libs))) |
1950 | 1986 | :ups-externs externs
|
1951 | 1987 | :emit-constants emit-constants
|
1952 | 1988 | :cache-analysis-format (:cache-analysis-format opts :transit))
|
|
1992 | 2028 |
|
1993 | 2029 | (defn maybe-install-node-deps!
|
1994 | 2030 | [{:keys [npm-deps verbose] :as opts}]
|
1995 |
| - (if-not (empty? npm-deps) |
1996 |
| - (do |
1997 |
| - (when (or ana/*verbose* verbose) |
1998 |
| - (util/debug-prn "Installing Node.js dependencies")) |
1999 |
| - (let [proc (-> (ProcessBuilder. |
2000 |
| - (into ["npm" "install" "module-deps"] |
2001 |
| - (map (fn [[dep version]] (str (name dep) "@" version))) |
2002 |
| - npm-deps)) |
2003 |
| - .start) |
2004 |
| - is (.getInputStream proc) |
2005 |
| - iw (StringWriter. (* 16 1024 1024)) |
2006 |
| - es (.getErrorStream proc) |
2007 |
| - ew (StringWriter. (* 1024 1024)) |
2008 |
| - _ (do (.start |
2009 |
| - (Thread. |
2010 |
| - (bound-fn [] (pipe proc is iw)))) |
2011 |
| - (.start |
2012 |
| - (Thread. |
2013 |
| - (bound-fn [] (pipe proc es ew))))) |
2014 |
| - err (.waitFor proc)] |
2015 |
| - (when (and (not (zero? err)) (not (.isAlive proc))) |
2016 |
| - (println (str ew))) |
2017 |
| - opts)) |
2018 |
| - opts)) |
| 2031 | + (let [npm-deps (merge npm-deps (compute-upstream-npm-deps opts))] |
| 2032 | + (if-not (empty? npm-deps) |
| 2033 | + (do |
| 2034 | + (when (or ana/*verbose* verbose) |
| 2035 | + (util/debug-prn "Installing Node.js dependencies")) |
| 2036 | + (let [proc (-> (ProcessBuilder. |
| 2037 | + (into ["npm" "install" "module-deps"] |
| 2038 | + (map (fn [[dep version]] (str (name dep) "@" version))) |
| 2039 | + npm-deps)) |
| 2040 | + .start) |
| 2041 | + is (.getInputStream proc) |
| 2042 | + iw (StringWriter. (* 16 1024 1024)) |
| 2043 | + es (.getErrorStream proc) |
| 2044 | + ew (StringWriter. (* 1024 1024)) |
| 2045 | + _ (do (.start |
| 2046 | + (Thread. |
| 2047 | + (bound-fn [] (pipe proc is iw)))) |
| 2048 | + (.start |
| 2049 | + (Thread. |
| 2050 | + (bound-fn [] (pipe proc es ew))))) |
| 2051 | + err (.waitFor proc)] |
| 2052 | + (when (and (not (zero? err)) (not (.isAlive proc))) |
| 2053 | + (println (str ew))) |
| 2054 | + opts)) |
| 2055 | + opts))) |
2019 | 2056 |
|
2020 | 2057 | (defn node-module-deps
|
2021 | 2058 | "EXPERIMENTAL: return the foreign libs entries as computed by running
|
|
2069 | 2106 | (into [] (distinct (mapcat #(node-module-deps % opts) entries)))))
|
2070 | 2107 |
|
2071 | 2108 | (defn index-node-modules
|
2072 |
| - ([] |
| 2109 | + ([npm-deps] |
2073 | 2110 | (index-node-modules
|
2074 | 2111 | (when env/*compiler*
|
2075 | 2112 | (:options @env/*compiler*))))
|
2076 |
| - ([{:keys [npm-deps] :as opts}] |
| 2113 | + ([npm-deps opts] |
2077 | 2114 | (let [node-modules (io/file "node_modules")]
|
2078 | 2115 | (when (and (.exists node-modules) (.isDirectory node-modules))
|
2079 | 2116 | (let [modules (map name (keys npm-deps))
|
|
2183 | 2220 | (add-externs-sources opts)))))
|
2184 | 2221 | ([source opts compiler-env]
|
2185 | 2222 | (env/with-compiler-env compiler-env
|
| 2223 | + ;; we want to warn about NPM dep conflicts before installing the modules |
| 2224 | + (check-npm-deps opts) |
2186 | 2225 | (let [compiler-stats (:compiler-stats opts)
|
2187 | 2226 | all-opts (-> opts
|
2188 | 2227 | maybe-install-node-deps!
|
|
0 commit comments