New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
venantius opened this Issue Sep 7, 2015 · 11 comments

Comments

Projects
None yet
4 participants
@venantius

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

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Sep 30, 2015

This issue was resolved for me by the steps detailed in #366 (comment)

This issue was resolved for me by the steps detailed in #366 (comment)

@venantius venantius closed this Sep 30, 2015

@venantius venantius reopened this Oct 1, 2015

@venantius

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Oct 1, 2015

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

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

@mneise

This comment has been minimized.

Show comment
Hide comment
@mneise

mneise Oct 1, 2015

Collaborator

Taking a look at this now 😉

Collaborator

mneise commented Oct 1, 2015

Taking a look at this now 😉

@mneise

This comment has been minimized.

Show comment
Hide comment
@mneise

mneise Oct 1, 2015

Collaborator

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

Collaborator

mneise commented Oct 1, 2015

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

@venantius

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Oct 11, 2015

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.

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

This comment has been minimized.

Show comment
Hide comment
@psalaberria002

psalaberria002 Nov 29, 2015

Contributor

@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.

Contributor

psalaberria002 commented Nov 29, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Nov 30, 2015

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

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

@mneise

This comment has been minimized.

Show comment
Hide comment
@mneise

mneise Dec 4, 2015

Collaborator

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.

Collaborator

mneise commented Dec 4, 2015

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

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Dec 4, 2015

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.

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

This comment has been minimized.

Show comment
Hide comment
@venantius

venantius Dec 4, 2015

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

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

@raxod502

This comment has been minimized.

Show comment
Hide comment
@raxod502

raxod502 Jul 21, 2017

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment