Question

Ring comes with the middleware 'reload' (https://github.com/ring-clojure/ring/blob/master/ring-devel/src/ring/middleware/reload.clj). It's based on ns-tracker (https://github.com/weavejester/ns-tracker). ns-tracker looks through source directories for likely source files that begin with an ns form. It builds a dependency graph from the information contained in those ns forms. This of course works perfectly, but only for dependencies explicitly included in the ns form.

There's an idiom in Clojure where a namespace is broken into several files. There is a single source file that defines a namespace (with an ns form). This file can contain any number of top-level forms, but notably will include loads, normally at the top level but not necessarily I suppose. The files loaded begin with in-ns forms. This is not as obscure a technique as you might think... clojure.core uses it.

The contents of these loaded files do not in themselves constitute modules, nor can they necessarily be coerced into being modules (circular dependencies etc).

ns-tracker does not scan source files looking for load expressions nor does it look for in-ns forms. And the reasons are clear enough. But it really messes up my workflow since changes to the loaded files, obviously, will not reload the namespace.

Does anyone know if there's a library that deals with explicitly loaded source files? If there isn't something I'll hack something together (probably by writing some ugly macro around load) and make it available publicly.

Was it helpful?

Solution

Okay, answering my question... I have extended ns-tracker and submitted a pull request. It's less hacky that I expected, actually reasonably reasonable.

My fork is at: https://github.com/hutch/ns-tracker

There are a number of changes to ns-tracker included. Specifically to my question, it supports the usage of load/in-ns in the way used by clojure/core.

You can use this fork in your projects by using the leiningen 'checkouts' mechanism.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top