Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,650 changes: 1,050 additions & 600 deletions Cargo.lock

Large diffs are not rendered by default.

86 changes: 44 additions & 42 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extra_features = ["worker", "snapshot_builder"]
# (See [NodePermissions])
node_experimental = [
"deno_node", "deno_resolver", "node_resolver", "deno_npm", "deno_semver", "deno_napi", "deno_runtime", "deno_process", "deno_package_json",
"deno_bundle_runtime",
"checksum", "sys_traits", "all_extensions"
]

Expand Down Expand Up @@ -118,7 +119,7 @@ web_stub = ["webidl", "base64-simd"]
web = [
"deno_web", "deno_tls", "deno_fetch", "deno_net", "dep:http", "deno_permissions", "deno_telemetry", "deno_fs",
"webidl", "console", "url", "crypto", "url_import", "fs_import",
"hyper-util", "rustls"
"hyper-util", "rustls", "sys_traits"
]

# [https://gpuweb.github.io/gpuweb/]
Expand Down Expand Up @@ -168,12 +169,12 @@ async-trait = "^0.1.89"
paste = "1.0.15"

# The deno runtime itself, and the webidl extension for the web APIs
deno_core = "^0.355.0"
deno_error = "=0.7.0"
deno_features = "0.10.0"
deno_core = "^0.376.0"
deno_error = "=0.7.1"
deno_features = "^0.23.0"

# For transpiling typescript
deno_ast = { version = "=0.49.0", features = ["transpiling", "cjs"] }
deno_ast = { version = "^0.52.0", features = ["transpiling", "cjs"] }
deno_media_type = { version = "=0.2.9", features = ["module_specifier"] }

# Runtime for async tasks
Expand All @@ -185,40 +186,41 @@ hyper-util = {version = "^0.1.10", optional = true}
rustls = {version = "0.23.28", optional = true}

# For URL imports
# Pinned for now due to upstream issues
reqwest = { version = "=0.12.8", optional = true, default-features = false, features = ["blocking", "rustls-tls"] }
# Upgraded to support axum 0.8+
reqwest = { version = "^0.12.20", optional = true, default-features = false, features = ["blocking", "rustls-tls"] }
http = { version = "^1.0", optional = true }
deno_permissions = { version = "^0.72.0", optional = true }
deno_permissions = { version = "^0.85.0", optional = true }


#
# Dependencies for the various extension features
#

deno_broadcast_channel = { version = "^0.207.0", optional = true }

deno_cache = { version = "^0.145.0", optional = true }
deno_console = { version = "^0.213.0", optional = true }
deno_cron = { version = "^0.93.0", optional = true }
deno_crypto = { version = "^0.227.0", optional = true }
deno_fetch = { version = "^0.237.0", optional = true }
deno_ffi = { version = "^0.200.0", optional = true }
deno_fs = { version = "^0.123.0", optional = true, features = ["sync_fs"] }
deno_http = { version = "^0.211.0", optional = true }
deno_kv = { version = "^0.121.0", optional = true }
deno_net = { version = "^0.205.0", optional = true }
deno_node = { version = "^0.151.0", optional = true }
deno_tls = { version = "^0.200.0", optional = true }
deno_url = { version = "^0.213.0", optional = true }

deno_web = { version = "^0.244.0", optional = true }
deno_webidl = { version = "^0.213.0", optional = true }
deno_webstorage = { version = "^0.208.0", optional = true }
deno_websocket = { version = "^0.218.0", optional = true }
deno_webgpu = { version = "^0.180.0", optional = true }

deno_io = { version = "^0.123.0", optional = true }
deno_telemetry = { version = "^0.35.0", optional = true }
deno_broadcast_channel = { version = "^0.216.0", optional = true }

deno_bundle_runtime = { version = "^0.13.0", optional = true }
deno_cache = { version = "^0.159.0", optional = true }
deno_console = { version = "^0.222.0", optional = true }
deno_cron = { version = "^0.106.0", optional = true }
deno_crypto = { version = "^0.240.0", optional = true }
deno_fetch = { version = "^0.250.0", optional = true }
deno_ffi = { version = "^0.213.0", optional = true }
deno_fs = { version = "^0.136.0", optional = true, features = ["sync_fs"] }
deno_http = { version = "^0.224.0", optional = true }
deno_kv = { version = "^0.134.0", optional = true }
deno_net = { version = "^0.218.0", optional = true }
deno_node = { version = "^0.164.0", optional = true }
deno_tls = { version = "^0.213.0", optional = true }
deno_url = { version = "^0.222.0", optional = true }

deno_web = { version = "^0.257.0", optional = true }
deno_webidl = { version = "^0.226.0", optional = true }
deno_webstorage = { version = "^0.221.0", optional = true }
deno_websocket = { version = "^0.231.0", optional = true }
deno_webgpu = { version = "^0.193.0", optional = true }

