1

Is it possible to add classpaths in a Clojurescript program running on Nodejs at runtime?

1 Answer 1

1

Assuming you are referring to modifying the classpath of a Node-based REPL at dev-time, perhaps if add-lib becomes a thing, then this would be pretty easy to do. Here is an experiment showing using add-lib in a revised version of ClojureScript to dynamically modify the classpath and load a (dynamically fetched) library:

deps.edn:

{:deps {org.clojure/clojurescript {:git/url "https://github.com/mfikes/clojurescript"
                                   :sha "4fa9edd736d47b8ef5648b61b199e64ef80735bb"}
        org.clojure/tools.deps.alpha {:git/url "https://github.com/clojure/tools.deps.alpha.git"
                                      :sha "d492e97259c013ba401c5238842cd3445839d020"}}}

Using it:

$ clj -m cljs.main -re node
cljs.user=> (require '[cljs.repl :refer [add-lib]])
nil
cljs.user=> (add-lib 'spec-provider {:mvn/version "0.4.14"})
Downloading: spec-provider/spec-provider/0.4.14/spec-provider-0.4.14.pom from https://repo.clojars.org/
Downloading: spec-provider/spec-provider/0.4.14/spec-provider-0.4.14.jar from https://repo.clojars.org/
true
cljs.user=> (require '[spec-provider.provider :as sp])
nil
cljs.user=> (sp/infer-specs
 [{:a 8  :b "foo" :c :k}
  {:a 10 :b "bar" :c "k"}
  {:a 1  :b "baz" :c "k"}]
 :toy/small-map)
((cljs.spec.alpha/def :toy/c (cljs.spec.alpha/or :keyword cljs.core/keyword? :string cljs.core/string?)) (cljs.spec.alpha/def :toy/b cljs.core/string?) (cljs.spec.alpha/def :toy/a cljs.core/integer?) (cljs.spec.alpha/def :toy/small-map (cljs.spec.alpha/keys :req-un [:toy/a :toy/b :toy/c])))
cljs.user=> 
Sign up to request clarification or add additional context in comments.

2 Comments

Ohh thanks this is plenty helpful, can I do this in a bootstrapped clojurescript environment?
@pankajdoharey In bootstrapped ClojureScript, you completely control how code is fetched for loading. If there is any notion of a "classpath" is is because you implemented it. So, it is completely up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.