diff --git a/bb/tasks.clj b/bb/tasks.clj index 95299063..0c074910 100644 --- a/bb/tasks.clj +++ b/bb/tasks.clj @@ -3,7 +3,8 @@ [babashka.fs :as fs] [babashka.process :refer [shell]] [cheshire.core :as json] - [node-repl-tests])) + [node-repl-tests] + [clojure.string :as str])) (def test-config '{:compiler-options {:load-tests true} @@ -44,10 +45,24 @@ (bump-core-vars) (shell "npx shadow-cljs --aliases :dev --config-merge .work/config-merge.edn watch squint")) +(defn test-project [_] + (let [dir "test-project"] + (fs/delete-tree (fs/path dir "lib")) + (shell {:dir dir} "npx squint compile") + (let [output (:out (shell {:dir dir :out :string} "node lib/main.mjs"))] + (println output) + (assert (str/includes? output "macros2/debug 10")) + (assert (str/includes? output "macros2/debug 6")) + (assert (str/includes? output "macros/debug 10",)) + (assert (str/includes? output "macros/debug 6"))))) + (defn test-squint [] (fs/create-dirs ".work") (spit ".work/config-merge.edn" (shadow-extra-test-config)) (bump-core-vars) (shell "npx shadow-cljs --config-merge .work/config-merge.edn compile squint") (shell "node lib/squint_tests.js") - (node-repl-tests/run-tests {})) + (node-repl-tests/run-tests {}) + (test-project {})) + + diff --git a/package.json b/package.json index 81f6a3eb..0a9a1166 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "squint-cljs": "." }, "dependencies": { - "chokidar": "^3.5.3" + "chokidar": "^3.5.3", + "glob": "^10.3.10" } } diff --git a/src/squint/internal/cli.cljs b/src/squint/internal/cli.cljs index 5eab457d..55ad6d72 100644 --- a/src/squint/internal/cli.cljs +++ b/src/squint/internal/cli.cljs @@ -2,6 +2,7 @@ (:require ["fs" :as fs] ["path" :as path] + ["glob" :as glob] [babashka.cli :as cli] [shadow.esm :as esm] [squint.compiler :as cc] @@ -21,10 +22,19 @@ ext' (path/extname resolved)] (str "./" (str/replace resolved (re-pattern (str ext' "$")) ext))))) +(defn glob-cljs-files [dir] + (glob/globSync (str dir "/**/*.{cljs,cljc}"))) + +(defn files-from-paths [paths] + (mapcat glob-cljs-files paths)) + (defn compile-files [opts files] (let [cfg @utils/!cfg - opts (merge cfg opts)] + opts (merge cfg opts) + files (if (empty? files) + (files-from-paths (:paths cfg)) + files)] ;; shouldn't need this if :coerce worked in babashka.cli (when-let [out-dir (:output-dir opts)] (when-not (string? out-dir) diff --git a/test-project/src/macros.cljc b/test-project/src/macros.cljc index bd0d9df4..e0e883c4 100644 --- a/test-project/src/macros.cljc +++ b/test-project/src/macros.cljc @@ -1,4 +1,4 @@ (ns macros) (defmacro debug [_kwd body] - [::debug body]) + `(println ::debug ~body)) diff --git a/test-project/src/macros2.cljc b/test-project/src/macros2.cljc index 4e503f64..dec14b28 100644 --- a/test-project/src/macros2.cljc +++ b/test-project/src/macros2.cljc @@ -1,4 +1,4 @@ (ns macros2) (defmacro debug [_kwd body] - [::debug body]) + `(println ::debug ~body)) diff --git a/test-project/src/main.cljs b/test-project/src/main.cljs index 61d41715..26010b1e 100644 --- a/test-project/src/main.cljs +++ b/test-project/src/main.cljs @@ -3,7 +3,7 @@ (:require [other-ns])) (defn foo [] - (m/debug :foo (+ 1 2 3 4))) + (m/debug :foo (+ 1 2 3))) -(prn (foo)) -(prn (debug :foo (+ 1 2 3 4))) +(foo) +(debug :foo (+ 1 2 3 4)) diff --git a/test-project/src/other_ns.cljs b/test-project/src/other_ns.cljs index 36340a2b..66431e17 100644 --- a/test-project/src/other_ns.cljs +++ b/test-project/src/other_ns.cljs @@ -1,5 +1,5 @@ (ns other-ns (:require-macros [macros2 :as m :refer [debug]])) -(prn (debug :foo (+ 1 2 3))) -(prn (m/debug :foo (+ 1 2 3))) +(debug :foo (+ 1 2 3 4)) +(m/debug :foo (+ 1 2 3))