From 80350ebd1fe444f8dc52699a9816cbe68ed98955 Mon Sep 17 00:00:00 2001
From: Cam Saul <1455846+camsaul@users.noreply.github.com>
Date: Fri, 21 Jul 2023 13:19:32 -0700
Subject: [PATCH] Build script: make sure all orphan namespaces are compiled
 (#32540)

---
 bin/build/src/build/uberjar.clj | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/bin/build/src/build/uberjar.clj b/bin/build/src/build/uberjar.clj
index fa5d50a011a..9d6dfeae85f 100644
--- a/bin/build/src/build/uberjar.clj
+++ b/bin/build/src/build/uberjar.clj
@@ -64,14 +64,20 @@
    ns-decls))
 
 (defn metabase-namespaces-in-topo-order [basis]
-  (let [ns-decls   (mapcat
-                    (comp ns.find/find-ns-decls-in-dir io/file)
-                    (all-paths basis))
-        ns-symbols (set (map ns.parse/name-from-ns-decl ns-decls))]
-    (->> (dependencies-graph ns-decls)
-         ns.deps/topo-sort
-         (filter ns-symbols)
-         (cons 'metabase.bootstrap))))
+  (let [ns-decls   (into []
+                         (comp (map io/file)
+                               (mapcat ns.find/find-ns-decls-in-dir))
+                         (all-paths basis))
+        ns-symbols (into #{} (map ns.parse/name-from-ns-decl) ns-decls)
+        sorted     (->> (dependencies-graph ns-decls)
+                        ns.deps/topo-sort
+                        (filter ns-symbols))
+        orphans    (remove (set sorted) ns-symbols)
+        all        (concat orphans sorted)]
+    (assert (contains? (set all) 'metabase.bootstrap))
+    (when (contains? ns-symbols 'metabase-enterprise.core)
+      (assert (contains? (set all) 'metabase-enterprise.core)))
+    all))
 
 (defn compile-sources! [basis]
   (u/step "Compile Clojure source files"
-- 
GitLab