是否可以在运行时在 Nodejs 上运行的 Clojurescript 程序中添加类路径?
问问题
49 次
1 回答
1
假设您指的是在开发时修改基于节点的 REPL 的类路径,也许如果add-lib成为一个东西,那么这将很容易做到。这是一个实验,展示add-lib
了在修订版的 ClojureScript 中使用动态修改类路径并加载(动态获取的)库:
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"}}}
使用它:
$ 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=>
于 2019-08-27T16:26:06.330 回答