https://github.com/weavejester/ns-tracker
Library to keep track of changes to Clojure source files
https://github.com/weavejester/ns-tracker
clojure dependency-tracker repl ring
Last synced: about 1 month ago
JSON representation
Library to keep track of changes to Clojure source files
- Host: GitHub
- URL: https://github.com/weavejester/ns-tracker
- Owner: weavejester
- License: epl-1.0
- Created: 2011-10-01T20:14:22.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-06-19T16:34:54.000Z (11 months ago)
- Last Synced: 2025-03-31T14:59:45.417Z (about 2 months ago)
- Topics: clojure, dependency-tracker, repl, ring
- Language: Clojure
- Homepage:
- Size: 57.6 KB
- Stars: 116
- Watchers: 8
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ns-tracker
[](https://github.com/weavejester/ns-tracker/actions/workflows/test.yml)
ns-tracker is a Clojure library for keeping track of changes to source
files and their associated namespaces. This is usually used to
automatically reload modified namespaces in a running Clojure
application.It is derived from code in Stuart Sierra's [Lazytest][] tool, and the
credit for writing the vast majority of the code used in this library
should therefore go to him.[lazytest]: https://github.com/stuartsierra/lazytest
## Installation
Add the following dependency to your deps.edn file:
ns-tracker/ns-tracker {:mvn/version "1.0.0"}
Or this to your Leiningen dependencies:
[ns-tracker "1.0.0"]
## Usage
Use the `ns-tracker.core/ns-tracker` function to create a new tracker
function for one or more source directories:(require '[ns-tracker.core :as nt])
(def modified-namespaces
(nt/ns-tracker ["src" "test"]))When you call the `modified-namespaces` function, it will return a list
of Clojure namespaces that have changed. You can then reload them on
the fly:(doseq [ns-sym (modified-namespaces)]
(require ns-sym :reload))This can be placed in a background thread, or triggered by some user
request.### Declaring Dependencies to Static Resources
Some Clojure libraries, such as
[HugSQL](https://www.hugsql.org/#using-def-db-fns), define functions in
a namespace based on the content of a static resource file. ns-tracker
is able to reload such a namespace when the resource file is modified
with the help of a bit metadata.You will need to declare the resources under the
`:ns-tracker/resource-deps` key in the namespace's metadata:(ns example.db
{:ns-tracker/resource-deps ["sql/queries.sql"]}
(:require example.utils))The resource path needs to be relative to one of the source directories
which you gave as a parameter to the `ns-tracker.core/ns-tracker`
function.## License
Copyright © 2024 James Reeves, Stuart Sierra
Distributed under the Eclipse Public License.