Skip to content

Commit 35813ab

Browse files
committed
Warn when merging shadow-cljs configs and build-ids conflict
1 parent c676f18 commit 35813ab

File tree

7 files changed

+111
-93
lines changed

7 files changed

+111
-93
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
## Added
44

5-
## Fixed
6-
7-
## Changed
5+
- Warn when merging shadow-cljs configs and build-ids conflict
86

97
# 0.30.139-alpha (2024-06-12 / 3221f94)
108

@@ -237,4 +235,4 @@ Initial release
237235
- lambdaisland.classpath integration
238236
- Support for cider-nrepl, refactor-nrepl
239237
- Basic support for shadow-cljs cljs nREPL-base REPL
240-
- Auto-connect for Emacs
238+
- Auto-connect for Emacs

deps.edn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{:paths ["src" "resources"]
22

33
:deps
4-
{org.clojure/clojure {:mvn/version "1.11.1"}
4+
{org.clojure/clojure {:mvn/version "1.11.2"}
55
com.lambdaisland/dotenv {:mvn/version "0.2.5"}}
66

77
:aliases
88
{:clojure
9-
{:extra-deps {babashka/babashka {:mvn/version "1.3.188" :scope "provided"}
9+
{:extra-deps {babashka/babashka {:mvn/version "1.3.190" :scope "provided"}
1010
org.clojure/tools.deps.alpha {:mvn/version "0.15.1254"}
1111
com.nextjournal/beholder {:mvn/version "1.0.2"}
12-
thheller/shadow-cljs {:mvn/version "2.26.5"}
12+
thheller/shadow-cljs {:mvn/version "2.28.3"}
1313
;; prevent tools.deps.alpha from dragging in an old guava
14-
com.google.guava/guava {:mvn/version "33.0.0-jre"}
14+
com.google.guava/guava {:mvn/version "33.1.0-jre"}
1515
com.lambdaisland/classpath {:mvn/version "0.5.48"}}}
1616
:dev
1717
{:extra-paths ["dev"]
1818
:extra-deps {djblue/portal {:mvn/version "RELEASE"}}}
1919

2020
:test
2121
{:extra-paths ["test"]
22-
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}}}
22+
:extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}}
2323

2424
:self-deps
2525
{:extra-deps {com.lambdaisland/launchpad-deps {:local/root "resources/launchpad"}}}

resources/launchpad/deps.edn

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
;; things to use. We keep it in deps.edn format so antq can automatically
33
;; upgrade versions.
44
{:deps
5-
{com.lambdaisland/launchpad {:mvn/version "0.22.110-alpha"}
5+
{com.lambdaisland/launchpad {:mvn/version "0.28.129-alpha"}
66
com.lambdaisland/classpath {:mvn/version "0.5.48"}
7-
com.github.jnr/jnr-posix {:mvn/version "3.1.18"}
8-
thheller/shadow-cljs {:mvn/version "2.26.5"}
9-
com.google.guava/guava {:mvn/version "33.0.0-jre"}
10-
cider/cider-nrepl {:mvn/version "0.45.0"}
11-
nrepl/nrepl {:mvn/version "1.1.0"}
12-
refactor-nrepl/refactor-nrepl {:mvn/version "3.9.1"}
13-
djblue/portal {:mvn/version "0.51.1"}
7+
com.github.jnr/jnr-posix {:mvn/version "3.1.19"}
8+
thheller/shadow-cljs {:mvn/version "2.28.3"}
9+
com.google.guava/guava {:mvn/version "33.1.0-jre"}
10+
cider/cider-nrepl {:mvn/version "0.47.1"}
11+
nrepl/nrepl {:mvn/version "1.1.1"}
12+
refactor-nrepl/refactor-nrepl {:mvn/version "3.10.0"}
13+
djblue/portal {:mvn/version "0.55.1"}
1414
com.billpiel/sayid {:mvn/version "0.1.0"}
15-
com.gfredericks/debug-repl {:mvn/version "0.0.12"}
15+
com.gfredericks/debug-repl {:mvn/version "0.3.1-p1"}
1616
}}

src/lambdaisland/launchpad.clj

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[clojure.pprint :as pprint]
99
[clojure.string :as str]
1010
[clojure.tools.cli :as tools-cli]
11-
[lambdaisland.dotenv :as dotenv])
11+
[lambdaisland.dotenv :as dotenv]
12+
[lambdaisland.launchpad.log :refer :all])
1213
(:import
1314
(java.io InputStream OutputStream)
1415
(java.lang Process ProcessBuilder)
@@ -63,13 +64,6 @@
6364
;; the current version in `bb.edn`"
6465
;; {:mvn/version "RELEASE"})
6566

