[ClojureScript] How to require a library only if it is on the classpath?
I'm trying to write some code (to run at compilation time) that will only do a require if a library is present. Initially I thought of trying something like this: (defmacro include-if-present [] (when (io/resource "foo/bar.cljc") '(require 'foo.bar))) Now I understand that 'require' in cljs is intended as a repl-only thing which expands to an ns form: https://clojurescript.org/guides/ns-forms#_the_require_and_require_macros_macros So, rather than 'cljs.core/require', then perhaps what'd work it to be able to hook in at the point the ns forms as read initially. Any ideas please let me know. Thanks, Henry -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.
[ClojureScript] Re: How to require a library only if it is on the classpath?
I realize this doesn't directly answer you're problem, as you're asking about how you might do this in ClojureScript, but you may still be interested to take a look at https://github.com/clojure-goes-fast/lazy-require If you figure out a solution, it could be helpful for that library to have a cljc implementation of the underlying idea here. Good luck Chris -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.
[ClojureScript] Re: How to require a library only if it is on the classpath?
What you are trying to do in include-if-present is not possible in CLJS. require is completely static and you can't do dynamic require outside the REPL. On Friday, February 8, 2019 at 9:43:03 AM UTC+1, Henry Widd wrote: > > I'm trying to write some code (to run at compilation time) that will only > do a require if a library is present. Initially I thought of trying > something like this: > > (defmacro include-if-present [] > (when (io/resource "foo/bar.cljc") > '(require 'foo.bar))) > > > Now I understand that 'require' in cljs is intended as a repl-only thing > which expands to an ns form: > https://clojurescript.org/guides/ns-forms#_the_require_and_require_macros_macros > > So, rather than 'cljs.core/require', then perhaps what'd work it to be > able to hook in at the point the ns forms as read initially. > > Any ideas please let me know. > > Thanks, > Henry > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.