deno_io = { version = "^0.136.0", optional = true }
deno_telemetry = { version = "^0.48.0", optional = true }

# Dependencies for the IO feature
rustyline = {version = "=13.0.0", optional = true}
Expand All @@ -235,17 +237,17 @@ once_cell = {version = "^1.17.1", optional = true}
base64-simd = {version = "0.8.0", optional = true}

# Dependencies for the node feature
deno_resolver = { version = "^0.44.0", optional = true }
node_resolver = { version = "^0.51.0", optional = true, features = ["sync"] }
deno_runtime = { version = "^0.221.0", optional = true, features = ["exclude_runtime_main_js"] }
deno_terminal = { version = "=0.2.2", optional = true }
deno_semver = { version = "=0.9.0", optional = true }
deno_napi = { version = "^0.144.0", optional = true }
deno_npm = { version = "=0.36.0", optional = true }
deno_process = { version = "^0.28.0", optional = true }
deno_package_json = { version = "=0.15.0", optional = true }
deno_resolver = { version = "^0.57.0", optional = true }
node_resolver = { version = "^0.64.0", optional = true, features = ["sync"] }
deno_runtime = { version = "^0.234.0", optional = true, features = ["exclude_runtime_main_js"] }
deno_terminal = { version = "^0.2.3", optional = true }
deno_semver = { version = "^0.9.1", optional = true }
deno_napi = { version = "^0.157.0", optional = true }
deno_npm = { version = "^0.42.2", optional = true }
deno_process = { version = "^0.41.0", optional = true }
deno_package_json = { version = "^0.28.0", optional = true }
checksum = { version = "0.2.1", optional = true }
sys_traits = { version = "=0.1.17", optional = true }
sys_traits = { version = "=0.1.17", optional = true, features = ["libc", "real", "winapi"] }

