mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor(core): Extension::builder_with_deps (#18093)
Prerequisite for https://github.com/denoland/deno/pull/18080
This commit is contained in:
parent
521cb4ca9b
commit
c3cba7f22c
17 changed files with 309 additions and 289 deletions
|
@ -77,7 +77,7 @@ pub struct Extension {
|
|||
initialized: bool,
|
||||
enabled: bool,
|
||||
name: &'static str,
|
||||
deps: Option<Vec<&'static str>>,
|
||||
deps: Option<&'static [&'static str]>,
|
||||
}
|
||||
|
||||
// Note: this used to be a trait, but we "downgraded" it to a single concrete type
|
||||
|
@ -90,11 +90,22 @@ impl Extension {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn builder_with_deps(
|
||||
name: &'static str,
|
||||
deps: &'static [&'static str],
|
||||
) -> ExtensionBuilder {
|
||||
ExtensionBuilder {
|
||||
name,
|
||||
deps,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if dependencies have been loaded, and errors if either:
|
||||
/// - The extension is depending on itself or an extension with the same name.
|
||||
/// - A dependency hasn't been loaded yet.
|
||||
pub fn check_dependencies(&self, previous_exts: &[&mut Extension]) {
|
||||
if let Some(deps) = &self.deps {
|
||||
if let Some(deps) = self.deps {
|
||||
'dep_loop: for dep in deps {
|
||||
if dep == &self.name {
|
||||
panic!("Extension '{}' is either depending on itself or there is another extension with the same name", self.name);
|
||||
|
@ -194,15 +205,10 @@ pub struct ExtensionBuilder {
|
|||
middleware: Option<Box<OpMiddlewareFn>>,
|
||||
event_loop_middleware: Option<Box<OpEventLoopFn>>,
|
||||
name: &'static str,
|
||||
deps: Vec<&'static str>,
|
||||
deps: &'static [&'static str],
|
||||
}
|
||||
|
||||
impl ExtensionBuilder {
|
||||
pub fn dependencies(&mut self, dependencies: Vec<&'static str>) -> &mut Self {
|
||||
self.deps.extend(dependencies);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn js(&mut self, js_files: Vec<ExtensionFileSource>) -> &mut Self {
|
||||
let js_files =
|
||||
// TODO(bartlomieju): if we're automatically remapping here, then we should
|
||||
|
|
|
@ -110,8 +110,10 @@ pub fn init<BC: BroadcastChannel + 'static>(
|
|||
bc: BC,
|
||||
unstable: bool,
|
||||
) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_web"],
|
||||
)
|
||||
.esm(include_js_files!("01_broadcast_channel.js",))
|
||||
.ops(vec![
|
||||
op_broadcast_subscribe::decl::<BC>(),
|
||||
|
|
6
ext/cache/lib.rs
vendored
6
ext/cache/lib.rs
vendored
|
@ -25,8 +25,10 @@ pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
|
|||
pub fn init<CA: Cache + 'static>(
|
||||
maybe_create_cache: Option<CreateCache<CA>>,
|
||||
) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_fetch"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_web", "deno_url", "deno_fetch"],
|
||||
)
|
||||
.esm(include_js_files!("01_cache.js",))
|
||||
.ops(vec![
|
||||
op_cache_storage_open::decl::<CA>(),
|
||||
|
|
|
@ -73,8 +73,10 @@ use crate::key::HkdfOutput;
|
|||
use crate::shared::RawKeyData;
|
||||
|
||||
pub fn init(maybe_seed: Option<u64>) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_web"],
|
||||
)
|
||||
.esm(include_js_files!("00_crypto.js", "01_webidl.js",))
|
||||
.ops(vec![
|
||||
op_crypto_get_random_values::decl(),
|
||||
|
|
|
@ -95,8 +95,10 @@ pub fn init<FP>(options: Options) -> Extension
|
|||
where
|
||||
FP: FetchPermissions + 'static,
|
||||
{
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web", "deno_url", "deno_console"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_web", "deno_url", "deno_console"],
|
||||
)
|
||||
.esm(include_js_files!(
|
||||
"20_headers.js",
|
||||
"21_formdata.js",
|
||||
|
|
|
@ -82,8 +82,7 @@ pub(crate) struct FfiState {
|
|||
}
|
||||
|
||||
pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_web"])
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
||||
.esm(include_js_files!("00_ffi.js",))
|
||||
.ops(vec![
|
||||
op_ffi_load::decl::<P>(),
|
||||
|
|
|
@ -1527,14 +1527,16 @@ pub trait FlashPermissions {
|
|||
}
|
||||
|
||||
pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec![
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&[
|
||||
"deno_web",
|
||||
"deno_net",
|
||||
"deno_fetch",
|
||||
"deno_websocket",
|
||||
"deno_http",
|
||||
])
|
||||
],
|
||||
)
|
||||
.esm(deno_core::include_js_files!("01_http.js",))
|
||||
.ops(vec![
|
||||
op_flash_serve::decl::<P>(),
|
||||
|
|
|
@ -78,8 +78,10 @@ pub mod compressible;
|
|||
mod reader_stream;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_web", "deno_net", "deno_fetch", "deno_websocket"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_web", "deno_net", "deno_fetch", "deno_websocket"],
|
||||
)
|
||||
.esm(include_js_files!("01_http.js",))
|
||||
.ops(vec![
|
||||
op_http_accept::decl(),
|
||||
|
|
|
@ -82,9 +82,8 @@ pub fn init(stdio: Stdio) -> Extension {
|
|||
// todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics
|
||||
let stdio = Rc::new(RefCell::new(Some(stdio)));
|
||||
|
||||
Extension::builder("deno_io")
|
||||
Extension::builder_with_deps("deno_io", &["deno_web"])
|
||||
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
||||
.dependencies(vec!["deno_web"])
|
||||
.esm(include_js_files!("12_io.js",))
|
||||
.middleware(|op| match op.name {
|
||||
"op_print" => op_print::decl(),
|
||||
|
|
|
@ -84,8 +84,7 @@ pub fn init<P: NetPermissions + 'static>(
|
|||
) -> Extension {
|
||||
let mut ops = ops::init::<P>();
|
||||
ops.extend(ops_tls::init::<P>());
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_web"])
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_web"])
|
||||
.esm(include_js_files!("01_net.js", "02_tls.js",))
|
||||
.ops(ops)
|
||||
.state(move |state| {
|
||||
|
|
|
@ -332,10 +332,9 @@ pub fn init_polyfill_ops_and_esm() -> Extension {
|
|||
"zlib.ts",
|
||||
);
|
||||
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_io", "deno_fs"])
|
||||
.esm(esm_files)
|
||||
.esm_entry_point("ext:deno_node/module_all.ts")
|
||||
.dependencies(vec!["deno_io", "deno_fs"])
|
||||
.ops(vec![
|
||||
crypto::op_node_create_hash::decl(),
|
||||
crypto::op_node_hash_update::decl(),
|
||||
|
|
|
@ -18,8 +18,7 @@ use crate::urlpattern::op_urlpattern_parse;
|
|||
use crate::urlpattern::op_urlpattern_process_match_input;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl"])
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
||||
.esm(include_js_files!("00_url.js", "01_urlpattern.js",))
|
||||
.ops(vec![
|
||||
op_url_reparse::decl(),
|
||||
|
|
|
@ -62,8 +62,10 @@ pub fn init<P: TimersPermission + 'static>(
|
|||
blob_store: BlobStore,
|
||||
maybe_location: Option<Url>,
|
||||
) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_console", "deno_url"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_console", "deno_url"],
|
||||
)
|
||||
.esm(include_js_files!(
|
||||
"00_infra.js",
|
||||
"01_dom_exception.js",
|
||||
|
|
|
@ -117,8 +117,10 @@ impl Resource for WebGpuQuerySet {
|
|||
}
|
||||
|
||||
pub fn init(unstable: bool) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_webidl", "deno_web"],
|
||||
)
|
||||
.esm(include_js_files!("01_webgpu.js", "02_idl_types.js",))
|
||||
.ops(declare_webgpu_ops())
|
||||
.state(move |state| {
|
||||
|
|
|
@ -502,8 +502,10 @@ pub fn init<P: WebSocketPermissions + 'static>(
|
|||
root_cert_store: Option<RootCertStore>,
|
||||
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
||||
) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_url", "deno_webidl"])
|
||||
Extension::builder_with_deps(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&["deno_url", "deno_webidl"],
|
||||
)
|
||||
.esm(include_js_files!(
|
||||
"01_websocket.js",
|
||||
"02_websocketstream.js",
|
||||
|
|
|
@ -22,8 +22,7 @@ struct OriginStorageDir(PathBuf);
|
|||
const MAX_STORAGE_BYTES: u32 = 10 * 1024 * 1024;
|
||||
|
||||
pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl"])
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl"])
|
||||
.esm(include_js_files!("01_webstorage.js",))
|
||||
.ops(vec![
|
||||
op_webstorage_length::decl(),
|
||||
|
|
|
@ -204,8 +204,9 @@ mod startup_snapshot {
|
|||
snapshot_path: PathBuf,
|
||||
maybe_additional_extension: Option<Extension>,
|
||||
) {
|
||||
let runtime_extension = Extension::builder("runtime")
|
||||
.dependencies(vec![
|
||||
let runtime_extension = Extension::builder_with_deps(
|
||||
"runtime",
|
||||
&[
|
||||
"deno_webidl",
|
||||
"deno_console",
|
||||
"deno_url",
|
||||
|
@ -227,7 +228,8 @@ mod startup_snapshot {
|
|||
"deno_flash",
|
||||
"deno_io",
|
||||
"deno_fs",
|
||||
])
|
||||
],
|
||||
)
|
||||
.esm(include_js_files!(
|
||||
dir "js",
|
||||
"01_errors.js",
|
||||
|
|
Loading…
Add table
Reference in a new issue