From 0078fe68bb57061bd796145ef1b830cfe60aae14 Mon Sep 17 00:00:00 2001 From: ikappaki Date: Sat, 4 Dec 2021 19:03:39 +0000 Subject: [PATCH 1/2] Ignore Emacs lock files from visualization Also upgraded shadow-cljs to 2.16.7 to solve potential issue with gitlibs on MS-Windows. --- .gitignore | 1 + deps.edn | 12 +++++++++--- package.json | 2 +- src/nextjournal/clerk.clj | 16 +++++++++++++--- test/nextjournal/clerk_test.clj | 13 +++++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 test/nextjournal/clerk_test.clj diff --git a/.gitignore b/.gitignore index 7d9456f95..f8b315e20 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ clerk.iml public/girouette.css public/images/ yarn.lock +*~ diff --git a/deps.edn b/deps.edn index f7b366101..07c869294 100644 --- a/deps.edn +++ b/deps.edn @@ -31,7 +31,7 @@ :dev {:extra-deps {arrowic/arrowic {:mvn/version "0.1.1"} binaryage/devtools {:mvn/version "1.0.3"} cider/cider-nrepl {:mvn/version "0.26.0"} - thheller/shadow-cljs {:mvn/version "2.15.9"}} + thheller/shadow-cljs {:mvn/version "2.16.7"}} :extra-paths ["dev"] :jvm-opts ["-Dclerk.live_js=true" "-XX:-OmitStackTraceInFastThrow"] :main-opts ["-m" "shadow.cljs.devtools.cli"]} @@ -43,8 +43,14 @@ :build {:deps {io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"} io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"} - io.github.nextjournal/cas {:git/url "git@github.com:nextjournal/cas" + io.github.nextjournal/cas {:git/url "https://github.com/nextjournal/cas" :git/sha "5e8079b720e347b9466db9c2282ce79a125a011c"} rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"} babashka/fs {:mvn/version "0.0.5"}} - :ns-default build}}} + :ns-default build} + + :test {:extra-paths ["test"] + :extra-deps {io.github.cognitect-labs/test-runner + {:git/tag "v0.5.0" :git/sha "b3fd0d2"}} + :main-opts ["-m" "cognitect.test-runner"] + :exec-fn cognitect.test-runner.api/test}}} diff --git a/package.json b/package.json index 2487b4580..e4c9ea4d0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "shadow-cljs": "^2.15.13", + "shadow-cljs": "^2.16.7", "tailwindcss": "2.2.12" } } diff --git a/src/nextjournal/clerk.clj b/src/nextjournal/clerk.clj index 8ab28d4b5..87c82fda8 100644 --- a/src/nextjournal/clerk.clj +++ b/src/nextjournal/clerk.clj @@ -175,11 +175,21 @@ (webserver/show-error! e) (throw e)))) +(defn supported-file? + "Returns whether PATH points to a file that can be visualized." + [path] + + ;; Notes + ;; + ;; 1. file names starting with .# are most likely Emacs lock files + ;; and should be ignored. + (->> path io/file .getName + (re-matches #"(?!^\.#).+\.(md|clj|cljc)$") + some?)) + (defn file-event [{:keys [type path]}] (when (and (contains? #{:modify :create} type) - (or (str/ends-with? path ".md") - (str/ends-with? path ".clj") - (str/ends-with? path ".cljc"))) + (supported-file? path)) (binding [*ns* (find-ns 'user)] (let [rel-path (str/replace (str path) (str (fs/canonicalize ".") fs/file-separator) "") show-file? (or (not @!show-filter-fn) diff --git a/test/nextjournal/clerk_test.clj b/test/nextjournal/clerk_test.clj new file mode 100644 index 000000000..9cbc7d16a --- /dev/null +++ b/test/nextjournal/clerk_test.clj @@ -0,0 +1,13 @@ +(ns nextjournal.clerk-test + (:require [nextjournal.clerk :as c] + [clojure.test :as t])) + +(t/deftest supported-filenames + (t/is (= true (c/supported-file? "xyz/name.md"))) + (t/is (= true (c/supported-file? "xyz/name.clj"))) + (t/is (= true (c/supported-file? "name.clj"))) + (t/is (= true (c/supported-file? "xyz/name.cljc"))) + (t/is (= false (c/supported-file? "xyz/name.any"))) + (t/is (= false (c/supported-file? "xyz/.#name.cljc"))) + (t/is (= true (c/supported-file? "xyz/abc.#name.cljc"))) + ) From 1a086e1d52a787368c0e866cf0ffef36744681fa Mon Sep 17 00:00:00 2001 From: Martin Kavalar Date: Wed, 8 Dec 2021 13:20:04 +0100 Subject: [PATCH 2/2] Move tests inline & revert cas coord change --- deps.edn | 10 ++-------- src/nextjournal/clerk.clj | 15 +++++++++------ test/nextjournal/clerk_test.clj | 13 ------------- 3 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 test/nextjournal/clerk_test.clj diff --git a/deps.edn b/deps.edn index 07c869294..62cc0659e 100644 --- a/deps.edn +++ b/deps.edn @@ -43,14 +43,8 @@ :build {:deps {io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"} io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"} - io.github.nextjournal/cas {:git/url "https://github.com/nextjournal/cas" + io.github.nextjournal/cas {:git/url "git@github.com:nextjournal/cas" :git/sha "5e8079b720e347b9466db9c2282ce79a125a011c"} rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"} babashka/fs {:mvn/version "0.0.5"}} - :ns-default build} - - :test {:extra-paths ["test"] - :extra-deps {io.github.cognitect-labs/test-runner - {:git/tag "v0.5.0" :git/sha "b3fd0d2"}} - :main-opts ["-m" "cognitect.test-runner"] - :exec-fn cognitect.test-runner.api/test}}} + :ns-default build}}} diff --git a/src/nextjournal/clerk.clj b/src/nextjournal/clerk.clj index 87c82fda8..3564e7e1a 100644 --- a/src/nextjournal/clerk.clj +++ b/src/nextjournal/clerk.clj @@ -176,17 +176,20 @@ (throw e)))) (defn supported-file? - "Returns whether PATH points to a file that can be visualized." + "Returns whether `path` points to a file that should be shown." [path] - - ;; Notes - ;; - ;; 1. file names starting with .# are most likely Emacs lock files - ;; and should be ignored. + ;; file names starting with .# are most likely Emacs lock files and should be ignored. (->> path io/file .getName (re-matches #"(?!^\.#).+\.(md|clj|cljc)$") some?)) +#_(supported-file? "foo_bar.clj") +#_(supported-file? "xyz/foo.md") +#_(supported-file? "xyz/foo.clj") +#_(supported-file? "xyz/abc.#name.cljc") +#_(supported-file? ".#name.clj") +#_(supported-file? "xyz/.#name.cljc") + (defn file-event [{:keys [type path]}] (when (and (contains? #{:modify :create} type) (supported-file? path)) diff --git a/test/nextjournal/clerk_test.clj b/test/nextjournal/clerk_test.clj deleted file mode 100644 index 9cbc7d16a..000000000 --- a/test/nextjournal/clerk_test.clj +++ /dev/null @@ -1,13 +0,0 @@ -(ns nextjournal.clerk-test - (:require [nextjournal.clerk :as c] - [clojure.test :as t])) - -(t/deftest supported-filenames - (t/is (= true (c/supported-file? "xyz/name.md"))) - (t/is (= true (c/supported-file? "xyz/name.clj"))) - (t/is (= true (c/supported-file? "name.clj"))) - (t/is (= true (c/supported-file? "xyz/name.cljc"))) - (t/is (= false (c/supported-file? "xyz/name.any"))) - (t/is (= false (c/supported-file? "xyz/.#name.cljc"))) - (t/is (= true (c/supported-file? "xyz/abc.#name.cljc"))) - )