dev-tooling

mafcocinco 2024-04-20T14:48:46.848449Z

Question about clojure.tools.namespace . In past projects, I have used ns-tracker to reload namespaces on a locally running server. This worked well but I would like to transition to tools.namespace as it seems to be more robust in its handling of dependencies and namespace reloading. However, tools.namespace.repl/refresh does not work when I run it in a separate thread, which makes it challenging to use in combination with ns-tracker. The specific error I receive is this:

Exception in thread "Thread-0" java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
There could be something I'm doing incorrectly when setting this up. I'm not particularly wedded to ns-tracker. Primarily, I would like to know what the proper way to do hot reloading of server code (running on a local machine) with clojure.tools.namespace?

vemv 2024-04-20T14:59:18.439139Z

It's more idiomatic to stop using ns-tracker and use t.n in conjunction with Component to also manage your local server or other such 'components'

vemv 2024-04-20T14:59:59.272449Z

Here's a nice template https://github.com/stuartsierra/reloaded (even if you weren't using Lein, you can just peek at the files)

mafcocinco 2024-04-20T15:00:24.538189Z

We are using polylith but I’m sure we can modify to make it work.

vemv 2024-04-20T15:00:57.538339Z

You can use poly with Component, or Integrant. t.n plays well with both

1
vemv 2024-04-20T15:01:40.341209Z

Lastly, generally, don't do any sort of code (re)loading from a parallel thread - require and friends are thread-unsafe, as of today

1
mafcocinco 2024-04-20T15:05:03.076569Z

So is it best practice now to just move off of ns-tracker?

vemv 2024-04-20T15:06:33.744109Z

I'd say it's a pretty old-school tool, very rare to see

1
vemv 2024-04-20T15:07:33.498939Z

https://github.com/tonsky/clj-reload aspires to be tools.namespace's successor , I'd say it's doing a good job at that and it already has CIDER support (personally I keep using t.n but I'm a cranky dev)

➕ 1