diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-22 18:37:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 17:37:28 +0000 |
commit | d20c9e75d1540b1a27e721d0cf66d29ba6a2c3fb (patch) | |
tree | 83059b5759fad286d8131795d7d79d6fee5bb440 /cli/standalone | |
parent | bc92f872988fd8b9cdf2ae1479278789911237a5 (diff) |
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
Diffstat (limited to 'cli/standalone')
-rw-r--r-- | cli/standalone/binary.rs | 13 | ||||
-rw-r--r-- | cli/standalone/mod.rs | 6 |
2 files changed, 12 insertions, 7 deletions
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<String>, - pub unstable: bool, - pub unstable_features: Vec<String>, pub seed: Option<u64>, pub permissions: PermissionsOptions, pub location: Option<Url>, @@ -151,6 +150,7 @@ pub struct Metadata { pub entrypoint: ModuleSpecifier, pub node_modules: Option<NodeModules>, pub disable_deprecated_api_warning: bool, + pub unstable_config: UnstableConfig, } pub fn load_npm_vfs(root_dir_path: PathBuf) -> Result<FileBackedVfs, AnyError> { @@ -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, |