-
Notifications
You must be signed in to change notification settings - Fork 116
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
Plugin API Surface Refactor #879
Plugin API Surface Refactor #879
Conversation
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.
Thanks for the work! I understand it takes time to do and I appreciate you taking the time to do it.
That said, I do have concerns about what's in here. I think there was some misunderstanding around the abstractions I would've liked to see for the Plugin
. Specifically, I wanted a richer Plugin
struct/abstraction for use in the CLI crate and a different and very slimmed down Plugin
struct/abstraction for use in the future codegen crate (specifically in the Generator
) with additional properties and gated setters on the Generator
to preserve behaviour with a very slimmed down plugin abstraction.
Does that make sense?
crates/cli/src/js_config.rs
Outdated
} | ||
|
||
impl ConfigSchema { | ||
pub(crate) fn from_plugin(plugin: &Plugin) -> Result<Option<ConfigSchema>> { |
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 think you can keep this method on CliPlugin
, just not the codegen plugin.
4aaa655
to
ce388f5
Compare
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 couldn't see a use case where this was required over just implementing the generator itself as a builder pattern.
crates/cli/src/codegen/mod.rs
Outdated
/// Set true if linking with a default plugin module. | ||
pub fn linking_default_plugin(&mut self, value: bool) -> &mut Self { | ||
self.plugin_kind = if value { | ||
plugin::PluginKind::Default | ||
} else { | ||
plugin::PluginKind::None | ||
}; | ||
|
||
self | ||
} | ||
|
||
/// Set true if linking with a V2 plugin module. | ||
pub fn linking_v2_plugin(&mut self, value: bool) -> &mut Self { | ||
self.plugin_kind = if value { | ||
plugin::PluginKind::V2 | ||
} else { | ||
plugin::PluginKind::None | ||
}; | ||
|
||
self | ||
} | ||
|
||
/// Runtime configuration options to pass to the module. | ||
pub fn js_runtime_config(&mut self, js_runtime_config: Vec<u8>) -> &mut Self { | ||
self.js_runtime_config = js_runtime_config; | ||
self | ||
} | ||
} |
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.
These will all sit behind the feature flag.
crates/cli/src/codegen/mod.rs
Outdated
let import_namespace = match self.plugin_kind { | ||
plugin::PluginKind::V2 => "javy_quickjs_provider_v2".to_string(), | ||
_ => self.plugin.import_namespace()?, | ||
}; |
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.
So this kind of sucks... I'll admit it... but I couldn't think of a better way to keep the import_namespace
function in this crate while supporting the existing behavior/tests.
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.
Could you add a function like plugin_kind.import_namespace(&plugin) -> String
to PluginKind
with this implementation? It's moving logic around but at least that way the namespace will be in the plugin
module as opposed to the generator.
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 like that quite a bit more.
crates/cli/src/codegen/plugin.rs
Outdated
|
||
/// Uses the plugin to generate QuickJS bytecode. | ||
impl Plugin { | ||
/// Uses a plugin to generate QuickJS bytecode. | ||
pub fn compile_source(&self, js_source_code: &[u8]) -> Result<Vec<u8>> { |
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 probably doesn't matter quite yet but do we want/need this to be public? Do we not just want the Generators
generate method to be public instead?
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.
Yeah a bunch of the methods that were public probably should be changed to pub(super)
or pub(crate)
.
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.
Mostly looks good! Just would like to figure out where the plugin initialization logic should live and fix up some minor things but otherwise it's what I'm looking for structurally.
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.
Thank you for your hard work and patience! LGTM!
Actually I do need you to run |
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.
LGTM
Description of the change
These changes clean up the interfaces around code generation and plugins so that they will be ready to spin off into their own crate without dramatically increasing the API surface of the new crate. The overview of the changes made are below,
Plugin
is now a wrapper around aVec<u8>
.Generator
now storesplugin_kind
internally to determine if it's linking to a User/Default/V2Plugin
.Generator
now exposeslinking_v2_plugin
orlinking_default_plugin
that can have their visibility controlled with a future feature flag to support the existingcli
use cases.codegen
crate rather thencli
.CliPlugin
wrapper that storesPluginKind
information for use with config generation logic in thecli
.CodeGenBuilder
was removed as it's behavior is provided byGenerator
.Why am I making this change?
To lower the API surface of the plugin/code-generation components in preparation for a future split of that logic into a
javy-codegen
crate based on @jeffcharles request.Checklist
javy-cli
andjavy-plugin
do not require updating CHANGELOG files.