Add js plugin with eval command using rquickjs #2753
Merged
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.
Add js plugin with eval command using rquickjs
Summary
Adds a new Tauri plugin
jsthat exposes a singleevalcommand for evaluating JavaScript code using the rquickjs library. The plugin follows the existing plugin conventions (modeled afteranalyticsplugin) and includes TypeScript bindings generated via tauri-specta.The
evalcommand accepts a JavaScript code string and returns the stringified result. It handles various JS types (undefined, null, bool, int, float, string) and falls back to JSON.stringify for complex objects.Review & Testing Checklist for Human
Security review: The
evalcommand executes arbitrary JavaScript code. Verify this is acceptable for your use case and that the permission model (js:defaultincludesallow-eval) is appropriate.Test end-to-end: Run the desktop app and test that
commands.eval("1 + 2")returns"3"from the frontend.Performance consideration: Each
evalcall creates a new QuickJS runtime. If you plan to make many eval calls, consider whether this overhead is acceptable or if runtime reuse should be implemented.Recommended test plan:
ONBOARDING=0 pnpm -F desktop tauri devawait window.__TAURI__.invoke('plugin:js|eval', { code: '1 + 2' })"3"Notes
managerfield in theJsstruct - this is benign but could be cleaned upUpdates since last revision
.plugin(tauri_plugin_js::init())to desktop app initialization inapps/desktop/src-tauri/src/lib.rs- the plugin is now fully integrated