Fork me on GitHub
#duct
<
2018-05-25
>
lambder13:05:12

before the follow up on the prev issue, may I have different question ,please?

lambder13:05:47

I've generated the project with lein new duct foobar +cljs

lambder13:05:11

and I can see it compiles the cljs while lein uberjar

lambder13:05:42

for some reason my hand defined project is not doing this

lambder13:05:02

I've checked the duct config and I can see:

lambder13:05:44

:duct.compiler/cljs {:builds [{:source-paths ["src"], :build-options {:main firds-mirror.ui.core, :output-to "/Users/daniel/work/daniel-nuvo-firds-mirror/firds-mirror/target/resources/firds_mirror/public/js/main.js", :output-dir "/Users/daniel/work/daniel-nuvo-firds-mirror/firds-mirror/target/resources/firds_mirror/public/js", :asset-path "/js", :closure-defines {goog.DEBUG false}, :verbose true, :optimizations :advanced}

lambder13:05:20

now the question is which step during lein uberjar is building the cljs?

lambder13:05:18

@weavejester is it the last task on :prep-tasks ["javac" "compile" ["run" ":duct/compiler"]] ?

weavejester13:05:30

Yes - I was just in the middle of writing that 🙂

weavejester13:05:56

You also need a config option like :resource-paths ["resources" "target/resources"]

lambder13:05:23

when I manually do lein run :duct/compiler I see nothing on the stdout

lambder13:05:38

I have :resource-paths ["resources" "target/resources"]

weavejester13:05:13

lein run :duct/compiler should have output.

weavejester13:05:24

Have you changed your -main function in any way?

lambder13:05:37

it does on the foobar project but on mine

weavejester13:05:04

What does your -main function look like now?

lambder13:05:01

(ns mirror.main
  (:gen-class)
  (:require [ :as io]
            [duct.core :as duct]))

(duct/load-hierarchy)

(defn -main [& args]
  (let [keys (or (duct/parse-keys args) [:duct/daemon])]
    (-> (duct/read-config (io/resource "mirror/config.edn"))
        (duct/prep keys)
        (duct/exec keys))))

lambder13:05:12

it looks pretty standard

lambder13:05:43

is the main called during the uberjar?

weavejester13:05:15

It’s what’s called via lein run.

weavejester13:05:07

Perhaps try putting a (doto prn) in the thread -> after the read-config

weavejester13:05:19

Make sure there is a `:duct.compiler/cljs

lambder14:05:23

as we discussed before

lambder14:05:45

I have removed the duct.module/cljs

lambder14:05:07

and I've added my own module (to avoid figwheel in dev)

lambder14:05:21

I will check if I got the :duct.compiler/cljs

lambder14:05:42

after adding (doto prn) I can see my module hasn't been run

lambder14:05:44

:mirror.ui/duct-cljs {:main mirror.ui.core}

lambder14:05:42

the duct-cljs is modified duct.module/cljs

lambder14:05:13

(ns mirror.ui.duct-cljs
  (:require [clojure.string :as str]
            [duct.core :as core]
            [integrant.core :as ig]))
....


(derive :mirror.ui/duct-cljs :duct/module)

(defmethod ig/init-key :mirror.ui/duct-cljs [_ options]
  {:fn (fn [config]
         (let [path   (target-public-path config options)
               main   (:main options)
               config (if (= :production (get-environment config options))
                        (core/merge-configs config (compiler-config path main))
                        config)]
           config))})

lambder14:05:16

it looks like the module hasn't been run at all

lambder14:05:51

on other hand in repl when I do (dev) (go) config

lambder14:05:59

I can see the module has been run

lambder14:05:36

@weavejester what makes module to be run?

lambder14:05:38

I've replaced :mirror.ui/duct-cljs with :duct.module/cljs and it works

lambder14:05:16

how to run duct modules which are part of the project codebase

lambder14:05:30

e.g without having them in duct_hierarchy.edn

lambder14:05:21

my understanding was that (derive :mirror.ui/duct-cljs :duct/module) should do, no?

weavejester15:05:44

Only if the derive is in a namespace you’ve already loaded.

weavejester15:05:17

However, why not put the derives in duct_hierarchy.edn? That’s what it’s designed for.

weavejester15:05:51

Also, remind me again why you’re forgoing figwheel in development? Is there a problem with it?

lambder15:05:13

I want to run it via lein figwheel to have hot reaload

lambder15:05:45

derive is in the same ns as the module

weavejester15:05:51

By “hot reload” you mean reloading based on file change, rather than the (reset) command?

lambder15:05:52

why it is ignored?

lambder15:05:00

that's right

weavejester15:05:28

It needs to know that the module is a module first of all, which means checking if it derives from :duct/module.

weavejester15:05:50

So the derive needs to be in place before the module is loaded.

lambder15:05:16

it's just in the same ns top level

lambder15:05:24

so it is being called when the ns is loaded

lambder15:05:32

before the ig/init

weavejester15:05:39

Right, but that ns won’t be loaded unless it knows that it’s a module.

weavejester15:05:00

Duct looks at the keys in your configuration, determines which are modules, then loads the appropriate namespaces.

lambder15:05:04

but the ig/init is called

lambder15:05:11

I can see it

lambder15:05:23

but rather than beign treated as a module

lambder15:05:36

it is as a regular duct component

lambder15:05:53

which value is a function

weavejester16:05:02

Right - but it’s being loaded after the modules.

lambder16:05:10

that function (the module mod) is not being called

weavejester16:05:47

Duct looks at a configuration and asks “Which of these are modules?” then it loads in those modules, applies them to the configuration, and then runs ig/init across the augmented configuration.

weavejester16:05:05

In order to know if a key is a module, it needs the derive already in place.

weavejester16:05:41

duct_hierarchy.edn was created to provide a fast way of loading up all the key dependencies in a project, without the need to load in their namespaces.

đź‘Ť 4
lambder16:05:12

and that explains the different behaviour in repl

weavejester16:05:25

Namespace loading in Clojure is relatively slow, so it’s worth avoiding when we can.

lambder16:05:32

as the namespaces are reloaded

weavejester16:05:39

Instead of turning off Duct’s figwheel, have you considered either (a) binding a key in your editor to save-and-reset, or (b) using a file monitor library to trigger a reset on file change?