|
20 | 20 | [ns-parser :as ns-parser]
|
21 | 21 | [prune-dependencies :refer [prune-dependencies]]
|
22 | 22 | [rebuild :refer [rebuild-ns-form]]]
|
23 |
| - [clojure.string :as str])) |
| 23 | + [clojure.string :as str] |
| 24 | + [clojure.java.io :as io])) |
24 | 25 |
|
25 | 26 | (defn- assert-no-exclude-clause
|
26 | 27 | [use-form]
|
|
35 | 36 | (assert-no-exclude-clause (core/get-ns-component ns-form :use))
|
36 | 37 | ns-form)
|
37 | 38 |
|
38 |
| -(defn clean-ns [{:keys [path]}] |
| 39 | +(defn clean-ns [{:keys [path relative-path]}] |
39 | 40 | {:pre [(seq path) (string? path) (core/source-file? path)]}
|
40 |
| - ;; Prefix notation not supported in cljs. |
41 |
| - ;; We also turn it off for cljc for reasons of symmetry |
42 |
| - (config/with-config {:prefix-rewriting (if (or (core/cljs-file? path) |
43 |
| - (core/cljc-file? path)) |
44 |
| - false |
45 |
| - (:prefix-rewriting config/*config*))} |
46 |
| - (let [ns-form (validate (core/read-ns-form-with-meta path)) |
47 |
| - deps-preprocessor (if (get config/*config* :prune-ns-form) |
48 |
| - #(prune-dependencies % path) |
49 |
| - identity) |
50 |
| - new-ns-form (-> (ns-parser/parse-ns path) |
51 |
| - deps-preprocessor |
52 |
| - (rebuild-ns-form ns-form))] |
53 |
| - (when-not (= ns-form new-ns-form) |
54 |
| - new-ns-form)))) |
| 41 | + ;; Try first the absolute, then the relative path |
| 42 | + (let [path (first (filter #(some-> % io/file .exists) [path relative-path]))] |
| 43 | + ;; Prefix notation not supported in cljs. |
| 44 | + ;; We also turn it off for cljc for reasons of symmetry |
| 45 | + (config/with-config {:prefix-rewriting (if (or (core/cljs-file? path) |
| 46 | + (core/cljc-file? path)) |
| 47 | + false |
| 48 | + (:prefix-rewriting config/*config*))} |
| 49 | + (let [ns-form (validate (core/read-ns-form-with-meta path)) |
| 50 | + deps-preprocessor (if (get config/*config* :prune-ns-form) |
| 51 | + #(prune-dependencies % path) |
| 52 | + identity) |
| 53 | + new-ns-form (-> (ns-parser/parse-ns path) |
| 54 | + deps-preprocessor |
| 55 | + (rebuild-ns-form ns-form))] |
| 56 | + (when-not (= ns-form new-ns-form) |
| 57 | + new-ns-form))))) |
0 commit comments