bensu / doo

doo is a library and lein plugin to run cljs.test on different js environments.
Eclipse Public License 1.0
324 stars 63 forks source link

Make :main compatible with Figwheel #26

Closed bensu closed 8 years ago

bensu commented 9 years ago

There are three ways to specify :main:

  1. :main 'app.core
  2. :main app.core
  3. :main "app.core"

We should support all of them. As noticed by @teaforthecat we currently don't support 2. which is Figwheel's preferred method.

  1. Is important since it is used in scripts for the compiler, and beginners will probably paste those to project.clj.
dqdinh commented 8 years ago

I had the following bug below while using doo and figwheel.

 $ lein clean; lein figwheel 
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Named
 at clojure.core$name.invoke (core.clj:1524)
    clojure.lang.AFn.applyToHelper (AFn.java:154)
    clojure.lang.AFn.applyTo (AFn.java:144)
    ...

After several hours of leiningen config trial and error, it turns out that Figwheel will specifically error out if it sees :main 'app.core. Options 2 and 3 will work.

It might help prevent others from spending time debugging if the :main 'app.core in the README and example config was changed to Option 2 or 3. The error only occurs when specifying :main 'app.core inside :cljsbuild {:builds {:build-id {:compiler ...} and calling lein figwheel. All other cljsbuild commands work.

This is my current working project.clj for reference.

(defproject frontend "0.1.0"
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.48"]
                 [reagent "0.5.1-rc3"]
                 [re-frame "0.4.1"]
                 [environ "1.0.0"]
                 [prismatic/schema "1.0.1"]
                 [prismatic/plumbing "0.4.4"]
                 [figwheel "0.4.0"]
                 [cljs-ajax "0.3.14"]]

  :plugins [[lein-environ "1.0.0"]
            [lein-figwheel "0.4.0"]
            [lein-cljsbuild "1.0.6"]
            [lein-doo "0.1.5-SNAPSHOT"]
            [codox "0.8.13"]]

  :source-paths ["src"]

  :codox {:language :clojurescript
          :exclude clojure.string}

  :profiles {:dev {:env {:dev? true
                                    :cors? true}

                           :cljsbuild {:builds {:client {:figwheel {:on-jsload "frontend.core/mount-root"}
                                                                   :compiler {:main "frontend.core"
                                                                        :source-map true
                                                                        :source-map-timestamp true
                                                                        :optimizations :none
                                                                        :output-dir "resources/public/js/out"
                                                                        :asset-path "js/out"}}}}}}

  :clean-targets ^{:protect false} [:target-path
                                    :compile-path
                                    "resources/public/js"
                                    "../public/frontend-dev"
                                    "../public/frontend-prod"]

  :cljsbuild {:builds {:client {:source-paths ["src"]
                             :compiler {:output-to "resources/public/js/main.js"}}

                       :browser-test {:source-paths ["src" "test"]
                                      :compiler {:output-to "resources/public/js/browser_tests.js"
                                                 :main "frontendtest.browser"
                                                 :optimizations :none}}}}

  :figwheel {:css-dirs ["resource/public/css"]
             :server-port 3333
             :repl false})
flosell commented 8 years ago

+1 to changing the examples in README.md to something like :main "example.runner", would have saved me half an hour of debugging and googling.

@bensu: Any doubts?