|
202 | 202 | :fn-invoke-direct :checked-arrays :closure-module-roots :rewrite-polyfills :use-only-custom-externs
|
203 | 203 | :watch :watch-error-fn :watch-fn :install-deps :process-shim :rename-prefix :rename-prefix-namespace
|
204 | 204 | :closure-variable-map-in :closure-property-map-in :closure-variable-map-out :closure-property-map-out
|
205 |
| - :stable-names :ignore-js-module-exts :opts-cache :aot-cache :elide-strict}) |
| 205 | + :stable-names :ignore-js-module-exts :opts-cache :aot-cache :elide-strict :fingerprint}) |
206 | 206 |
|
207 | 207 | (def string->charset
|
208 | 208 | {"iso-8859-1" StandardCharsets/ISO_8859_1
|
|
1595 | 1595 | (cond-> js
|
1596 | 1596 | (not (false? elide-strict)) (string/replace #"(?m)^['\"]use strict['\"]" " ")))
|
1597 | 1597 |
|
1598 |
| -(defn output-one-file [{:keys [output-to] :as opts} js] |
| 1598 | +(defn ^File fingerprint-out-file |
| 1599 | + [content ^File out-file] |
| 1600 | + (let [dir (.getParent out-file) |
| 1601 | + fn (.getName out-file) |
| 1602 | + idx (.lastIndexOf fn ".") |
| 1603 | + ext (subs fn (inc idx)) |
| 1604 | + name (subs fn 0 idx)] |
| 1605 | + (io/file dir |
| 1606 | + (str name "-" |
| 1607 | + (string/lower-case |
| 1608 | + (util/content-sha content 7)) "." ext)))) |
| 1609 | + |
| 1610 | +(defn output-one-file [{:keys [output-to fingerprint] :as opts} js] |
1599 | 1611 | (let [js (elide-strict js opts)]
|
1600 | 1612 | (cond
|
1601 | 1613 | (nil? output-to) js
|
|
1604 | 1616 | (util/file? output-to))
|
1605 | 1617 | (let [f (io/file output-to)]
|
1606 | 1618 | (util/mkdirs f)
|
1607 |
| - (spit f js)) |
| 1619 | + (spit f js) |
| 1620 | + (when fingerprint |
| 1621 | + (let [dir (.getParent f) |
| 1622 | + mf (io/file dir "manifest.edn") |
| 1623 | + g (fingerprint-out-file js f)] |
| 1624 | + (.renameTo f g) |
| 1625 | + (spit mf (pr-str {(.toString f) (.toString g)}))))) |
1608 | 1626 |
|
1609 | 1627 | :else (println js))))
|
1610 | 1628 |
|
|
1722 | 1740 | (when-let [main (:main opts)]
|
1723 | 1741 | [main])))))))))
|
1724 | 1742 |
|
| 1743 | +(defn fingerprinted-modules [modules fingerprint-info] |
| 1744 | + (into {} |
| 1745 | + (map |
| 1746 | + (fn [[module-name module-info]] |
| 1747 | + (let [module-info' |
| 1748 | + (assoc module-info :output-to |
| 1749 | + (get-in fingerprint-info |
| 1750 | + [module-name :output-to-fingerprint]))] |
| 1751 | + [module-name module-info']))) |
| 1752 | + modules)) |
| 1753 | + |
1725 | 1754 | (defn output-modules
|
1726 | 1755 | "Given compiler options, original IJavaScript sources and a sequence of
|
1727 | 1756 | module name and module description tuples output module sources to disk.
|
1728 | 1757 | Modules description must define :output-to and supply :source entry with
|
1729 | 1758 | the JavaScript source to write to disk."
|
1730 | 1759 | [opts js-sources modules]
|
1731 |
| - (doseq [[name {:keys [output-to source foreign-deps] :as module-desc}] modules] |
1732 |
| - (assert (not (nil? output-to)) |
1733 |
| - (str "Module " name " does not define :output-to")) |
1734 |
| - (assert (not (nil? source)) |
1735 |
| - (str "Module " name " did not supply :source")) |
1736 |
| - (let [fdeps-str (when-not (empty? foreign-deps) |
1737 |
| - (foreign-deps-str opts foreign-deps)) |
1738 |
| - sm-name (when (:source-map opts) |
1739 |
| - (str output-to ".map")) |
1740 |
| - out-file (io/file output-to)] |
1741 |
| - (util/mkdirs out-file) |
1742 |
| - (spit out-file |
1743 |
| - (as-> source source |
1744 |
| - (if (= name :cljs-base) |
1745 |
| - (add-header opts source) |
1746 |
| - source) |
1747 |
| - (if fdeps-str |
1748 |
| - (str fdeps-str "\n" source) |
1749 |
| - source) |
1750 |
| - (elide-strict source opts) |
1751 |
| - (if sm-name |
1752 |
| - (add-source-map-link |
1753 |
| - (assoc opts |
1754 |
| - :output-to output-to |
1755 |
| - :source-map sm-name) |
1756 |
| - source) |
1757 |
| - source))) |
1758 |
| - (when (:source-map opts) |
1759 |
| - (let [sm-json-str (:source-map-json module-desc) |
1760 |
| - sm-json (json/read-str sm-json-str :key-fn keyword)] |
1761 |
| - (when (true? (:closure-source-map opts)) |
1762 |
| - (spit (io/file (:source-map-name module-desc)) sm-json-str)) |
1763 |
| - (emit-optimized-source-map sm-json js-sources sm-name |
1764 |
| - (merge opts |
1765 |
| - {:source-map sm-name |
1766 |
| - :preamble-line-count |
1767 |
| - (if (= name :cljs-base) |
1768 |
| - (+ (- (count (.split #"\r?\n" (make-preamble opts) -1)) 1) |
1769 |
| - (if (:output-wrapper opts) 1 0)) |
1770 |
| - 0) |
1771 |
| - :foreign-deps-line-count |
1772 |
| - (if fdeps-str |
1773 |
| - (- (count (.split #"\r?\n" fdeps-str -1)) 1) |
1774 |
| - 0)}))))))) |
| 1760 | + (let [fingerprint-info (atom {})] |
| 1761 | + (doseq [[name {:keys [output-to source foreign-deps] :as module-desc}] modules] |
| 1762 | + (assert (not (nil? output-to)) |
| 1763 | + (str "Module " name " does not define :output-to")) |
| 1764 | + (assert (not (nil? source)) |
| 1765 | + (str "Module " name " did not supply :source")) |
| 1766 | + (let [fdeps-str (when-not (empty? foreign-deps) |
| 1767 | + (foreign-deps-str opts foreign-deps)) |
| 1768 | + sm-name (when (:source-map opts) |
| 1769 | + (str output-to ".map")) |
| 1770 | + out-file (io/file output-to) |
| 1771 | + _ (util/mkdirs out-file) |
| 1772 | + js (as-> source source |
| 1773 | + (if (= name :cljs-base) |
| 1774 | + (add-header opts source) |
| 1775 | + source) |
| 1776 | + (if fdeps-str |
| 1777 | + (str fdeps-str "\n" source) |
| 1778 | + source) |
| 1779 | + (elide-strict source opts) |
| 1780 | + (if sm-name |
| 1781 | + (add-source-map-link |
| 1782 | + (assoc opts |
| 1783 | + :output-to output-to |
| 1784 | + :source-map sm-name) |
| 1785 | + source) |
| 1786 | + source)) |
| 1787 | + fingerprint-base? (and (:fingerprint opts) (= :cljs-base name))] |
| 1788 | + (when-not fingerprint-base? |
| 1789 | + (spit out-file js)) |
| 1790 | + (when (:fingerprint opts) |
| 1791 | + (let [out-file' (fingerprint-out-file js out-file)] |
| 1792 | + (when-not fingerprint-base? |
| 1793 | + (.renameTo out-file out-file')) |
| 1794 | + (swap! fingerprint-info update name merge |
| 1795 | + (when fingerprint-base? {:source js}) |
| 1796 | + {:output-to (.toString output-to) |
| 1797 | + :output-to-fingerprint (.toString out-file')}))) |
| 1798 | + (when (:source-map opts) |
| 1799 | + (let [sm-json-str (:source-map-json module-desc) |
| 1800 | + sm-json (json/read-str sm-json-str :key-fn keyword)] |
| 1801 | + (when (true? (:closure-source-map opts)) |
| 1802 | + (spit (io/file (:source-map-name module-desc)) sm-json-str)) |
| 1803 | + (emit-optimized-source-map sm-json js-sources sm-name |
| 1804 | + (merge opts |
| 1805 | + {:source-map sm-name |
| 1806 | + :preamble-line-count |
| 1807 | + (if (= name :cljs-base) |
| 1808 | + (+ (- (count (.split #"\r?\n" (make-preamble opts) -1)) 1) |
| 1809 | + (if (:output-wrapper opts) 1 0) |
| 1810 | + (if (:fingerprint opts) 1 0)) |
| 1811 | + 0) |
| 1812 | + :foreign-deps-line-count |
| 1813 | + (if fdeps-str |
| 1814 | + (- (count (.split #"\r?\n" fdeps-str -1)) 1) |
| 1815 | + 0)})))))) |
| 1816 | + (when (:fingerprint opts) |
| 1817 | + (let [fi @fingerprint-info |
| 1818 | + g (get-in fi [:cljs-base :output-to-fingerprint]) |
| 1819 | + out (io/file g) |
| 1820 | + dir (.getParent out) |
| 1821 | + mnf (io/file dir "manifest.edn") |
| 1822 | + uris (module-graph/modules->module-uris |
| 1823 | + (fingerprinted-modules modules fi) js-sources opts)] |
| 1824 | + (spit mnf |
| 1825 | + (pr-str |
| 1826 | + (into {} |
| 1827 | + (map (juxt :output-to :output-to-fingerprint)) |
| 1828 | + (vals fi)))) |
| 1829 | + (spit out |
| 1830 | + (str "var COMPILED_MODULE_URIS = " |
| 1831 | + (json/write-str |
| 1832 | + (into {} |
| 1833 | + (map (fn [[k v]] [(-> k name munge) v])) uris)) |
| 1834 | + ";\n" |
| 1835 | + (get-in fi [:cljs-base :source]))))))) |
1775 | 1836 |
|
1776 | 1837 | (defn lib-rel-path [{:keys [lib-path url provides] :as ijs}]
|
1777 | 1838 | (if (nil? lib-path)
|
|
0 commit comments