-
Notifications
You must be signed in to change notification settings - Fork 73
refactor(cli): Librarify nova_cli to avoid code duplication
#916
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
base: main
Are you sure you want to change the base?
Conversation
nova_cli to avoid code duplicationnova_cli to avoid code duplication
262a806 to
5bcfde9
Compare
This already factored out some logic that was duplicated between the `eval` and `repl` subcommands. However, the real goal is to provide a library the benchmark runner can use, to avoid code duplication there.
5bcfde9 to
0dbdc3a
Compare
load1n9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aapoalas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me: I don't unfortunately have any particularly good ideas about what a more generic API would look like. Storing parsed-but-not-executed Scripts could indeed be done using Global<Script>s, but I don't have a handle on if that would work nicely for a benchmarking CLI or not.
I'd be happy to merge this as-is; I kind of expect that figuring out the correct API is something that can only be done through experiment.
nova_cli/src/lib/host_hooks.rs
Outdated
| ) { | ||
| let specifier = module_request.specifier(agent); | ||
| let specifier = specifier.to_string_lossy(agent); | ||
| let specifier_target = if let Some(specifier) = specifier.strip_prefix("./") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I wonder if some of this code would belong in the ModuleMap now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch. Yes, that makes a lot of sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to say: sorry it took so long for me to review this <3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely no problem, I was busy as well so it was a blessing, not a curse ;)
nova_cli to avoid code duplicationnova_cli to avoid code duplication
|
Ok, indeed we can further experiment after this is merged; the no semver guarantee gives us flexibility there. And it would be quite a nightmare to merge/rebase this if someone makes significant changes to the cli code in the meantime... How about I rebase this on top of main so we lose the merge commit, and squash my two commits together? |
Sounds good to me! |

Right now this is mostly moving code around, so the benchmark runner (which I have in a separate branch) can share most of its code with the cli. I have no idea whether this library could be useful for users of nova as well, I don't really know their requirements, but I assume the current setup is not flexible enough for that. (For example, currently everything assumes there is only one realm.)
The benchmark runner needs to separately parse and execute scripts, while the cli can just immediately execute a parsed script, which is why I haven't touched the script parsing and execution logic of the cli. However, maybe we can store a list of parsed but not yet executed scripts in
HostDefined(alongside the module map of already executed modules, or maybe merge them?), and then implement convenience commands for script/module parsing and execution for theInstance. Or maybe that is overly complicated and it is better to leave this work to the library user.I would love to hear any suggestions, as I find myself really struggling to provide a flexible and convenient API.