Skip to content

Commit

Permalink
CLJS-3255: cljs.build.api/build doesn't work with single arity / 2-ar…
Browse files Browse the repository at this point in the history
…ity with nil

While actually supported make a small change so that `source` argument to cljs.build/build
can actually be nil in all cases. If `:main` is supplied, `:optimizations` `:none`, and
source nil, go ahead supply source as that will always be what the user intended.

Note cljs.cli already fixed this problem some time ago but at a higher level.
  • Loading branch information
swannodette committed Jul 8, 2020
1 parent b7895ae commit 0ea117b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/clojure/cljs/closure.clj
Expand Up @@ -3109,11 +3109,15 @@
(util/debug-prn "Options passed to ClojureScript compiler:" (pr-str opts)))
(let [one-file? (and (:main opts)
(#{:advanced :simple :whitespace} (:optimizations opts)))
source (if one-file?
source (if (or one-file?
;; if source is nil, :main is supplied, :optimizations :none,
;; fix up source for the user, see CLJS-3255
(and (nil? source) (:main opts) (= :none (:optimizations opts))))
(let [main (:main opts)
uri (:uri (cljs-source-for-namespace main))]
(assert uri (str "No file for namespace " main " exists"))
uri)
;; old compile directory behavior, or code-splitting
source)
compile-opts (if one-file?
(assoc opts :output-file (:output-to opts))
Expand Down
12 changes: 12 additions & 0 deletions src/test/clojure/cljs/build_api_tests.clj
Expand Up @@ -719,3 +719,15 @@
(test/delete-out-files out)
(build/build (build/inputs (io/file inputs "trivial/core.cljs")) opts cenv)
(is (< (.length out-file) 10000))))

(deftest cljs-3255-nil-inputs-build
(let [out (.getPath (io/file (test/tmp-dir) "3255-test-out"))
out-file (io/file out "main.js")
opts {:main 'trivial.core
:output-to (.getPath out-file)
:output-dir out
:language-in :es6
:optimizations :none}
cenv (env/default-compiler-env)]
(test/delete-out-files out)
(build/build nil opts cenv)))

0 comments on commit 0ea117b

Please sign in to comment.