Skip to content

Commit 4d2b569

Browse files
authored
refactor: merge deno_broadcast_channel into deno_web (#31198)
This commit deprecated `deno_broadcast_channel` crate and merges it into `deno_web`. This will allow us to limit number of crates we need to publish and (maybe) improve compile and link times. The actual `ext/broadcast_channel` directory will be removed in a follow up PR, once a new version is published and points to deno_web crate.
1 parent 2eb0341 commit 4d2b569

24 files changed

+299
-330
lines changed

Cargo.lock

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ members = [
88
"cli/lib",
99
"cli/rt",
1010
"cli/snapshot",
11-
"ext/broadcast_channel",
1211
"ext/bundle",
1312
"ext/canvas",
1413
"ext/cron",
@@ -86,7 +85,6 @@ denokv_remote = "0.12.0"
8685
denokv_sqlite = { default-features = false, version = "0.12.0" }
8786

8887
# exts
89-
deno_broadcast_channel = { version = "0.215.0", path = "./ext/broadcast_channel" }
9088
deno_bundle_runtime = { version = "0.8.0", path = "./ext/bundle" }
9189
deno_canvas = { version = "0.90.0", path = "./ext/canvas" }
9290
deno_cron = { version = "0.101.0", path = "./ext/cron" }
@@ -438,8 +436,6 @@ opt-level = 3
438436
opt-level = 3
439437
[profile.release.package.deno_bench_util]
440438
opt-level = 3
441-
[profile.release.package.deno_broadcast_channel]
442-
opt-level = 3
443439
[profile.release.package.deno_core]
444440
opt-level = 3
445441
[profile.release.package.deno_crypto]

cli/lib/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use deno_runtime::UNSTABLE_FEATURES;
1818
use deno_runtime::WorkerExecutionMode;
1919
use deno_runtime::WorkerLogLevel;
2020
use deno_runtime::colors;
21-
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
2221
use deno_runtime::deno_core;
2322
use deno_runtime::deno_core::CompiledWasmModuleStore;
2423
use deno_runtime::deno_core::Extension;
@@ -38,6 +37,7 @@ use deno_runtime::deno_process::NpmProcessStateProviderRc;
3837
use deno_runtime::deno_telemetry::OtelConfig;
3938
use deno_runtime::deno_tls::RootCertStoreProvider;
4039
use deno_runtime::deno_web::BlobStore;
40+
use deno_runtime::deno_web::InMemoryBroadcastChannel;
4141
use deno_runtime::fmt_errors::format_js_error;
4242
use deno_runtime::inspector_server::InspectorServer;
4343
use deno_runtime::ops::worker_host::CreateWebWorkerCb;

ext/broadcast_channel/Cargo.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22

33
[package]
44
name = "deno_broadcast_channel"
5-
version = "0.215.0"
5+
version = "0.216.0"
66
authors.workspace = true
77
edition.workspace = true
88
license.workspace = true
99
readme = "README.md"
1010
repository.workspace = true
11-
description = "Implementation of BroadcastChannel API for Deno"
11+
description = "DEPRECATED: Use deno_web instead"
1212

1313
[lib]
1414
path = "lib.rs"
15-
16-
[dependencies]
17-
async-trait.workspace = true
18-
deno_core.workspace = true
19-
deno_error.workspace = true
20-
deno_features.workspace = true
21-
thiserror.workspace = true
22-
tokio.workspace = true
23-
uuid.workspace = true

ext/broadcast_channel/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# deno_broadcast_channel
1+
# deno_cache
22

3-
This crate implements the BroadcastChannel functions of Deno.
4-
5-
Spec: https://html.spec.whatwg.org/multipage/web-messaging.html
3+
This crate has been deprecated, use
4+
[deno_web](https://crates.io/crates/deno_web) instead.

ext/broadcast_channel/in_memory_broadcast_channel.rs

Lines changed: 0 additions & 102 deletions
This file was deleted.

ext/broadcast_channel/lib.rs

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
2-
3-
mod in_memory_broadcast_channel;
4-
5-
use std::cell::RefCell;
6-
use std::rc::Rc;
7-
use std::sync::Arc;
8-
9-
use async_trait::async_trait;
10-
use deno_core::JsBuffer;
11-
use deno_core::OpState;
12-
use deno_core::Resource;
13-
use deno_core::ResourceId;
14-
use deno_core::op2;
15-
use deno_error::JsErrorBox;
16-
use deno_features::FeatureChecker;
17-
pub use in_memory_broadcast_channel::InMemoryBroadcastChannel;
18-
pub use in_memory_broadcast_channel::InMemoryBroadcastChannelResource;
19-
use tokio::sync::broadcast::error::SendError as BroadcastSendError;
20-
use tokio::sync::mpsc::error::SendError as MpscSendError;
21-
22-
pub const UNSTABLE_FEATURE_NAME: &str = "broadcast-channel";
23-
24-
#[derive(Debug, thiserror::Error, deno_error::JsError)]
25-
pub enum BroadcastChannelError {
26-
#[class(inherit)]
27-
#[error(transparent)]
28-
Resource(
29-
#[from]
30-
#[inherit]
31-
deno_core::error::ResourceError,
32-
),
33-
#[class(generic)]
34-
#[error(transparent)]
35-
MPSCSendError(MpscSendError<Box<dyn std::fmt::Debug + Send + Sync>>),
36-
#[class(generic)]
37-
#[error(transparent)]
38-
BroadcastSendError(
39-
BroadcastSendError<Box<dyn std::fmt::Debug + Send + Sync>>,
40-
),
41-
#[class(inherit)]
42-
#[error(transparent)]
43-
Other(#[inherit] JsErrorBox),
44-
}
45-
46-
impl<T: std::fmt::Debug + Send + Sync + 'static> From<MpscSendError<T>>
47-
for BroadcastChannelError
48-
{
49-
fn from(value: MpscSendError<T>) -> Self {
50-
BroadcastChannelError::MPSCSendError(MpscSendError(Box::new(value.0)))
51-
}
52-
}
53-
impl<T: std::fmt::Debug + Send + Sync + 'static> From<BroadcastSendError<T>>
54-
for BroadcastChannelError
55-
{
56-
fn from(value: BroadcastSendError<T>) -> Self {
57-
BroadcastChannelError::BroadcastSendError(BroadcastSendError(Box::new(
58-
value.0,
59-
)))
60-
}
61-
}
62-
63-
#[async_trait]
64-
pub trait BroadcastChannel: Clone {
65-
type Resource: Resource;
66-
67-
fn subscribe(&self) -> Result<Self::Resource, BroadcastChannelError>;
68-
69-
fn unsubscribe(
70-
&self,
71-
resource: &Self::Resource,
72-
) -> Result<(), BroadcastChannelError>;
73-
74-
async fn send(
75-
&self,
76-
resource: &Self::Resource,
77-
name: String,
78-
data: Vec<u8>,
79-
) -> Result<(), BroadcastChannelError>;
80-
81-
async fn recv(
82-
&self,
83-
resource: &Self::Resource,
84-
) -> Result<Option<Message>, BroadcastChannelError>;
85-
}
86-
87-
pub type Message = (String, Vec<u8>);
88-
89-
#[op2(fast)]
90-
#[smi]
91-
pub fn op_broadcast_subscribe<BC>(
92-
state: &mut OpState,
93-
) -> Result<ResourceId, BroadcastChannelError>
94-
where
95-
BC: BroadcastChannel + 'static,
96-
{
97-
state
98-
.borrow::<Arc<FeatureChecker>>()
99-
.check_or_exit(UNSTABLE_FEATURE_NAME, "BroadcastChannel");
100-
let bc = state.borrow::<BC>();
101-
let resource = bc.subscribe()?;
102-
Ok(state.resource_table.add(resource))
103-
}
104-
105-
#[op2(fast)]
106-
pub fn op_broadcast_unsubscribe<BC>(
107-
state: &mut OpState,
108-
#[smi] rid: ResourceId,
109-
) -> Result<(), BroadcastChannelError>
110-
where
111-
BC: BroadcastChannel + 'static,
112-
{
113-
let resource = state.resource_table.get::<BC::Resource>(rid)?;
114-
let bc = state.borrow::<BC>();
115-
bc.unsubscribe(&resource)
116-
}
117-
118-
#[op2(async)]
119-
pub async fn op_broadcast_send<BC>(
120-
state: Rc<RefCell<OpState>>,
121-
#[smi] rid: ResourceId,
122-
#[string] name: String,
123-
#[buffer] buf: JsBuffer,
124-
) -> Result<(), BroadcastChannelError>
125-
where
126-
BC: BroadcastChannel + 'static,
127-
{
128-
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
129-
let bc = state.borrow().borrow::<BC>().clone();
130-
bc.send(&resource, name, buf.to_vec()).await
131-
}
132-
133-
#[op2(async)]
134-
#[serde]
135-
pub async fn op_broadcast_recv<BC>(
136-
state: Rc<RefCell<OpState>>,
137-
#[smi] rid: ResourceId,
138-
) -> Result<Option<Message>, BroadcastChannelError>
139-
where
140-
BC: BroadcastChannel + 'static,
141-
{
142-
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
143-
let bc = state.borrow().borrow::<BC>().clone();
144-
bc.recv(&resource).await
145-
}
146-
147-
deno_core::extension!(deno_broadcast_channel,
148-
deps = [ deno_webidl, deno_web ],
149-
parameters = [BC: BroadcastChannel],
150-
ops = [
151-
op_broadcast_subscribe<BC>,
152-
op_broadcast_unsubscribe<BC>,
153-
op_broadcast_send<BC>,
154-
op_broadcast_recv<BC>,
155-
],
156-
esm = [ "01_broadcast_channel.js" ],
157-
options = {
158-
bc: BC,
159-
},
160-
state = |state, options| {
161-
state.put(options.bc);
162-
},
163-
);

ext/node/polyfills/worker_threads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import * as webidl from "ext:deno_webidl/00_webidl.js";
2727
import { notImplemented } from "ext:deno_node/_utils.ts";
2828
import { EventEmitter } from "node:events";
29-
import { BroadcastChannel } from "ext:deno_broadcast_channel/01_broadcast_channel.js";
29+
import { BroadcastChannel } from "ext:deno_web/01_broadcast_channel.js";
3030
import { untransferableSymbol } from "ext:deno_node/internal_binding/util.ts";
3131
import process from "node:process";
3232
import { createRequire } from "node:module";
File renamed without changes.

ext/web/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bytes.workspace = true
2121
chrono = { workspace = true, features = ["now"] }
2222
deno_core.workspace = true
2323
deno_error.workspace = true
24+
deno_features.workspace = true
2425
deno_permissions.workspace = true
2526
encoding_rs.workspace = true
2627
flate2 = { workspace = true, features = ["default"] }

0 commit comments

Comments
 (0)