feat: support output options plugin #408
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
OutputPlugin binding
The pr intend to find a solution to support
OutputPlugin
, but here has some issue need to resolve.The
write/generate
is async function, it isn't allow hasPluginOptions
argument, because theJsFunction
isn'tSend
, here has some solution to resolve it.ThreadsafeFunction
to replaceJsFunction
forPluginOptions
, see this issue fix: future cannot be sent between threads safely napi-rs/napi-rs#1644, but theThreadsafeFunction
isn'tToNapiValue
, we only can be using it directly as argument at the async function, it is ugly for many plugin hook.write/generate
to sync function, but it will block node main thread work. Here I also try usingAsyncTask
to rewritewrite/generate
function, but it also has issue with theJsFunction
isn'tSend
.So here is a solution to using a sync function
set_output_plugins
to passPluginOptions
to rust side before callwrite/generate
. Here use a map to storeplugin
using the sync function and take it to thewrite/generate
call.Rust side OutputPluginDriver and
OutputPlugin
Here not create new a struct/trait to do that, but can be do for rust API clear. I'm free to implement it if anyone think it should do.
Test Plan
Not need at now.