emezeske / lein-cljsbuild

Leiningen plugin to make ClojureScript development easy.
Other
1.1k stars 151 forks source link

`lein uberjar` doesn't remove prior version of compiled JS, shipping dev code #414

Open venantius opened 9 years ago

venantius commented 9 years ago

I'm relatively new to Cljs, but not to Clojure, and this behavior has been confusing to me. I have a project.clj as follows:

(defproject clip "0.1.0-SNAPSHOT"
  :description ""
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/tools.logging "0.3.1"]
                 [org.slf4j/slf4j-log4j12 "1.7.12"]
                 [org.clojure/clojurescript "1.7.48"]
                 [org.omcljs/om "0.9.0"]
                 [korma "0.4.2"]
                 [ragtime "0.5.2"]

                 [ring "1.4.0"]
                 [aleph "0.4.0"] ;; let's try Aleph
                 [ring/ring-defaults "0.1.5"]
                 [compojure "1.4.0"]

                 [prismatic/schema "1.0.1"]
                 [environ "1.0.0"]
                 [clj-time "0.11.0"]

                 [org.postgresql/postgresql "9.4-1202-jdbc4"]
                 ]

  :plugins [[lein-cljsbuild "1.0.5"]
            [lein-environ "1.0.0"]]

  :main clip.core
  :source-paths ["src/clj"]
  :test-paths ["test/clj"]
  :min-lein-version "2.5.0"

  :cljsbuild {:builds {:app {:source-paths ["src/cljs"]
                             :compiler {:output-to     "resources/public/js/app.js"
                                        :output-dir    "target/out"
                                        :source-map    "resources/public/js/out.js.map"
                                        :preamble      ["react/react.min.js"]
                                        :optimizations :none
                                        :main "clip.core"
                                        :asset-path "js/out"
                                        :pretty-print  true}}}}

  :profiles {:dev
             {:env {:environment "dev"
                    :database-url "postgres://localhost:5432/clip"
                    :port "8080"
                    :is-dev true}

              :plugins [[jonase/eastwood "0.1.4"]
                        [lein-figwheel "0.3.9"]]

              :eastwood {:exclude-linters [:deprecations]}

              :figwheel {:http-server-root "public"
                         :css-dirs ["resources/public/css"]
                         :nrepl-port 7002
                         :ring-handler clip.core/app}

              :cljsbuild {:test-commands {"test"
                                          ["phantomjs"
                                           "env/test/js/unit-test.js"
                                           "env/test/unit-test.html"]}
                          :builds {:app {:figwheel true}
                                   :test {:source-paths ["src/cljs" "test/cljs"]
                                          :compiler {:output-to     "resources/public/js/app_test.js"
                                                     :output-dir    "resources/public/js/test"
                                                     :source-map    "resources/public/js/test.js.map"
                                                     :preamble      ["react/react.min.js"]
                                                     :optimizations :whitespace
                                                     :pretty-print  false}}}}}

             :test
             {:env {:environment "test"
                    :database-url "postgres://localhost:5432/clip_test"
                    :port "8080"
                    :session-key "antarctica--bear"}
              :plugins [[jonase/eastwood "0.1.4"]]
              :jvm-opts ["-Dlog4j.configuration=log4j-test.properties"]}

             :staging
             {:env {:environment "staging"}}

             :production
             {:env {:environment "production"}}

             :uberjar {:hooks [leiningen.cljsbuild]
                       :env {:production true}
                       :omit-source true
                       :aot :all
                       :cljsbuild {:builds {:app
                                            {:jar true
                                             :compiler
                                             {:optimizations :advanced
                                              :pretty-print false}}}}}}
  )

If I've been running figwheel for a while in development, but I stop and then run lein uberjar, my ClojureScript code is not re-compiled for the different uberjar profile, meaning my uberjar now ships with application code that tries to open a figwheel connection.

If I manually delete /resources/public/js/app.js and trigger a re-compile by running lein with-profile uberjar cljs build once, then run lein uberjar, the jar file has the correct javascript file (no figwheel connection attempted).

venantius commented 9 years ago

This issue was resolved for me by the steps detailed in https://github.com/emezeske/lein-cljsbuild/issues/366#issuecomment-134230350

venantius commented 9 years ago

I lied. Cljsbuild still doesn't overwrite existing compiled js during an uberjar build.

mneise commented 9 years ago

Taking a look at this now :wink:

mneise commented 9 years ago

Not able to reproduce this yet. Could you maybe provide a minimal repository to reproduce this issue?

venantius commented 9 years ago

So, after a bit of work, my running hypothesis is that Cljsbuild won't try to re-compile js if it finds the existing file, in this case "resources/public/js/app.js"

I can work on putting together a minimal test case to further drill in on this, but by looking at the actual files that my uberjar contained as I tweaked various aspects of the build system the only thing that caused files to be included in the uberjar was nuking the entirety of the resources/public/js folder, and critically that file.

psalaberria002 commented 9 years ago

@venantius Did you find any solution to this issue? Indeed, removing "resources/public/js/app.js" does the trick. However, this is not an elegant solution at all.

venantius commented 9 years ago

@psalaberria002 The other thing I found that helped was adding the build path to leiningen's :clean-targets

mneise commented 9 years ago

The reason it doesn't recompile is that lein-cljsbuild only recompiles if the sources have been modified since the last build. I'm currently not aware of another solution, other than running lein clean or using different output files for different builds.

I think for 2.0 I will probably remove this behaviour, since ClojureScript itself is pretty good when it comes to incremental builds.

venantius commented 9 years ago

That's interesting. I think using the plugin to force cleaning of the compilation target directory prior to uberjar compilation is probably the desirable / "expected" behavior here.

venantius commented 9 years ago

Anyways, happy that we've been able to nail this down as something warranting investigation rather than a "can't-reproduce" ^.^

raxod502 commented 7 years ago

I have the same problem. If I change my cljsbuild configuration, then I have to remove app.js in order to force lein cljsbuild once to do anything.