From 4f42dce649fd67ca68f3385e1d29275a340209b7 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 5 Mar 2026 14:43:29 +0100 Subject: [PATCH] refactor: use #shadow/env for replicant dev-http port instead of rewriting config Replace the pattern of reading shadow-cljs.edn, mutating it with pr-str (which destroyed formatting), and writing it back. Instead, use shadow-cljs's built-in `#shadow/env` reader tag to read the port from the SHADOW_HTTP_PORT environment variable at startup, with a default of 3001. Both `dev-replicant` and `dev-all` tasks now pass the port via env var instead of file mutation. This eliminates the dirty-file problem where the rewritten single-line config would show up as an unrelated change. --- bb.edn | 18 +++++------------- dev/replicant/shadow-cljs.edn | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/bb.edn b/bb.edn index e700818..e73a5fb 100644 --- a/bb.edn +++ b/bb.edn @@ -77,13 +77,10 @@ dev-replicant {:doc "Start replicant dev server (PORT env var, default 3001)" :depends [build-theme ensure-npm] - :requires ([clojure.edn :as edn]) :task (let [port (some-> (System/getenv "PORT") parse-long) - cfg-path "dev/replicant/shadow-cljs.edn"] - (when port - (let [cfg (edn/read-string (slurp cfg-path))] - (spit cfg-path (pr-str (assoc cfg :dev-http {port "public"}))))) - (shell {:dir "dev/replicant"} "npx" "shadow-cljs" "watch" "app"))} + env (cond-> {} port (assoc "SHADOW_HTTP_PORT" (str port)))] + (shell {:dir "dev/replicant" :extra-env env} + "npx" "shadow-cljs" "watch" "app"))} dev-squint {:doc "Start squint dev server (PORT env var, default 3002)" @@ -108,21 +105,16 @@ dev-all {:doc "Start all dev servers in tmux panes (bb dev-all [BASE_PORT], default 3000)" :depends [build-theme ensure-npm] - :requires ([clojure.edn :as edn]) :task (let [base (or (some-> (first *command-line-args*) parse-long) 3000) rport (+ base 1) sport (+ base 2) hport (+ base 3) - session "ui-dev" - ;; Write shadow-cljs.edn with the correct port before launching - cfg-path "dev/replicant/shadow-cljs.edn" - cfg (edn/read-string (slurp cfg-path))] - (spit cfg-path (pr-str (assoc cfg :dev-http {rport "public"}))) + session "ui-dev"] (shell {:continue true} "tmux kill-session -t" session) (shell "tmux new-session -d -s" session (str "PORT=" hport " bb dev-hiccup")) (shell "tmux split-window -h -t" session - (str "bash -c 'cd dev/replicant && npx shadow-cljs watch app'")) + (str "bash -c 'cd dev/replicant && SHADOW_HTTP_PORT=" rport " npx shadow-cljs watch app'")) (shell "tmux split-window -v -t" session (str "bash -c 'cd dev/squint && npx squint watch" " & cd dev/squint && npx vite --port " sport "'")) diff --git a/dev/replicant/shadow-cljs.edn b/dev/replicant/shadow-cljs.edn index 8b84fcc..f8f2fe8 100644 --- a/dev/replicant/shadow-cljs.edn +++ b/dev/replicant/shadow-cljs.edn @@ -1,5 +1,5 @@ {:deps true - :dev-http {3001 "public"} + :dev-http {#shadow/env ["SHADOW_HTTP_PORT" :as :int :default 3001] "public"} :builds {:app {:target :browser