Skip to content

Commit 0b21cfa

Browse files
committed
fix: update API compatibility for all features
- Fix ImportProvider trait signature (remove requested_module_type param) - Update node resolver APIs (PackageJsonCache, NpmPackageFolderResolver) - Move BroadcastChannel type from deno_broadcast_channel to deno_web - Add broadcast_channel field to WebOptions - Remove generic type parameters from extension init functions - Update permissions and resolver traits to match deno upgrades
1 parent 2cd6dfc commit 0b21cfa

17 files changed

Lines changed: 1279 additions & 1328 deletions

File tree

examples/custom_import_logic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ impl ImportProvider for MyImportProvider {
7878
specifier: &ModuleSpecifier,
7979
_referrer: Option<&ModuleSpecifier>,
8080
_is_dyn_import: bool,
81-
_requested_module_type: deno_core::RequestedModuleType,
8281
) -> Option<Result<String, ModuleLoaderError>> {
8382
match specifier.scheme() {
8483
//

examples/module_loader_cache.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl ImportProvider for MemoryCache {
4343
specifier: &ModuleSpecifier,
4444
_referrer: Option<&ModuleSpecifier>,
4545
_is_dyn_import: bool,
46-
_requested_module_type: deno_core::RequestedModuleType,
4746
) -> Option<Result<String, ModuleLoaderError>> {
4847
// Return the source code if the module is in the cache
4948
self.get(specifier).map(Ok)

src/ext/broadcast_channel/mod.rs

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,41 @@
1-
use deno_broadcast_channel::InMemoryBroadcastChannel;
21
use deno_core::{extension, Extension};
2+
use deno_web::InMemoryBroadcastChannel;
33

44
use super::ExtensionTrait;
55

66
mod wrapper;
7-
pub use wrapper::BroadcastChannelWrapper;
7+
pub use wrapper::{BroadcastChannel, BroadcastChannelWrapper};
88

99
extension!(
1010
init_broadcast_channel,
1111
deps = [rustyscript],
1212
esm_entry_point = "ext:init_broadcast_channel/init_broadcast_channel.js",
1313
esm = [ dir "src/ext/broadcast_channel", "init_broadcast_channel.js" ],
1414
);
15+
16+
extension!(
17+
deno_broadcast_channel,
18+
deps = [deno_web],
19+
esm = [ dir "src/ext/broadcast_channel", "01_broadcast_channel.js" ],
20+
);
21+
1522
impl ExtensionTrait<()> for init_broadcast_channel {
1623
fn init((): ()) -> Extension {
1724
init_broadcast_channel::init()
1825
}
1926
}
20-
impl ExtensionTrait<InMemoryBroadcastChannel> for deno_broadcast_channel::deno_broadcast_channel {
21-
fn init(channel: InMemoryBroadcastChannel) -> Extension {
22-
deno_broadcast_channel::deno_broadcast_channel::init(channel)
27+
28+
impl ExtensionTrait<()> for deno_broadcast_channel {
29+
fn init((): ()) -> Extension {
30+
deno_broadcast_channel::init()
2331
}
2432
}
2533

26-
pub fn extensions(channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
34+
// Note: broadcast_channel functionality is now integrated into deno_web
35+
// No separate initialization is needed as it's handled by deno_web extension
36+
pub fn extensions(_channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
2737
vec![
28-
deno_broadcast_channel::deno_broadcast_channel::build(channel, is_snapshot),
38+
deno_broadcast_channel::build((), is_snapshot),
2939
init_broadcast_channel::build((), is_snapshot),
3040
]
3141
}
32-
33-
#[cfg(test)]
34-
mod test {
35-
use deno_core::PollEventLoopOptions;
36-
37-
use crate::{module, BroadcastChannelWrapper, Module, Runtime, RuntimeOptions};
38-
39-
static TEST_MOD: Module = module!(
40-
"test.js",
41-
"
42-
const channel = new BroadcastChannel('my_channel');
43-
channel.onmessage = (event) => {
44-
channel.postMessage('Received: ' + event.data);
45-
};
46-
"
47-
);
48-
49-
#[test]
50-
fn test_broadcast_channel() {
51-
let options = RuntimeOptions::default();
52-
let channel = options.extension_options.broadcast_channel.clone();
53-
54-
let mut runtime = Runtime::new(options).unwrap();
55-
let tokio_runtime = runtime.tokio_runtime();
56-
57-
let channel = BroadcastChannelWrapper::new(&channel, "my_channel").unwrap();
58-
59-
tokio_runtime
60-
.block_on(runtime.load_module_async(&TEST_MOD))
61-
.unwrap();
62-
63-
channel.send_sync(&mut runtime, "foo").unwrap();
64-
65-
runtime
66-
.block_on_event_loop(
67-
PollEventLoopOptions::default(),
68-
Some(std::time::Duration::from_secs(1)),
69-
)
70-
.unwrap();
71-
72-
let value = channel
73-
.recv_sync::<String>(&mut runtime, Some(std::time::Duration::from_secs(1)))
74-
.unwrap()
75-
.unwrap();
76-
77-
assert_eq!(value, "Received: foo");
78-
}
79-
}

0 commit comments

Comments
 (0)