Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Upgrade to ClojureScript 1.10 w/o Google Closure Compiler #379

Merged
merged 16 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
### Changes

- Upgrade Node.js to version 9.10.0.
- Bump ClojureScript to 1.10.X ([#379](https://github.com/anmonteiro/lumo/pull/379)).
Plus miscellaneous fixes, most notably:
- Use cljs.core/eval in lumo.core.
- Bundle `cljs.core.specs.alpha`.
- Use `$HOME/.cljs/.lumo-cache` as global cache folder.
- Throw in case of the unsupported `:parallel-build`.
- Fix init of `cljs.core/*print-newline*`.

## [1.8.0](https://github.com/anmonteiro/lumo/compare/1.8.0-beta...1.8.0) (2018-02-15)

Expand Down
16 changes: 11 additions & 5 deletions build.boot
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(def +clojurescript-version+ (or (System/getenv "CANARY_CLOJURESCRIPT_VERSION")
"1.9.946"))
"1.10.238"))
(def +node-version+ (or (System/getenv "BUILD_NODE_VERSION")
"9.10.0"))

(set-env!
:source-paths #{"src/cljs/snapshot"}
:asset-paths #{"src/js" "src/cljs/bundled"}
Expand All @@ -16,7 +15,7 @@
[com.cognitect/transit-clj "0.8.303" :scope "test"]
[com.cemerick/piggieback "0.2.2" :scope "test"]
[adzerk/boot-cljs "2.1.4" :scope "test"]
[crisptrutski/boot-cljs-test "0.3.4" :scope "test"]
[crisptrutski/boot-cljs-test "0.3.5-SNAPSHOT" :scope "test"]
[org.clojure/tools.nrepl "0.2.13" :scope "test"]
[weasel "0.7.0" :scope "test"]
[doo "0.1.8" :scope "test"]])
Expand Down Expand Up @@ -48,6 +47,9 @@
(let [exit? (cond-> exit?
(nil? exit?) not)]
(comp
(sift :add-jar
{'org.clojure/clojurescript #"^cljs[\\\/]core.cljs.cache.aot.json$"}
:move {#"^(cljs[\\\/]core.cljs.cache.aot.json)$" "lumo_test/test_suite.out/$1"})
(testing)
(test-cljs
:js-env :node
Expand All @@ -56,6 +58,7 @@
:target :nodejs
:verbose true
:asset-path "test_suite.out"}
:update-fs? true
:exit? exit?
:ids #{"lumo_test/test_suite"}))))

Expand Down Expand Up @@ -126,12 +129,14 @@

(deftask sift-cljs-resources []
(comp
(sift :add-jar
{'org.clojure/clojurescript #"\.class$"}
:invert true)
(sift :add-jar
{'org.clojure/clojure #"^clojure[\\\/]template\.clj"
'org.clojure/google-closure-library #"^goog[\\\/].*(?<!_test)\.js$"
'org.clojure/google-closure-library-third-party #"^goog[\\\/].*(?<!_test)\.js$"
'org.clojure/tools.reader #"^cljs.*clj$"
'org.clojure/clojurescript #""
'org.clojure/test.check #""}
:move {#"^main.out[\\\/]((cljs|clojure|cognitect|lumo|lazy_map|fipp|process).*)" "$1"})
(sift :include #{#"^main.js" #"^bundle.js" #"^cljs(?!\.js)" #"core\$macros"
Expand All @@ -158,6 +163,7 @@
:dump-core false
:static-fns true
:optimize-constants false
:npm-deps false
:verbose true
:closure-defines {'cljs.core/*target* "nodejs"
'lumo.core/*lumo-version* lumo-version}
Expand Down Expand Up @@ -185,7 +191,7 @@
(deftask package-executable
[c ci-build bool "CI build"]
(with-pass-thru _
(dosh "node" "scripts/package.js" +node-version+ (str ci-build))))
(dosh "node" "scripts/package.js" +node-version+)))

(deftask backup-resources
"Backup resources to be gzipped in the 2nd stage binary
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"bundle": "node scripts/bundle.js --dev",
"build": "cross-env NODE_ENV=production node scripts/bundle.js",
"dev": "node target/bundle.js -k lumo-cache -c target",
"test-dev": "node target/bundle.js -k test-lumo-cache -c target:src/test/cljs:src/test/lumo:src/test/cljs_cp -D org.clojure/test.check:0.10.0-alpha",
"test-dev": "node target/bundle.js -k test-lumo-cache -c target:src/test/cljs:src/test/lumo:src/test/cljs_cp -D org.clojure/test.check:0.10.0-alpha2",
"postinstall": "opencollective postinstall"
},
"main": "./src/js/index.js",
Expand Down
6 changes: 5 additions & 1 deletion scripts/aot-bundle-macros.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo "### Compiling Macro Namespaces"

mkdir lumo-cljs\out\macros-tmp || goto :error

echo (require 'lumo.build.api 'lumo.analyzer 'lumo.cljs-deps 'lumo.classpath 'lumo.closure 'lumo.compiler 'lumo.io 'lumo.json 'lumo.util 'clojure.core.reducers 'clojure.zip 'clojure.data 'clojure.reflect 'clojure.browser.net 'clojure.browser.event 'cljs.nodejs 'cljs.pprint 'cljs.test 'cljs.analyzer.api 'cljs.spec.test.alpha) (require-macros 'lumo.repl 'lumo.util 'clojure.template 'cljs.pprint 'cljs.support 'cljs.spec.alpha 'cljs.spec.gen.alpha 'cljs.spec.test.alpha 'cljs.test 'cljs.reader 'cljs.env.macros 'cljs.analyzer.macros 'cljs.compiler.macros) | build\lumo.exe --quiet -c target -sfdk lumo-cljs/out/macros-tmp || goto :error
echo (require 'lumo.build.api 'lumo.analyzer 'lumo.cljs-deps 'lumo.classpath 'lumo.closure 'lumo.compiler 'lumo.io 'lumo.json 'lumo.util 'clojure.core.reducers 'clojure.zip 'clojure.data 'clojure.reflect 'clojure.browser.net 'clojure.browser.event 'cljs.nodejs 'cljs.pprint 'cljs.test 'cljs.analyzer.api 'cljs.spec.test.alpha 'cljs.core.specs.alpha) (require-macros 'lumo.repl 'lumo.util 'clojure.template 'cljs.pprint 'cljs.support 'cljs.spec.alpha 'cljs.spec.gen.alpha 'cljs.spec.test.alpha 'cljs.test 'cljs.reader 'cljs.env.macros 'cljs.analyzer.macros 'cljs.compiler.macros) | build\lumo.exe --quiet -c target -sfdk lumo-cljs/out/macros-tmp || goto :error
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing moving the generated files for cljs.core.specs.alpha to the target dir

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I thought I added those, will add them again

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adressed.


move lumo-cljs\out\macros-tmp\clojure_SLASH_core_SLASH_reducers.js target\clojure\core\reducers.js || goto :error
move lumo-cljs\out\macros-tmp\clojure_SLASH_core_SLASH_reducers.cache.json target\clojure\core\reducers.cache.json || goto :error
Expand Down Expand Up @@ -53,6 +53,8 @@ move lumo-cljs\out\macros-tmp\lumo_SLASH_util.js target\lumo\util.js || goto :er
move lumo-cljs\out\macros-tmp\lumo_SLASH_util.cache.json target\lumo\util.cache.json || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_test_SLASH_alpha.js target\cljs\spec\test\alpha.js || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_test_SLASH_alpha.cache.json target\cljs\spec\test\alpha.cache.json || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_core_SLASH_specs_SLASH_alpha.js target\cljs\core\specs\alpha.js || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_core_SLASH_specs_SLASH_alpha.cache.json target\cljs\core\specs\alpha.cache.json || goto :error

move lumo-cljs\out\macros-tmp\lumo_SLASH_repl$macros.js target\lumo\repl$macros.js || goto :error
move lumo-cljs\out\macros-tmp\lumo_SLASH_repl$macros.cache.json target\lumo\repl$macros.cache.json || goto :error
Expand Down Expand Up @@ -82,6 +84,8 @@ move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_gen_SLASH_alpha$macros.js ta
move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_gen_SLASH_alpha$macros.cache.json target\cljs\spec\gen\alpha$macros.cache.json || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_test_SLASH_alpha$macros.js target\cljs\spec\test\alpha$macros.js || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_spec_SLASH_test_SLASH_alpha$macros.cache.json target\cljs\spec\test\alpha$macros.cache.json || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_core_SLASH_specs_SLASH_alpha$macros.js target\cljs\core\specs\alpha$macros.js || goto :error
move lumo-cljs\out\macros-tmp\cljs_SLASH_core_SLASH_specs_SLASH_alpha$macros.cache.json target\cljs\core\specs\alpha$macros.cache.json || goto :error

echo y | rd lumo-cljs /s

Expand Down
7 changes: 6 additions & 1 deletion scripts/aot-bundle-macros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ $(pwd)/build/lumo --quiet -c target -sfdk lumo-cljs/out/macros-tmp <<REPL_INPUT
'cljs.nodejs
'cljs.test
'cljs.analyzer.api
'cljs.spec.test.alpha)
'cljs.spec.test.alpha
'cljs.core.specs.alpha)
(require-macros 'lumo.repl
'lumo.util
'clojure.template
Expand Down Expand Up @@ -90,6 +91,8 @@ mv lumo-cljs/out/macros-tmp/lumo_SLASH_util.js target/lumo/util.js
mv lumo-cljs/out/macros-tmp/lumo_SLASH_util.cache.json target/lumo/util.cache.json
mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_test_SLASH_alpha.js target/cljs/spec/test/alpha.js
mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_test_SLASH_alpha.cache.json target/cljs/spec/test/alpha.cache.json
mv lumo-cljs/out/macros-tmp/cljs_SLASH_core_SLASH_specs_SLASH_alpha.js target/cljs/core/specs/alpha.js
mv lumo-cljs/out/macros-tmp/cljs_SLASH_core_SLASH_specs_SLASH_alpha.cache.json target/cljs/core/specs/alpha.cache.json

mv lumo-cljs/out/macros-tmp/lumo_SLASH_repl\$macros.js target/lumo/repl\$macros.js
mv lumo-cljs/out/macros-tmp/lumo_SLASH_repl\$macros.cache.json target/lumo/repl\$macros.cache.json
Expand Down Expand Up @@ -119,5 +122,7 @@ mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_gen_SLASH_alpha\$macros.js tar
mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_gen_SLASH_alpha\$macros.cache.json target/cljs/spec/gen/alpha\$macros.cache.json
mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_test_SLASH_alpha\$macros.js target/cljs/spec/test/alpha\$macros.js
mv lumo-cljs/out/macros-tmp/cljs_SLASH_spec_SLASH_test_SLASH_alpha\$macros.cache.json target/cljs/spec/test/alpha\$macros.cache.json
mv lumo-cljs/out/macros-tmp/cljs_SLASH_core_SLASH_specs_SLASH_alpha\$macros.js target/cljs/core/specs/alpha\$macros.js
mv lumo-cljs/out/macros-tmp/cljs_SLASH_core_SLASH_specs_SLASH_alpha\$macros.cache.json target/cljs/core/specs/alpha\$macros.cache.json

rm -rf lumo-cljs
33 changes: 33 additions & 0 deletions scripts/lumo_test.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(require '[cljs.test]
'[lumo.test-runner]
'[lumo.test-util]
'[lumo.core :as lumo]
;; needs to be here for testing get-completions
'[goog :as g])
Expand All @@ -8,4 +9,36 @@
(when-not (cljs.test/successful? m)
(lumo/exit 1)))

(defmethod cljs.test/report [:cljs.test/default :error] [m]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does adding the code below help you debug what's going on in tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is a better reporter basically, using this at work too, can take it away and add it in another PR as well if you want

(cljs.test/inc-report-counter! :error)
(println "\nERROR in" (cljs.test/testing-vars-str m))
(when (seq (:testing-contexts (cljs.test/get-current-env)))
(println (cljs.test/testing-contexts-str)))
(when-let [message (:message m)] (println message))
(let [actual (:actual m)
ex-data (ex-data actual)]
(if (:cljs.spec.alpha/failure ex-data)
(do (println "expected:" (pr-str (:expected m)))
(print " actual:\n")
(println (.-message actual)))
(cljs.test/print-comparison m))
(when lumo.test-util/*print-stack-traces*
(println (.-stack actual)))))

(defmethod cljs.test/report [:cljs.test/default :fail] [m]
(cljs.test/inc-report-counter! :error)
(println "\nERROR in" (cljs.test/testing-vars-str m))
(when (seq (:testing-contexts (cljs.test/get-current-env)))
(println (cljs.test/testing-contexts-str)))
(when-let [message (:message m)] (println message))
(let [actual (:actual m)
ex-data (ex-data actual)]
(if (:cljs.spec.alpha/failure ex-data)
(do (println "expected:" (pr-str (:expected m)))
(print " actual:\n")
(println (.-message actual)))
(cljs.test/print-comparison m))
(when lumo.test-util/*print-stack-traces*
(println (.-stack actual)))))

(lumo.test-runner/run-all-tests)
107 changes: 85 additions & 22 deletions src/cljs/bundled/lumo/analyzer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
[cljs.tagged-literals :as tags]
[clojure.string :as string]
fs
path))
path
os))

(defn gen-user-ns [src]
(let [full-name (str src)
name (.substring full-name
(inc (.lastIndexOf full-name "/"))
(.lastIndexOf full-name "."))]
(symbol
(str "cljs.user." name (util/content-sha full-name 7)))))
(if (sequential? src)
(symbol (str "cljs.user.source$form$" (util/content-sha (pr-str src) 7)))
(let [full-name (str src)
name (.substring full-name
(inc (string/last-index-of full-name "/"))
(string/last-index-of full-name "."))]
(symbol (str "cljs.user." name (util/content-sha full-name 7))))))

(defn- resolve-symbol
[sym]
Expand Down Expand Up @@ -99,7 +101,8 @@
(remove nil?))
(concat (vals uses) (vals requires))))

(defn parse-ns
;; We bind `parse-ns` to memoize in `lumo.closure`
(defn ^:dynamic parse-ns
"Helper for parsing only the essential namespace information from a
ClojureScript source file and returning a cljs.closure/IJavaScript compatible
map _not_ a namespace AST node.
Expand Down Expand Up @@ -149,7 +152,7 @@
:requires (cond-> #{'cljs.core}
(get-in @env/*compiler* [:options :emit-constants])
(conj ana/constants-ns-sym))}
(when (and dest (js/$$LUMO_GLOBALS.fs.existsSync dest))
(when (and dest (fs/existsSync dest))
{:lines (let [reader dest]
(-> reader line-seq count))}))]
(if (seq forms)
Expand Down Expand Up @@ -178,7 +181,7 @@
:ast ast
:macros-ns (or (:macros-ns opts)
(= 'cljs.core$macros ns-name))}
(when (and dest (js/$$LUMO_GLOBALS.fs.existsSync dest))
(when (and dest (fs/existsSync dest))
{:lines (let [reader dest]
(-> reader line-seq count))})))

Expand All @@ -194,31 +197,83 @@

:else ret))
ret)))))]
ijs))))
(cond-> ijs
(not (contains? ijs :ns))
(merge
{:ns (gen-user-ns src)
:provides [(gen-user-ns src)]}))))))

(defn- cache-analysis-ext
([] (cache-analysis-ext (get-in @env/*compiler* [:options :cache-analysis-format] :transit)))
([format]
(if (= format :transit) "json" "edn")))

(defn build-affecting-options [opts]
(select-keys opts
[:static-fns :fn-invoke-direct :optimize-constants :elide-asserts :target
:cache-key :checked-arrays :language-out]))

(defn build-affecting-options-sha [path opts]
(let [m (assoc (build-affecting-options opts) :path path)]
(util/content-sha (pr-str m) 7)))

(defn cache-base-path
([path]
(cache-base-path path nil))
([path opts]
(let [homedir (os/homedir)]
(path/join (if (fs/existsSync homedir) homedir "")
".cljs" ".lumo_cache" (util/clojurescript-version)
(build-affecting-options-sha path opts)))))

(defn cacheable-files
([rsrc ext]
(cacheable-files rsrc ext nil))
([rsrc ext opts]
(let [{:keys [ns]} (parse-ns rsrc)
path (cache-base-path (util/path rsrc) opts)
name (util/ns->relpath ns nil path/sep)]
(into {}
(map
(fn [[k v]]
[k (path/join path
(if (and (= (str "cljs" path/sep "core$macros") name)
(= :source k))
(str "cljs" path/sep "core.cljc")
(str name v)))]))
{:source (str "." ext)
:output-file ".js"
:source-map ".js.map"
:analysis-cache-edn (str "." ext ".cache.edn")
:analysis-cache-json (str "." ext ".cache.json")}))))

(defn cache-file
"Given a ClojureScript source file returns the read/write path to the analysis
cache file. Defaults to the read path which is usually also the write path."
([src] (cache-file src "out"))
([src output-dir] (cache-file src (parse-ns src) output-dir))
([src ns-info output-dir]
(cache-file src (parse-ns src) output-dir :read))
(cache-file src ns-info output-dir :read nil))
([src ns-info output-dir mode]
(cache-file src ns-info output-dir mode nil))
([src ns-info output-dir mode opts]
{:pre [(map? ns-info)]}
(let [ext (cache-analysis-ext)]
(if-let [core-cache
(and (= mode :read)
(= (:ns ns-info) 'cljs.core)
(io/resource (str "cljs/core.cljs.cache.aot._COLON_defs." ext)))]
core-cache
(let [target-file (util/to-target-file output-dir ns-info
(util/ext (:source-file ns-info)))]
(str target-file ".cache." ext))))))
(let [aot-cache-file
;; TODO: check if what we really want is `bundled-resource?`
(when (util/bundled-resource? src)
((keyword (str "analysis-cache-" ext))
(cacheable-files src (util/ext src) opts)))]
(if (and aot-cache-file (fs/existsSync aot-cache-file))
aot-cache-file
(let [target-file (util/to-target-file output-dir ns-info
(util/ext (:source-file ns-info)))]
(str target-file ".cache." ext))))))))

(defn requires-analysis?
"Given a src, a resource, and output-dir, a compilation output directory
Expand All @@ -227,8 +282,10 @@
([src] (requires-analysis? src "out"))
([src output-dir]
(let [cache (cache-file src output-dir)]
(requires-analysis? src cache output-dir)))
(requires-analysis? src cache output-dir nil)))
([src cache output-dir]
(requires-analysis? src cache output-dir nil))
([src cache output-dir opts]
(cond
(util/bundled-resource? cache)
(let [path (.-src cache)]
Expand All @@ -241,10 +298,12 @@
true

:else
(let [out-src (util/to-target-file output-dir (parse-ns src))]
(if (not (fs/existsSync out-src))
(let [out-src (util/to-target-file output-dir (parse-ns src))
cache-src (:output-file (cacheable-files src (util/ext src) opts))]
(if (and (not (fs/existsSync out-src))
(not (fs/existsSync cache-src)))
true
(util/changed? src cache))))))
(or (not cache) (util/changed? src cache)))))))

(defn write-analysis-cache
([ns cache-file]
Expand Down Expand Up @@ -290,8 +349,10 @@
:source (slurp source-file)})
(if (and (not macros) (empty? cache))
(let [path (path/join (util/output-directory opts) path)
f (or (io/resource (str path ".cljs"))
(io/resource (str path ".cljc")))]
f (or (when (fs/existsSync (str path ".cljs"))
(str path ".cljs"))
(when (fs/existsSync (str path ".cljc"))
(str path ".cljc")))]
(try
(read-analysis-cache
(when (:cache-analysis opts)
Expand Down Expand Up @@ -371,6 +432,8 @@
(analyze-file f false opts))
([f skip-cache opts]
(binding [ana/*file-defs* (atom #{})
;; ana/*unchecked-if* false
;; ana/*unchecked-arrays* false
ana/*cljs-warnings* ana/*cljs-warnings*]
(let [output-dir (util/output-directory opts)
res (cond
Expand All @@ -387,7 +450,7 @@
cache (when (:cache-analysis opts)
(cache-file res ns-info output-dir))]
(when-not (get-in @env/*compiler* [::ana/namespaces (:ns ns-info) :defs])
(if (or skip-cache (not cache) (requires-analysis? res output-dir))
(if (or skip-cache (not cache) (requires-analysis? res cache output-dir opts))
(binding [ana/*cljs-ns* 'cljs.user
ana/*cljs-file* path
reader/*alias-map* (or reader/*alias-map* {})]
Expand Down
Loading