From d20c9e75d1540b1a27e721d0cf66d29ba6a2c3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 22 Jan 2024 18:37:28 +0100 Subject: refactor: add "UnstableConfig" struct to cli/args/flags.rs (#21993) This commit adds "UnstableConfig" struct which centralizes handling of all "--unstable-*" flags. Closes https://github.com/denoland/deno/issues/21920 --- cli/standalone/binary.rs | 13 +++++++++---- cli/standalone/mod.rs | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'cli/standalone') diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index cdf86fffa..3204ca397 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -33,6 +33,7 @@ use crate::args::CaData; use crate::args::CliOptions; use crate::args::CompileFlags; use crate::args::PackageJsonDepsProvider; +use crate::args::UnstableConfig; use crate::cache::DenoDir; use crate::file_fetcher::FileFetcher; use crate::http_util::HttpClient; @@ -137,8 +138,6 @@ pub enum NodeModules { #[derive(Deserialize, Serialize)] pub struct Metadata { pub argv: Vec, - pub unstable: bool, - pub unstable_features: Vec, pub seed: Option, pub permissions: PermissionsOptions, pub location: Option, @@ -151,6 +150,7 @@ pub struct Metadata { pub entrypoint: ModuleSpecifier, pub node_modules: Option, pub disable_deprecated_api_warning: bool, + pub unstable_config: UnstableConfig, } pub fn load_npm_vfs(root_dir_path: PathBuf) -> Result { @@ -543,8 +543,6 @@ impl<'a> DenoCompileBinaryWriter<'a> { let metadata = Metadata { argv: compile_flags.args.clone(), - unstable: cli_options.unstable(), - unstable_features: cli_options.unstable_features(), seed: cli_options.seed(), location: cli_options.location_flag().clone(), permissions: cli_options.permissions_options(), @@ -560,6 +558,13 @@ impl<'a> DenoCompileBinaryWriter<'a> { node_modules, disable_deprecated_api_warning: cli_options .disable_deprecated_api_warning, + unstable_config: UnstableConfig { + legacy_flag_enabled: cli_options.legacy_unstable_flag(), + bare_node_builtins: cli_options.unstable_bare_node_builtins(), + byonm: cli_options.unstable_byonm(), + sloppy_imports: cli_options.unstable_sloppy_imports(), + features: cli_options.unstable_features(), + }, }; write_binary_bytes( diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 8a98636a4..7054e3451 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -487,10 +487,10 @@ pub async fn run( // TODO(bartlomieju): enable, once we deprecate `--unstable` in favor // of granular --unstable-* flags. // feature_checker.set_warn_cb(Box::new(crate::unstable_warn_cb)); - if metadata.unstable { + if metadata.unstable_config.legacy_flag_enabled { checker.enable_legacy_unstable(); } - for feature in metadata.unstable_features { + for feature in metadata.unstable_config.features { // `metadata` is valid for the whole lifetime of the program, so we // can leak the string here. checker.enable_feature(feature.leak()); @@ -535,7 +535,7 @@ pub async fn run( seed: metadata.seed, unsafely_ignore_certificate_errors: metadata .unsafely_ignore_certificate_errors, - unstable: metadata.unstable, + unstable: metadata.unstable_config.legacy_flag_enabled, maybe_root_package_json_deps: package_json_deps_provider.deps().cloned(), }, None, -- cgit v1.2.3