<commit_before>(ns script.bootstrap.build
  (:require [clojure.java.io :as io]
            [cljs.closure :as closure]
            [cljs.env :as env]
            [clojure.edn :as edn]
            [cognitect.transit :as transit])
  (:import [java.io FileOutputStream]))

(defn compile1 [copts file]
  (let [targ (io/resource file)
        _ (println "Compiling:" targ)
        core-js (closure/compile targ
                  (assoc copts
                    :output-file (closure/src-file->target-file targ)))
        deps    (closure/add-dependencies copts core-js)]
    deps))

(defn build [dir file opts]
  ;; Used to generate core$macros
  (io/make-parents "resources/cljs/core.cljc")
  ;; TODO: only do this if timestamps are newer
  ;;(if (not (.exists (io/as-file "resources/cljs/core.cljc"))))
  (spit "resources/cljs/core.cljc" (slurp (io/resource "cljs/core.cljc")))
  (spit "resources/cljs/core.cljs" (slurp (io/resource "cljs/core.cljs")))
  ;; Compilation core.cljc below breaks if the cache file is present
  (io/delete-file "resources/cljs/core.cljs.cache.aot.edn" true)

  (let [output-dir (io/file dir)
        copts (assoc opts
                :output-dir output-dir
                :cache-analysis true
                :source-map true
                :static-fns true
                :def-emits-var true)]
    (env/with-compiler-env (env/default-compiler-env opts)
      (let [;; Generate core$macros
            deps-macros (compile1 copts "cljs/core.cljc")
            ;; Compile main file
            deps (compile1 copts file)]
        ;; output unoptimized code and the deps file
        ;; for all compiled namespaces
        (apply closure/output-unoptimized
          (assoc copts
            :output-to (.getPath (io/file output-dir "deps.js")))
          (concat deps deps-macros)))))

  (let [core-cache (edn/read-string (slurp (io/resource "cljs/core.cljs.cache.aot.edn")))
        out (FileOutputStream. "./resources/cljs/core.cljs.cache.aot.transit")
        writer (transit/writer out :json)
        _ (transit/write writer core-cache)]
    (.close out))<commit_msg>Eliminate :def-emits-var from compiler opts<commit_after>(ns script.bootstrap.build
  (:require [clojure.java.io :as io]
            [cljs.closure :as closure]
            [cljs.env :as env]
            [clojure.edn :as edn]
            [cognitect.transit :as transit])
  (:import [java.io FileOutputStream]))

(defn compile1 [copts file]
  (let [targ (io/resource file)
        _ (println "Compiling:" targ)
        core-js (closure/compile targ
                  (assoc copts
                    :output-file (closure/src-file->target-file targ)))
        deps    (closure/add-dependencies copts core-js)]
    deps))

(defn build [dir file opts]
  ;; Used to generate core$macros
  (io/make-parents "resources/cljs/core.cljc")
  ;; TODO: only do this if timestamps are newer
  ;;(if (not (.exists (io/as-file "resources/cljs/core.cljc"))))
  (spit "resources/cljs/core.cljc" (slurp (io/resource "cljs/core.cljc")))
  (spit "resources/cljs/core.cljs" (slurp (io/resource "cljs/core.cljs")))
  ;; Compilation core.cljc below breaks if the cache file is present
  (io/delete-file "resources/cljs/core.cljs.cache.aot.edn" true)

  (let [output-dir (io/file dir)
        copts (assoc opts
                :output-dir output-dir
                :cache-analysis true
                :source-map true
                :static-fns true)]
    (env/with-compiler-env (env/default-compiler-env opts)
      (let [;; Generate core$macros
            deps-macros (compile1 copts "cljs/core.cljc")
            ;; Compile main file
            deps (compile1 copts file)]
        ;; output unoptimized code and the deps file
        ;; for all compiled namespaces
        (apply closure/output-unoptimized
          (assoc copts
            :output-to (.getPath (io/file output-dir "deps.js")))
          (concat deps deps-macros)))))

  (let [core-cache (edn/read-string (slurp (io/resource "cljs/core.cljs.cache.aot.edn")))
        out (FileOutputStream. "./resources/cljs/core.cljs.cache.aot.transit")
        writer (transit/writer out :json)
        _ (transit/write writer core-cache)]
    (.close out))
{'fraction_non_alphanumeric': 0.1316793893129771, 'fraction_numerical': 0.0014312977099236641, 'mean_word_length': 2.3093922651933703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380140', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1378, 'n_words': 335}