Skip to content

Conversation

@flightofthefox
Copy link
Contributor

Hello,

Thanks for this crate. Great to see such a feature-complete implementation!

I'm porting my code from my bespoke/spaghetti deno_core runtime over to this crate and have hit a snag WRT to loader permissions.

Using regular deno_core I was able to define extensions like the following:

extension!(
    sessions_ext,
    ops = [op_get_current_identity],
    esm_entry_point = "proven:sessions",
    esm = [ dir "src/extensions", "proven:sessions" = "sessions.js" ],
);

These extensions could then be used inside user-provided runtime code like:

import { getCurrentIdentity } from "proven:sessions";

However, in rustyscript the InnerLoader permissions checker will error with Error: Runtime("unrecognized schema for module import: proven:sessions") unless the module begins with ext:.

Switching the extension to use ext:sessions also results in deno_core [correctly] throwing Error: Runtime("Importing ext: modules is only allowed from ext: and node: modules.").

This pull request creates an additional runtime option which allows such custom schemas to be whitelisted. Allowing for a similar setup to deno_core. E.g.

let mut schema_whlist = HashSet::new();
schema_whlist.insert("proven:".to_string());
let mut runtime = Runtime::new(RuntimeOptions {
    schema_whlist,
    extensions: vec![sessions_ext::init_ops_and_esm()],
    ..Default::default()
})?;

Thanks again!

@rscarson
Copy link
Owner

rscarson commented Oct 16, 2024

Looks great!! Thanks!!
Wonder if it may be worth altering the extension example to showcase this?

@flightofthefox
Copy link
Contributor Author

Looks great!! Thanks!! Wonder if it may be worth altering the extension example to showcase this?

No problem. Updated now :)

@rscarson rscarson merged commit e98037a into rscarson:master Oct 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants