#Deno Runtime Extension with JS File
67 messages · Page 1 of 1 (latest)
those will be ran at start up before the user code is ran iirc
Doesn't look like it is doing anything with it. Tried console.log, deno.core.print, also tried calling something that doesn't exist to provoke a error from the runtime... but nothing... as if it would be ignored
is it bound to any object in javascript like on the GlobalThis etc
I think so, i tried this
"use strict";
((window) => {
// then do stuff here like
Deno.exit(-1);
// or
somethingThatDoesNotExist();
})(globalThis);
Like in other scripts from deno, but nothing happens
Is that script you are adding via include file?
I believe your extension ops are bound on Deno.core.ops and then you should bind your js glue code via the following code
((window) => {
const ops = window.Deno.core.ops;
function yourFunc() {
ops.your_op_call();
}
window.yourFunc = yourFunc;
})(globalThis);
Yes
Now you should be able to just call yourFunc as it is in the global namespace
This is exactly what i am trying to do but it does not work xD
When i try to call my custom function it says its not defined
The function
yourFunc is not defined
When i use Deno.core.ops.... directly it works
can you call the IIFE with (this) instead of globalThis
((window) => {
const ops = window.Deno.core.ops;
function yourFunc() {
ops.your_op_call();
}
window.yourFunc = yourFunc;
})(this);
Like this
Maybe i did something wrong with bootstrapping and running:
fn create_main_worker() -> Result<MainWorker, Error> {
let mut worker = MainWorker::bootstrap_from_options(
deno_core::resolve_url_or_path(deno_core::DUMMY_SPECIFIER)?,
Permissions::allow_all(),
WorkerOptions {
extensions: vec![
Extension::builder()
.ops(vec![
op_get_header::decl()
])
.js(include_js_files!(
prefix "prefix:idk",
"js/01_helpers.js",
))
.build()
],
..Default::default()
},
);
Ok(worker)
}
async fn run_worker() -> Result<(), Error> {
let mut runtime = create_main_worker()?;
let module = deno_core::resolve_url_or_path("bundle.js")?;
runtime.execute_main_module(&module).await?;
runtime.run_event_loop(false).await?;
Ok(())
}
Also debugged it, and the script that is embedded is correct
Maybe because of the "dummy specifier"?
i mean that i bootstrap the runtime with deno_core::DUMMY_SPECIFIER instead of the real script
I don't think that should matter? not sure tho
If you don't use snapshots you need to pass it as extensions_with_js
Ok, i see this option in the JsRuntime but not in MainWorker, how do i pass this then?
uhh, lemme check
i didnt follow the entire discussion, but @peak grotto are you using deno_core or deno_runtime?
deno_runtime
And MainWorker doesn't let you use extensions_with_js
Or at least, i couldn't see an option for this
@peak grotto from the looks of it you need to pass it to extensions then
Yeah but the js then gets never executed, thats the main problem of this thread here
hmm
Is there any workaround maybe?
are you using snapshot from snapshot?
As far as i know i dont use any snapshots
I bootstrap it like there
Can't i use #[op] without depending on deno_core when deno_runtime is present? I don't know which version of deno_core i should use when using deno_runtime 0.80.0
deno_runtime re-exports deno_core
Yeah but when not having deno_core in cargo.toml #[op] tells me: deno_core not present in Cargo.toml: CrateNotFound
Yeah i never bothered, because it does seem to work when always using newest versions
Thanks 😄
Nothing changes (it doesn't seem to execute the script), but i do see the code inlined correctly (as always)
hm ok looking into it
Thanks 🙂
Could MainWorker not just expose the extensions_with_js Option?
Nice
Can you tell when I can expect this to be merged/released (i do see some failed pipelines)?
Also, should i open an issue about #[op] requiring deno_core to be in the cargo.toml, even if deno_runtime is present?