orvit
orvit•2y ago

deno_core Extension with Global Access

Is there a way to make a Deno Extension be accessed by Extension.op() instead of Deno.core.ops.op()?
38 Replies
Doctor 🤖
Doctor 🤖•2y ago
Does this work?
const Extension = Deno.core.ops
Extension.op()
const Extension = Deno.core.ops
Extension.op()
orvit
orvit•2y ago
Of course that does work, but that'd require asking everyone to add that, I'm looking for a way to make it so whenever deno_core::JsRuntime::execute_script is run, it'll just work.
bartlomieju
bartlomieju•2y ago
currently it's not possible OOTB, you need to handle it yourself
orvit
orvit•2y ago
So how do extensions like console and fetch have their stuff globally? I'm willing to add a JS file to the extension.
bartlomieju
bartlomieju•2y ago
the global scope is assembled in a file called 99_main.js that is executed after all extensions have been loaded and added their relevant stuff to different window.__bootstrap namespaces
orvit
orvit•2y ago
So is there no way to implement a similar functionality as that into my own project without forking?
bartlomieju
bartlomieju•2y ago
you certainly can, which crates do you use? do you use deno_runtime crate?
orvit
orvit•2y ago
Yes, runtime.
bartlomieju
bartlomieju•2y ago
if you use deno_runtime it will be harder right now - @crowlkats and I are working on a PR that will make it much easier (https://github.com/denoland/deno/pull/16597) that will allows to extend global scope as you see fit
bartlomieju
bartlomieju•2y ago
all in all you should still be able to assign whatever you want to globalThis after all JS code from crates executes
orvit
orvit•2y ago
What's the goal for that pr? (If any)
bartlomieju
bartlomieju•2y ago
to allow creating V8 snapshots from existing V8 snapshots so you can extend what's already in deno_runtime and change it as you see fit mainly useful for a windowing project Leo is working on
orvit
orvit•2y ago
Around how long should I expect to wait for that
bartlomieju
bartlomieju•2y ago
a week probably
orvit
orvit•2y ago
So next patch? Alright. I appreciate all of this work. Thanks for the knowledge.