Fork me on GitHub
#boot
<
2018-02-06
>
Nikki03:02:23

hi - I'm working on a clojurescript project and using boot-cljs. Just added a node server and trying to figure out how to separate out :source-paths between the 2 build tasks. my build.boot is currently like this:

(set-env!
  :source-paths #{"src"}
  :dependencies '[[org.clojure/clojure "1.9.0"]
                  [org.clojure/clojurescript "1.9.854"]
                  [adzerk/boot-cljs "2.1.4" :scope "test"]
                  [adzerk/boot-reload "0.5.2" :scope "test"]
                  [reagent "0.7.0" :exclusions [[cljsjs/react]
                                                [cljsjs/react-dom]
                                                [cljsjs/react-dom-server]
                                                [cljsjs/create-react-class]]]
                  [secretary "1.2.3"]])

(require
  '[adzerk.boot-cljs   :refer [cljs]]
  '[adzerk.boot-reload :refer [reload]])

(deftask client
  "Make client files"
  []
  (comp
    (cljs :source-map true
          :optimizations :none
          :compiler-options {:main "client.load"
                             :output-dir "public/js"
                             :output-to "public/js/app.js"
                             :npm-deps {:react "16.2.0"
                                        :react-dom "16.2.0"
                                        :create-react-class "^15.6.3"}
                             :install-deps true
                             :infer-externs true})
    (target)))

(deftask server
  "Make server files"
  []
  (comp
    (cljs :source-map true
          :optimizations :none
          :compiler-options {:main "server.main"
                             :target :nodejs
                             :npm-deps {:express "4.16.2"
                                        :react "16.2.0"
                                        :react-dom "16.2.0"
                                        :create-react-class "^15.6.3"}
                             :install-deps true
                             :infer-externs true})
    (target)))

andre.stylianos13:02:25

Possibly using https://github.com/seancorfield/boot-tools-deps? That could help as well with keeping deps separate (if that is something you'd like do to) You could maybe use it with either two aliases or even separate deps.edn files

Nikki03:02:14

any help would be appreciated

martinklepsch11:02:24

Hey @lalanikki what do you mean with separate source paths? would you like to have different values for :source-paths for the two builds?

nha12:02:12

you could call set-env! inside the task. That would prevent chaining them though, so the next step would be to run the task in a pod and set the sources there. That would mean having subfolders for the client and server code (if I understood correctly) (?)

nha12:02:28

If you scroll up I had a similar problem and candera kindly suggested a solution https://clojurians.slack.com/archives/C053K90BR/p1517755943000006

Nikki14:02:14

@martinklepsch @nha I do seem to have the same situation - common, client, & server subdirectories where I want to exclude client from server file path and vice versa. Trying the solution @candera suggested with including in the task.

candera14:02:50

It’s sort of gross to have that sort of side effect, though. The more I think about it the less I’m thrilled with that. But not a Boot expert - maybe @micha or @alandipert or someone with more experience can comment. It’s certainly ought to be an option to have more than one build.boot in the same repo. But I guess if nothing else you can always restore the environment afterward.

micha14:02:22

what is the goal you wish to achieve by separating source paths?

Nikki14:02:41

the goal is to not have errors on client or server

Nikki14:02:08

Client-side entrypoint targets the browser and references document which you only find on client. When that runs when the server starts up, it causes a crash

Nikki14:02:45

Also, in loading the client entrypoint file it has references to server side libraries that cause errors

juhoteperi14:02:49

Nothing should reference files not used by build, no need to separate source-paths

Nikki14:02:27

^ that's what I would think. Maybe I have a different problem than I think

juhoteperi14:02:50

You don't have .cljs.edn files? That would break this because that case is horrible hack and breaks everything

micha14:02:26

@juhoteperi which case is the hack?

juhoteperi14:02:40

Without .cljs.edn file Boot-cljs will require all .cljs files in the fileset

juhoteperi14:02:57

Which is really bad idea, but required for legacy reasons in this case (boot-reload etc.)

micha14:02:28

yeah the .cljs.edn files are pretty important

Nikki14:02:45

ahhh okay

Nikki14:02:17

thank you

martinklepsch16:02:08

Maybe this should be deprecated and instead the task could spit out a default “fill-in-the-blanks” cljs.edn file?

micha16:02:36

i believe that's what it does in the default case

micha16:02:08

it's just unable to figure out what exactly the entry point is, so it pulls in everything

juhoteperi17:02:22

Only way around this would be to hardcode boot-cljs to include boot-reload/cljs-repl/figwheel files in addition to main/require option, so it wouldn't have to load everything

juhoteperi17:02:48

The problem is that "addon" tools presume boot-cljs will automatically load their namespaces, if .cljs.edn can't be found

juhoteperi17:02:10

That is, only way if we keep supporting using boot-cljs without .cljs.edn, if we force everyone to use .cljs.edn files, that will remove lots of problems

grzm21:02:00

When using Boot and Cider and am trying to compile a class with :gen-class in the namespace declaration, I’m getting a ClassCastException. Example:

(ns com.grzm.ex.boot.ds
  (:gen-class
   :name com.grzm.ex.boot.DS))

(comment
  (compile 'com.grzm.ex.boot.DS) ;; evaling this line
  )

grzm21:02:11

Exception details:

java.lang.ClassCastException: java.base/java.io.File cannot be cast to java.base/java.lang.String
clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: java.base/java.io.File cannot be cast to java.base/java.lang.String, compiling:(com/grzm/ex/boot/DS.clj:1:1)

grzm21:02:43

Works okay under a Lein repl. Any thoughts?