buildclojureclojurescriptleiningenshadow-cljs

How to improve the workflow of editing dependencies and watching the changes on a main Clojure/ClojureScript dynamic web app project?


I have been using Clojure, ClojureScript, lein, shadow-cljs, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic web app project.

There is the main repository, let's call it principal. And also a supporting repository, let's call it supporting.

Ok. On my local ~/projects folder, I have ~/projects/principal/ and also ~/projects/supporting.

As the names suggest, supporting is a dependency of principal.

Currently, the workflow to work on both repositories is extremely painful. I would like to know if there is a better way.

This is the current workflow:

1 - Build the project on principal with: cider-jack-in-cljs, I choose shadow-cljs, then shadow for REPL type, and app for build option.

2 - If principal needs a tweak on the interfaces of supporting, it is not possible to edit supporting directly and watch the changes live.

3 - Thus, I copy the function to be tweaked on supporting and paste it on principal. Then, I tweak namespaces and some names. I do the tweak and adjust the invocation. More importantly, I am able to watch the changes on the live app being displayed on localhost.

4 - Everything seems to work fine after some tests.

5 - Now, it is time to edit things on supporting repository. This time, with the proper namespaces and names. Also, it is time to remove the temporary duplicate on main

6 - It is not possible to watch the changes on supporting without re-building the whole thing on principal after doing a new lein install on supporting.

7 - After a lein install on supporting, quitting watch app and re-doing the entire build of principal, I can see the app live and check if everything is fine.

Is there a better way to achieve the same result?


Solution

  • As far as shadow-cljs is concerned it'll always watch files. The only rule is that it doesn't watch files in .jar, since those can't change. So, all you need is telling shadow-cljs where it can find the files.

    You didn't specify how you are managing dependencies, so I'm going to assume you just have them in shadow-cljs.edn :dependencies.

    One way to have shadow-cljs watch the supporting files is just adding the source paths directly.

    {:source-paths ["src/main" "../supporting/src/main"]
     :dependencies [[your/supporting "0.1.0"]]
     :builds ...}
    

    You keep the dependency as well, but by including the source path entry you ensure those files are used over the files in the installed .jar. You keep the declared supporting dependency so its dependencies are picked up properly.

    Another option is using lein checkouts and managing dependencies in project.clj. lein can also use the trick above by adding source paths outside the project.

    Another option is using deps.edn to manage dependencies and declaring the supporting dep via :local/root.

    {:paths ["src/main"]
     :deps {your/supporting {:local/root "../supporting"}}}