diff --git a/deps.edn b/deps.edn index d9ed180b..b89e400f 100644 --- a/deps.edn +++ b/deps.edn @@ -7,6 +7,7 @@ "feature-hiccup" "feature-test-check" "feature-spec-alpha" + "feature-malli" "pods/src" "babashka.nrepl/src" "depstar/src" "process/src" @@ -34,7 +35,8 @@ babashka/clojure-lanterna {:mvn/version "0.9.8-SNAPSHOT"} org.clojure/math.combinatorics {:mvn/version "0.1.6"} org.clojure/core.match {:mvn/version "1.0.0"} - hiccup/hiccup {:mvn/version "2.0.0-alpha2"}} + hiccup/hiccup {:mvn/version "2.0.0-alpha2"} + metosin/malli {:mvn/version "0.2.1"}} :aliases {:main {:main-opts ["-m" "babashka.main"]} :profile diff --git a/feature-malli/babashka/impl/malli.clj b/feature-malli/babashka/impl/malli.clj new file mode 100644 index 00000000..29ee6218 --- /dev/null +++ b/feature-malli/babashka/impl/malli.clj @@ -0,0 +1,11 @@ +(ns babashka.impl.malli + {:no-doc true} + (:require [malli.core :as m] + [sci.core :as sci :refer [copy-var]])) + +(def mns (sci/create-ns 'malli.core nil)) + +(def malli-namespace + {'validate (copy-var m/validate mns) + 'validator (copy-var m/validator mns) + }) diff --git a/project.clj b/project.clj index b91000a0..fe674043 100644 --- a/project.clj +++ b/project.clj @@ -53,6 +53,8 @@ :dependencies [[hiccup/hiccup "2.0.0-alpha2"]]} :feature/test-check {:source-paths ["feature-test-check"]} :feature/spec-alpha {:source-paths ["feature-spec-alpha"]} + :feature/malli {:source-paths ["feature-malli"] + :dependencies [[metosin/malli "0.2.1"]]} :test [:feature/xml :feature/lanterna :feature/yaml diff --git a/script/compile b/script/compile index 5451c4f6..6c8bf451 100755 --- a/script/compile +++ b/script/compile @@ -103,6 +103,7 @@ then export BABASHKA_FEATURE_HICCUP="${BABASHKA_FEATURE_HICCUP:-false}" export BABASHKA_FEATURE_TEST_CHECK="${BABASHKA_FEATURE_TEST_CHECK:-false}" export BABASHKA_FEATURE_SPEC_ALPHA="${BABASHKA_FEATURE_SPEC_ALPHA:-false}" + export BABASHKA_FEATURE_MALLI="${BABASHKA_FEATURE_MALLI:-false}" fi "$GRAALVM_HOME/bin/native-image" "${args[@]}" diff --git a/script/uberjar b/script/uberjar index 56e64669..f6c942c7 100755 --- a/script/uberjar +++ b/script/uberjar @@ -146,6 +146,13 @@ else BABASHKA_LEIN_PROFILES+=",-feature/spec-alpha" fi +if [ "$BABASHKA_FEATURE_MALLI" != "false" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/malli" +else + BABASHKA_LEIN_PROFILES+=",-feature/malli" +fi + if [ -z "$BABASHKA_JAR" ]; then lein with-profiles "$BABASHKA_LEIN_PROFILES,+reflection,-uberjar" do run lein with-profiles "$BABASHKA_LEIN_PROFILES" do clean, uberjar diff --git a/script/uberjar.bat b/script/uberjar.bat index 6e71856f..f8144a94 100755 --- a/script/uberjar.bat +++ b/script/uberjar.bat @@ -112,6 +112,13 @@ set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/spec-alpha set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/spec-alpha ) +if not "%BABASHKA_FEATURE_MALLI%"=="false" ( +set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/malli +) else ( +set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/malli +) + + call lein with-profiles %BABASHKA_LEIN_PROFILES% bb "(+ 1 2 3)" call lein with-profiles %BABASHKA_LEIN_PROFILES%,+reflection,-uberjar do run diff --git a/src/babashka/impl/features.clj b/src/babashka/impl/features.clj index ee097903..4afcac92 100644 --- a/src/babashka/impl/features.clj +++ b/src/babashka/impl/features.clj @@ -14,6 +14,7 @@ (def core-match? (not= "false" (System/getenv "BABASHKA_FEATURE_CORE_MATCH"))) (def hiccup? (not= "false" (System/getenv "BABASHKA_FEATURE_HICCUP"))) (def test-check? (not= "false" (System/getenv "BABASHKA_FEATURE_TEST_CHECK"))) +(def malli? (not= "false" (System/getenv "BABASHKA_FEATURE_MALLI"))) ;; excluded by default (def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC"))) @@ -66,3 +67,6 @@ (when spec-alpha? (require '[babashka.impl.spec])) + +(when malli? + (require '[babashka.impl.malli])) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index fbe391a8..2097cdc3 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -273,7 +273,8 @@ Use -- to separate script command line args from bb command line args. :feature/core-match %s :feature/hiccup %s :feature/test-check %s - :feature/spec-alpha %s}") + :feature/spec-alpha %s + :feature/malli %s}") version features/core-async? features/csv? @@ -290,7 +291,8 @@ Use -- to separate script command line args from bb command line args. features/core-match? features/hiccup? features/test-check? - features/spec-alpha?))) + features/spec-alpha? + features/malli?))) (defn read-file [file] (let [f (io/file file)] @@ -421,7 +423,9 @@ Use -- to separate script command line args from bb command line args. features/spec-alpha? (-> (assoc ;; spec 'clojure.spec.alpha @(resolve 'babashka.impl.spec/spec-namespace) 'clojure.spec.gen.alpha @(resolve 'babashka.impl.spec/gen-namespace) - 'clojure.spec.test.alpha @(resolve 'babashka.impl.spec/test-namespace))))) + 'clojure.spec.test.alpha @(resolve 'babashka.impl.spec/test-namespace))) + features/malli? (assoc 'malli.core + @(resolve 'babashka.impl.malli/malli-namespace)))) (def imports '{ArithmeticException java.lang.ArithmeticException