diff --git a/sci b/sci index 0da67e32..a92fce09 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 0da67e32e2930aa0ea18c9350b8a40fc0b9cb502 +Subproject commit a92fce09210f47a8243a30e6d4a0a6febca21c27 diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 6d8ee62d..ea6b2e16 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -32,6 +32,7 @@ [clojure.string :as str] [sci.addons :as addons] [sci.core :as sci] + [sci.impl.namespaces :as sci-namespaces] [sci.impl.unrestrict :refer [*unrestricted*]] [sci.impl.vars :as vars]) (:gen-class)) @@ -479,11 +480,18 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that (System/getenv "BABASHKA_CLASSPATH")) _ (when classpath (add-classpath* classpath)) - load-fn (fn [{:keys [:namespace]}] - (when-let [{:keys [:loader]} @cp-state] - (let [res (cp/source-for-namespace loader namespace nil)] - (when uberscript (swap! uberscript-sources conj (:source res))) - res))) + load-fn (fn [{:keys [:namespace :reload]}] + (when-let [{:keys [:loader]} + @cp-state] + (if ;; ignore built-in namespaces when uberscripting, unless with :reload + (and uberscript + (not reload) + (or (contains? namespaces namespace) + (contains? sci-namespaces/namespaces namespace))) + "" + (let [res (cp/source-for-namespace loader namespace nil)] + (when uberscript (swap! uberscript-sources conj (:source res))) + res)))) _ (when file (let [abs-path (.getAbsolutePath (io/file file))] (vars/bindRoot sci/file abs-path) @@ -516,8 +524,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that :classes classes/class-map :imports imports :load-fn load-fn - :dry-run uberscript - :reload true + :uberscript uberscript :readers core/data-readers} opts (addons/future opts) sci-ctx (sci/init opts) diff --git a/test-resources/babashka/uberscript/src/my/impl.clj b/test-resources/babashka/uberscript/src/my/impl.clj new file mode 100644 index 00000000..0dfd77e7 --- /dev/null +++ b/test-resources/babashka/uberscript/src/my/impl.clj @@ -0,0 +1,6 @@ +(ns my.impl + (:require [clojure.string])) + +(defn impl-fn + "identity" + [x] x) diff --git a/test-resources/babashka/uberscript/src/my/impl2.clj b/test-resources/babashka/uberscript/src/my/impl2.clj new file mode 100644 index 00000000..d5483e20 --- /dev/null +++ b/test-resources/babashka/uberscript/src/my/impl2.clj @@ -0,0 +1,4 @@ +(ns my.impl2 + (:require [my.impl :as impl])) + +(def impl-fn impl/impl-fn) diff --git a/test-resources/babashka/uberscript/src/my/main.clj b/test-resources/babashka/uberscript/src/my/main.clj new file mode 100644 index 00000000..ea0b6d59 --- /dev/null +++ b/test-resources/babashka/uberscript/src/my/main.clj @@ -0,0 +1,6 @@ +(ns my.main + (:require [my.impl :as impl]) + (:require [my.impl2 :as impl2])) + +(defn -main [& args] + (impl/impl-fn args)) diff --git a/test/babashka/classpath_test.clj b/test/babashka/classpath_test.clj index 0e4c363e..618f2d8d 100644 --- a/test/babashka/classpath_test.clj +++ b/test/babashka/classpath_test.clj @@ -39,7 +39,12 @@ (.deleteOnExit tmp-file) (is (empty? (tu/bb nil "--classpath" "test-resources/babashka/src_for_classpath_test" "-m" "my.main" "--uberscript" (.getPath tmp-file)))) (is (= "(\"1\" \"2\" \"3\" \"4\")\n" - (tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4"))))) + (tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4"))) + (testing "order of namespaces is correct" + (tu/bb nil "--classpath" "test-resources/babashka/uberscript/src" "-m" "my.main" "--uberscript" (.getPath tmp-file)) + (prn (slurp (.getPath tmp-file))) + (is (= "(\"1\" \"2\" \"3\" \"4\")\n" + (tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4")))))) (deftest error-while-loading-test (is (true?