|
270 | 270 | env-type))] |
271 | 271 | (assoc nrepl-client-map ::config/config (assoc config :nrepl-env-type final-env-type))))) |
272 | 272 |
|
| 273 | +(def ^:private cli-config-override-keys |
| 274 | + "Keys from the startup opts that override config.edn values." |
| 275 | + [:shadow-cljs-repl-message]) |
| 276 | + |
| 277 | +(defn- apply-cli-config-overrides |
| 278 | + "Applies CLI option overrides to the config attached to an nrepl-client-map. |
| 279 | + Only overrides keys that are explicitly provided (non-nil) in opts." |
| 280 | + [nrepl-client-map opts] |
| 281 | + (let [overrides (reduce (fn [m k] |
| 282 | + (if (some? (get opts k)) |
| 283 | + (assoc m k (get opts k)) |
| 284 | + m)) |
| 285 | + {} |
| 286 | + cli-config-override-keys)] |
| 287 | + (if (seq overrides) |
| 288 | + (update nrepl-client-map ::config/config merge overrides) |
| 289 | + nrepl-client-map))) |
| 290 | + |
273 | 291 | (defn create-and-start-nrepl-connection |
274 | 292 | "Creates an nREPL client map and loads configuration. |
275 | 293 |
|
|
282 | 300 | when the first eval-code call is made. |
283 | 301 |
|
284 | 302 | Takes initial-config map with optional :port, :host, :project-dir, :nrepl-env-type, |
285 | | - :config-file, :config-profile. |
| 303 | + :config-file, :config-profile, :shadow-cljs-repl-message. |
286 | 304 | - If :project-dir is provided, uses it directly (no REPL query needed) |
287 | 305 | - If :project-dir is NOT provided, queries REPL for project directory (requires :port) |
288 | 306 | - If :config-profile is provided, merges profile overlay on top of base config |
|
293 | 311 | (log/info "Creating nREPL client for port" port) |
294 | 312 | (log/info "Starting without nREPL connection (project-dir mode)")) |
295 | 313 | (try |
296 | | - (let [nrepl-client-map (nrepl/create (dissoc initial-config :project-dir :nrepl-env-type :config-profile)) |
| 314 | + (let [nrepl-client-map (nrepl/create (apply dissoc initial-config |
| 315 | + :project-dir :nrepl-env-type :config-profile |
| 316 | + cli-config-override-keys)) |
297 | 317 | cli-env-type (:nrepl-env-type initial-config) |
298 | | - _ (log/info "nREPL client map created")] |
299 | | - (if project-dir |
300 | | - ;; Project dir provided - load config directly, no REPL query needed |
301 | | - (let [user-dir (.getCanonicalPath (io/file project-dir)) |
302 | | - _ (log/info "Working directory set to:" user-dir) |
303 | | - config (load-config-handling-validation-errors config-file user-dir config-profile) |
304 | | - ;; Use cli-env-type or config's env-type, default to :clj |
305 | | - final-env-type (or cli-env-type |
306 | | - (:nrepl-env-type config) |
307 | | - :clj)] |
308 | | - (assoc nrepl-client-map ::config/config (assoc config :nrepl-env-type final-env-type))) |
309 | | - ;; No project dir - need to query REPL (requires port) |
310 | | - (let [;; Detect environment type (uses describe op, no full init needed) |
311 | | - env-type (nrepl/detect-nrepl-env-type nrepl-client-map) |
312 | | - _ (nrepl/set-port-env-type! nrepl-client-map env-type)] |
313 | | - (fetch-config nrepl-client-map config-file cli-env-type env-type project-dir config-profile)))) |
| 318 | + _ (log/info "nREPL client map created") |
| 319 | + result (if project-dir |
| 320 | + ;; Project dir provided - load config directly, no REPL query needed |
| 321 | + (let [user-dir (.getCanonicalPath (io/file project-dir)) |
| 322 | + _ (log/info "Working directory set to:" user-dir) |
| 323 | + config (load-config-handling-validation-errors config-file user-dir config-profile) |
| 324 | + ;; Use cli-env-type or config's env-type, default to :clj |
| 325 | + final-env-type (or cli-env-type |
| 326 | + (:nrepl-env-type config) |
| 327 | + :clj)] |
| 328 | + (assoc nrepl-client-map ::config/config (assoc config :nrepl-env-type final-env-type))) |
| 329 | + ;; No project dir - need to query REPL (requires port) |
| 330 | + (let [;; Detect environment type (uses describe op, no full init needed) |
| 331 | + env-type (nrepl/detect-nrepl-env-type nrepl-client-map) |
| 332 | + _ (nrepl/set-port-env-type! nrepl-client-map env-type)] |
| 333 | + (fetch-config nrepl-client-map config-file cli-env-type env-type project-dir config-profile)))] |
| 334 | + (apply-cli-config-overrides result initial-config)) |
314 | 335 | (catch Exception e |
315 | 336 | (log/error e "Failed to create nREPL connection") |
316 | 337 | (throw e)))) |
|
369 | 390 | (catch Exception _ false)))) |
370 | 391 | (s/def ::start-nrepl-cmd (s/coll-of string? :kind vector?)) |
371 | 392 | (s/def ::config-profile (s/or :keyword keyword? :symbol symbol? :string string?)) |
| 393 | +(s/def ::shadow-cljs-repl-message boolean?) |
372 | 394 | (s/def ::nrepl-args (s/keys :req-un [] |
373 | 395 | :opt-un [::port ::host ::config-file ::project-dir ::nrepl-env-type |
374 | | - ::start-nrepl-cmd ::config-profile])) |
| 396 | + ::start-nrepl-cmd ::config-profile ::shadow-cljs-repl-message])) |
375 | 397 |
|
376 | 398 | (def nrepl-client-atom (atom nil)) |
377 | 399 |
|
|
0 commit comments