(defn
create-node-script-import-fn
[]
(let
[node-path-lib
(js/require "path")
util-pattern
(str
(.-sep node-path-lib)
(.join node-path-lib "goog" "bootstrap" "nodejs.js"))
util-path
(gobj/findKey
js/require.cache
(fn [v k o] (gstring/endsWith k util-pattern)))
parts
(-> (string/split util-path #"[/\\]") pop pop)
root-path
(string/join (.-sep node-path-lib) parts)]
(fn
[request-url callback]
(dev-assert (string? request-url) (not (nil? callback)))
(let
[cache-path (.resolve node-path-lib root-path request-url)]
(gobj/remove (.-cache js/require) cache-path)
(callback
(try
(js/require cache-path)
(catch
js/Error
e
(utils/log
:error
(str "Figwheel: Error loading file " cache-path))
(utils/log :error (.-stack e))
false)))))))