66-
(def verbose? (some #{"-v" "--verbose"} *command-line-args*))
67-
68-
(defn debug [& args] (when verbose? (apply println (java.util.Date.) "[DEBUG]" args)))
69-
(defn info [& args] (apply println (java.util.Date.) "[INFO]" args))
70-
(defn warn [& args] (apply println (java.util.Date.) "[WARN]" args))
71-
(defn error [& args] (apply println (java.util.Date.) "[ERROR]" args))
72-
7367
(defn shellquote [a]
7468
(let [a (str a)]
7569
(cond
@@ -444,10 +438,11 @@
444438
(assoc :shadow-cljs/connect-ids connect-ids)
445439
(update :eval-forms (fnil conj [])
446440
'(require 'lambdaisland.launchpad.shadow)
447-
`(apply
448-
lambdaisland.launchpad.shadow/start-builds!
449-
(filter (set (keys (:builds (lambdaisland.launchpad.shadow/merged-config))))
450-
~(vec build-ids)))))
441+
`(let [config# (lambdaisland.launchpad.shadow/merged-config)]
442+
(apply
443+
lambdaisland.launchpad.shadow/start-builds! config#
444+
(filter (set (keys (:builds config#)))
445+
~(vec build-ids))))))
451446
ctx)))
452447

453448
(defn maybe-connect-emacs [{:keys [options nrepl-port project-root] :as ctx}]

src/lambdaisland/launchpad/log.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns lambdaisland.launchpad.log)
2+
3+
(def verbose? (some #{"-v" "--verbose"} *command-line-args*))
4+
5+
(defn debug [& args] (when verbose? (apply println #_(str (java.util.Date.)) "[DEBUG]" args)))
6+
(defn info [& args] (apply println #_(str (java.util.Date.)) "[INFO]" args))
7+
(defn warn [& args] (apply println #_(str (java.util.Date.)) "[WARN]" args))
8+
(defn error [& args] (apply println #_(str (java.util.Date.)) "[ERROR]" args))

src/lambdaisland/launchpad/shadow.clj

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
(ns ^:no-doc ;TODO re-enable
2-
lambdaisland.launchpad.shadow
3-
(:require [clojure.java.io :as io]
4-
[shadow.cljs.devtools.api :as api]
5-
[shadow.cljs.devtools.config :as config]
6-
[shadow.cljs.devtools.server :as server]
7-
[shadow.cljs.devtools.server.runtime :as runtime]
8-
[lambdaisland.classpath :as licp])
1+
(ns lambdaisland.launchpad.shadow
2+
"Shadow-cljs support, generates a shadow-cljs config based on subprojects."
3+
(:require
4+
[clojure.java.io :as io]
5+
[clojure.string :as str]
6+
[lambdaisland.classpath :as licp]
7+
[lambdaisland.launchpad.log :as log]
8+
[shadow.cljs.devtools.api :as api]
9+
[shadow.cljs.devtools.config :as config]
10+
[shadow.cljs.devtools.server :as server]
11+
[shadow.cljs.devtools.server.runtime :as runtime])
912
(:import (java.nio.file Path)))
1013

1114
(def process-root
@@ -53,61 +56,73 @@
5356
"Given multiple locations that contain a shadow-cljs.edn, merge them into a
5457
single config, where the path locations have been updated."
5558
[module-paths]
56-
(-> (apply
57-
merge-with
58-
(fn [a b]
59-
(cond
60-
(and (map? a) (map? b))
61-
(merge a b)
62-
(and (set? a) (set? b))
63-
(into a b)
64-
:else
65-
b))
66-
(for [module-path module-paths
67-
:let [module-root (.toAbsolutePath (Path/of module-path (into-array String [])))
68-
config-file (str (.resolve module-root "shadow-cljs.edn"))
69-
module-name (str (.getFileName module-root))]]
70-
(-> config-file
71-
read-shadow-config
72-
(update
73-
:builds
74-
(fn [builds]
75-
(into {}
76-
(map (fn [[k v]]
77-
(let [build-id k
78-
;; Not sure yet if this is a good idea
79-
#_(if (qualified-keyword? k)
80-
k
81-
(keyword module-name (name k)))]
82-
[build-id
83-
(assoc (update-build-keys process-root module-root v)
84-
:build-id build-id
85-
:js-options (if (= "" module-path)
86-
{}
87-
{:js-package-dirs [(str module-path "/node_modules")]}))])))
59+
(let [modules
60+
(for [module-path module-paths
61+
:let [module-root (.toAbsolutePath (Path/of module-path (into-array String [])))
62+
config-file (str (.resolve module-root "shadow-cljs.edn"))
63+
module-name (str (.getFileName module-root))]]
64+
{:module-path module-path
65+
:module-root module-root
66+
:config-file config-file
67+
:module-name module-name
68+
:config (read-shadow-config config-file)})]
69+
(doseq [[build-id modules]
70+
(group-by :build-id (for [{:keys [config module-name]} modules
71+
[build-id] (:builds config)]
72+
{:build-id build-id
73+
:module-name module-name}))
74+
:when (< 1 (count modules))]
75+
(log/warn "Shadow-cljs build-id conflict:" build-id "used in" (str/join ", " (map :module-name modules)) ". Ensure build-ids are unique to prevent issues."))
76+
(-> (apply
77+
merge-with
78+
(fn [a b]
79+
(cond
80+
(and (map? a) (map? b))
81+
(merge a b)
82+
(and (set? a) (set? b))
83+
(into a b)
84+
:else
85+
b))
86+
(for [{:keys [config module-root module-path]} modules]
87+
(update
88+
config
89+
:builds
90+
(fn [builds]
91+
(into {}
92+
(map (fn [[k v]]
93+
(let [build-id k
94+
;; Not sure yet if this is a good idea
95+
#_(if (qualified-keyword? k)
96+
k
97+
(keyword module-name (name k)))]
98+
[build-id
99+
(assoc (update-build-keys process-root module-root v)
100+
:build-id build-id
101+
:js-options (if (= "" module-path)
102+
{}
103+
{:js-package-dirs [(str module-path "/node_modules")]}))])))
88104

89-
builds))))))
90-
(assoc :deps {})
91-
(dissoc :source-paths :dependencies)))
105+
builds)))))
106+
(assoc :deps {})
107+
(dissoc :source-paths :dependencies))))
92108

93109
(defn merged-config
94110
"Return a complete, combined, shadow-cljs config map, that combines all
95111
shadow-cljs.edn files found in projects that were references via :local/root."
96112
[]
97113
(merged-shadow-config (find-shadow-roots)))
98114

99-
(defn start-builds! [& build-ids]
115+
(defn start-builds! [config & build-ids]
100116
(when (nil? @runtime/instance-ref)
101-
(let [config (merged-config)]
102-
(server/start! config)
103-
(doseq [build-id build-ids]
104-
(-> (get-in config [:builds build-id])
105-
(assoc :build-id build-id)
106-
api/watch))
107-
(loop []
108-
(when (nil? @runtime/instance-ref)
109-
(Thread/sleep 250)
110-
(recur))))))
117+
(server/start! config)
118+
(doseq [build-id build-ids]
119+
(-> (get-in config [:builds build-id])
120+
(assoc :build-id build-id)
121+
api/watch))
122+
(loop []
123+
(when (nil? @runtime/instance-ref)
124+
(Thread/sleep 250)
125+
(recur)))))
111126

112127
#_(start-builds :main)
113128
#_(require 'shadow.build)

src/lambdaisland/launchpad/watcher.clj

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
specific directories. This can be done with [[watch!]], which will start the
66
minimum number of watchers to cover all directories, and will dispatch to the
77
right handler based on the changed file."
8-
(:require [nextjournal.beholder :as beholder]
9-
[clojure.java.io :as io])
10-
(:import java.util.regex.Pattern
11-
java.nio.file.LinkOption
12-
java.nio.file.Files
13-
java.nio.file.Paths
14-
java.nio.file.Path
15-
java.io.File
16-
io.methvin.watcher.DirectoryWatcher))
8+
(:require
9+
[nextjournal.beholder :as beholder]
10+
[clojure.java.io :as io])
11+
(:import
12+
java.util.regex.Pattern
13+
java.nio.file.LinkOption
14+
java.nio.file.Files
15+
java.nio.file.Paths
16+
java.nio.file.Path
17+
java.io.File
18+
io.methvin.watcher.DirectoryWatcher))
1719

1820
(defonce handlers (atom nil))
1921
(defonce watchers (atom nil))

0 commit comments

Comments
 (0)