diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc6994..9bbe01f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ +- [#95](https://github.com/babashka/scittle/issues/121): support string requires of `globalThis` js deps ([@chr15m](https://github.com/chr15m)) + ## v0.7.26 (2025-08-20) - [#121](https://github.com/babashka/scittle/issues/121): add `cjohansen/dataspex` plugin ([@jeroenvandijk](https://github.com/jeroenvandijk)) diff --git a/src/scittle/core.cljs b/src/scittle/core.cljs index 6ba88ad..6a7ac60 100644 --- a/src/scittle/core.cljs +++ b/src/scittle/core.cljs @@ -53,13 +53,19 @@ 'sci.core {'stacktrace sci/stacktrace 'format-stacktrace sci/format-stacktrace}}) +(defn load-fn [{:keys [ctx] :as opts}] + (when-let [lib (and (string? (:namespace opts)) + (gobject/get js/globalThis (:namespace opts)))] + (sci/add-js-lib! ctx (:namespace opts) lib))) + (store/reset-ctx! (sci/init {:namespaces namespaces :classes {'js js/globalThis :allow :all 'Math js/Math} :ns-aliases {'clojure.pprint 'cljs.pprint} - :features #{:scittle :cljs}})) + :features #{:scittle :cljs} + :load-fn load-fn})) (unchecked-set js/globalThis "import" (js/eval "(x) => import(x)"))