[dev-dependencies]
version-sync = "0.9.5"
Expand Down
10 changes: 6 additions & 4 deletions examples/custom_import_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl ImportProvider for MyImportProvider {
specifier: &ModuleSpecifier,
_referrer: Option<&ModuleSpecifier>,
_is_dyn_import: bool,
_requested_module_type: deno_core::RequestedModuleType,
) -> Option<Result<String, ModuleLoaderError>> {
match specifier.scheme() {
//
Expand All @@ -102,7 +101,10 @@ impl ImportProvider for MyImportProvider {

fn main() -> Result<(), rustyscript::Error> {
let mut import_provider = MyImportProvider::default();
import_provider.add_redirect("mod_assert", "https://deno.land/std@0.224.0/assert/mod.ts")?;
import_provider.add_redirect(
"mod_assert",
"https://deno.land/std@0.224.0/assert/assert.ts",
)?;
import_provider.add_static_module("my-module", "export const foo = 1");

let mut runtime = Runtime::new(RuntimeOptions {
Expand All @@ -113,10 +115,10 @@ fn main() -> Result<(), rustyscript::Error> {
let module = Module::new(
"custom_imports.js",
"
import { assertEquals } from 'redirect:mod_assert';
import { assert } from 'redirect:mod_assert';
import { foo } from 'static:my-module';

assertEquals(1, foo)
assert(foo === 1);
",
);

Expand Down
1 change: 0 additions & 1 deletion examples/module_loader_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl ImportProvider for MemoryCache {
specifier: &ModuleSpecifier,
_referrer: Option<&ModuleSpecifier>,
_is_dyn_import: bool,
_requested_module_type: deno_core::RequestedModuleType,
) -> Option<Result<String, ModuleLoaderError>> {
// Return the source code if the module is in the cache
self.get(specifier).map(Ok)
Expand Down
4 changes: 2 additions & 2 deletions src/async_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl TokioRuntime {
///
/// This runs the given future on the current thread, blocking until it is complete, and yielding its resolved result. Any tasks or timers which the future spawns internally will be executed on the runtime.
///
/// When this is used on a `current_thread` runtime, only the [`Runtime::block_on`] method can drive the IO and timer drivers, but the `Handle::block_on` method cannot drive them.
/// This means that, when using this method on a `current_thread` runtime, anything that relies on IO or timers will not work unless there is another thread currently calling [`Runtime::block_on`] on the same runtime.
/// When this is used on a `current_thread` runtime, only the [`tokio::runtime::Runtime::block_on`] method can drive the IO and timer drivers, but the `Handle::block_on` method cannot drive them.
/// This means that, when using this method on a `current_thread` runtime, anything that relies on IO or timers will not work unless there is another thread currently calling [`tokio::runtime::Runtime::block_on`] on the same runtime.
pub fn block_on<F, T>(&self, f: F) -> T
where
F: std::future::Future<Output = T>,
Expand Down
13 changes: 8 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ impl From<deno_core::error::JsError> for Error {
}
}

impl From<Box<deno_core::error::JsError>> for Error {
fn from(err: Box<deno_core::error::JsError>) -> Self {
Self::JsError(err)
}
}

impl Error {
/// Formats an error for display in a terminal
/// If the error is a `JsError`, it will attempt to highlight the source line
Expand Down Expand Up @@ -239,7 +245,7 @@ map_error!(deno_ast::TranspileError, |e| Error::Runtime(e.to_string()));
map_error!(deno_core::error::CoreError, |e| {
let e = e.into_kind();
match e {
CoreErrorKind::Js(js_error) => Error::JsError(Box::new(js_error)),
CoreErrorKind::Js(js_error) => Error::JsError(js_error),
_ => Error::Runtime(e.to_string()),
}
});
Expand Down Expand Up @@ -273,10 +279,7 @@ map_error!(deno_core::futures::channel::oneshot::Canceled, |e| {
Error::Timeout(e.to_string())
});

#[cfg(feature = "broadcast_channel")]
map_error!(deno_broadcast_channel::BroadcastChannelError, |e| {
Error::Runtime(e.to_string())
});
// Note: BroadcastChannelError mapping removed - no longer exported from deno_web

#[cfg(test)]
mod test {
Expand Down
1 change: 1 addition & 0 deletions src/ext/broadcast_channel/01_broadcast_channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "ext:deno_web/01_broadcast_channel.js";
75 changes: 19 additions & 56 deletions src/ext/broadcast_channel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,42 @@
use deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_core::{extension, Extension};
use deno_web::InMemoryBroadcastChannel;

use super::ExtensionTrait;

mod wrapper;
pub use wrapper::BroadcastChannelWrapper;
// Note: The BroadcastChannelWrapper has been removed due to upstream API changes
// in deno_web. The broadcast channel methods are now private and only accessible
// through JavaScript ops. Use the JavaScript BroadcastChannel API directly.

extension!(
init_broadcast_channel,
deps = [rustyscript],
esm_entry_point = "ext:init_broadcast_channel/init_broadcast_channel.js",
esm = [ dir "src/ext/broadcast_channel", "init_broadcast_channel.js" ],
);

extension!(
deno_broadcast_channel,
deps = [deno_web],
esm = [ dir "src/ext/broadcast_channel", "01_broadcast_channel.js" ],
);

impl ExtensionTrait<()> for init_broadcast_channel {
fn init((): ()) -> Extension {
init_broadcast_channel::init()
}
}
impl ExtensionTrait<InMemoryBroadcastChannel> for deno_broadcast_channel::deno_broadcast_channel {
fn init(channel: InMemoryBroadcastChannel) -> Extension {
deno_broadcast_channel::deno_broadcast_channel::init(channel)

impl ExtensionTrait<()> for deno_broadcast_channel {
fn init((): ()) -> Extension {
deno_broadcast_channel::init()
}
}

pub fn extensions(channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
// Note: broadcast_channel functionality is now integrated into deno_web
// No separate initialization is needed as it's handled by deno_web extension
pub fn extensions(_channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
vec![
deno_broadcast_channel::deno_broadcast_channel::build(channel, is_snapshot),
deno_broadcast_channel::build((), is_snapshot),
init_broadcast_channel::build((), is_snapshot),
]
}

#[cfg(test)]
mod test {
use deno_core::PollEventLoopOptions;

use crate::{module, BroadcastChannelWrapper, Module, Runtime, RuntimeOptions};

static TEST_MOD: Module = module!(
"test.js",
"
const channel = new BroadcastChannel('my_channel');
channel.onmessage = (event) => {
channel.postMessage('Received: ' + event.data);
};
"
);

#[test]
fn test_broadcast_channel() {
let options = RuntimeOptions::default();
let channel = options.extension_options.broadcast_channel.clone();

let mut runtime = Runtime::new(options).unwrap();
let tokio_runtime = runtime.tokio_runtime();

let channel = BroadcastChannelWrapper::new(&channel, "my_channel").unwrap();

tokio_runtime
.block_on(runtime.load_module_async(&TEST_MOD))
.unwrap();

channel.send_sync(&mut runtime, "foo").unwrap();

runtime
.block_on_event_loop(
PollEventLoopOptions::default(),
Some(std::time::Duration::from_secs(1)),
)
.unwrap();

let value = channel
.recv_sync::<String>(&mut runtime, Some(std::time::Duration::from_secs(1)))
.unwrap()
.unwrap();

assert_eq!(value, "Received: foo");
}
}
Loading