Skip to content

Commit 432882f

Browse files
committed
Transform *.ext patterns to **.ext
1 parent 15e553d commit 432882f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Fixed
66

77
- Fix beholder watch functionality that would cause a NullPointerException earlier.
8+
- `*.<ext>` will now match files with `.ext` extensions in any directory.
89

910
## Changed
1011

src/kaocha/watch.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@
8787
(assoc tracker ::tracker-error e)
8888
(throw e)))))
8989

90+
(defn- fix-pattern
91+
"beholder, the file change watcher, will always produce fully qualified paths.
92+
A '*.<ext>' pattern will never match anything.
93+
Such a pattern will be prefixed with '*'.
94+
This will cause the pattern to match all files ending in '.<ext>' in any directory."
95+
[pattern]
96+
(assert (string? pattern))
97+
(if (str/starts-with? pattern "*.")
98+
(str "*" pattern)
99+
pattern))
100+
90101
(defn glob?
91102
"Does path match any of the glob patterns.
92103
@@ -96,7 +107,7 @@
96107
[path patterns]
97108
(assert (instance? Path path))
98109
(let [fs (FileSystems/getDefault)
99-
patterns (map #(.getPathMatcher fs (str "glob:" %)) patterns)]
110+
patterns (map #(.getPathMatcher fs (str "glob:" (fix-pattern %))) patterns)]
100111
(some #(.matches ^PathMatcher % path) patterns)))
101112

102113
(defn convert

0 commit comments

Comments
 (0)