Hi! This is a slightly broad question, I was wondering if there are any open source Clojure projects using https://playwright.dev/ that I can check? Or just any project for browser automation.
Seems like both https://github.com/logseq/logseq and https://github.com/penpot/penpot use it. But those are rather big projects.
logseq use playwright for e2e-test, along with clj lib https://github.com/pfeodrippe/wally code located in https://github.com/logseq/logseq/tree/master/clj-e2e
there's talk about using playwright in Clay on zulip in https://clojurians.zulipchat.com/#narrow/channel/422115-clay-dev/topic/investigate.20darkstar.20for.20static.20visualizations/with/539690073
Will check all of them out, thanks for your replies!
Thanks, will check this one out. It seems like this would be more my speed.
Hi, I am using nrepl via clj running from deps.edn, is there a way to run code in every namespace, e.g. (require '[clojure.pprint :refer [pprint]]) so I can keep my normal code free of development code?
Alternatively, use tap> which is part of clojure.core namespace, instead of pretty print.
Consider using Portal or similar taps source tools to inspect the results of each evaluation.
Using wrap-portal then a log of all evaluations can be navigated and filtered.
https://practical.li/clojure/data-inspector/portal/
Don't know an answer to that, but I myself prefer to have a single-segment dev namespace that's loaded but not explicitly required.
That way, I can use (dev/something ...) anywhere. Unless there's an alias like [... :as dev], which I don't use.
common solution is a deps.edn :dev alias that requires a clj file. Along the lines:
(ns user
(:require [clojure.pprint :refer [pprint]])) ; Initial require/refer for user ns
;; Hack: Redefine in-ns to auto-refer dev libs in *every* new namespace.
;; This works for manual (in-ns ...) calls and ns forms (which call in-ns internally).
(defn dev-auto-refer []
(require '[clojure.pprint :refer [pprint]]))
(def original-in-ns clojure.core/in-ns)
(defn my-in-ns [ns-sym]
(original-in-ns ns-sym)
(dev-auto-refer))
;; Now make it global: Swap the root of clojure.core/in-ns to point to our wrapper.
(alter-var-root #'clojure.core/in-ns (constantly #'my-in-ns))
(println "Autorequired namespaces.")
;; Optional: Add more global setup here, e.g., for debugging or other libs.
;; (require '[some.dev.lib :refer [some-macro]])
Then after running it by clj -A:dev it will load that file and pprint should work everywhere, as ns internally uses in-ns.This seems to have done the trick:
(ns user)
(do
(in-ns 'clojure.core)
(defn after-in-ns []
(require '[clojure.pprint :refer [pprint]])
(defonce original-in-ns clojure.core/in-ns)
(defn in-ns [ns-sym]
(original-in-ns ns-sym)
(when
(or
(clojure.string/starts-with? (str ns-sym) "user")
(clojure.string/starts-with? (str ns-sym) "project-name"))
(println (str "Altering namespace `" ns-sym "` with `after-in-ns`"))
(after-in-ns)))
(in-ns 'user))edited my reply above to do it actually.
btw: are you sure your solution works when jumping in different namespaces? seems to me that in-ns is in the user namespace only.
Wrapping it in the do block enables me to run it with cider.nrepl
that all being said, i personally do not like these "smart/hacky" solutions and stick to a rich comment:
(comment
(require '[clojure.pprint :refer [pprint]])
:end)
as usually there is more stuff there anyway, like obtaining context from integrant, example calls etc etc...I found hashp and my own reader tag literals convenient, e.g. you can have data_readers.clj in dev folder, once on classpath they are available everywhere without requires.
an old trick I haven't seen in a while is a namespace named . with all the dev conveniences. there was a library for it whose name I am forgetting. but in my personal experience user is not so onerous to type out while developing
@karol.adamiec that's interesting, and might be improved by copying what core does with repl-requires
user=> clojure.main/repl-requires
[[clojure.repl :refer (source apropos dir pst doc find-doc)] [clojure.java.javadoc :refer (javadoc)] [clojure.pprint :refer (pp pprint)] [clojure.repl.deps :refer (add-libs add-lib sync-deps)]]
ins)user=> (in-ns 'broken)
#object[clojure.lang.Namespace 0x12365c88 "broken"]
(ins)broken=> (pprint [1 2 3])
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: pprint in this context
(ins)broken=> (clojure.core/refer-clojure)
nil
(ins)broken=> (apply require clojure.main/repl-requires)
nil
(ins)broken=> (pprint [1 2 3])
[1 2 3]
nilthe advantage as I see it, is that eg. in an individual session I could conj another lib onto the requires, and that would update the auto-includes from that point on without having to fork the helper code
usually conjing onto something belonging to clojure.main would be a BAD IDEA but maybe given the fact it's explicitly repl affordance, you could argue for monkey patching that vector directly
I'd draw the line at publishing code that does that though - it should belong to the internals and the end user, and none of the middleware between should touch it IMHO
just stumbled on this. Yes, definitely do this, not what i hacked away at before 😄 https://insideclojure.org/2020/02/11/custom-repl/