Support string requires of globalThis js deps #95 (#129)

* Add a :load-fn for js libs on globalThis.

Fixes #95.

* Update changelog.
This commit is contained in:
Chris McCormick 2025-08-21 17:08:56 +08:00 committed by GitHub
parent ab527ad5a1
commit 7aebb5bbb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -9,6 +9,8 @@
<!-- - Create Github release with updated links from `doc/links.md` -->
<!-- - `bb gh-pages` -->
- [#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))

View file

@ -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)"))