feat: Codegen feature flags (#28920)

This commit adds "deno_features" crate that contains definitions of all
unstable features in Deno.

Based on these definitions, both Rust and JS code is generated ensuring
that the two are always in sync.

In addition some of flag handling was rewritten to use the generated
definitions, instead of hand rolling these flag definitions.

---------

Co-authored-by: snek <snek@deno.com>
This commit is contained in:
Bartek Iwańczuk 2025-04-25 10:33:45 +02:00 committed by GitHub
parent 4924731ac3
commit 189ccffdb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 701 additions and 284 deletions

View file

@ -51,133 +51,7 @@ pub use worker_bootstrap::WorkerExecutionMode;
pub use worker_bootstrap::WorkerLogLevel;
pub mod shared;
pub use deno_features::UnstableFeatureKind;
pub use deno_features::UNSTABLE_FEATURES;
pub use deno_os::exit;
pub use shared::runtime;
pub struct UnstableGranularFlag {
pub name: &'static str,
pub help_text: &'static str,
pub show_in_help: bool,
// id to enable it in runtime/99_main.js
pub id: i32,
}
// NOTE(bartlomieju): keep IDs in sync with `runtime/js/90_deno_ns.js` (search for `unstableFeatures`)
pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
UnstableGranularFlag {
name: deno_broadcast_channel::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable `BroadcastChannel` API",
show_in_help: true,
id: 1,
},
UnstableGranularFlag {
name: deno_cron::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable Deno.cron API",
show_in_help: true,
id: 2,
},
UnstableGranularFlag {
name: deno_ffi::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable FFI APIs",
show_in_help: false,
id: 3,
},
UnstableGranularFlag {
name: deno_fs::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable file system APIs",
show_in_help: false,
id: 4,
},
UnstableGranularFlag {
name: ops::http::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable HTTP APIs",
show_in_help: false,
id: 5,
},
UnstableGranularFlag {
name: deno_kv::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable Key-Value store APIs",
show_in_help: true,
id: 6,
},
UnstableGranularFlag {
name: deno_net::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable net APIs",
show_in_help: true,
id: 7,
},
UnstableGranularFlag {
name: "no-legacy-abort",
help_text: "Enable abort signal in Deno.serve without legacy behavior. This will not abort the server when the request is handled successfully.",
show_in_help: true,
id: 8,
},
UnstableGranularFlag {
name: "node-globals",
help_text: "Expose Node globals everywhere",
show_in_help: true,
id: 9,
},
UnstableGranularFlag {
name: "otel",
help_text: "Enable unstable OpenTelemetry features",
show_in_help: false,
id: 10,
},
// TODO(bartlomieju): consider removing it
UnstableGranularFlag {
name: deno_process::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable process APIs",
show_in_help: false,
id: 11,
},
UnstableGranularFlag {
name: "temporal",
help_text: "Enable unstable Temporal API",
show_in_help: true,
id: 12,
},
UnstableGranularFlag {
name: "unsafe-proto",
help_text: "Enable unsafe __proto__ support. This is a security risk.",
show_in_help: true,
// This number is used directly in the JS code. Search
// for "unstableIds" to see where it's used.
id: 13,
},
UnstableGranularFlag {
name: "vsock",
help_text: "Enable unstable VSOCK APIs",
show_in_help: false,
id: 14,
},
UnstableGranularFlag {
name: deno_webgpu::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable `WebGPU` APIs",
show_in_help: true,
id: 15,
},
UnstableGranularFlag {
name: ops::worker_host::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable Web Worker APIs",
show_in_help: true,
id: 16,
},
];
#[cfg(test)]
mod test {
use super::*;
#[test]
fn unstable_granular_flag_names_sorted() {
let flags = UNSTABLE_GRANULAR_FLAGS
.iter()
.map(|granular_flag| granular_flag.name.to_string())
.collect::<Vec<_>>();
let mut sorted_flags = flags.clone();
sorted_flags.sort();
// sort the flags by name so they appear nicely in the help text
assert_eq!(flags, sorted_flags);
}
}