WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 6002681

Browse files
authored
[Fix #12] Introduce feature flags to make extension of io/Coercions optional
These allow dependent libraries to use `fs` without the side-effect of extend. Otherwise one can unawarely create issues, as seen in https://github.com/clojure-emacs/clj-refactor.el/issues/508. https://clojure.org/reference/protocols#_guidelines_for_extension says: > If you don’t own the protocol or the target type, you should only extend in app (not public lib) code, and expect to maybe be broken by either owner.
1 parent 04c7b1a commit 6002681

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/me/raynes/fs.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
(:refer-clojure :exclude [name parents])
44
(:require [clojure.zip :as zip]
55
[clojure.java.io :as io]
6-
[clojure.java.shell :as sh])
6+
[clojure.java.shell :as sh]
7+
[me.raynes.fs.feature-flags :as feature-flags])
78
(:import [java.io File FilenameFilter]
89
[java.nio.file Files Path LinkOption CopyOption]
910
[java.nio.file.attribute FileAttribute]))
@@ -141,10 +142,11 @@
141142
[path]
142143
(predicate isHidden (file path)))
143144

144-
(extend-protocol io/Coercions
145-
Path
146-
(as-file [this] (.toFile this))
147-
(as-url [this] (.. this (toFile) (toURL))))
145+
(when feature-flags/extend-coercions?
146+
(extend-protocol io/Coercions
147+
Path
148+
(as-file [this] (.toFile this))
149+
(as-url [this] (.. this (toFile) (toURL)))))
148150

149151
(defn- ^Path as-path
150152
"Convert `path` to a `java.nio.file.Path`.

src/me/raynes/fs/feature_flags.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(ns me.raynes.fs.feature-flags
2+
"Compile-time feature flags.
3+
4+
In order to use them:
5+
6+
* `require` this ns before any other ns from this lib.
7+
* `alter-var-root` a given feature flag within this ns to a different, desired value
8+
* proceed to `require` the rest of this library.")
9+
10+
(def extend-coercions?
11+
"Should the clojure.java.io/Coercions protocol be extended by this library?"
12+
true)

0 commit comments

Comments
 (0)