Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :reload Support #343

Closed
athomasoriginal opened this issue Nov 22, 2023 · 6 comments
Closed

Add :reload Support #343

athomasoriginal opened this issue Nov 22, 2023 · 6 comments

Comments

@athomasoriginal
Copy link

athomasoriginal commented Nov 22, 2023

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.

@eval
Copy link
Contributor

eval commented Jul 29, 2024

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

@borkdude
Copy link
Collaborator

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

@eval
Copy link
Contributor

eval commented Jul 29, 2024

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).

@borkdude
Copy link
Collaborator

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

(if (sci/eval-form (store/get-ctx) (list 'clojure.core/find-ns (list 'quote libname)))

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.

@chr15m
Copy link

chr15m commented Nov 3, 2024

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

@borkdude
Copy link
Collaborator

borkdude commented Nov 7, 2024

Fixed in 1.3.195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants