summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs147
-rw-r--r--cli/args/lockfile.rs8
-rw-r--r--cli/args/mod.rs131
3 files changed, 91 insertions, 195 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");
diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs
index 3b6bcc2e5..35552b5b4 100644
--- a/cli/args/lockfile.rs
+++ b/cli/args/lockfile.rs
@@ -239,12 +239,6 @@ impl CliLockfile {
}
let lockfile = self.lockfile.lock();
if lockfile.has_content_changed {
- let suggested = if *super::DENO_FUTURE {
- "`deno cache --frozen=false`, `deno install --frozen=false`,"
- } else {
- "`deno cache --frozen=false`"
- };
-
let contents =
std::fs::read_to_string(&lockfile.filename).unwrap_or_default();
let new_contents = lockfile.as_json_string();
@@ -252,7 +246,7 @@ impl CliLockfile {
// has an extra newline at the end
let diff = diff.trim_end();
Err(deno_core::anyhow::anyhow!(
- "The lockfile is out of date. Run {suggested} or rerun with `--frozen=false` to update it.\nchanges:\n{diff}"
+ "The lockfile is out of date. Run `deno cache --frozen=false`, `deno install --frozen=false`, or rerun with `--frozen=false` to update it.\nchanges:\n{diff}"
))
} else {
Ok(())
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index de64a5785..89ecc8da7 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -8,8 +8,9 @@ mod lockfile;
mod package_json;
use deno_ast::SourceMapOption;
-use deno_config::deno_json::NodeModulesMode;
+use deno_config::deno_json::NodeModulesDirMode;
use deno_config::workspace::CreateResolverOptions;
+use deno_config::workspace::FolderConfigs;
use deno_config::workspace::PackageJsonDepResolution;
use deno_config::workspace::VendorEnablement;
use deno_config::workspace::Workspace;
@@ -51,7 +52,6 @@ use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::url::Url;
-use deno_runtime::deno_node::PackageJson;
use deno_runtime::deno_permissions::PermissionsOptions;
use deno_runtime::deno_tls::deno_native_certs::load_native_certs;
use deno_runtime::deno_tls::rustls;
@@ -64,6 +64,7 @@ use dotenvy::from_filename;
use once_cell::sync::Lazy;
use serde::Deserialize;
use serde::Serialize;
+use std::borrow::Cow;
use std::collections::HashMap;
use std::env;
use std::io::BufReader;
@@ -117,9 +118,6 @@ pub static DENO_DISABLE_PEDANTIC_NODE_WARNINGS: Lazy<bool> = Lazy::new(|| {
.is_some()
});
-// TODO(2.0): remove this in a follow up.
-pub static DENO_FUTURE: Lazy<bool> = Lazy::new(|| true);
-
pub fn jsr_url() -> &'static Url {
static JSR_URL: Lazy<Url> = Lazy::new(|| {
let env_var_name = "JSR_URL";
@@ -814,15 +812,12 @@ impl CliOptions {
}
let maybe_lockfile = maybe_lockfile.filter(|_| !force_global_cache);
- let root_folder = start_dir.workspace.root_folder_configs();
let deno_dir_provider =
Arc::new(DenoDirProvider::new(flags.cache_path.clone()));
let maybe_node_modules_folder = resolve_node_modules_folder(
&initial_cwd,
&flags,
&start_dir.workspace,
- root_folder.deno_json.as_deref(),
- root_folder.pkg_json.as_deref(),
&deno_dir_provider,
)
.with_context(|| "Resolving node_modules folder.")?;
@@ -919,10 +914,6 @@ impl CliOptions {
};
for diagnostic in start_dir.workspace.diagnostics() {
- // TODO(2.0): remove
- if matches!(diagnostic.kind, deno_config::workspace::WorkspaceDiagnosticKind::DeprecatedNodeModulesDirOption(_)) && !*DENO_FUTURE {
- continue;
- }
log::warn!("{} {}", colors::yellow("Warning"), diagnostic);
}
@@ -1143,10 +1134,6 @@ impl CliOptions {
self.flags.env_file.as_ref()
}
- pub fn enable_future_features(&self) -> bool {
- *DENO_FUTURE
- }
-
pub fn resolve_main_module(&self) -> Result<ModuleSpecifier, AnyError> {
let main_module = match &self.flags.subcommand {
DenoSubcommand::Bundle(bundle_flags) => {
@@ -1261,29 +1248,13 @@ impl CliOptions {
}
}
- pub fn node_modules_mode(&self) -> Result<Option<NodeModulesMode>, AnyError> {
- if *DENO_FUTURE {
- if let Some(flag) = self.flags.node_modules_mode {
- return Ok(Some(flag));
- }
- self.workspace().node_modules_mode().map_err(Into::into)
- } else {
- Ok(
- self
- .flags
- .node_modules_dir
- .or_else(|| self.workspace().node_modules_dir())
- .map(|enabled| {
- if enabled && self.byonm_enabled() {
- NodeModulesMode::LocalManual
- } else if enabled {
- NodeModulesMode::LocalAuto
- } else {
- NodeModulesMode::GlobalAuto
- }
- }),
- )
+ pub fn node_modules_dir(
+ &self,
+ ) -> Result<Option<NodeModulesDirMode>, AnyError> {
+ if let Some(flag) = self.flags.node_modules_dir {
+ return Ok(Some(flag));
}
+ self.workspace().node_modules_dir_mode().map_err(Into::into)
}
pub fn vendor_dir_path(&self) -> Option<&PathBuf> {
@@ -1637,17 +1608,15 @@ impl CliOptions {
fn byonm_enabled(&self) -> bool {
// check if enabled via unstable
- self.flags.unstable_config.byonm
+ self.node_modules_dir().ok().flatten() == Some(NodeModulesDirMode::Manual)
|| NPM_PROCESS_STATE
.as_ref()
.map(|s| matches!(s.kind, NpmProcessStateKind::Byonm))
.unwrap_or(false)
- || self.workspace().has_unstable("byonm")
}
pub fn use_byonm(&self) -> bool {
- if self.enable_future_features()
- && self.node_modules_mode().ok().flatten().is_none()
+ if self.node_modules_dir().ok().flatten().is_none()
&& self.maybe_node_modules_folder.is_some()
&& self
.workspace()
@@ -1680,19 +1649,17 @@ impl CliOptions {
}
});
- // TODO(2.0): remove this conditional and enable these features in `99_main.js` by default.
- if *DENO_FUTURE {
- let future_features = [
- deno_runtime::deno_ffi::UNSTABLE_FEATURE_NAME.to_string(),
- deno_runtime::deno_fs::UNSTABLE_FEATURE_NAME.to_string(),
- deno_runtime::deno_webgpu::UNSTABLE_FEATURE_NAME.to_string(),
- ];
- future_features.iter().for_each(|future_feature| {
- if !from_config_file.contains(future_feature) {
- from_config_file.push(future_feature.to_string());
- }
- });
- }
+ // TODO(2.0): remove this code and enable these features in `99_main.js` by default.
+ let future_features = [
+ deno_runtime::deno_ffi::UNSTABLE_FEATURE_NAME.to_string(),
+ deno_runtime::deno_fs::UNSTABLE_FEATURE_NAME.to_string(),
+ deno_runtime::deno_webgpu::UNSTABLE_FEATURE_NAME.to_string(),
+ ];
+ future_features.iter().for_each(|future_feature| {
+ if !from_config_file.contains(future_feature) {
+ from_config_file.push(future_feature.to_string());
+ }
+ });
if !from_config_file.is_empty() {
// collect unstable granular flags
@@ -1792,54 +1759,54 @@ fn resolve_node_modules_folder(
cwd: &Path,
flags: &Flags,
workspace: &Workspace,
- maybe_config_file: Option<&ConfigFile>,
- maybe_package_json: Option<&PackageJson>,
deno_dir_provider: &Arc<DenoDirProvider>,
) -> Result<Option<PathBuf>, AnyError> {
- let use_node_modules_dir = if *DENO_FUTURE {
- if let Some(mode) = flags.node_modules_mode {
- Some(mode.uses_node_modules_dir())
- } else {
- workspace
- .node_modules_mode()?
- .map(|m| m.uses_node_modules_dir())
- .or(flags.vendor)
- .or_else(|| maybe_config_file.and_then(|c| c.json.vendor))
- }
+ fn resolve_from_root(root_folder: &FolderConfigs, cwd: &Path) -> PathBuf {
+ root_folder
+ .deno_json
+ .as_ref()
+ .map(|c| Cow::Owned(c.dir_path()))
+ .or_else(|| {
+ root_folder
+ .pkg_json
+ .as_ref()
+ .map(|c| Cow::Borrowed(c.dir_path()))
+ })
+ .unwrap_or(Cow::Borrowed(cwd))
+ .join("node_modules")
+ }
+
+ let root_folder = workspace.root_folder_configs();
+ let use_node_modules_dir = if let Some(mode) = flags.node_modules_dir {
+ Some(mode.uses_node_modules_dir())
} else {
- flags
- .node_modules_dir
- .or_else(|| maybe_config_file.and_then(|c| c.json.node_modules_dir))
+ workspace
+ .node_modules_dir_mode()?
+ .map(|m| m.uses_node_modules_dir())
.or(flags.vendor)
- .or_else(|| maybe_config_file.and_then(|c| c.json.vendor))
+ .or_else(|| root_folder.deno_json.as_ref().and_then(|c| c.json.vendor))
};
let path = if use_node_modules_dir == Some(false) {
return Ok(None);
} else if let Some(state) = &*NPM_PROCESS_STATE {
return Ok(state.local_node_modules_path.as_ref().map(PathBuf::from));
- } else if let Some(package_json_path) = maybe_package_json.map(|c| &c.path) {
+ } else if workspace.package_jsons().next().is_some() {
+ let node_modules_dir = resolve_from_root(root_folder, cwd);
if let Ok(deno_dir) = deno_dir_provider.get_or_create() {
// `deno_dir.root` can be symlink in macOS
if let Ok(root) = canonicalize_path_maybe_not_exists(&deno_dir.root) {
- if package_json_path.starts_with(root) {
+ if node_modules_dir.starts_with(root) {
// if the package.json is in deno_dir, then do not use node_modules
// next to it as local node_modules dir
return Ok(None);
}
}
}
- // auto-discover the local_node_modules_folder when a package.json exists
- // and it's not in deno_dir
- package_json_path.parent().unwrap().join("node_modules")
+ node_modules_dir
} else if use_node_modules_dir.is_none() {
return Ok(None);
- } else if let Some(config_path) = maybe_config_file
- .as_ref()
- .and_then(|c| c.specifier.to_file_path().ok())
- {
- config_path.parent().unwrap().join("node_modules")
} else {
- cwd.join("node_modules")
+ resolve_from_root(root_folder, cwd)
};
Ok(Some(canonicalize_path_maybe_not_exists(&path)?))
}