nbb icon indicating copy to clipboard operation
nbb copied to clipboard

Add `:reload` Support

Open tmattacchione opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe.

I would like to run nbb from a JS program which is itself running in a "watch loop". The blocker is that dependencies of the nbb scripts won't reload when changes are made to them.

Describe the solution you'd like

I'm not opinionated about the solution, but it sounds like adding support for :reload may resolve this issue.

Describe alternatives you've considered

nbb seeing a file was modified and reloading the namespace accordingly (but this is a naive approach and may not be the responsibility of nbb itself)

Additional context

see eleventy-test-cljs for a "minimal" repro of the problem. Also refer to the original slack thread.

tmattacchione avatar Nov 22 '23 21:11 tmattacchione

Running into this issue as well. Any ideas @borkdude ?

eval avatar Jul 29 '24 14:07 eval

Sure, :reload support can be added. Do you want me to look into this, or do you want to have any guidance?

borkdude avatar Jul 29 '24 14:07 borkdude

Pointers would be nice. I guess here's where the magic should happen.... I read dev.md - what are the options to do interactive dev? (using Cider).

eval avatar Jul 29 '24 20:07 eval

Yes. If the namespace is already loaded, which is discovered here:

https://github.com/babashka/nbb/blob/6485523c78e2f0639a9fcf5eade7b55bb0af5b81/src/nbb/core.cljs#L282

then we just handle the aliases etc, but don't reload the namespace. I think right there the :reload should be handled.

Note that :reload affects all the namespaces in a require, not just the libspec you write it after.

I don't use CIDER for developing nbb, just bb dev and loading a script on the command line via cli.js and writing tests.

borkdude avatar Jul 29 '24 20:07 borkdude

Not sure if this is of any help but here is a minimal single-script reloader for nbb that seems to work reliably for me. It depends on node-watch.

(ns hello
  (:require
    ["node-watch$default" :as watch]
    [nbb.core :refer [load-file *file*]]))

(print "hello")

(defonce watcher
  (watch *file* (fn [_event-type filename]
                  (js/console.log "Reloading" filename)
                  (load-file filename))))

chr15m avatar Nov 03 '24 21:11 chr15m

Fixed in 1.3.195

borkdude avatar Nov 07 '24 19:11 borkdude