diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-08-30 17:58:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-30 21:58:24 +0000 |
commit | f891e73bbfc4a8f4f24039dd046c8d3de80e2c56 (patch) | |
tree | d3ca7e1163550cc7fee6d523269d6a3636218da0 /cli/args/flags.rs | |
parent | 55137c9db4ed7226a6a68256c3cb9fdad7ad7c83 (diff) |
refactor: remove DENO_FUTURE (#25314)
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 147 |
1 files changed, 41 insertions, 106 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 050d55f4c..a0cf4d7bf 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -10,7 +10,7 @@ use clap::ColorChoice; use clap::Command; use clap::ValueHint; use color_print::cstr; -use deno_config::deno_json::NodeModulesMode; +use deno_config::deno_json::NodeModulesDirMode; use deno_config::glob::FilePatterns; use deno_config::glob::PathOrPatternSet; use deno_core::anyhow::bail; @@ -41,7 +41,6 @@ use crate::args::resolve_no_prompt; use crate::util::fs::canonicalize_path; use super::flags_net; -use super::DENO_FUTURE; #[derive(Clone, Debug, Default, Eq, PartialEq)] pub enum ConfigFlag { @@ -580,7 +579,6 @@ fn parse_packages_allowed_scripts(s: &str) -> Result<String, AnyError> { pub struct UnstableConfig { pub legacy_flag_enabled: bool, // --unstable pub bare_node_builtins: bool, // --unstable-bare-node-builts - pub byonm: bool, pub sloppy_imports: bool, pub features: Vec<String>, // --unstabe-kv --unstable-cron } @@ -602,8 +600,7 @@ pub struct Flags { pub cached_only: bool, pub type_check_mode: TypeCheckMode, pub config_flag: ConfigFlag, - pub node_modules_dir: Option<bool>, - pub node_modules_mode: Option<NodeModulesMode>, + pub node_modules_dir: Option<NodeModulesDirMode>, pub vendor: Option<bool>, pub enable_op_summary_metrics: bool, pub enable_testing_features: bool, @@ -1114,7 +1111,6 @@ static ENV_VARIABLES_HELP: &str = cstr!( <g>DENO_AUTH_TOKENS</> A semi-colon separated list of bearer tokens and hostnames to use when fetching remote modules from private repositories <p(245)>(e.g. "abcde12345@deno.land;54321edcba@github.com")</> - <g>DENO_FUTURE</> Set to "1" to enable APIs that will take effect in Deno 2 <g>DENO_CERT</> Load certificate authorities from PEM encoded file <g>DENO_DIR</> Set the cache directory <g>DENO_INSTALL_ROOT</> Set deno install's output directory @@ -1508,11 +1504,7 @@ pub fn clap_root() -> Command { .subcommand(fmt_subcommand()) .subcommand(init_subcommand()) .subcommand(info_subcommand()) - .subcommand(if *DENO_FUTURE { - future_install_subcommand() - } else { - install_subcommand() - }) + .subcommand(future_install_subcommand()) .subcommand(json_reference_subcommand()) .subcommand(jupyter_subcommand()) .subcommand(uninstall_subcommand()) @@ -2365,7 +2357,7 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.", .arg(no_lock_arg()) .arg(config_arg()) .arg(import_map_arg()) - .args(node_modules_args()) + .arg(node_modules_dir_arg()) .arg(vendor_arg()) .arg( Arg::new("json") @@ -2375,22 +2367,13 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.", )) } -fn install_args(cmd: Command, deno_future: bool) -> Command { - let cmd = if deno_future { - cmd.arg( - Arg::new("cmd") - .required_if_eq("global", "true") - .num_args(1..) - .value_hint(ValueHint::FilePath), - ) - } else { - cmd.arg( - Arg::new("cmd") - .required_unless_present("help") - .num_args(1..) - .value_hint(ValueHint::FilePath), - ) - }; +fn install_args(cmd: Command) -> Command { + let cmd = cmd.arg( + Arg::new("cmd") + .required_if_eq("global", "true") + .num_args(1..) + .value_hint(ValueHint::FilePath), + ); cmd .arg( Arg::new("name") @@ -2466,40 +2449,7 @@ These must be added to the path manually if required.", UnstableArgsConfig::Reso .visible_alias("i") .defer(|cmd| { let cmd = runtime_args(cmd, true, true).arg(check_arg(true)).arg(allow_scripts_arg()); - install_args(cmd, true) - }) -} - -fn install_subcommand() -> Command { - command("install", - "Installs a script as an executable in the installation root's bin directory. - - deno install --global --allow-net --allow-read jsr:@std/http/file-server - deno install -g https://examples.deno.land/color-logging.ts - -To change the executable name, use -n/--name: - deno install -g --allow-net --allow-read -n serve jsr:@std/http/file-server - -The executable name is inferred by default: - - Attempt to take the file stem of the URL path. The above example would - become 'file_server'. - - If the file stem is something generic like 'main', 'mod', 'index' or 'cli', - and the path has no parent, take the file name of the parent path. Otherwise - settle with the generic name. - - If the resulting name has an '@...' suffix, strip it. - -To change the installation root, use --root: - deno install -g --allow-net --allow-read --root /usr/local jsr:@std/http/file-server - -The installation root is determined, in order of precedence: - - --root option - - DENO_INSTALL_ROOT environment variable - - $HOME/.deno - -These must be added to the path manually if required.", UnstableArgsConfig::ResolutionAndRuntime) - .defer(|cmd| { - let cmd = runtime_args(cmd, true, true).arg(check_arg(true)); - install_args(cmd, false) + install_args(cmd) }) } @@ -3180,7 +3130,7 @@ Remote modules and multiple modules may also be specified: .arg(config_arg()) .arg(import_map_arg()) .arg(lock_arg()) - .args(node_modules_args()) + .arg(node_modules_dir_arg()) .arg(vendor_arg()) .arg(reload_arg()) .arg(ca_file_arg()) @@ -3242,7 +3192,7 @@ fn compile_args_without_check_args(app: Command) -> Command { .arg(import_map_arg()) .arg(no_remote_arg()) .arg(no_npm_arg()) - .args(node_modules_args()) + .arg(node_modules_dir_arg()) .arg(vendor_arg()) .arg(config_arg()) .arg(no_config_arg()) @@ -3919,48 +3869,35 @@ fn no_npm_arg() -> Arg { } fn node_modules_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { - if *DENO_FUTURE { - let value = matches.remove_one::<NodeModulesMode>("node-modules"); - if let Some(mode) = value { - flags.node_modules_mode = Some(mode); + let value = matches.remove_one::<NodeModulesDirMode>("node-modules-dir"); + if let Some(mode) = value { + flags.node_modules_dir = Some(mode); + } +} + +fn node_modules_dir_arg() -> Arg { + fn parse_node_modules_dir_mode( + s: &str, + ) -> Result<NodeModulesDirMode, String> { + match s { + "auto" | "true" => Ok(NodeModulesDirMode::Auto), + "manual" => Ok(NodeModulesDirMode::Manual), + "none" | "false" => Ok(NodeModulesDirMode::None), + _ => Err(format!( + "Invalid value '{}': expected \"auto\", \"manual\" or \"none\"", + s + )), } - } else { - flags.node_modules_dir = matches.remove_one::<bool>("node-modules-dir"); } -} -fn node_modules_args() -> Vec<Arg> { - if *DENO_FUTURE { - vec![ - Arg::new("node-modules") - .long("node-modules") - .num_args(0..=1) - .value_parser(NodeModulesMode::parse) - .value_name("MODE") - .require_equals(true) - .help("Sets the node modules management mode for npm packages") - .help_heading(DEPENDENCY_MANAGEMENT_HEADING), - Arg::new("node-modules-dir") - .long("node-modules-dir") - .num_args(0..=1) - .value_parser(clap::builder::UnknownArgumentValueParser::suggest_arg( - "--node-modules", - )) - .require_equals(true), - ] - } else { - vec![ - Arg::new("node-modules-dir") - .long("node-modules-dir") - .num_args(0..=1) - .value_parser(value_parser!(bool)) - .value_name("ENABLED") - .default_missing_value("true") - .require_equals(true) - .help("Enables or disables the use of a local node_modules folder for npm packages") - .help_heading(DEPENDENCY_MANAGEMENT_HEADING) - ] - } + Arg::new("node-modules-dir") + .long("node-modules-dir") + .num_args(0..=1) + .value_parser(clap::builder::ValueParser::new(parse_node_modules_dir_mode)) + .value_name("MODE") + .require_equals(true) + .help("Sets the node modules management mode for npm packages") + .help_heading(DEPENDENCY_MANAGEMENT_HEADING) } fn vendor_arg() -> Arg { @@ -4039,7 +3976,6 @@ impl Iterator for UnstableArgsIter { Arg::new("unstable-byonm") .long("unstable-byonm") .help("Enable unstable 'bring your own node_modules' feature") - .env("DENO_UNSTABLE_BYONM") .value_parser(FalseyValueParser::new()) .action(ArgAction::SetTrue) .hide(true) @@ -4476,7 +4412,7 @@ fn install_parse(flags: &mut Flags, matches: &mut ArgMatches) { runtime_args_parse(flags, matches, true, true); let global = matches.get_flag("global"); - if global || !*DENO_FUTURE { + if global { let root = matches.remove_one::<String>("root"); let force = matches.get_flag("force"); let name = matches.remove_one::<String>("name"); @@ -5422,7 +5358,6 @@ fn unstable_args_parse( flags.unstable_config.bare_node_builtins = matches.get_flag("unstable-bare-node-builtins"); - flags.unstable_config.byonm = matches.get_flag("unstable-byonm"); flags.unstable_config.sloppy_imports = matches.get_flag("unstable-sloppy-imports"); |