Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 7, 2024
1 parent a7a4fce commit c33c626
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/nbb/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,27 @@
(defn register-module [mod internal-name]
(swap! loaded-modules assoc internal-name mod))

(defn debug [& xs]
(binding [*print-fn* *print-err-fn*]
(apply prn xs)))

(defn load-js-module [libname internal-name reload?]
(-> (if-let [resolve (:resolve @ctx)]
(-> (resolve libname)
(.catch
(fn [_]
((.-resolve (:require @ctx)) libname))))
(js/Promise.resolve ((.-resolve (:require @ctx)) libname)))
(.then (fn [path]
;; (prn :path path)
(let [file-url (if (str/starts-with? path "file:")
(.then (fn [path]
(let [file-url (if (str/starts-with? (str path) "file:")
path
(when (fs/existsSync path)
(url/pathToFileURL path)))
(when (fs/existsSync path)
(str (url/pathToFileURL path))))
path (if (and reload?
;; not "node:fs" etc
file-url)
(str file-url "?uuid=" (random-uuid))
path)]
(or file-url path))]
(esm/dynamic-import path))))
(.then (fn [mod]
(register-module mod internal-name)
Expand Down

0 comments on commit c33c626

Please sign in to comment.