thheller / shadow-css

CSS-in-CLJ(S)
https://github.com/thheller/shadow-css
Eclipse Public License 1.0
108 stars 10 forks source link

String `:include` configuration for `shadow.css.build/generate` #25

Closed harishcm closed 5 months ago

harishcm commented 5 months ago

Hi there, I see that the shadow.css.build/collect-namespaces-for-chunk function also allows for a string :include configuration to be provided to shadow.css.build/generate.

I was trying to use the string :include configuration, but kept getting the error below.

class clojure.lang.Symbol cannot be cast to class java.lang.CharSequence (clojure.lang.Symbol is in unnamed module of loader 'app'; java.lang.CharSequence is in module java.base of loader 'bootstrap')

It seems that the error occurs because a regular expression comparison is being used directly on the namespace symbol.

I have included a suggested fix below to use the name string of the namespace symbol instead for this comparison - for your kind consideration.

Many thanks for this wonderful library!

(defn collect-namespaces-for-chunk
  [{:keys [include entries] :as chunk} {:keys [namespaces] :as build-state}]
  (let [namespace-matchers
        (->> include
             (map (fn [x]
                    (cond
                      (string? x)
                      (let [re (re-pattern x)]
                        #(re-find re (name %))) ;; <-- use `name` string of symbol instead

                      (not (symbol? x))
                      (throw (ex-info "invalid include pattern" {:x x}))

                      :else
                      (let [s (str x)]
                        ;; FIXME: allow more patterns that can be expressed as string?
                        ;; foo.bar.*.views?

                        (if (str/ends-with? s "*")
                          ;; foo.bar.* - prefix match
                          (let [prefix (subs s 0 (-> s count dec))]
                            (fn [ns]
                              (str/starts-with? (str ns) prefix)))

                          ;; exact match
                          (fn [ns]
                            (= x ns)))))))
             (into []))
thheller commented 5 months ago

Ooops, thanks. Fixed in master.