weavejester / resauce

Clojure library for handling JVM resources
24 stars 6 forks source link

Question: get all resources/files that match a name #10

Open awb99 opened 3 years ago

awb99 commented 3 years ago

I hope me posting a question is not considered bad manner.

I want to search for all resources matching the name 'gorilla-config.clj', irrespective in which path they are and irrespective if they are still a file or already a resource (from a jar). Once I have this sequence I want to slurp them. Could you give a snippet for that? Your solution on my prior ticket were so smooth .. I doubt I would be able to come up with something similar.

This question I think should be interesting to many apps that want to make themselves expandable with plug-in libraries, that describe their capabilities in a specially named file. Shadow-cljs does this for example with deps.cljs files .. so shadow-cljs determines which npm dependencies are needed by slurping and merging all deps.cljs files prior to clojurescript compilation.

weavejester commented 3 years ago

Why not just use the recursive-resource-paths function we discussed in the PR?

(->> (recursive-resource-paths "")
     (filter #(str/ends-with? % "/gorilla-config.clj")))
awb99 commented 3 years ago

Thanks @weavejester This works beautifully!

There is only one issue: In the repl it all works perfect. When running with tools.deps resource path "" makes problems. There is a new type, other than "file"and "jar". It might be related to "javax" (no idea what that is). I spent a few hours trying to find the reason, but could not find it.

And the other thing I noted is that the new functions are not yet in resauce. :-)

weavejester commented 3 years ago

The functions are there for you to use, but I don't think I'll add them to resauce. They're probably too specific, and outside resauce's domain. I'm afraid I can't help you with the "new type" of resource, particularly with no additional information on what the new type is.

awb99 commented 3 years ago

I understand. I wuill report anyway my findings. Possibly another user of resauce finds it useful in the future. There is one more issue: multiple artefacts can bring resources with the same name. :-) Not ideal if I want to load all of them