<< Back to previous view

[TNS-48] Ability to track files that are not namespaces Created: 03/Nov/17  Updated: 18/Sep/18

Status: Open
Project: tools.namespace
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Ray Huang Assignee: Stuart Sierra
Resolution: Unresolved Votes: 2
Labels: None

Attachments: Text File tns-48-1.patch    


Support tracking non-clojure files when performing a refresh. The idea here is to make the reloaded workflow work well for libraries like HugSQL (which may depend on non-clojure files in the project).

See https://github.com/layerware/hugsql/issues/72 for some additional context

Comment by Stuart Sierra [ 16/Jan/18 4:54 PM ]

I have been aware of the value of this feature for a long time now, but I expect it would require significant, breaking changes to the internal data structures used by tools.namespace.

Comment by Ray Huang [ 01/Feb/18 2:40 AM ]

I've been thinking about the internal data structures for a bit, I think it may be possible to track this without breaking the internal data structures. The insight is that we need to determine `modified` clojure source files by taking the max modified timestamp of the clojure src file and any of it's external dependencies.

This would require three changes:

1. a way of defining external file dependencies (perhaps as metadata on the namespaces). Example:

(ns my.testing.ns
  {:clojure.tools.namespace.files/filedeps #{"resources/foo1.properties" 

2. a new entry in tracker named ::files/filedeps that maps source files -> other files.

3. update the `modified-files` predicate to take in `file-deps`, roughly like so:

(defn- modified? [tracker ^File file]
  (let [filedeps  (get-in tracker [::file/filedeps file])
        time (::time tracker 0)]
    (or (< time (.lastModified file))
        (< time (apply max (map #(.lastModified %) filedeps)))
        (not-every? #(.exists %) filedeps))))

(defn- modified-files [tracker files]
  (filter #(modified? tracker %) files))
Comment by Ray Huang [ 10/Feb/18 12:22 PM ]

I took a stab at implementing this, would love your thoughts. The docs do need a bit of work to explain how this works though.

Comment by Ray Huang [ 27/Jul/18 1:25 PM ]

Following Stuart's advice, I've created a fork with some instructions for how to set it up! https://github.com/rymndhng/tools.namespace

Comment by Daniel Compton [ 18/Sep/18 10:01 PM ]

I'm trying this out now and it seems to do just what I want. The only thing I'm noticing is that there is no indication that a filedep has changed in the `:reloading` message, it only shows the namespaces. Not sure how/if you want to show that though.

Generated at Sun May 19 14:23:51 CDT 2019 using JIRA 4.4#649-r158309.